summaryrefslogtreecommitdiff
path: root/chromium/dbus
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-11-20 15:06:40 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-11-22 11:48:58 +0000
commitdaa093eea7c773db06799a13bd7e4e2e2a9f8f14 (patch)
tree96cc5e7b9194c1b29eab927730bfa419e7111c25 /chromium/dbus
parentbe59a35641616a4cf23c4a13fa0632624b021c1b (diff)
downloadqtwebengine-chromium-daa093eea7c773db06799a13bd7e4e2e2a9f8f14.tar.gz
BASELINE: Update Chromium to 63.0.3239.58
Change-Id: Ia93b322a00ba4dd4004f3bcf1254063ba90e1605 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/dbus')
-rw-r--r--chromium/dbus/end_to_end_async_unittest.cc23
-rw-r--r--chromium/dbus/end_to_end_sync_unittest.cc18
-rw-r--r--chromium/dbus/exported_object.cc1
-rw-r--r--chromium/dbus/message.cc75
-rw-r--r--chromium/dbus/message.h10
-rw-r--r--chromium/dbus/mock_object_proxy.cc9
-rw-r--r--chromium/dbus/mock_object_proxy.h14
-rw-r--r--chromium/dbus/object_manager.cc1
-rw-r--r--chromium/dbus/object_proxy.cc139
-rw-r--r--chromium/dbus/object_proxy.h7
-rw-r--r--chromium/dbus/values_util.cc36
-rw-r--r--chromium/dbus/values_util_unittest.cc9
12 files changed, 156 insertions, 186 deletions
diff --git a/chromium/dbus/end_to_end_async_unittest.cc b/chromium/dbus/end_to_end_async_unittest.cc
index 2de55c38f6e..d96ebda0218 100644
--- a/chromium/dbus/end_to_end_async_unittest.cc
+++ b/chromium/dbus/end_to_end_async_unittest.cc
@@ -512,32 +512,13 @@ TEST_F(EndToEndAsyncTest, BrokenMethodWithErrorCallback) {
ASSERT_EQ(DBUS_ERROR_FAILED, error_names_[0]);
}
-TEST_F(EndToEndAsyncTest, InvalidObjectPath) {
- // Trailing '/' is only allowed for the root path.
- const ObjectPath invalid_object_path("/org/chromium/TestObject/");
-
- // Replace object proxy with new one.
- object_proxy_ = bus_->GetObjectProxy(test_service_->service_name(),
- invalid_object_path);
-
- MethodCall method_call("org.chromium.TestInterface", "Echo");
-
- const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
- CallMethodWithErrorCallback(&method_call, timeout_ms);
- WaitForErrors(1);
-
- // Should fail because of the invalid path.
- ASSERT_TRUE(response_strings_.empty());
- ASSERT_EQ("", error_names_[0]);
-}
-
TEST_F(EndToEndAsyncTest, InvalidServiceName) {
// Bus name cannot contain '/'.
const std::string invalid_service_name = ":1/2";
// Replace object proxy with new one.
- object_proxy_ = bus_->GetObjectProxy(
- invalid_service_name, ObjectPath("org.chromium.TestObject"));
+ object_proxy_ = bus_->GetObjectProxy(invalid_service_name,
+ ObjectPath("/org/chromium/TestObject"));
MethodCall method_call("org.chromium.TestInterface", "Echo");
diff --git a/chromium/dbus/end_to_end_sync_unittest.cc b/chromium/dbus/end_to_end_sync_unittest.cc
index 4eb9cd1950c..d0dafcced3a 100644
--- a/chromium/dbus/end_to_end_sync_unittest.cc
+++ b/chromium/dbus/end_to_end_sync_unittest.cc
@@ -108,29 +108,13 @@ TEST_F(EndToEndSyncTest, BrokenMethod) {
ASSERT_FALSE(response.get());
}
-TEST_F(EndToEndSyncTest, InvalidObjectPath) {
- // Trailing '/' is only allowed for the root path.
- const ObjectPath invalid_object_path("/org/chromium/TestObject/");
-
- // Replace object proxy with new one.
- object_proxy_ = client_bus_->GetObjectProxy(test_service_->service_name(),
- invalid_object_path);
-
- MethodCall method_call("org.chromium.TestInterface", "Echo");
-
- const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
- std::unique_ptr<Response> response(
- object_proxy_->CallMethodAndBlock(&method_call, timeout_ms));
- ASSERT_FALSE(response.get());
-}
-
TEST_F(EndToEndSyncTest, InvalidServiceName) {
// Bus name cannot contain '/'.
const std::string invalid_service_name = ":1/2";
// Replace object proxy with new one.
object_proxy_ = client_bus_->GetObjectProxy(
- invalid_service_name, ObjectPath("org.chromium.TestObject"));
+ invalid_service_name, ObjectPath("/org/chromium/TestObject"));
MethodCall method_call("org.chromium.TestInterface", "Echo");
diff --git a/chromium/dbus/exported_object.cc b/chromium/dbus/exported_object.cc
index 2047f3fe6f9..47d06603dfc 100644
--- a/chromium/dbus/exported_object.cc
+++ b/chromium/dbus/exported_object.cc
@@ -34,6 +34,7 @@ ExportedObject::ExportedObject(Bus* bus,
: bus_(bus),
object_path_(object_path),
object_is_registered_(false) {
+ LOG_IF(FATAL, !object_path_.IsValid()) << object_path_.value();
}
ExportedObject::~ExportedObject() {
diff --git a/chromium/dbus/message.cc b/chromium/dbus/message.cc
index b33345ec236..ec0b2234494 100644
--- a/chromium/dbus/message.cc
+++ b/chromium/dbus/message.cc
@@ -47,9 +47,7 @@ bool IsDBusTypeUnixFdSupported() {
return major >= 1 && minor >= 4;
}
-Message::Message()
- : raw_message_(NULL) {
-}
+Message::Message() : raw_message_(nullptr) {}
Message::~Message() {
if (raw_message_)
@@ -344,21 +342,20 @@ uint32_t Message::GetReplySerial() {
//
MethodCall::MethodCall(const std::string& interface_name,
- const std::string& method_name)
- : Message() {
+ const std::string& method_name) {
Init(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL));
CHECK(SetInterface(interface_name));
CHECK(SetMember(method_name));
}
-MethodCall::MethodCall() : Message() {
-}
+MethodCall::MethodCall() = default;
-MethodCall* MethodCall::FromRawMessage(DBusMessage* raw_message) {
+std::unique_ptr<MethodCall> MethodCall::FromRawMessage(
+ DBusMessage* raw_message) {
DCHECK_EQ(DBUS_MESSAGE_TYPE_METHOD_CALL, dbus_message_get_type(raw_message));
- MethodCall* method_call = new MethodCall;
+ std::unique_ptr<MethodCall> method_call(new MethodCall());
method_call->Init(raw_message);
return method_call;
}
@@ -367,21 +364,19 @@ MethodCall* MethodCall::FromRawMessage(DBusMessage* raw_message) {
// Signal implementation.
//
Signal::Signal(const std::string& interface_name,
- const std::string& method_name)
- : Message() {
+ const std::string& method_name) {
Init(dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL));
CHECK(SetInterface(interface_name));
CHECK(SetMember(method_name));
}
-Signal::Signal() : Message() {
-}
+Signal::Signal() = default;
-Signal* Signal::FromRawMessage(DBusMessage* raw_message) {
+std::unique_ptr<Signal> Signal::FromRawMessage(DBusMessage* raw_message) {
DCHECK_EQ(DBUS_MESSAGE_TYPE_SIGNAL, dbus_message_get_type(raw_message));
- Signal* signal = new Signal;
+ std::unique_ptr<Signal> signal(new Signal());
signal->Init(raw_message);
return signal;
}
@@ -390,26 +385,25 @@ Signal* Signal::FromRawMessage(DBusMessage* raw_message) {
// Response implementation.
//
-Response::Response() : Message() {
-}
+Response::Response() = default;
std::unique_ptr<Response> Response::FromRawMessage(DBusMessage* raw_message) {
DCHECK_EQ(DBUS_MESSAGE_TYPE_METHOD_RETURN,
dbus_message_get_type(raw_message));
- std::unique_ptr<Response> response(new Response);
+ std::unique_ptr<Response> response(new Response());
response->Init(raw_message);
return response;
}
std::unique_ptr<Response> Response::FromMethodCall(MethodCall* method_call) {
- std::unique_ptr<Response> response(new Response);
+ std::unique_ptr<Response> response(new Response());
response->Init(dbus_message_new_method_return(method_call->raw_message()));
return response;
}
std::unique_ptr<Response> Response::CreateEmpty() {
- std::unique_ptr<Response> response(new Response);
+ std::unique_ptr<Response> response(new Response());
response->Init(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN));
return response;
}
@@ -418,14 +412,13 @@ std::unique_ptr<Response> Response::CreateEmpty() {
// ErrorResponse implementation.
//
-ErrorResponse::ErrorResponse() : Response() {
-}
+ErrorResponse::ErrorResponse() = default;
std::unique_ptr<ErrorResponse> ErrorResponse::FromRawMessage(
DBusMessage* raw_message) {
DCHECK_EQ(DBUS_MESSAGE_TYPE_ERROR, dbus_message_get_type(raw_message));
- std::unique_ptr<ErrorResponse> response(new ErrorResponse);
+ std::unique_ptr<ErrorResponse> response(new ErrorResponse());
response->Init(raw_message);
return response;
}
@@ -434,7 +427,7 @@ std::unique_ptr<ErrorResponse> ErrorResponse::FromMethodCall(
MethodCall* method_call,
const std::string& error_name,
const std::string& error_message) {
- std::unique_ptr<ErrorResponse> response(new ErrorResponse);
+ std::unique_ptr<ErrorResponse> response(new ErrorResponse());
response->Init(dbus_message_new_error(method_call->raw_message(),
error_name.c_str(),
error_message.c_str()));
@@ -466,7 +459,7 @@ void MessageWriter::AppendBool(bool value) {
// dbus_message_iter_append_basic() used in AppendBasic() expects four
// bytes for DBUS_TYPE_BOOLEAN, so we must pass a dbus_bool_t, instead
// of a bool, to AppendBasic().
- dbus_bool_t dbus_value = value;
+ dbus_bool_t dbus_value = value ? 1 : 0;
AppendBasic(DBUS_TYPE_BOOLEAN, &dbus_value);
}
@@ -551,11 +544,10 @@ void MessageWriter::OpenVariant(const std::string& signature,
void MessageWriter::OpenStruct(MessageWriter* writer) {
DCHECK(!container_is_open_);
- const bool success = dbus_message_iter_open_container(
- &raw_message_iter_,
- DBUS_TYPE_STRUCT,
- NULL, // Signature should be NULL.
- &writer->raw_message_iter_);
+ const bool success =
+ dbus_message_iter_open_container(&raw_message_iter_, DBUS_TYPE_STRUCT,
+ nullptr, // Signature should be nullptr.
+ &writer->raw_message_iter_);
CHECK(success) << "Unable to allocate memory";
container_is_open_ = true;
}
@@ -563,11 +555,10 @@ void MessageWriter::OpenStruct(MessageWriter* writer) {
void MessageWriter::OpenDictEntry(MessageWriter* writer) {
DCHECK(!container_is_open_);
- const bool success = dbus_message_iter_open_container(
- &raw_message_iter_,
- DBUS_TYPE_DICT_ENTRY,
- NULL, // Signature should be NULL.
- &writer->raw_message_iter_);
+ const bool success =
+ dbus_message_iter_open_container(&raw_message_iter_, DBUS_TYPE_DICT_ENTRY,
+ nullptr, // Signature should be nullptr.
+ &writer->raw_message_iter_);
CHECK(success) << "Unable to allocate memory";
container_is_open_ = true;
}
@@ -777,7 +768,7 @@ bool MessageReader::PopDouble(double* value) {
}
bool MessageReader::PopString(std::string* value) {
- char* tmp_value = NULL;
+ char* tmp_value = nullptr;
const bool success = PopBasic(DBUS_TYPE_STRING, &tmp_value);
if (success)
value->assign(tmp_value);
@@ -785,7 +776,7 @@ bool MessageReader::PopString(std::string* value) {
}
bool MessageReader::PopObjectPath(ObjectPath* value) {
- char* tmp_value = NULL;
+ char* tmp_value = nullptr;
const bool success = PopBasic(DBUS_TYPE_OBJECT_PATH, &tmp_value);
if (success)
*value = ObjectPath(tmp_value);
@@ -815,7 +806,7 @@ bool MessageReader::PopArrayOfBytes(const uint8_t** bytes, size_t* length) {
// An empty array is allowed.
if (!array_reader.HasMoreData()) {
*length = 0;
- *bytes = NULL;
+ *bytes = nullptr;
return true;
}
if (!array_reader.CheckDataType(DBUS_TYPE_BYTE))
@@ -879,8 +870,8 @@ bool MessageReader::PopArrayOfObjectPaths(
bool MessageReader::PopArrayOfBytesAsProto(
google::protobuf::MessageLite* protobuf) {
- DCHECK(protobuf != NULL);
- const char* serialized_buf = NULL;
+ DCHECK(protobuf);
+ const char* serialized_buf = nullptr;
size_t buf_size = 0;
if (!PopArrayOfBytes(reinterpret_cast<const uint8_t**>(&serialized_buf),
&buf_size)) {
@@ -935,7 +926,7 @@ bool MessageReader::PopVariantOfDouble(double* value) {
}
bool MessageReader::PopVariantOfString(std::string* value) {
- char* tmp_value = NULL;
+ char* tmp_value = nullptr;
const bool success = PopVariantOfBasic(DBUS_TYPE_STRING, &tmp_value);
if (success)
value->assign(tmp_value);
@@ -943,7 +934,7 @@ bool MessageReader::PopVariantOfString(std::string* value) {
}
bool MessageReader::PopVariantOfObjectPath(ObjectPath* value) {
- char* tmp_value = NULL;
+ char* tmp_value = nullptr;
const bool success = PopVariantOfBasic(DBUS_TYPE_OBJECT_PATH, &tmp_value);
if (success)
*value = ObjectPath(tmp_value);
diff --git a/chromium/dbus/message.h b/chromium/dbus/message.h
index f54cb7a6590..c9eca4385bd 100644
--- a/chromium/dbus/message.h
+++ b/chromium/dbus/message.h
@@ -158,9 +158,8 @@ class CHROME_DBUS_EXPORT MethodCall : public Message {
const std::string& method_name);
// Returns a newly created MethodCall from the given raw message of the
- // type DBUS_MESSAGE_TYPE_METHOD_CALL. The caller must delete the
- // returned object. Takes the ownership of |raw_message|.
- static MethodCall* FromRawMessage(DBusMessage* raw_message);
+ // type DBUS_MESSAGE_TYPE_METHOD_CALL. Takes the ownership of |raw_message|.
+ static std::unique_ptr<MethodCall> FromRawMessage(DBusMessage* raw_message);
private:
// Creates a method call message. The internal raw message is NULL.
@@ -187,9 +186,8 @@ class CHROME_DBUS_EXPORT Signal : public Message {
const std::string& method_name);
// Returns a newly created SIGNAL from the given raw message of the type
- // DBUS_MESSAGE_TYPE_SIGNAL. The caller must delete the returned
- // object. Takes the ownership of |raw_message|.
- static Signal* FromRawMessage(DBusMessage* raw_message);
+ // DBUS_MESSAGE_TYPE_SIGNAL. Takes the ownership of |raw_message|.
+ static std::unique_ptr<Signal> FromRawMessage(DBusMessage* raw_message);
private:
// Creates a signal message. The internal raw message is NULL.
diff --git a/chromium/dbus/mock_object_proxy.cc b/chromium/dbus/mock_object_proxy.cc
index 616fb02dc23..1ba754fe1a9 100644
--- a/chromium/dbus/mock_object_proxy.cc
+++ b/chromium/dbus/mock_object_proxy.cc
@@ -30,4 +30,13 @@ void MockObjectProxy::CallMethodWithErrorCallback(
&error_callback);
}
+void MockObjectProxy::ConnectToSignal(
+ const std::string& interface_name,
+ const std::string& signal_name,
+ SignalCallback signal_callback,
+ OnConnectedCallback on_connected_callback) {
+ DoConnectToSignal(interface_name, signal_name, signal_callback,
+ &on_connected_callback);
+}
+
} // namespace dbus
diff --git a/chromium/dbus/mock_object_proxy.h b/chromium/dbus/mock_object_proxy.h
index dabb33082e2..c430fac631c 100644
--- a/chromium/dbus/mock_object_proxy.h
+++ b/chromium/dbus/mock_object_proxy.h
@@ -53,15 +53,21 @@ class MockObjectProxy : public ObjectProxy {
int timeout_ms,
ResponseCallback* callback,
ErrorCallback* error_callback));
- MOCK_METHOD4(ConnectToSignal,
+
+ // This method is not mockable because it takes a move-only argument. To work
+ // around this, ConnectToSignal() implementation here calls
+ // DoConnectToSignal() which is mockable.
+ void ConnectToSignal(const std::string& interface_name,
+ const std::string& signal_name,
+ SignalCallback signal_callback,
+ OnConnectedCallback on_connected_callback) override;
+ MOCK_METHOD4(DoConnectToSignal,
void(const std::string& interface_name,
const std::string& signal_name,
SignalCallback signal_callback,
- OnConnectedCallback on_connected_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/chromium/dbus/object_manager.cc b/chromium/dbus/object_manager.cc
index 3a39cd6fb64..cdcd63a1664 100644
--- a/chromium/dbus/object_manager.cc
+++ b/chromium/dbus/object_manager.cc
@@ -38,6 +38,7 @@ ObjectManager::ObjectManager(Bus* bus,
setup_success_(false),
cleanup_called_(false),
weak_ptr_factory_(this) {
+ LOG_IF(FATAL, !object_path_.IsValid()) << object_path_.value();
DVLOG(1) << "Creating ObjectManager for " << service_name_
<< " " << object_path_.value();
DCHECK(bus_);
diff --git a/chromium/dbus/object_proxy.cc b/chromium/dbus/object_proxy.cc
index cb41cc968fe..4d4ef1218df 100644
--- a/chromium/dbus/object_proxy.cc
+++ b/chromium/dbus/object_proxy.cc
@@ -27,23 +27,25 @@ namespace dbus {
namespace {
-const char kErrorServiceUnknown[] = "org.freedesktop.DBus.Error.ServiceUnknown";
-const char kErrorObjectUnknown[] = "org.freedesktop.DBus.Error.UnknownObject";
+constexpr char kErrorServiceUnknown[] =
+ "org.freedesktop.DBus.Error.ServiceUnknown";
+constexpr char kErrorObjectUnknown[] =
+ "org.freedesktop.DBus.Error.UnknownObject";
// Used for success ratio histograms. 1 for success, 0 for failure.
-const int kSuccessRatioHistogramMaxValue = 2;
+constexpr int kSuccessRatioHistogramMaxValue = 2;
// The path of D-Bus Object sending NameOwnerChanged signal.
-const char kDBusSystemObjectPath[] = "/org/freedesktop/DBus";
+constexpr char kDBusSystemObjectPath[] = "/org/freedesktop/DBus";
// The D-Bus Object interface.
-const char kDBusSystemObjectInterface[] = "org.freedesktop.DBus";
+constexpr char kDBusSystemObjectInterface[] = "org.freedesktop.DBus";
// The D-Bus Object address.
-const char kDBusSystemObjectAddress[] = "org.freedesktop.DBus";
+constexpr char kDBusSystemObjectAddress[] = "org.freedesktop.DBus";
// The NameOwnerChanged member in |kDBusSystemObjectInterface|.
-const char kNameOwnerChangedMember[] = "NameOwnerChanged";
+constexpr char kNameOwnerChangedMember[] = "NameOwnerChanged";
// An empty function used for ObjectProxy::EmptyResponseCallback().
void EmptyResponseCallbackBody(Response* /*response*/) {
@@ -60,6 +62,7 @@ ObjectProxy::ObjectProxy(Bus* bus,
object_path_(object_path),
ignore_service_unknown_errors_(
options & IGNORE_SERVICE_UNKNOWN_ERRORS) {
+ LOG_IF(FATAL, !object_path_.IsValid()) << object_path_.value();
}
ObjectProxy::~ObjectProxy() {
@@ -155,7 +158,7 @@ void ObjectProxy::CallMethodInternal(MethodCall* method_call,
// In case of a failure, run the error callback with nullptr.
base::OnceClosure task = base::BindOnce(
&ObjectProxy::RunCallMethodInternalCallback, this, std::move(callback),
- start_time, nullptr /* response_message */);
+ start_time, nullptr /* response */, nullptr /* error_response */);
bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, std::move(task));
return;
}
@@ -186,16 +189,17 @@ void ObjectProxy::ConnectToSignal(const std::string& interface_name,
if (bus_->HasDBusThread()) {
base::PostTaskAndReplyWithResult(
bus_->GetDBusTaskRunner(), FROM_HERE,
- base::Bind(&ObjectProxy::ConnectToSignalInternal, this, interface_name,
- signal_name, signal_callback),
- base::Bind(on_connected_callback, interface_name, signal_name));
+ base::BindOnce(&ObjectProxy::ConnectToSignalInternal, this,
+ interface_name, signal_name, signal_callback),
+ base::BindOnce(std::move(on_connected_callback), interface_name,
+ signal_name));
} else {
// If the bus doesn't have a dedicated dbus thread we need to call
// ConnectToSignalInternal directly otherwise we might miss a signal
// that is currently queued if we do a PostTask.
const bool success =
ConnectToSignalInternal(interface_name, signal_name, signal_callback);
- on_connected_callback.Run(interface_name, signal_name, success);
+ std::move(on_connected_callback).Run(interface_name, signal_name, success);
}
}
@@ -210,10 +214,10 @@ void ObjectProxy::WaitForServiceToBeAvailable(
WaitForServiceToBeAvailableCallback callback) {
bus_->AssertOnOriginThread();
- wait_for_service_to_be_available_callbacks_.push_back(callback);
+ wait_for_service_to_be_available_callbacks_.push_back(std::move(callback));
bus_->GetDBusTaskRunner()->PostTask(
FROM_HERE,
- base::Bind(&ObjectProxy::WaitForServiceToBeAvailableInternal, this));
+ base::BindOnce(&ObjectProxy::WaitForServiceToBeAvailableInternal, this));
}
void ObjectProxy::Detach() {
@@ -265,7 +269,7 @@ void ObjectProxy::StartAsyncMethodCall(int timeout_ms,
// In case of a failure, run the error callback with nullptr.
base::OnceClosure task = base::BindOnce(
&ObjectProxy::RunCallMethodInternalCallback, this, std::move(callback),
- start_time, nullptr /* response_message */);
+ start_time, nullptr /* response */, nullptr /* error_response */);
bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, std::move(task));
dbus_message_unref(request_message);
@@ -299,10 +303,46 @@ void ObjectProxy::OnPendingCallIsComplete(DBusPendingCall* pending_call,
bus_->AssertOnDBusThread();
DBusMessage* response_message = dbus_pending_call_steal_reply(pending_call);
- base::OnceClosure task =
- base::BindOnce(&ObjectProxy::RunCallMethodInternalCallback, this,
- std::move(callback), start_time, response_message);
- bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, std::move(task));
+
+ // Either |response| or |error_response| takes ownership of the
+ // |response_message|.
+ std::unique_ptr<Response> response;
+ std::unique_ptr<ErrorResponse> error_response;
+ if (dbus_message_get_type(response_message) == DBUS_MESSAGE_TYPE_ERROR) {
+ error_response = ErrorResponse::FromRawMessage(response_message);
+ } else {
+ response = Response::FromRawMessage(response_message);
+ }
+
+ base::OnceClosure task = base::BindOnce(
+ &ObjectProxy::RunCallMethodInternalCallback, this, std::move(callback),
+ start_time, response.get(), error_response.get());
+
+ // The message should be deleted on the D-Bus thread for a complicated
+ // reason:
+ //
+ // libdbus keeps track of the number of bytes in the incoming message
+ // queue to ensure that the data size in the queue is manageable. The
+ // bookkeeping is partly done via dbus_message_unref(), and immediately
+ // asks the client code (Chrome) to stop monitoring the underlying
+ // socket, if the number of bytes exceeds a certian number, which is set
+ // to 63MB, per dbus-transport.cc:
+ //
+ // /* Try to default to something that won't totally hose the system,
+ // * but doesn't impose too much of a limitation.
+ // */
+ // transport->max_live_messages_size = _DBUS_ONE_MEGABYTE * 63;
+ //
+ // The monitoring of the socket is done on the D-Bus thread (see Watch
+ // class in bus.cc), hence we should stop the monitoring on D-Bus thread.
+ bus_->GetOriginTaskRunner()->PostTaskAndReply(
+ FROM_HERE, std::move(task),
+ base::BindOnce(
+ [](Response* response, ErrorResponse* error_response) {
+ // Do nothing.
+ },
+ base::Owned(response.release()),
+ base::Owned(error_response.release())));
// Remove the pending call from the set.
pending_calls_.erase(pending_call);
@@ -312,60 +352,19 @@ void ObjectProxy::OnPendingCallIsComplete(DBusPendingCall* pending_call,
void ObjectProxy::RunCallMethodInternalCallback(
CallMethodInternalCallback callback,
base::TimeTicks start_time,
- DBusMessage* response_message) {
+ Response* response,
+ ErrorResponse* error_response) {
bus_->AssertOnOriginThread();
- bool method_call_successful = false;
- if (!response_message) {
- // The response is not received.
- std::move(callback).Run(nullptr, nullptr);
- } else if (dbus_message_get_type(response_message) ==
- DBUS_MESSAGE_TYPE_ERROR) {
- // This will take |response_message| and release (unref) it.
- std::unique_ptr<ErrorResponse> error_response(
- ErrorResponse::FromRawMessage(response_message));
- std::move(callback).Run(nullptr, error_response.get());
- // Delete the message on the D-Bus thread. See below for why.
- bus_->GetDBusTaskRunner()->PostTask(
- FROM_HERE,
- base::Bind(&base::DeletePointer<ErrorResponse>,
- error_response.release()));
- } else {
- // This will take |response_message| and release (unref) it.
- std::unique_ptr<Response> response(
- Response::FromRawMessage(response_message));
- // The response is successfully received.
- std::move(callback).Run(response.get(), nullptr);
- // The message should be deleted on the D-Bus thread for a complicated
- // reason:
- //
- // libdbus keeps track of the number of bytes in the incoming message
- // queue to ensure that the data size in the queue is manageable. The
- // bookkeeping is partly done via dbus_message_unref(), and immediately
- // asks the client code (Chrome) to stop monitoring the underlying
- // socket, if the number of bytes exceeds a certian number, which is set
- // to 63MB, per dbus-transport.cc:
- //
- // /* Try to default to something that won't totally hose the system,
- // * but doesn't impose too much of a limitation.
- // */
- // transport->max_live_messages_size = _DBUS_ONE_MEGABYTE * 63;
- //
- // The monitoring of the socket is done on the D-Bus thread (see Watch
- // class in bus.cc), hence we should stop the monitoring from D-Bus
- // thread, not from the current thread here, which is likely UI thread.
- bus_->GetDBusTaskRunner()->PostTask(
- FROM_HERE,
- base::Bind(&base::DeletePointer<Response>, response.release()));
+ std::move(callback).Run(response, error_response);
- method_call_successful = true;
+ if (response) {
// Record time spent for the method call. Don't include failures.
UMA_HISTOGRAM_TIMES("DBus.AsyncMethodCallTime",
base::TimeTicks::Now() - start_time);
}
// Record if the method call is successful, or not. 1 if successful.
- UMA_HISTOGRAM_ENUMERATION("DBus.AsyncMethodCallSuccess",
- method_call_successful,
+ UMA_HISTOGRAM_ENUMERATION("DBus.AsyncMethodCallSuccess", response ? 1 : 0,
kSuccessRatioHistogramMaxValue);
}
@@ -436,8 +435,8 @@ void ObjectProxy::WaitForServiceToBeAvailableInternal() {
const bool service_is_ready = false;
bus_->GetOriginTaskRunner()->PostTask(
FROM_HERE,
- base::Bind(&ObjectProxy::RunWaitForServiceToBeAvailableCallbacks,
- this, service_is_ready));
+ base::BindOnce(&ObjectProxy::RunWaitForServiceToBeAvailableCallbacks,
+ this, service_is_ready));
return;
}
@@ -445,8 +444,8 @@ void ObjectProxy::WaitForServiceToBeAvailableInternal() {
if (service_is_available) { // Service is already available.
bus_->GetOriginTaskRunner()->PostTask(
FROM_HERE,
- base::Bind(&ObjectProxy::RunWaitForServiceToBeAvailableCallbacks,
- this, service_is_available));
+ base::BindOnce(&ObjectProxy::RunWaitForServiceToBeAvailableCallbacks,
+ this, service_is_available));
return;
}
}
@@ -711,7 +710,7 @@ void ObjectProxy::RunWaitForServiceToBeAvailableCallbacks(
std::vector<WaitForServiceToBeAvailableCallback> callbacks;
callbacks.swap(wait_for_service_to_be_available_callbacks_);
for (size_t i = 0; i < callbacks.size(); ++i)
- callbacks[i].Run(service_is_available);
+ std::move(callbacks[i]).Run(service_is_available);
}
} // namespace dbus
diff --git a/chromium/dbus/object_proxy.h b/chromium/dbus/object_proxy.h
index 48d84683aab..e1af335f2ff 100644
--- a/chromium/dbus/object_proxy.h
+++ b/chromium/dbus/object_proxy.h
@@ -83,7 +83,7 @@ class CHROME_DBUS_EXPORT ObjectProxy
// Called when the service becomes available.
using WaitForServiceToBeAvailableCallback =
- base::Callback<void(bool service_is_available)>;
+ base::OnceCallback<void(bool service_is_available)>;
// Called when the object proxy is connected to the signal.
// Parameters:
@@ -91,7 +91,7 @@ class CHROME_DBUS_EXPORT ObjectProxy
// - the signal name.
// - whether it was successful or not.
using OnConnectedCallback =
- base::Callback<void(const std::string&, const std::string&, bool)>;
+ base::OnceCallback<void(const std::string&, const std::string&, bool)>;
// Calls the method of the remote object and blocks until the response
// is returned. Returns NULL on error with the error details specified
@@ -239,7 +239,8 @@ class CHROME_DBUS_EXPORT ObjectProxy
// Runs the CallMethodInternalCallback with the given response object.
void RunCallMethodInternalCallback(CallMethodInternalCallback callback,
base::TimeTicks start_time,
- DBusMessage* response_message);
+ Response* response,
+ ErrorResponse* error_response);
// Redirects the function call to OnPendingCallIsComplete().
static void OnPendingCallIsCompleteThunk(DBusPendingCall* pending_call,
diff --git a/chromium/dbus/values_util.cc b/chromium/dbus/values_util.cc
index e57380d1fa7..4b1a4aecb76 100644
--- a/chromium/dbus/values_util.cc
+++ b/chromium/dbus/values_util.cc
@@ -4,11 +4,11 @@
#include "dbus/values_util.h"
+#include <memory>
#include <utility>
#include "base/json/json_writer.h"
#include "base/logging.h"
-#include "base/memory/ptr_util.h"
#include "base/values.h"
#include "dbus/message.h"
@@ -66,7 +66,7 @@ bool PopDictionaryEntries(MessageReader* reader,
// Gets the D-Bus type signature for the value.
std::string GetTypeSignature(const base::Value& value) {
- switch (value.GetType()) {
+ switch (value.type()) {
case base::Value::Type::BOOLEAN:
return "b";
case base::Value::Type::INTEGER:
@@ -82,7 +82,7 @@ std::string GetTypeSignature(const base::Value& value) {
case base::Value::Type::LIST:
return "av";
default:
- DLOG(ERROR) << "Unexpected type " << value.GetType();
+ DLOG(ERROR) << "Unexpected type " << value.type();
return std::string();
}
}
@@ -98,37 +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::Value>(value);
+ result = std::make_unique<base::Value>(value);
break;
}
case Message::BOOL: {
bool value = false;
if (reader->PopBool(&value))
- result = base::MakeUnique<base::Value>(value);
+ result = std::make_unique<base::Value>(value);
break;
}
case Message::INT16: {
int16_t value = 0;
if (reader->PopInt16(&value))
- result = base::MakeUnique<base::Value>(value);
+ result = std::make_unique<base::Value>(value);
break;
}
case Message::UINT16: {
uint16_t value = 0;
if (reader->PopUint16(&value))
- result = base::MakeUnique<base::Value>(value);
+ result = std::make_unique<base::Value>(value);
break;
}
case Message::INT32: {
int32_t value = 0;
if (reader->PopInt32(&value))
- result = base::MakeUnique<base::Value>(value);
+ result = std::make_unique<base::Value>(value);
break;
}
case Message::UINT32: {
uint32_t value = 0;
if (reader->PopUint32(&value)) {
- result = base::MakeUnique<base::Value>(static_cast<double>(value));
+ result = std::make_unique<base::Value>(static_cast<double>(value));
}
break;
}
@@ -137,7 +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::Value>(static_cast<double>(value));
+ result = std::make_unique<base::Value>(static_cast<double>(value));
}
break;
}
@@ -146,26 +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::Value>(static_cast<double>(value));
+ result = std::make_unique<base::Value>(static_cast<double>(value));
}
break;
}
case Message::DOUBLE: {
double value = 0;
if (reader->PopDouble(&value))
- result = base::MakeUnique<base::Value>(value);
+ result = std::make_unique<base::Value>(value);
break;
}
case Message::STRING: {
std::string value;
if (reader->PopString(&value))
- result = base::MakeUnique<base::Value>(value);
+ result = std::make_unique<base::Value>(value);
break;
}
case Message::OBJECT_PATH: {
ObjectPath value;
if (reader->PopObjectPath(&value))
- result = base::MakeUnique<base::Value>(value.value());
+ result = std::make_unique<base::Value>(value.value());
break;
}
case Message::UNIX_FD: {
@@ -215,7 +215,7 @@ std::unique_ptr<base::Value> PopDataAsValue(MessageReader* reader) {
}
void AppendBasicTypeValueData(MessageWriter* writer, const base::Value& value) {
- switch (value.GetType()) {
+ switch (value.type()) {
case base::Value::Type::BOOLEAN: {
bool bool_value = false;
bool success = value.GetAsBoolean(&bool_value);
@@ -245,7 +245,7 @@ void AppendBasicTypeValueData(MessageWriter* writer, const base::Value& value) {
break;
}
default:
- DLOG(ERROR) << "Unexpected type " << value.GetType();
+ DLOG(ERROR) << "Unexpected type " << value.type();
break;
}
}
@@ -259,7 +259,7 @@ void AppendBasicTypeValueDataAsVariant(MessageWriter* writer,
}
void AppendValueData(MessageWriter* writer, const base::Value& value) {
- switch (value.GetType()) {
+ switch (value.type()) {
case base::Value::Type::DICTIONARY: {
const base::DictionaryValue* dictionary = NULL;
value.GetAsDictionary(&dictionary);
@@ -294,7 +294,7 @@ void AppendValueData(MessageWriter* writer, const base::Value& value) {
AppendBasicTypeValueData(writer, value);
break;
default:
- DLOG(ERROR) << "Unexpected type: " << value.GetType();
+ DLOG(ERROR) << "Unexpected type: " << value.type();
}
}
diff --git a/chromium/dbus/values_util_unittest.cc b/chromium/dbus/values_util_unittest.cc
index 1ee2b69b764..f0d63a9d329 100644
--- a/chromium/dbus/values_util_unittest.cc
+++ b/chromium/dbus/values_util_unittest.cc
@@ -14,7 +14,6 @@
#include "base/json/json_writer.h"
#include "base/macros.h"
-#include "base/memory/ptr_util.h"
#include "base/values.h"
#include "dbus/message.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -517,11 +516,11 @@ TEST(ValuesUtilTest, AppendDictionary) {
const double kDoubleValue = 4.9;
const std::string kStringValue = "fifty";
- auto list_value = base::MakeUnique<base::ListValue>();
+ auto list_value = std::make_unique<base::ListValue>();
list_value->AppendBoolean(kBoolValue);
list_value->AppendInteger(kInt32Value);
- auto dictionary_value = base::MakeUnique<base::DictionaryValue>();
+ auto dictionary_value = std::make_unique<base::DictionaryValue>();
dictionary_value->SetBoolean(kKey1, kBoolValue);
dictionary_value->SetInteger(kKey2, kDoubleValue);
@@ -564,11 +563,11 @@ TEST(ValuesUtilTest, AppendDictionaryAsVariant) {
const double kDoubleValue = 4.9;
const std::string kStringValue = "fifty";
- auto list_value = base::MakeUnique<base::ListValue>();
+ auto list_value = std::make_unique<base::ListValue>();
list_value->AppendBoolean(kBoolValue);
list_value->AppendInteger(kInt32Value);
- auto dictionary_value = base::MakeUnique<base::DictionaryValue>();
+ auto dictionary_value = std::make_unique<base::DictionaryValue>();
dictionary_value->SetBoolean(kKey1, kBoolValue);
dictionary_value->SetInteger(kKey2, kDoubleValue);