summaryrefslogtreecommitdiff
path: root/dbus
diff options
context:
space:
mode:
authorJay Civelli <jcivelli@google.com>2017-03-22 17:31:44 -0700
committerTreehugger Robot <treehugger-gerrit@google.com>2017-07-26 01:47:45 +0000
commit0601274935e7f632eb0d6ce0fd223b744349d20b (patch)
tree09642629eabdbeccfd68e6338253228465088c57 /dbus
parentf320c0cf71af274e34404746d4303e6a2452e2d6 (diff)
downloadlibchrome-0601274935e7f632eb0d6ce0fd223b744349d20b.tar.gz
libchrome: Uprev the library to r456626 from Chromium
Pulled the latest and greatest version of libchrome from Chromium. The merge was done against r456626 which corresponds to git commit 08266b3fca707804065a2cfd60331722ade41969 of Mar 14, 2017 Notable changes are: - FOR_EACH_OBSERVER macro removed (replaced by use of C++ 11 range-base for loop) - base::Values no more FundamentalValue - stl_util moved to base namespace - some scoped pointers removed in crypto/ in favor of BoringSSL UniquePtr. - path() accessor renamed to GetPath() in ScopedTempDir (and other classes) - introduction of base::CallbackOnce Test: All unit-tests should still pass. Change-Id: I5c2cb41ea4c037fe69fbb425e711b1399d55d591
Diffstat (limited to 'dbus')
-rw-r--r--dbus/BUILD.gn2
-rw-r--r--dbus/bus.cc36
-rw-r--r--dbus/bus.h10
-rw-r--r--dbus/dbus.gyp141
-rw-r--r--dbus/dbus_statistics.cc118
-rw-r--r--dbus/exported_object.cc10
-rw-r--r--dbus/file_descriptor.cc68
-rw-r--r--dbus/file_descriptor.h92
-rw-r--r--dbus/message.cc19
-rw-r--r--dbus/message.h9
-rw-r--r--dbus/mock_bus.h9
-rw-r--r--dbus/mock_object_manager.h1
-rw-r--r--dbus/mock_object_proxy.h4
-rw-r--r--dbus/object_manager.cc75
-rw-r--r--dbus/object_manager.h20
-rw-r--r--dbus/object_proxy.cc7
-rw-r--r--dbus/object_proxy.h14
-rw-r--r--dbus/property.cc132
-rw-r--r--dbus/property.h23
-rw-r--r--dbus/values_util.cc59
20 files changed, 343 insertions, 506 deletions
diff --git a/dbus/BUILD.gn b/dbus/BUILD.gn
index 28efb93fe4..c0bd77d8db 100644
--- a/dbus/BUILD.gn
+++ b/dbus/BUILD.gn
@@ -17,8 +17,6 @@ component("dbus") {
"dbus_statistics.h",
"exported_object.cc",
"exported_object.h",
- "file_descriptor.cc",
- "file_descriptor.h",
"message.cc",
"message.h",
"object_manager.cc",
diff --git a/dbus/bus.cc b/dbus/bus.cc
index 57834d348a..b6a13d6b15 100644
--- a/dbus/bus.cc
+++ b/dbus/bus.cc
@@ -26,6 +26,11 @@ namespace dbus {
namespace {
+const char kDisconnectedSignal[] = "Disconnected";
+const char kDisconnectedMatchRule[] =
+ "type='signal', path='/org/freedesktop/DBus/Local',"
+ "interface='org.freedesktop.DBus.Local', member='Disconnected'";
+
// The NameOwnerChanged member in org.freedesktop.DBus
const char kNameOwnerChangedSignal[] = "NameOwnerChanged";
@@ -40,7 +45,7 @@ const char kServiceNameOwnerChangeMatchRule[] =
class Watch : public base::MessagePumpLibevent::Watcher {
public:
explicit Watch(DBusWatch* watch)
- : raw_watch_(watch) {
+ : raw_watch_(watch), file_descriptor_watcher_(FROM_HERE) {
dbus_watch_set_data(raw_watch_, this, NULL);
}
@@ -395,13 +400,6 @@ void Bus::RemoveObjectManagerInternalHelper(
callback.Run();
}
-void Bus::GetManagedObjects() {
- for (ObjectManagerTable::iterator iter = object_manager_table_.begin();
- iter != object_manager_table_.end(); ++iter) {
- iter->second->GetManagedObjects();
- }
-}
-
bool Bus::Connect() {
// dbus_bus_get_private() and dbus_bus_get() are blocking calls.
AssertOnDBusThread();
@@ -443,6 +441,12 @@ bool Bus::Connect() {
return false;
}
}
+ // We shouldn't exit on the disconnected signal.
+ dbus_connection_set_exit_on_disconnect(connection_, false);
+
+ // Watch Disconnected signal.
+ AddFilterFunction(Bus::OnConnectionDisconnectedFilter, this);
+ AddMatch(kDisconnectedMatchRule, error.get());
return true;
}
@@ -502,6 +506,8 @@ void Bus::ShutdownAndBlock() {
if (connection_) {
// Remove Disconnected watcher.
ScopedDBusError error;
+ RemoveFilterFunction(Bus::OnConnectionDisconnectedFilter, this);
+ RemoveMatch(kDisconnectedMatchRule, error.get());
if (connection_type_ == PRIVATE)
ClosePrivateConnection();
@@ -1180,6 +1186,20 @@ void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection,
}
// static
+DBusHandlerResult Bus::OnConnectionDisconnectedFilter(
+ DBusConnection* /*connection*/,
+ DBusMessage* message,
+ void* /*data*/) {
+ if (dbus_message_is_signal(message,
+ DBUS_INTERFACE_LOCAL,
+ kDisconnectedSignal)) {
+ // Abort when the connection is lost.
+ LOG(FATAL) << "D-Bus connection was disconnected. Aborting.";
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+// static
DBusHandlerResult Bus::OnServiceOwnerChangedFilter(
DBusConnection* /*connection*/,
DBusMessage* message,
diff --git a/dbus/bus.h b/dbus/bus.h
index 7d3915909b..59a19720ec 100644
--- a/dbus/bus.h
+++ b/dbus/bus.h
@@ -28,10 +28,6 @@ class SingleThreadTaskRunner;
class TaskRunner;
}
-namespace tracked_objects {
-class Location;
-}
-
namespace dbus {
class ExportedObject;
@@ -360,12 +356,6 @@ class CHROME_DBUS_EXPORT Bus : public base::RefCountedThreadSafe<Bus> {
const ObjectPath& object_path,
const base::Closure& callback);
- // Instructs all registered object managers to retrieve their set of managed
- // objects from their respective remote objects. There is no need to call this
- // manually, this is called automatically by the D-Bus thread manager once
- // implementation classes are registered.
- virtual void GetManagedObjects();
-
// Shuts down the bus and blocks until it's done. More specifically, this
// function does the following:
//
diff --git a/dbus/dbus.gyp b/dbus/dbus.gyp
deleted file mode 100644
index 264383ee4b..0000000000
--- a/dbus/dbus.gyp
+++ /dev/null
@@ -1,141 +0,0 @@
-# Copyright (c) 2012 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-{
- 'variables': {
- 'chromium_code': 1,
- },
- 'targets': [
- {
- 'target_name': 'dbus',
- 'type': '<(component)',
- 'dependencies': [
- '../base/base.gyp:base',
- '../build/linux/system.gyp:dbus',
- '../third_party/protobuf/protobuf.gyp:protobuf_lite',
- ],
- 'export_dependent_settings': [
- '../base/base.gyp:base',
- ],
- 'defines': [
- 'DBUS_IMPLEMENTATION',
- ],
- 'sources': [
- 'bus.cc',
- 'bus.h',
- 'dbus_export.h',
- 'dbus_statistics.cc',
- 'dbus_statistics.h',
- 'exported_object.cc',
- 'exported_object.h',
- 'file_descriptor.cc',
- 'file_descriptor.h',
- 'message.cc',
- 'message.h',
- 'object_manager.cc',
- 'object_manager.h',
- 'object_path.cc',
- 'object_path.h',
- 'object_proxy.cc',
- 'object_proxy.h',
- 'property.cc',
- 'property.h',
- 'scoped_dbus_error.cc',
- 'scoped_dbus_error.h',
- 'string_util.cc',
- 'string_util.h',
- 'util.cc',
- 'util.h',
- 'values_util.cc',
- 'values_util.h',
- ],
- },
- {
- # Protobuf compiler / generator test protocol buffer
- 'target_name': 'dbus_test_proto',
- 'type': 'static_library',
- 'sources': [ 'test_proto.proto' ],
- 'variables': {
- 'proto_out_dir': 'dbus',
- },
- 'includes': [ '../build/protoc.gypi' ],
- },
- {
- # This target contains mocks that can be used to write unit tests
- # without issuing actual D-Bus calls.
- 'target_name': 'dbus_test_support',
- 'type': 'static_library',
- 'dependencies': [
- '../build/linux/system.gyp:dbus',
- '../testing/gmock.gyp:gmock',
- 'dbus',
- ],
- 'sources': [
- 'mock_bus.cc',
- 'mock_bus.h',
- 'mock_exported_object.cc',
- 'mock_exported_object.h',
- 'mock_object_manager.cc',
- 'mock_object_manager.h',
- 'mock_object_proxy.cc',
- 'mock_object_proxy.h',
- ],
- 'include_dirs': [
- '..',
- ],
- },
- {
- 'target_name': 'dbus_unittests',
- 'type': 'executable',
- 'dependencies': [
- '../base/base.gyp:run_all_unittests',
- '../base/base.gyp:test_support_base',
- '../build/linux/system.gyp:dbus',
- '../testing/gmock.gyp:gmock',
- '../testing/gtest.gyp:gtest',
- 'dbus',
- 'dbus_test_proto',
- 'dbus_test_support',
- ],
- 'sources': [
- 'bus_unittest.cc',
- 'dbus_statistics_unittest.cc',
- 'end_to_end_async_unittest.cc',
- 'end_to_end_sync_unittest.cc',
- 'message_unittest.cc',
- 'mock_unittest.cc',
- 'object_manager_unittest.cc',
- 'object_proxy_unittest.cc',
- 'property_unittest.cc',
- 'signal_sender_verification_unittest.cc',
- 'string_util_unittest.cc',
- 'test_service.cc',
- 'test_service.h',
- 'util_unittest.cc',
- 'values_util_unittest.cc',
- ],
- 'include_dirs': [
- '..',
- ],
- },
- {
- 'target_name': 'dbus_test_server',
- 'type': 'executable',
- 'dependencies': [
- '../base/base.gyp:test_support_base',
- '../base/base.gyp:base',
- '../build/linux/system.gyp:dbus',
- 'dbus',
- ],
- 'sources': [
- 'test_server.cc',
- 'test_service.cc',
- 'test_service.h',
- ],
- 'include_dirs': [
- '..',
- ],
- },
- ],
-}
diff --git a/dbus/dbus_statistics.cc b/dbus/dbus_statistics.cc
index e1e0973d5c..2949c5032d 100644
--- a/dbus/dbus_statistics.cc
+++ b/dbus/dbus_statistics.cc
@@ -4,12 +4,11 @@
#include "dbus/dbus_statistics.h"
-#include <memory>
-#include <set>
+#include <map>
+#include <tuple>
#include "base/logging.h"
#include "base/macros.h"
-#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
@@ -18,43 +17,24 @@ namespace dbus {
namespace {
-// Used to store dbus statistics sorted alphabetically by service, interface,
-// then method (using std::string <).
-struct Stat {
- Stat(const std::string& service,
- const std::string& interface,
- const std::string& method)
- : service(service),
- interface(interface),
- method(method),
- sent_method_calls(0),
- received_signals(0),
- sent_blocking_method_calls(0) {
- }
+struct StatKey {
std::string service;
std::string interface;
std::string method;
- int sent_method_calls;
- int received_signals;
- int sent_blocking_method_calls;
-
- bool Compare(const Stat& other) const {
- if (service != other.service)
- return service < other.service;
- if (interface != other.interface)
- return interface < other.interface;
- return method < other.method;
- }
+};
- struct PtrCompare {
- bool operator()(Stat* lhs, Stat* rhs) const {
- DCHECK(lhs && rhs);
- return lhs->Compare(*rhs);
- }
- };
+bool operator<(const StatKey& lhs, const StatKey& rhs) {
+ return std::tie(lhs.service, lhs.interface, lhs.method) <
+ std::tie(rhs.service, rhs.interface, rhs.method);
+}
+
+struct StatValue {
+ int sent_method_calls = 0;
+ int received_signals = 0;
+ int sent_blocking_method_calls = 0;
};
-typedef std::set<Stat*, Stat::PtrCompare> StatSet;
+using StatMap = std::map<StatKey, StatValue>;
//------------------------------------------------------------------------------
// DBusStatistics
@@ -69,10 +49,9 @@ class DBusStatistics {
~DBusStatistics() {
DCHECK_EQ(origin_thread_id_, base::PlatformThread::CurrentId());
- STLDeleteContainerPointers(stats_.begin(), stats_.end());
}
- // Enum to specify which field in Stat to increment in AddStat
+ // Enum to specify which field in Stat to increment in AddStat.
enum StatType {
TYPE_SENT_METHOD_CALLS,
TYPE_RECEIVED_SIGNALS,
@@ -89,7 +68,7 @@ class DBusStatistics {
<< base::PlatformThread::CurrentId();
return;
}
- Stat* stat = GetStat(service, interface, method, true);
+ StatValue* stat = GetStats(service, interface, method, true);
DCHECK(stat);
if (type == TYPE_SENT_METHOD_CALLS)
++stat->sent_method_calls;
@@ -103,33 +82,35 @@ class DBusStatistics {
// Look up the Stat entry in |stats_|. If |add_stat| is true, add a new entry
// if one does not already exist.
- Stat* GetStat(const std::string& service,
- const std::string& interface,
- const std::string& method,
- bool add_stat) {
+ StatValue* GetStats(const std::string& service,
+ const std::string& interface,
+ const std::string& method,
+ bool add_stat) {
DCHECK_EQ(origin_thread_id_, base::PlatformThread::CurrentId());
- std::unique_ptr<Stat> stat(new Stat(service, interface, method));
- StatSet::iterator found = stats_.find(stat.get());
- if (found != stats_.end())
- return *found;
+
+ StatKey key = {service, interface, method};
+ auto it = stats_.find(key);
+ if (it != stats_.end())
+ return &(it->second);
+
if (!add_stat)
- return NULL;
- found = stats_.insert(stat.release()).first;
- return *found;
+ return nullptr;
+
+ return &(stats_[key]);
}
- StatSet& stats() { return stats_; }
+ StatMap& stats() { return stats_; }
base::Time start_time() { return start_time_; }
private:
- StatSet stats_;
+ StatMap stats_;
base::Time start_time_;
base::PlatformThreadId origin_thread_id_;
DISALLOW_COPY_AND_ASSIGN(DBusStatistics);
};
-DBusStatistics* g_dbus_statistics = NULL;
+DBusStatistics* g_dbus_statistics = nullptr;
} // namespace
@@ -145,7 +126,7 @@ void Initialize() {
void Shutdown() {
delete g_dbus_statistics;
- g_dbus_statistics = NULL;
+ g_dbus_statistics = nullptr;
}
void AddSentMethodCall(const std::string& service,
@@ -182,7 +163,7 @@ std::string GetAsString(ShowInString show, FormatString format) {
if (!g_dbus_statistics)
return "DBusStatistics not initialized.";
- const StatSet& stats = g_dbus_statistics->stats();
+ const StatMap& stats = g_dbus_statistics->stats();
if (stats.empty())
return "No DBus calls.";
@@ -193,19 +174,21 @@ std::string GetAsString(ShowInString show, FormatString format) {
std::string result;
int sent = 0, received = 0, sent_blocking = 0;
// Stats are stored in order by service, then interface, then method.
- for (StatSet::const_iterator iter = stats.begin(); iter != stats.end(); ) {
- StatSet::const_iterator cur_iter = iter;
- StatSet::const_iterator next_iter = ++iter;
- const Stat* stat = *cur_iter;
- sent += stat->sent_method_calls;
- received += stat->received_signals;
- sent_blocking += stat->sent_blocking_method_calls;
+ for (auto iter = stats.begin(); iter != stats.end();) {
+ auto cur_iter = iter;
+ auto next_iter = ++iter;
+ const StatKey& stat_key = cur_iter->first;
+ const StatValue& stat = cur_iter->second;
+ sent += stat.sent_method_calls;
+ received += stat.received_signals;
+ sent_blocking += stat.sent_blocking_method_calls;
// If this is not the last stat, and if the next stat matches the current
// stat, continue.
if (next_iter != stats.end() &&
- (*next_iter)->service == stat->service &&
- (show < SHOW_INTERFACE || (*next_iter)->interface == stat->interface) &&
- (show < SHOW_METHOD || (*next_iter)->method == stat->method))
+ next_iter->first.service == stat_key.service &&
+ (show < SHOW_INTERFACE ||
+ next_iter->first.interface == stat_key.interface) &&
+ (show < SHOW_METHOD || next_iter->first.method == stat_key.method))
continue;
if (!sent && !received && !sent_blocking)
@@ -214,12 +197,12 @@ std::string GetAsString(ShowInString show, FormatString format) {
// Add a line to the result and clear the counts.
std::string line;
if (show == SHOW_SERVICE) {
- line += stat->service;
+ line += stat_key.service;
} else {
// The interface usually includes the service so don't show both.
- line += stat->interface;
+ line += stat_key.interface;
if (show >= SHOW_METHOD)
- line += "." + stat->method;
+ line += "." + stat_key.method;
}
line += base::StringPrintf(":");
if (sent_blocking) {
@@ -269,7 +252,8 @@ bool GetCalls(const std::string& service,
int* blocking) {
if (!g_dbus_statistics)
return false;
- Stat* stat = g_dbus_statistics->GetStat(service, interface, method, false);
+ StatValue* stat =
+ g_dbus_statistics->GetStats(service, interface, method, false);
if (!stat)
return false;
*sent = stat->sent_method_calls;
diff --git a/dbus/exported_object.cc b/dbus/exported_object.cc
index b156308ace..ffc5eb391d 100644
--- a/dbus/exported_object.cc
+++ b/dbus/exported_object.cc
@@ -11,7 +11,7 @@
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
-#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_macros.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "dbus/bus.h"
@@ -186,8 +186,9 @@ bool ExportedObject::Register() {
return true;
}
-DBusHandlerResult ExportedObject::HandleMessage(DBusConnection*,
- DBusMessage* raw_message) {
+DBusHandlerResult ExportedObject::HandleMessage(
+ DBusConnection* /*connection*/,
+ DBusMessage* raw_message) {
bus_->AssertOnDBusThread();
DCHECK_EQ(DBUS_MESSAGE_TYPE_METHOD_CALL, dbus_message_get_type(raw_message));
@@ -300,7 +301,8 @@ void ExportedObject::OnMethodCompleted(std::unique_ptr<MethodCall> method_call,
base::TimeTicks::Now() - start_time);
}
-void ExportedObject::OnUnregistered(DBusConnection*) {}
+void ExportedObject::OnUnregistered(DBusConnection* /*connection*/) {
+}
DBusHandlerResult ExportedObject::HandleMessageThunk(
DBusConnection* connection,
diff --git a/dbus/file_descriptor.cc b/dbus/file_descriptor.cc
deleted file mode 100644
index b690881749..0000000000
--- a/dbus/file_descriptor.cc
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <algorithm>
-
-#include "base/bind.h"
-#include "base/files/file.h"
-#include "base/location.h"
-#include "base/logging.h"
-#include "base/threading/worker_pool.h"
-#include "dbus/file_descriptor.h"
-
-using std::swap;
-
-namespace dbus {
-
-void CHROME_DBUS_EXPORT FileDescriptor::Deleter::operator()(
- FileDescriptor* fd) {
- base::WorkerPool::PostTask(
- FROM_HERE, base::Bind(&base::DeletePointer<FileDescriptor>, fd), false);
-}
-
-FileDescriptor::FileDescriptor(FileDescriptor&& other) : FileDescriptor() {
- Swap(&other);
-}
-
-FileDescriptor::~FileDescriptor() {
- if (owner_)
- base::File auto_closer(value_);
-}
-
-FileDescriptor& FileDescriptor::operator=(FileDescriptor&& other) {
- Swap(&other);
- return *this;
-}
-
-int FileDescriptor::value() const {
- CHECK(valid_);
- return value_;
-}
-
-int FileDescriptor::TakeValue() {
- CHECK(valid_); // NB: check first so owner_ is unchanged if this triggers
- owner_ = false;
- return value_;
-}
-
-void FileDescriptor::CheckValidity() {
- base::File file(value_);
- if (!file.IsValid()) {
- valid_ = false;
- return;
- }
-
- base::File::Info info;
- bool ok = file.GetInfo(&info);
- file.TakePlatformFile(); // Prevent |value_| from being closed by |file|.
- valid_ = (ok && !info.is_directory);
-}
-
-void FileDescriptor::Swap(FileDescriptor* other) {
- swap(value_, other->value_);
- swap(owner_, other->owner_);
- swap(valid_, other->valid_);
-}
-
-} // namespace dbus
diff --git a/dbus/file_descriptor.h b/dbus/file_descriptor.h
deleted file mode 100644
index f8e86777ea..0000000000
--- a/dbus/file_descriptor.h
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef DBUS_FILE_DESCRIPTOR_H_
-#define DBUS_FILE_DESCRIPTOR_H_
-
-#include <memory>
-
-#include "base/macros.h"
-#include "dbus/dbus_export.h"
-
-namespace dbus {
-
-// FileDescriptor is a type used to encapsulate D-Bus file descriptors
-// and to follow the RAII idiom appropiate for use with message operations
-// where the descriptor might be easily leaked. To guard against this the
-// descriptor is closed when an instance is destroyed if it is owned.
-// Ownership is asserted only when PutValue is used and TakeValue can be
-// used to take ownership.
-//
-// For example, in the following
-// FileDescriptor fd;
-// if (!reader->PopString(&name) ||
-// !reader->PopFileDescriptor(&fd) ||
-// !reader->PopUint32(&flags)) {
-// the descriptor in fd will be closed if the PopUint32 fails. But
-// writer.AppendFileDescriptor(dbus::FileDescriptor(1));
-// will not automatically close "1" because it is not owned.
-//
-// Descriptors must be validated before marshalling in a D-Bus message
-// or using them after unmarshalling. We disallow descriptors to a
-// directory to reduce the security risks. Splitting out validation
-// also allows the caller to do this work on the File thread to conform
-// with i/o restrictions.
-class CHROME_DBUS_EXPORT FileDescriptor {
- public:
- // This provides a simple way to pass around file descriptors since they must
- // be closed on a thread that is allowed to perform I/O.
- struct Deleter {
- void CHROME_DBUS_EXPORT operator()(FileDescriptor* fd);
- };
-
- // Permits initialization without a value for passing to
- // dbus::MessageReader::PopFileDescriptor to fill in and from int values.
- FileDescriptor() : value_(-1), owner_(false), valid_(false) {}
- explicit FileDescriptor(int value) : value_(value), owner_(false),
- valid_(false) {}
-
- FileDescriptor(FileDescriptor&& other);
-
- virtual ~FileDescriptor();
-
- FileDescriptor& operator=(FileDescriptor&& other);
-
- // Retrieves value as an int without affecting ownership.
- int value() const;
-
- // Retrieves whether or not the descriptor is ok to send/receive.
- int is_valid() const { return valid_; }
-
- // Sets the value and assign ownership.
- void PutValue(int value) {
- value_ = value;
- owner_ = true;
- valid_ = false;
- }
-
- // Takes the value and ownership.
- int TakeValue();
-
- // Checks (and records) validity of the file descriptor.
- // We disallow directories to avoid potential sandbox escapes.
- // Note this call must be made on a thread where file i/o is allowed.
- void CheckValidity();
-
- private:
- void Swap(FileDescriptor* other);
-
- int value_;
- bool owner_;
- bool valid_;
-
- DISALLOW_COPY_AND_ASSIGN(FileDescriptor);
-};
-
-using ScopedFileDescriptor =
- std::unique_ptr<FileDescriptor, FileDescriptor::Deleter>;
-
-} // namespace dbus
-
-#endif // DBUS_FILE_DESCRIPTOR_H_
diff --git a/dbus/message.cc b/dbus/message.cc
index 4a84756c41..c8663f72ad 100644
--- a/dbus/message.cc
+++ b/dbus/message.cc
@@ -222,11 +222,11 @@ std::string Message::ToStringInternal(const std::string& indent,
case UNIX_FD: {
CHECK(IsDBusTypeUnixFdSupported());
- FileDescriptor file_descriptor;
+ base::ScopedFD file_descriptor;
if (!reader->PopFileDescriptor(&file_descriptor))
return kBrokenMessage;
output += indent + "fd#" +
- base::IntToString(file_descriptor.value()) + "\n";
+ base::IntToString(file_descriptor.get()) + "\n";
break;
}
default:
@@ -714,15 +714,9 @@ void MessageWriter::AppendVariantOfBasic(int dbus_type, const void* value) {
CloseContainer(&variant_writer);
}
-void MessageWriter::AppendFileDescriptor(const FileDescriptor& value) {
+void MessageWriter::AppendFileDescriptor(int value) {
CHECK(IsDBusTypeUnixFdSupported());
-
- if (!value.is_valid()) {
- // NB: sending a directory potentially enables sandbox escape
- LOG(FATAL) << "Attempt to pass invalid file descriptor";
- }
- int fd = value.value();
- AppendBasic(DBUS_TYPE_UNIX_FD, &fd);
+ AppendBasic(DBUS_TYPE_UNIX_FD, &value); // This duplicates the FD.
}
//
@@ -1016,7 +1010,7 @@ bool MessageReader::PopVariantOfBasic(int dbus_type, void* value) {
return variant_reader.PopBasic(dbus_type, value);
}
-bool MessageReader::PopFileDescriptor(FileDescriptor* value) {
+bool MessageReader::PopFileDescriptor(base::ScopedFD* value) {
CHECK(IsDBusTypeUnixFdSupported());
int fd = -1;
@@ -1024,8 +1018,7 @@ bool MessageReader::PopFileDescriptor(FileDescriptor* value) {
if (!success)
return false;
- value->PutValue(fd);
- // NB: the caller must check validity before using the value
+ *value = base::ScopedFD(fd);
return true;
}
diff --git a/dbus/message.h b/dbus/message.h
index 0aa010ccde..256a8428c5 100644
--- a/dbus/message.h
+++ b/dbus/message.h
@@ -13,9 +13,9 @@
#include <string>
#include <vector>
+#include "base/files/scoped_file.h"
#include "base/macros.h"
#include "dbus/dbus_export.h"
-#include "dbus/file_descriptor.h"
#include "dbus/object_path.h"
namespace google {
@@ -285,7 +285,10 @@ class CHROME_DBUS_EXPORT MessageWriter {
void AppendDouble(double value);
void AppendString(const std::string& value);
void AppendObjectPath(const ObjectPath& value);
- void AppendFileDescriptor(const FileDescriptor& value);
+
+ // Appends a file descriptor to the message.
+ // The FD will be duplicated so you still have to close the original FD.
+ void AppendFileDescriptor(int value);
// Opens an array. The array contents can be added to the array with
// |sub_writer|. The client code must close the array with
@@ -398,7 +401,7 @@ class CHROME_DBUS_EXPORT MessageReader {
bool PopDouble(double* value);
bool PopString(std::string* value);
bool PopObjectPath(ObjectPath* value);
- bool PopFileDescriptor(FileDescriptor* value);
+ bool PopFileDescriptor(base::ScopedFD* value);
// Sets up the given message reader to read an array at the current
// iterator position.
diff --git a/dbus/mock_bus.h b/dbus/mock_bus.h
index b50f230569..40b090b156 100644
--- a/dbus/mock_bus.h
+++ b/dbus/mock_bus.h
@@ -26,15 +26,6 @@ class MockBus : public Bus {
ObjectProxy*(const std::string& service_name,
const ObjectPath& object_path,
int options));
- MOCK_METHOD3(RemoveObjectProxy, bool(
- const std::string& service_name,
- const ObjectPath& object_path,
- const base::Closure& callback));
- MOCK_METHOD4(RemoveObjectProxyWithOptions, bool(
- const std::string& service_name,
- const ObjectPath& object_path,
- int options,
- const base::Closure& callback));
MOCK_METHOD1(GetExportedObject, ExportedObject*(
const ObjectPath& object_path));
MOCK_METHOD2(GetObjectManager, ObjectManager*(const std::string&,
diff --git a/dbus/mock_object_manager.h b/dbus/mock_object_manager.h
index e4c76ba711..2318e497ea 100644
--- a/dbus/mock_object_manager.h
+++ b/dbus/mock_object_manager.h
@@ -31,7 +31,6 @@ class MockObjectManager : public ObjectManager {
MOCK_METHOD1(GetObjectProxy, ObjectProxy*(const ObjectPath&));
MOCK_METHOD2(GetProperties, PropertySet*(const ObjectPath&,
const std::string&));
- MOCK_METHOD0(GetManagedObjects, void());
protected:
virtual ~MockObjectManager();
diff --git a/dbus/mock_object_proxy.h b/dbus/mock_object_proxy.h
index f27f6f6acc..17d2a9f0f4 100644
--- a/dbus/mock_object_proxy.h
+++ b/dbus/mock_object_proxy.h
@@ -56,6 +56,10 @@ class MockObjectProxy : public ObjectProxy {
const std::string& signal_name,
SignalCallback signal_callback,
OnConnectedCallback on_connected_callback));
+ MOCK_METHOD1(SetNameOwnerChangedCallback,
+ void(NameOwnerChangedCallback callback));
+ MOCK_METHOD1(WaitForServiceToBeAvailable,
+ void(WaitForServiceToBeAvailableCallback callback));
MOCK_METHOD0(Detach, void());
protected:
diff --git a/dbus/object_manager.cc b/dbus/object_manager.cc
index 178bb5ff12..08e6e048e2 100644
--- a/dbus/object_manager.cc
+++ b/dbus/object_manager.cc
@@ -167,35 +167,6 @@ void ObjectManager::CleanUp() {
match_rule_.clear();
}
-void ObjectManager::InitializeObjects() {
- DCHECK(bus_);
- DCHECK(object_proxy_);
- DCHECK(setup_success_);
-
- // |object_proxy_| is no longer valid if the Bus was shut down before this
- // call. Don't initiate any other action from the origin thread.
- if (cleanup_called_)
- return;
-
- object_proxy_->ConnectToSignal(
- kObjectManagerInterface,
- kObjectManagerInterfacesAdded,
- base::Bind(&ObjectManager::InterfacesAddedReceived,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&ObjectManager::InterfacesAddedConnected,
- weak_ptr_factory_.GetWeakPtr()));
-
- object_proxy_->ConnectToSignal(
- kObjectManagerInterface,
- kObjectManagerInterfacesRemoved,
- base::Bind(&ObjectManager::InterfacesRemovedReceived,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&ObjectManager::InterfacesRemovedConnected,
- weak_ptr_factory_.GetWeakPtr()));
-
- GetManagedObjects();
-}
-
bool ObjectManager::SetupMatchRuleAndFilter() {
DCHECK(bus_);
DCHECK(!setup_success_);
@@ -235,10 +206,39 @@ bool ObjectManager::SetupMatchRuleAndFilter() {
}
void ObjectManager::OnSetupMatchRuleAndFilterComplete(bool success) {
- LOG_IF(WARNING, !success) << service_name_ << " " << object_path_.value()
- << ": Failed to set up match rule.";
- if (success)
- InitializeObjects();
+ if (!success) {
+ LOG(WARNING) << service_name_ << " " << object_path_.value()
+ << ": Failed to set up match rule.";
+ return;
+ }
+
+ DCHECK(bus_);
+ DCHECK(object_proxy_);
+ DCHECK(setup_success_);
+
+ // |object_proxy_| is no longer valid if the Bus was shut down before this
+ // call. Don't initiate any other action from the origin thread.
+ if (cleanup_called_)
+ return;
+
+ object_proxy_->ConnectToSignal(
+ kObjectManagerInterface,
+ kObjectManagerInterfacesAdded,
+ base::Bind(&ObjectManager::InterfacesAddedReceived,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&ObjectManager::InterfacesAddedConnected,
+ weak_ptr_factory_.GetWeakPtr()));
+
+ object_proxy_->ConnectToSignal(
+ kObjectManagerInterface,
+ kObjectManagerInterfacesRemoved,
+ base::Bind(&ObjectManager::InterfacesRemovedReceived,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Bind(&ObjectManager::InterfacesRemovedConnected,
+ weak_ptr_factory_.GetWeakPtr()));
+
+ if (!service_name_owner_.empty())
+ GetManagedObjects();
}
// static
@@ -249,7 +249,7 @@ DBusHandlerResult ObjectManager::HandleMessageThunk(DBusConnection* connection,
return self->HandleMessage(connection, raw_message);
}
-DBusHandlerResult ObjectManager::HandleMessage(DBusConnection*,
+DBusHandlerResult ObjectManager::HandleMessage(DBusConnection* /*connection*/,
DBusMessage* raw_message) {
DCHECK(bus_);
bus_->AssertOnDBusThread();
@@ -385,10 +385,9 @@ void ObjectManager::InterfacesAddedReceived(Signal* signal) {
UpdateObject(object_path, &reader);
}
-void ObjectManager::InterfacesAddedConnected(
- const std::string& /*interface_name*/,
- const std::string& /*signal_name*/,
- bool success) {
+void ObjectManager::InterfacesAddedConnected(const std::string& /*interface_name*/,
+ const std::string& /*signal_name*/,
+ bool success) {
LOG_IF(WARNING, !success) << service_name_ << " " << object_path_.value()
<< ": Failed to connect to InterfacesAdded signal.";
}
diff --git a/dbus/object_manager.h b/dbus/object_manager.h
index a97495e1f9..90cf919639 100644
--- a/dbus/object_manager.h
+++ b/dbus/object_manager.h
@@ -71,8 +71,9 @@
// object_manager_->UnregisterInterface(kInterface);
// }
//
-// The D-Bus thread manager takes care of issuing the necessary call to
-// GetManagedObjects() after the implementation classes have been set up.
+// This class calls GetManagedObjects() asynchronously after the remote service
+// becomes available and additionally refreshes managed objects after the
+// service stops or restarts.
//
// The object manager interface class has one abstract method that must be
// implemented by the class to create Properties structures on demand. As well
@@ -167,7 +168,7 @@ public:
// |interface_name| as appropriate. An implementation class will only
// receive multiple calls if it has registered for multiple interfaces.
virtual void ObjectAdded(const ObjectPath& /*object_path*/,
- const std::string& /*interface_name*/) {}
+ const std::string& /*interface_name*/) { }
// Called by ObjectManager to inform the implementation class than an
// object with the path |object_path| has been removed. Ths D-Bus interface
@@ -179,7 +180,7 @@ public:
// ObjectProxy object for the given interface are cleaned up, it is safe
// to retrieve them during removal to vary processing.
virtual void ObjectRemoved(const ObjectPath& /*object_path*/,
- const std::string& /*interface_name*/) {}
+ const std::string& /*interface_name*/) { }
};
// Client code should use Bus::GetObjectManager() instead of this constructor.
@@ -238,17 +239,14 @@ public:
private:
friend class base::RefCountedThreadSafe<ObjectManager>;
- // Connects the InterfacesAdded and InterfacesRemoved signals and calls
- // GetManagedObjects. Called from OnSetupMatchRuleAndFilterComplete.
- void InitializeObjects();
-
// Called from the constructor to add a match rule for PropertiesChanged
- // signals on the DBus thread and set up a corresponding filter function.
+ // signals on the D-Bus thread and set up a corresponding filter function.
bool SetupMatchRuleAndFilter();
// Called on the origin thread once the match rule and filter have been set
- // up. |success| is false, if an error occurred during set up; it's true
- // otherwise.
+ // up. Connects the InterfacesAdded and InterfacesRemoved signals and
+ // refreshes objects if the service is available. |success| is false if an
+ // error occurred during setup and true otherwise.
void OnSetupMatchRuleAndFilterComplete(bool success);
// Called by dbus:: when a message is received. This is used to filter
diff --git a/dbus/object_proxy.cc b/dbus/object_proxy.cc
index ce0255154a..50e62a3a99 100644
--- a/dbus/object_proxy.cc
+++ b/dbus/object_proxy.cc
@@ -10,7 +10,7 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
-#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_macros.h"
#include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h"
#include "base/task_runner_util.h"
@@ -459,8 +459,9 @@ void ObjectProxy::WaitForServiceToBeAvailableInternal() {
}
}
-DBusHandlerResult ObjectProxy::HandleMessage(DBusConnection*,
- DBusMessage* raw_message) {
+DBusHandlerResult ObjectProxy::HandleMessage(
+ DBusConnection* /*connection*/,
+ DBusMessage* raw_message) {
bus_->AssertOnDBusThread();
if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL)
diff --git a/dbus/object_proxy.h b/dbus/object_proxy.h
index 033e88608a..5de390461e 100644
--- a/dbus/object_proxy.h
+++ b/dbus/object_proxy.h
@@ -137,10 +137,10 @@ class CHROME_DBUS_EXPORT ObjectProxy
// from the method (i.e. calling a method that does not return a value),
// EmptyResponseCallback() can be passed to the |callback| parameter.
//
- // If the method call is successful, a pointer to Response object will
- // be passed to the callback. If unsuccessful, the error callback will be
- // called and a pointer to ErrorResponse object will be passed to the error
- // callback if available, otherwise NULL will be passed.
+ // If the method call is successful, |callback| will be invoked with a
+ // Response object. If unsuccessful, |error_callback| will be invoked with an
+ // ErrorResponse object (if the remote object returned an error) or nullptr
+ // (if a response was not received at all).
//
// Must be called in the origin thread.
virtual void CallMethodWithErrorCallback(MethodCall* method_call,
@@ -174,7 +174,11 @@ class CHROME_DBUS_EXPORT ObjectProxy
// represented by |service_name_|.
virtual void SetNameOwnerChangedCallback(NameOwnerChangedCallback callback);
- // Runs the callback as soon as the service becomes available.
+ // Registers |callback| to run when the service becomes available. If the
+ // service is already available, or if connecting to the name-owner-changed
+ // signal fails, |callback| will be run once asynchronously. Otherwise,
+ // |callback| will be run once in the future after the service becomes
+ // available.
virtual void WaitForServiceToBeAvailable(
WaitForServiceToBeAvailableCallback callback);
diff --git a/dbus/property.cc b/dbus/property.cc
index aa58436f51..93f9ed693c 100644
--- a/dbus/property.cc
+++ b/dbus/property.cc
@@ -6,6 +6,8 @@
#include <stddef.h>
+#include <memory>
+
#include "base/bind.h"
#include "base/logging.h"
@@ -659,6 +661,134 @@ void Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>::
writer->CloseContainer(&variant_writer);
}
+//
+// Property<std::unordered_map<std::string, std::vector<uint8_t>>>
+// specialization.
+//
+
+template <>
+bool Property<std::unordered_map<std::string, std::vector<uint8_t>>>::
+ PopValueFromReader(MessageReader* reader) {
+ MessageReader variant_reader(nullptr);
+ MessageReader dict_reader(nullptr);
+ if (!reader->PopVariant(&variant_reader) ||
+ !variant_reader.PopArray(&dict_reader))
+ return false;
+
+ value_.clear();
+ while (dict_reader.HasMoreData()) {
+ MessageReader entry_reader(nullptr);
+ if (!dict_reader.PopDictEntry(&entry_reader))
+ return false;
+
+ std::string key;
+ MessageReader value_varient_reader(nullptr);
+ if (!entry_reader.PopString(&key) ||
+ !entry_reader.PopVariant(&value_varient_reader))
+ return false;
+
+ const uint8_t* bytes = nullptr;
+ size_t length = 0;
+ if (!value_varient_reader.PopArrayOfBytes(&bytes, &length))
+ return false;
+
+ value_[key].assign(bytes, bytes + length);
+ }
+ return true;
+}
+
+template <>
+void Property<std::unordered_map<std::string, std::vector<uint8_t>>>::
+ AppendSetValueToWriter(MessageWriter* writer) {
+ MessageWriter variant_writer(nullptr);
+ MessageWriter dict_writer(nullptr);
+
+ writer->OpenVariant("a{sv}", &variant_writer);
+ variant_writer.OpenArray("{sv}", &dict_writer);
+
+ for (const auto& pair : set_value_) {
+ MessageWriter entry_writer(nullptr);
+ dict_writer.OpenDictEntry(&entry_writer);
+
+ entry_writer.AppendString(pair.first);
+
+ MessageWriter value_varient_writer(nullptr);
+ entry_writer.OpenVariant("ay", &value_varient_writer);
+ value_varient_writer.AppendArrayOfBytes(pair.second.data(),
+ pair.second.size());
+ entry_writer.CloseContainer(&value_varient_writer);
+
+ dict_writer.CloseContainer(&entry_writer);
+ }
+
+ variant_writer.CloseContainer(&dict_writer);
+ writer->CloseContainer(&variant_writer);
+}
+
+//
+// Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>
+// specialization.
+//
+
+template <>
+bool Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>::
+ PopValueFromReader(MessageReader* reader) {
+ MessageReader variant_reader(nullptr);
+ MessageReader dict_reader(nullptr);
+ if (!reader->PopVariant(&variant_reader) ||
+ !variant_reader.PopArray(&dict_reader))
+ return false;
+
+ value_.clear();
+ while (dict_reader.HasMoreData()) {
+ MessageReader entry_reader(nullptr);
+ if (!dict_reader.PopDictEntry(&entry_reader))
+ return false;
+
+ uint16_t key;
+ MessageReader value_varient_reader(nullptr);
+ if (!entry_reader.PopUint16(&key) ||
+ !entry_reader.PopVariant(&value_varient_reader))
+ return false;
+
+ const uint8_t* bytes = nullptr;
+ size_t length = 0;
+ if (!value_varient_reader.PopArrayOfBytes(&bytes, &length))
+ return false;
+
+ value_[key].assign(bytes, bytes + length);
+ }
+ return true;
+}
+
+template <>
+void Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>::
+ AppendSetValueToWriter(MessageWriter* writer) {
+ MessageWriter variant_writer(nullptr);
+ MessageWriter dict_writer(nullptr);
+
+ writer->OpenVariant("a{qv}", &variant_writer);
+ variant_writer.OpenArray("{qv}", &dict_writer);
+
+ for (const auto& pair : set_value_) {
+ MessageWriter entry_writer(nullptr);
+ dict_writer.OpenDictEntry(&entry_writer);
+
+ entry_writer.AppendUint16(pair.first);
+
+ MessageWriter value_varient_writer(nullptr);
+ entry_writer.OpenVariant("ay", &value_varient_writer);
+ value_varient_writer.AppendArrayOfBytes(pair.second.data(),
+ pair.second.size());
+ entry_writer.CloseContainer(&value_varient_writer);
+
+ dict_writer.CloseContainer(&entry_writer);
+ }
+
+ variant_writer.CloseContainer(&dict_writer);
+ writer->CloseContainer(&variant_writer);
+}
+
template class Property<uint8_t>;
template class Property<bool>;
template class Property<int16_t>;
@@ -675,5 +805,7 @@ template class Property<std::vector<ObjectPath> >;
template class Property<std::vector<uint8_t>>;
template class Property<std::map<std::string, std::string>>;
template class Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>;
+template class Property<std::unordered_map<std::string, std::vector<uint8_t>>>;
+template class Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>;
} // namespace dbus
diff --git a/dbus/property.h b/dbus/property.h
index efbad226a6..0559ea0554 100644
--- a/dbus/property.h
+++ b/dbus/property.h
@@ -9,6 +9,7 @@
#include <map>
#include <string>
+#include <unordered_map>
#include <utility>
#include <vector>
@@ -610,6 +611,28 @@ Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>::
extern template class CHROME_DBUS_EXPORT
Property<std::vector<std::pair<std::vector<uint8_t>, uint16_t>>>;
+template <>
+CHROME_DBUS_EXPORT bool
+Property<std::unordered_map<std::string, std::vector<uint8_t>>>::
+ PopValueFromReader(MessageReader* reader);
+template <>
+CHROME_DBUS_EXPORT void
+Property<std::unordered_map<std::string, std::vector<uint8_t>>>::
+ AppendSetValueToWriter(MessageWriter* writer);
+extern template class CHROME_DBUS_EXPORT
+ Property<std::unordered_map<std::string, std::vector<uint8_t>>>;
+
+template <>
+CHROME_DBUS_EXPORT bool
+Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>::
+ PopValueFromReader(MessageReader* reader);
+template <>
+CHROME_DBUS_EXPORT void
+Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>::
+ AppendSetValueToWriter(MessageWriter* writer);
+extern template class CHROME_DBUS_EXPORT
+ Property<std::unordered_map<uint16_t, std::vector<uint8_t>>>;
+
#pragma GCC diagnostic pop
} // namespace dbus
diff --git a/dbus/values_util.cc b/dbus/values_util.cc
index bea7bea746..1e035c9cfe 100644
--- a/dbus/values_util.cc
+++ b/dbus/values_util.cc
@@ -67,19 +67,19 @@ bool PopDictionaryEntries(MessageReader* reader,
// Gets the D-Bus type signature for the value.
std::string GetTypeSignature(const base::Value& value) {
switch (value.GetType()) {
- case base::Value::TYPE_BOOLEAN:
+ case base::Value::Type::BOOLEAN:
return "b";
- case base::Value::TYPE_INTEGER:
+ case base::Value::Type::INTEGER:
return "i";
- case base::Value::TYPE_DOUBLE:
+ case base::Value::Type::DOUBLE:
return "d";
- case base::Value::TYPE_STRING:
+ case base::Value::Type::STRING:
return "s";
- case base::Value::TYPE_BINARY:
+ case base::Value::Type::BINARY:
return "ay";
- case base::Value::TYPE_DICTIONARY:
+ case base::Value::Type::DICTIONARY:
return "a{sv}";
- case base::Value::TYPE_LIST:
+ case base::Value::Type::LIST:
return "av";
default:
DLOG(ERROR) << "Unexpected type " << value.GetType();
@@ -98,38 +98,37 @@ std::unique_ptr<base::Value> PopDataAsValue(MessageReader* reader) {
case Message::BYTE: {
uint8_t value = 0;
if (reader->PopByte(&value))
- result = base::MakeUnique<base::FundamentalValue>(value);
+ result = base::MakeUnique<base::Value>(value);
break;
}
case Message::BOOL: {
bool value = false;
if (reader->PopBool(&value))
- result = base::MakeUnique<base::FundamentalValue>(value);
+ result = base::MakeUnique<base::Value>(value);
break;
}
case Message::INT16: {
int16_t value = 0;
if (reader->PopInt16(&value))
- result = base::MakeUnique<base::FundamentalValue>(value);
+ result = base::MakeUnique<base::Value>(value);
break;
}
case Message::UINT16: {
uint16_t value = 0;
if (reader->PopUint16(&value))
- result = base::MakeUnique<base::FundamentalValue>(value);
+ result = base::MakeUnique<base::Value>(value);
break;
}
case Message::INT32: {
int32_t value = 0;
if (reader->PopInt32(&value))
- result = base::MakeUnique<base::FundamentalValue>(value);
+ result = base::MakeUnique<base::Value>(value);
break;
}
case Message::UINT32: {
uint32_t value = 0;
if (reader->PopUint32(&value)) {
- result = base::MakeUnique<base::FundamentalValue>(
- static_cast<double>(value));
+ result = base::MakeUnique<base::Value>(static_cast<double>(value));
}
break;
}
@@ -138,8 +137,7 @@ std::unique_ptr<base::Value> PopDataAsValue(MessageReader* reader) {
if (reader->PopInt64(&value)) {
DLOG_IF(WARNING, !IsExactlyRepresentableByDouble(value)) <<
value << " is not exactly representable by double";
- result = base::MakeUnique<base::FundamentalValue>(
- static_cast<double>(value));
+ result = base::MakeUnique<base::Value>(static_cast<double>(value));
}
break;
}
@@ -148,27 +146,26 @@ std::unique_ptr<base::Value> PopDataAsValue(MessageReader* reader) {
if (reader->PopUint64(&value)) {
DLOG_IF(WARNING, !IsExactlyRepresentableByDouble(value)) <<
value << " is not exactly representable by double";
- result = base::MakeUnique<base::FundamentalValue>(
- static_cast<double>(value));
+ result = base::MakeUnique<base::Value>(static_cast<double>(value));
}
break;
}
case Message::DOUBLE: {
double value = 0;
if (reader->PopDouble(&value))
- result = base::MakeUnique<base::FundamentalValue>(value);
+ result = base::MakeUnique<base::Value>(value);
break;
}
case Message::STRING: {
std::string value;
if (reader->PopString(&value))
- result = base::MakeUnique<base::StringValue>(value);
+ result = base::MakeUnique<base::Value>(value);
break;
}
case Message::OBJECT_PATH: {
ObjectPath value;
if (reader->PopObjectPath(&value))
- result = base::MakeUnique<base::StringValue>(value.value());
+ result = base::MakeUnique<base::Value>(value.value());
break;
}
case Message::UNIX_FD: {
@@ -219,28 +216,28 @@ std::unique_ptr<base::Value> PopDataAsValue(MessageReader* reader) {
void AppendBasicTypeValueData(MessageWriter* writer, const base::Value& value) {
switch (value.GetType()) {
- case base::Value::TYPE_BOOLEAN: {
+ case base::Value::Type::BOOLEAN: {
bool bool_value = false;
bool success = value.GetAsBoolean(&bool_value);
DCHECK(success);
writer->AppendBool(bool_value);
break;
}
- case base::Value::TYPE_INTEGER: {
+ case base::Value::Type::INTEGER: {
int int_value = 0;
bool success = value.GetAsInteger(&int_value);
DCHECK(success);
writer->AppendInt32(int_value);
break;
}
- case base::Value::TYPE_DOUBLE: {
+ case base::Value::Type::DOUBLE: {
double double_value = 0;
bool success = value.GetAsDouble(&double_value);
DCHECK(success);
writer->AppendDouble(double_value);
break;
}
- case base::Value::TYPE_STRING: {
+ case base::Value::Type::STRING: {
std::string string_value;
bool success = value.GetAsString(&string_value);
DCHECK(success);
@@ -263,7 +260,7 @@ void AppendBasicTypeValueDataAsVariant(MessageWriter* writer,
void AppendValueData(MessageWriter* writer, const base::Value& value) {
switch (value.GetType()) {
- case base::Value::TYPE_DICTIONARY: {
+ case base::Value::Type::DICTIONARY: {
const base::DictionaryValue* dictionary = NULL;
value.GetAsDictionary(&dictionary);
dbus::MessageWriter array_writer(NULL);
@@ -279,7 +276,7 @@ void AppendValueData(MessageWriter* writer, const base::Value& value) {
writer->CloseContainer(&array_writer);
break;
}
- case base::Value::TYPE_LIST: {
+ case base::Value::Type::LIST: {
const base::ListValue* list = NULL;
value.GetAsList(&list);
dbus::MessageWriter array_writer(NULL);
@@ -290,10 +287,10 @@ void AppendValueData(MessageWriter* writer, const base::Value& value) {
writer->CloseContainer(&array_writer);
break;
}
- case base::Value::TYPE_BOOLEAN:
- case base::Value::TYPE_INTEGER:
- case base::Value::TYPE_DOUBLE:
- case base::Value::TYPE_STRING:
+ case base::Value::Type::BOOLEAN:
+ case base::Value::Type::INTEGER:
+ case base::Value::Type::DOUBLE:
+ case base::Value::Type::STRING:
AppendBasicTypeValueData(writer, value);
break;
default: