diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-20 10:33:36 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-22 11:45:12 +0000 |
commit | be59a35641616a4cf23c4a13fa0632624b021c1b (patch) | |
tree | 9da183258bdf9cc413f7562079d25ace6955467f /chromium/dbus | |
parent | d702e4b6a64574e97fc7df8fe3238cde70242080 (diff) | |
download | qtwebengine-chromium-be59a35641616a4cf23c4a13fa0632624b021c1b.tar.gz |
BASELINE: Update Chromium to 62.0.3202.101
Change-Id: I2d5eca8117600df6d331f6166ab24d943d9814ac
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/dbus')
-rw-r--r-- | chromium/dbus/mock_object_proxy.cc | 15 | ||||
-rw-r--r-- | chromium/dbus/mock_object_proxy.h | 31 | ||||
-rw-r--r-- | chromium/dbus/mock_unittest.cc | 13 | ||||
-rw-r--r-- | chromium/dbus/object_proxy.cc | 122 | ||||
-rw-r--r-- | chromium/dbus/object_proxy.h | 66 | ||||
-rw-r--r-- | chromium/dbus/values_util_unittest.cc | 8 |
6 files changed, 152 insertions, 103 deletions
diff --git a/chromium/dbus/mock_object_proxy.cc b/chromium/dbus/mock_object_proxy.cc index 7e26f01ba5c..616fb02dc23 100644 --- a/chromium/dbus/mock_object_proxy.cc +++ b/chromium/dbus/mock_object_proxy.cc @@ -15,4 +15,19 @@ MockObjectProxy::MockObjectProxy(Bus* bus, MockObjectProxy::~MockObjectProxy() { } +void MockObjectProxy::CallMethod(MethodCall* method_call, + int timeout_ms, + ResponseCallback callback) { + DoCallMethod(method_call, timeout_ms, &callback); +} + +void MockObjectProxy::CallMethodWithErrorCallback( + MethodCall* method_call, + int timeout_ms, + ResponseCallback callback, + ErrorCallback error_callback) { + DoCallMethodWithErrorCallback(method_call, timeout_ms, &callback, + &error_callback); +} + } // namespace dbus diff --git a/chromium/dbus/mock_object_proxy.h b/chromium/dbus/mock_object_proxy.h index 6b0258bc58d..dabb33082e2 100644 --- a/chromium/dbus/mock_object_proxy.h +++ b/chromium/dbus/mock_object_proxy.h @@ -29,13 +29,30 @@ class MockObjectProxy : public ObjectProxy { MOCK_METHOD2(CallMethodAndBlock, std::unique_ptr<Response>(MethodCall* method_call, int timeout_ms)); - MOCK_METHOD3(CallMethod, void(MethodCall* method_call, - int timeout_ms, - ResponseCallback callback)); - MOCK_METHOD4(CallMethodWithErrorCallback, void(MethodCall* method_call, - int timeout_ms, - ResponseCallback callback, - ErrorCallback error_callback)); + + // This method is not mockable because it takes a move-only argument. To work + // around this, CallMethod() implementation here calls DoCallMethod() which is + // mockable. + void CallMethod(MethodCall* method_call, + int timeout_ms, + ResponseCallback callback) override; + MOCK_METHOD3(DoCallMethod, + void(MethodCall* method_call, + int timeout_ms, + ResponseCallback* callback)); + + // This method is not mockable because it takes a move-only argument. To work + // around this, CallMethodWithErrorCallback() implementation here calls + // DoCallMethodWithErrorCallback() which is mockable. + void CallMethodWithErrorCallback(MethodCall* method_call, + int timeout_ms, + ResponseCallback callback, + ErrorCallback error_callback) override; + MOCK_METHOD4(DoCallMethodWithErrorCallback, + void(MethodCall* method_call, + int timeout_ms, + ResponseCallback* callback, + ErrorCallback* error_callback)); MOCK_METHOD4(ConnectToSignal, void(const std::string& interface_name, const std::string& signal_name, diff --git a/chromium/dbus/mock_unittest.cc b/chromium/dbus/mock_unittest.cc index 7f3d759eaf4..f7540ec11a9 100644 --- a/chromium/dbus/mock_unittest.cc +++ b/chromium/dbus/mock_unittest.cc @@ -54,8 +54,9 @@ class MockTest : public testing::Test { // Set an expectation so mock_proxy's CallMethod() will use // HandleMockProxyResponseWithMessageLoop() to return responses. - EXPECT_CALL(*mock_proxy_.get(), CallMethod(_, _, _)).WillRepeatedly( - Invoke(this, &MockTest::HandleMockProxyResponseWithMessageLoop)); + EXPECT_CALL(*mock_proxy_.get(), DoCallMethod(_, _, _)) + .WillRepeatedly( + Invoke(this, &MockTest::HandleMockProxyResponseWithMessageLoop)); // Set an expectation so mock_bus's GetObjectProxy() for the given // service name and the object path will return mock_proxy_. @@ -120,20 +121,20 @@ class MockTest : public testing::Test { void HandleMockProxyResponseWithMessageLoop( MethodCall* method_call, int timeout_ms, - ObjectProxy::ResponseCallback response_callback) { + ObjectProxy::ResponseCallback* response_callback) { std::unique_ptr<Response> response = CreateMockProxyResponse(method_call, timeout_ms); message_loop_.task_runner()->PostTask( FROM_HERE, - base::Bind(&MockTest::RunResponseCallback, base::Unretained(this), - response_callback, base::Passed(&response))); + base::BindOnce(&MockTest::RunResponseCallback, base::Unretained(this), + std::move(*response_callback), base::Passed(&response))); } // Runs the given response callback with the given response. void RunResponseCallback( ObjectProxy::ResponseCallback response_callback, std::unique_ptr<Response> response) { - response_callback.Run(response.get()); + std::move(response_callback).Run(response.get()); } }; diff --git a/chromium/dbus/object_proxy.cc b/chromium/dbus/object_proxy.cc index abc8c9b71f9..cb41cc968fe 100644 --- a/chromium/dbus/object_proxy.cc +++ b/chromium/dbus/object_proxy.cc @@ -118,18 +118,34 @@ std::unique_ptr<Response> ObjectProxy::CallMethodAndBlock( void ObjectProxy::CallMethod(MethodCall* method_call, int timeout_ms, ResponseCallback callback) { - CallMethodWithErrorCallback(method_call, timeout_ms, callback, - base::Bind(&ObjectProxy::OnCallMethodError, - this, - method_call->GetInterface(), - method_call->GetMember(), - callback)); + CallMethodInternalCallback internal_callback = base::BindOnce( + &ObjectProxy::OnCallMethod, this, method_call->GetInterface(), + method_call->GetMember(), std::move(callback)); + + CallMethodInternal(method_call, timeout_ms, std::move(internal_callback)); } void ObjectProxy::CallMethodWithErrorCallback(MethodCall* method_call, int timeout_ms, ResponseCallback callback, ErrorCallback error_callback) { + CallMethodInternalCallback internal_callback = base::BindOnce( + [](ResponseCallback callback, ErrorCallback error_callback, + Response* response, ErrorResponse* error_response) { + if (response) { + std::move(callback).Run(response); + } else { + std::move(error_callback).Run(error_response); + } + }, + std::move(callback), std::move(error_callback)); + + CallMethodInternal(method_call, timeout_ms, std::move(internal_callback)); +} + +void ObjectProxy::CallMethodInternal(MethodCall* method_call, + int timeout_ms, + CallMethodInternalCallback callback) { bus_->AssertOnOriginThread(); const base::TimeTicks start_time = base::TimeTicks::Now(); @@ -137,10 +153,10 @@ void ObjectProxy::CallMethodWithErrorCallback(MethodCall* method_call, if (!method_call->SetDestination(service_name_) || !method_call->SetPath(object_path_)) { // In case of a failure, run the error callback with nullptr. - base::Closure task = - base::Bind(&ObjectProxy::RunResponseCallback, this, callback, - error_callback, start_time, nullptr /* response_message */); - bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, task); + base::OnceClosure task = base::BindOnce( + &ObjectProxy::RunCallMethodInternalCallback, this, std::move(callback), + start_time, nullptr /* response_message */); + bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, std::move(task)); return; } @@ -150,19 +166,15 @@ void ObjectProxy::CallMethodWithErrorCallback(MethodCall* method_call, DBusMessage* request_message = method_call->raw_message(); dbus_message_ref(request_message); - base::Closure task = base::Bind(&ObjectProxy::StartAsyncMethodCall, - this, - timeout_ms, - request_message, - callback, - error_callback, - start_time); statistics::AddSentMethodCall(service_name_, method_call->GetInterface(), method_call->GetMember()); // Wait for the response in the D-Bus thread. - bus_->GetDBusTaskRunner()->PostTask(FROM_HERE, task); + base::OnceClosure task = + base::BindOnce(&ObjectProxy::StartAsyncMethodCall, this, timeout_ms, + request_message, std::move(callback), start_time); + bus_->GetDBusTaskRunner()->PostTask(FROM_HERE, std::move(task)); } void ObjectProxy::ConnectToSignal(const std::string& interface_name, @@ -234,31 +246,27 @@ ObjectProxy::ResponseCallback ObjectProxy::EmptyResponseCallback() { ObjectProxy::OnPendingCallIsCompleteData::OnPendingCallIsCompleteData( ObjectProxy* in_object_proxy, - ResponseCallback in_response_callback, - ErrorCallback in_error_callback, + CallMethodInternalCallback in_callback, base::TimeTicks in_start_time) : object_proxy(in_object_proxy), - response_callback(in_response_callback), - error_callback(in_error_callback), - start_time(in_start_time) { -} + callback(std::move(in_callback)), + start_time(in_start_time) {} ObjectProxy::OnPendingCallIsCompleteData::~OnPendingCallIsCompleteData() = default; void ObjectProxy::StartAsyncMethodCall(int timeout_ms, DBusMessage* request_message, - ResponseCallback response_callback, - ErrorCallback error_callback, + CallMethodInternalCallback callback, base::TimeTicks start_time) { bus_->AssertOnDBusThread(); if (!bus_->Connect() || !bus_->SetUpAsyncOperations()) { // In case of a failure, run the error callback with nullptr. - base::Closure task = - base::Bind(&ObjectProxy::RunResponseCallback, this, response_callback, - error_callback, start_time, nullptr /* response_message */); - bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, task); + base::OnceClosure task = base::BindOnce( + &ObjectProxy::RunCallMethodInternalCallback, this, std::move(callback), + start_time, nullptr /* response_message */); + bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, std::move(task)); dbus_message_unref(request_message); return; @@ -270,8 +278,7 @@ void ObjectProxy::StartAsyncMethodCall(int timeout_ms, // Prepare the data we'll be passing to OnPendingCallIsCompleteThunk(). // The data will be deleted in OnPendingCallIsCompleteThunk(). OnPendingCallIsCompleteData* data = - new OnPendingCallIsCompleteData(this, response_callback, error_callback, - start_time); + new OnPendingCallIsCompleteData(this, std::move(callback), start_time); // This returns false only when unable to allocate memory. const bool success = dbus_pending_call_set_notify( @@ -287,41 +294,37 @@ void ObjectProxy::StartAsyncMethodCall(int timeout_ms, } void ObjectProxy::OnPendingCallIsComplete(DBusPendingCall* pending_call, - ResponseCallback response_callback, - ErrorCallback error_callback, + CallMethodInternalCallback callback, base::TimeTicks start_time) { bus_->AssertOnDBusThread(); DBusMessage* response_message = dbus_pending_call_steal_reply(pending_call); - base::Closure task = base::Bind(&ObjectProxy::RunResponseCallback, - this, - response_callback, - error_callback, - start_time, - response_message); - bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, task); + base::OnceClosure task = + base::BindOnce(&ObjectProxy::RunCallMethodInternalCallback, this, + std::move(callback), start_time, response_message); + bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, std::move(task)); // Remove the pending call from the set. pending_calls_.erase(pending_call); dbus_pending_call_unref(pending_call); } -void ObjectProxy::RunResponseCallback(ResponseCallback response_callback, - ErrorCallback error_callback, - base::TimeTicks start_time, - DBusMessage* response_message) { +void ObjectProxy::RunCallMethodInternalCallback( + CallMethodInternalCallback callback, + base::TimeTicks start_time, + DBusMessage* response_message) { bus_->AssertOnOriginThread(); bool method_call_successful = false; if (!response_message) { // The response is not received. - error_callback.Run(nullptr); + 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)); - error_callback.Run(error_response.get()); + 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, @@ -332,7 +335,7 @@ void ObjectProxy::RunResponseCallback(ResponseCallback response_callback, std::unique_ptr<Response> response( Response::FromRawMessage(response_message)); // The response is successfully received. - response_callback.Run(response.get()); + std::move(callback).Run(response.get(), nullptr); // The message should be deleted on the D-Bus thread for a complicated // reason: // @@ -371,9 +374,7 @@ void ObjectProxy::OnPendingCallIsCompleteThunk(DBusPendingCall* pending_call, OnPendingCallIsCompleteData* data = reinterpret_cast<OnPendingCallIsCompleteData*>(user_data); ObjectProxy* self = data->object_proxy; - self->OnPendingCallIsComplete(pending_call, - data->response_callback, - data->error_callback, + self->OnPendingCallIsComplete(pending_call, std::move(data->callback), data->start_time); } @@ -532,7 +533,7 @@ void ObjectProxy::RunMethod(base::TimeTicks start_time, iter->Run(signal); // Delete the message on the D-Bus thread. See comments in - // RunResponseCallback(). + // RunCallMethodInternalCallback(). bus_->GetDBusTaskRunner()->PostTask( FROM_HERE, base::Bind(&base::DeletePointer<Signal>, signal)); @@ -573,10 +574,17 @@ void ObjectProxy::LogMethodCallFailure( LOG(ERROR) << msg.str(); } -void ObjectProxy::OnCallMethodError(const std::string& interface_name, - const std::string& method_name, - ResponseCallback response_callback, - ErrorResponse* error_response) { +void ObjectProxy::OnCallMethod(const std::string& interface_name, + const std::string& method_name, + ResponseCallback response_callback, + Response* response, + ErrorResponse* error_response) { + if (response) { + // Method call was successful. + std::move(response_callback).Run(response); + return; + } + // Method call failed. std::string error_name; std::string error_message; if (error_response) { @@ -589,7 +597,7 @@ void ObjectProxy::OnCallMethodError(const std::string& interface_name, } LogMethodCallFailure(interface_name, method_name, error_name, error_message); - response_callback.Run(nullptr); + std::move(response_callback).Run(nullptr); } bool ObjectProxy::AddMatchRuleWithCallback( diff --git a/chromium/dbus/object_proxy.h b/chromium/dbus/object_proxy.h index 5de390461e6..48d84683aab 100644 --- a/chromium/dbus/object_proxy.h +++ b/chromium/dbus/object_proxy.h @@ -68,30 +68,30 @@ class CHROME_DBUS_EXPORT ObjectProxy // Called when an error response is returned or no response is returned. // Used for CallMethodWithErrorCallback(). - typedef base::Callback<void(ErrorResponse*)> ErrorCallback; + using ErrorCallback = base::OnceCallback<void(ErrorResponse*)>; // Called when the response is returned. Used for CallMethod(). - typedef base::Callback<void(Response*)> ResponseCallback; + using ResponseCallback = base::OnceCallback<void(Response*)>; // Called when a signal is received. Signal* is the incoming signal. - typedef base::Callback<void (Signal*)> SignalCallback; + using SignalCallback = base::Callback<void(Signal*)>; // Called when NameOwnerChanged signal is received. - typedef base::Callback<void( - const std::string& old_owner, - const std::string& new_owner)> NameOwnerChangedCallback; + using NameOwnerChangedCallback = + base::Callback<void(const std::string& old_owner, + const std::string& new_owner)>; // Called when the service becomes available. - typedef base::Callback<void( - bool service_is_available)> WaitForServiceToBeAvailableCallback; + using WaitForServiceToBeAvailableCallback = + base::Callback<void(bool service_is_available)>; // Called when the object proxy is connected to the signal. // Parameters: // - the interface name. // - the signal name. // - whether it was successful or not. - typedef base::Callback<void (const std::string&, const std::string&, bool)> - OnConnectedCallback; + using OnConnectedCallback = + base::Callback<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 @@ -201,40 +201,45 @@ class CHROME_DBUS_EXPORT ObjectProxy private: friend class base::RefCountedThreadSafe<ObjectProxy>; + using CallMethodInternalCallback = + base::OnceCallback<void(Response* response, + ErrorResponse* error_response)>; + // Struct of data we'll be passing from StartAsyncMethodCall() to // OnPendingCallIsCompleteThunk(). struct OnPendingCallIsCompleteData { OnPendingCallIsCompleteData(ObjectProxy* in_object_proxy, - ResponseCallback in_response_callback, - ErrorCallback error_callback, + CallMethodInternalCallback callback, base::TimeTicks start_time); ~OnPendingCallIsCompleteData(); ObjectProxy* object_proxy; - ResponseCallback response_callback; - ErrorCallback error_callback; + CallMethodInternalCallback callback; base::TimeTicks start_time; }; + // This is a helpr function to implement CallMethod() and + // CallMethodWithErrorCallback(). + void CallMethodInternal(MethodCall* method_call, + int timeout_ms, + CallMethodInternalCallback callback); + // Starts the async method call. This is a helper function to implement // CallMethod(). void StartAsyncMethodCall(int timeout_ms, DBusMessage* request_message, - ResponseCallback response_callback, - ErrorCallback error_callback, + CallMethodInternalCallback callback, base::TimeTicks start_time); // Called when the pending call is complete. void OnPendingCallIsComplete(DBusPendingCall* pending_call, - ResponseCallback response_callback, - ErrorCallback error_callback, + CallMethodInternalCallback callback, base::TimeTicks start_time); - // Runs the response callback with the given response object. - void RunResponseCallback(ResponseCallback response_callback, - ErrorCallback error_callback, - base::TimeTicks start_time, - DBusMessage* response_message); + // Runs the CallMethodInternalCallback with the given response object. + void RunCallMethodInternalCallback(CallMethodInternalCallback callback, + base::TimeTicks start_time, + DBusMessage* response_message); // Redirects the function call to OnPendingCallIsComplete(). static void OnPendingCallIsCompleteThunk(DBusPendingCall* pending_call, @@ -272,11 +277,14 @@ class CHROME_DBUS_EXPORT ObjectProxy const base::StringPiece& error_name, const base::StringPiece& error_message) const; - // Used as ErrorCallback by CallMethod(). - void OnCallMethodError(const std::string& interface_name, - const std::string& method_name, - ResponseCallback response_callback, - ErrorResponse* error_response); + // Used as CallMethodInternalCallback by CallMethod(). (i.e. ErrorCallback + // wasn't provided, hence response_callback will be used for handling the + // error response). + void OnCallMethod(const std::string& interface_name, + const std::string& method_name, + ResponseCallback response_callback, + Response* response, + ErrorResponse* error_response); // Adds the match rule to the bus and associate the callback with the signal. bool AddMatchRuleWithCallback(const std::string& match_rule, @@ -310,7 +318,7 @@ class CHROME_DBUS_EXPORT ObjectProxy // The method table where keys are absolute signal names (i.e. interface // name + signal name), and values are lists of the corresponding callbacks. - typedef std::map<std::string, std::vector<SignalCallback> > MethodTable; + using MethodTable = std::map<std::string, std::vector<SignalCallback>>; MethodTable method_table_; // The callback called when NameOwnerChanged signal is received. diff --git a/chromium/dbus/values_util_unittest.cc b/chromium/dbus/values_util_unittest.cc index a4854dc40f4..1ee2b69b764 100644 --- a/chromium/dbus/values_util_unittest.cc +++ b/chromium/dbus/values_util_unittest.cc @@ -339,9 +339,9 @@ TEST(ValuesUtilTest, PopDictionaryWithDottedStringKey) { // Create the expected value. base::DictionaryValue dictionary_value; - dictionary_value.SetBooleanWithoutPathExpansion(kKey1, kBoolValue); - dictionary_value.SetIntegerWithoutPathExpansion(kKey2, kInt32Value); - dictionary_value.SetDoubleWithoutPathExpansion(kKey3, kDoubleValue); + dictionary_value.SetKey(kKey1, base::Value(kBoolValue)); + dictionary_value.SetKey(kKey2, base::Value(kInt32Value)); + dictionary_value.SetKey(kKey3, base::Value(kDoubleValue)); // Pop a dictinoary. MessageReader reader(response.get()); @@ -377,7 +377,7 @@ TEST(ValuesUtilTest, PopDoubleToIntDictionary) { for (size_t i = 0; i != values.size(); ++i) { std::string key_string; base::JSONWriter::Write(base::Value(keys[i]), &key_string); - dictionary_value.SetIntegerWithoutPathExpansion(key_string, values[i]); + dictionary_value.SetKey(key_string, base::Value(values[i])); } // Pop a dictionary. |