summaryrefslogtreecommitdiff
path: root/chromium/dbus
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-18 14:34:04 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-10-04 11:15:27 +0000
commite6430e577f105ad8813c92e75c54660c4985026e (patch)
tree88115e5d1fb471fea807111924dcccbeadbf9e4f /chromium/dbus
parent53d399fe6415a96ea6986ec0d402a9c07da72453 (diff)
downloadqtwebengine-chromium-e6430e577f105ad8813c92e75c54660c4985026e.tar.gz
BASELINE: Update Chromium to 61.0.3163.99
Change-Id: I8452f34574d88ca2b27af9bd56fc9ff3f16b1367 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/dbus')
-rw-r--r--chromium/dbus/bus.cc121
-rw-r--r--chromium/dbus/mock_object_proxy.h31
-rw-r--r--chromium/dbus/mock_unittest.cc26
-rw-r--r--chromium/dbus/object_manager.h4
-rw-r--r--chromium/dbus/values_util_unittest.cc17
5 files changed, 74 insertions, 125 deletions
diff --git a/chromium/dbus/bus.cc b/chromium/dbus/bus.cc
index b35718d0471..a3139e44639 100644
--- a/chromium/dbus/bus.cc
+++ b/chromium/dbus/bus.cc
@@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/files/file_descriptor_watcher_posix.h"
#include "base/logging.h"
+#include "base/memory/weak_ptr.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread.h"
@@ -47,10 +48,10 @@ const char kServiceNameOwnerChangeMatchRule[] =
class Watch {
public:
explicit Watch(DBusWatch* watch) : raw_watch_(watch) {
- dbus_watch_set_data(raw_watch_, this, NULL);
+ dbus_watch_set_data(raw_watch_, this, nullptr);
}
- ~Watch() { dbus_watch_set_data(raw_watch_, NULL, NULL); }
+ ~Watch() { dbus_watch_set_data(raw_watch_, nullptr, nullptr); }
// Returns true if the underlying file descriptor is ready to be watched.
bool IsReadyToBeWatched() {
@@ -92,24 +93,23 @@ class Watch {
DBusWatch* raw_watch_;
std::unique_ptr<base::FileDescriptorWatcher::Controller> read_watcher_;
std::unique_ptr<base::FileDescriptorWatcher::Controller> write_watcher_;
+
+ DISALLOW_COPY_AND_ASSIGN(Watch);
};
// The class is used for monitoring the timeout used for D-Bus method
// calls.
-//
-// Unlike Watch, Timeout is a ref counted object, to ensure that |this| of
-// the object is is alive when HandleTimeout() is called. It's unlikely
-// but it may be possible that HandleTimeout() is called after
-// Bus::OnRemoveTimeout(). That's why we don't simply delete the object in
-// Bus::OnRemoveTimeout().
-class Timeout : public base::RefCountedThreadSafe<Timeout> {
+class Timeout {
public:
explicit Timeout(DBusTimeout* timeout)
- : raw_timeout_(timeout),
- monitoring_is_active_(false),
- is_completed(false) {
- dbus_timeout_set_data(raw_timeout_, this, NULL);
- AddRef(); // Balanced on Complete().
+ : raw_timeout_(timeout), weak_ptr_factory_(this) {
+ // Associated |this| with the underlying DBusTimeout.
+ dbus_timeout_set_data(raw_timeout_, this, nullptr);
+ }
+
+ ~Timeout() {
+ // Remove the association between |this| and the |raw_timeout_|.
+ dbus_timeout_set_data(raw_timeout_, nullptr, nullptr);
}
// Returns true if the timeout is ready to be monitored.
@@ -121,54 +121,27 @@ class Timeout : public base::RefCountedThreadSafe<Timeout> {
void StartMonitoring(Bus* bus) {
bus->GetDBusTaskRunner()->PostDelayedTask(
FROM_HERE,
- base::Bind(&Timeout::HandleTimeout, this),
+ base::Bind(&Timeout::HandleTimeout, weak_ptr_factory_.GetWeakPtr()),
GetInterval());
- monitoring_is_active_ = true;
}
// Stops monitoring the timeout.
- void StopMonitoring() {
- // We cannot take back the delayed task we posted in
- // StartMonitoring(), so we just mark the monitoring is inactive now.
- monitoring_is_active_ = false;
- }
+ void StopMonitoring() { weak_ptr_factory_.InvalidateWeakPtrs(); }
- // Returns the interval.
base::TimeDelta GetInterval() {
return base::TimeDelta::FromMilliseconds(
dbus_timeout_get_interval(raw_timeout_));
}
- // Cleans up the raw_timeout and marks that timeout is completed.
- // See the class comment above for why we are doing this.
- void Complete() {
- dbus_timeout_set_data(raw_timeout_, NULL, NULL);
- is_completed = true;
- Release();
- }
-
private:
- friend class base::RefCountedThreadSafe<Timeout>;
- ~Timeout() {
- }
+ // Calls DBus to handle the timeout.
+ void HandleTimeout() { CHECK(dbus_timeout_handle(raw_timeout_)); }
- // Handles the timeout.
- void HandleTimeout() {
- // If the timeout is marked completed, we should do nothing. This can
- // occur if this function is called after Bus::OnRemoveTimeout().
- if (is_completed)
- return;
- // Skip if monitoring is canceled.
- if (!monitoring_is_active_)
- return;
+ DBusTimeout* raw_timeout_;
- const bool success = dbus_timeout_handle(raw_timeout_);
- CHECK(success) << "Unable to allocate memory";
- }
+ base::WeakPtrFactory<Timeout> weak_ptr_factory_;
- DBusTimeout* raw_timeout_;
- bool monitoring_is_active_;
- bool is_completed;
+ DISALLOW_COPY_AND_ASSIGN(Timeout);
};
} // namespace
@@ -187,7 +160,7 @@ Bus::Bus(const Options& options)
dbus_task_runner_(options.dbus_task_runner),
on_shutdown_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED),
- connection_(NULL),
+ connection_(nullptr),
origin_thread_id_(base::PlatformThread::CurrentId()),
async_operations_set_up_(false),
shutdown_completed_(false),
@@ -276,7 +249,7 @@ void Bus::RemoveObjectProxyInternal(scoped_refptr<ObjectProxy> object_proxy,
const base::Closure& callback) {
AssertOnDBusThread();
- object_proxy.get()->Detach();
+ object_proxy->Detach();
GetOriginTaskRunner()->PostTask(FROM_HERE, callback);
}
@@ -388,10 +361,10 @@ void Bus::RemoveObjectManagerInternalHelper(
scoped_refptr<dbus::ObjectManager> object_manager,
const base::Closure& callback) {
AssertOnOriginThread();
- DCHECK(object_manager.get());
+ DCHECK(object_manager);
// Release the object manager and run the callback.
- object_manager = NULL;
+ object_manager = nullptr;
callback.Run();
}
@@ -510,13 +483,13 @@ void Bus::ShutdownAndBlock() {
dbus_connection_unref(connection_);
}
- connection_ = NULL;
+ connection_ = nullptr;
shutdown_completed_ = true;
}
void Bus::ShutdownOnDBusThreadAndBlock() {
AssertOnOriginThread();
- DCHECK(dbus_task_runner_.get());
+ DCHECK(dbus_task_runner_);
GetDBusTaskRunner()->PostTask(
FROM_HERE,
@@ -622,27 +595,18 @@ bool Bus::SetUpAsyncOperations() {
// be called when the incoming data is ready.
ProcessAllIncomingDataIfAny();
- bool success = dbus_connection_set_watch_functions(connection_,
- &Bus::OnAddWatchThunk,
- &Bus::OnRemoveWatchThunk,
- &Bus::OnToggleWatchThunk,
- this,
- NULL);
+ bool success = dbus_connection_set_watch_functions(
+ connection_, &Bus::OnAddWatchThunk, &Bus::OnRemoveWatchThunk,
+ &Bus::OnToggleWatchThunk, this, nullptr);
CHECK(success) << "Unable to allocate memory";
- success = dbus_connection_set_timeout_functions(connection_,
- &Bus::OnAddTimeoutThunk,
- &Bus::OnRemoveTimeoutThunk,
- &Bus::OnToggleTimeoutThunk,
- this,
- NULL);
+ success = dbus_connection_set_timeout_functions(
+ connection_, &Bus::OnAddTimeoutThunk, &Bus::OnRemoveTimeoutThunk,
+ &Bus::OnToggleTimeoutThunk, this, nullptr);
CHECK(success) << "Unable to allocate memory";
dbus_connection_set_dispatch_status_function(
- connection_,
- &Bus::OnDispatchStatusChangedThunk,
- this,
- NULL);
+ connection_, &Bus::OnDispatchStatusChangedThunk, this, nullptr);
async_operations_set_up_ = true;
@@ -692,8 +656,8 @@ void Bus::AddFilterFunction(DBusHandleMessageFunction filter_function,
return;
}
- const bool success = dbus_connection_add_filter(
- connection_, filter_function, user_data, NULL);
+ const bool success = dbus_connection_add_filter(connection_, filter_function,
+ user_data, nullptr);
CHECK(success) << "Unable to allocate memory";
filter_functions_added_.insert(filter_data_pair);
}
@@ -822,19 +786,19 @@ void Bus::ProcessAllIncomingDataIfAny() {
}
base::TaskRunner* Bus::GetDBusTaskRunner() {
- if (dbus_task_runner_.get())
+ if (dbus_task_runner_)
return dbus_task_runner_.get();
else
return GetOriginTaskRunner();
}
base::TaskRunner* Bus::GetOriginTaskRunner() {
- DCHECK(origin_task_runner_.get());
+ DCHECK(origin_task_runner_);
return origin_task_runner_.get();
}
bool Bus::HasDBusThread() {
- return dbus_task_runner_.get() != NULL;
+ return dbus_task_runner_ != nullptr;
}
void Bus::AssertOnOriginThread() {
@@ -844,7 +808,7 @@ void Bus::AssertOnOriginThread() {
void Bus::AssertOnDBusThread() {
base::ThreadRestrictions::AssertIOAllowed();
- if (dbus_task_runner_.get()) {
+ if (dbus_task_runner_) {
DCHECK(dbus_task_runner_->RunsTasksInCurrentSequence());
} else {
AssertOnOriginThread();
@@ -1052,8 +1016,7 @@ void Bus::OnToggleWatch(DBusWatch* raw_watch) {
dbus_bool_t Bus::OnAddTimeout(DBusTimeout* raw_timeout) {
AssertOnDBusThread();
- // timeout will be deleted when raw_timeout is removed in
- // OnRemoveTimeoutThunk().
+ // |timeout| will be deleted by OnRemoveTimeoutThunk().
Timeout* timeout = new Timeout(raw_timeout);
if (timeout->IsReadyToBeMonitored()) {
timeout->StartMonitoring(this);
@@ -1066,7 +1029,7 @@ void Bus::OnRemoveTimeout(DBusTimeout* raw_timeout) {
AssertOnDBusThread();
Timeout* timeout = static_cast<Timeout*>(dbus_timeout_get_data(raw_timeout));
- timeout->Complete();
+ delete timeout;
--num_pending_timeouts_;
}
diff --git a/chromium/dbus/mock_object_proxy.h b/chromium/dbus/mock_object_proxy.h
index 17d2a9f0f4e..6b0258bc58d 100644
--- a/chromium/dbus/mock_object_proxy.h
+++ b/chromium/dbus/mock_object_proxy.h
@@ -5,6 +5,7 @@
#ifndef DBUS_MOCK_OBJECT_PROXY_H_
#define DBUS_MOCK_OBJECT_PROXY_H_
+#include <memory>
#include <string>
#include "dbus/message.h"
@@ -21,29 +22,13 @@ class MockObjectProxy : public ObjectProxy {
const std::string& service_name,
const ObjectPath& object_path);
- // GMock doesn't support the return type of std::unique_ptr<> because
- // std::unique_ptr is uncopyable. This is a workaround which defines
- // |MockCallMethodAndBlock| as a mock method and makes
- // |CallMethodAndBlock| call the mocked method. Use |MockCallMethodAndBlock|
- // for setting/testing expectations.
- MOCK_METHOD3(MockCallMethodAndBlockWithErrorDetails,
- Response*(MethodCall* method_call,
- int timeout_ms,
- ScopedDBusError* error));
- std::unique_ptr<Response> CallMethodAndBlockWithErrorDetails(
- MethodCall* method_call,
- int timeout_ms,
- ScopedDBusError* error) override {
- return std::unique_ptr<Response>(
- MockCallMethodAndBlockWithErrorDetails(method_call, timeout_ms, error));
- }
- MOCK_METHOD2(MockCallMethodAndBlock, Response*(MethodCall* method_call,
- int timeout_ms));
- std::unique_ptr<Response> CallMethodAndBlock(MethodCall* method_call,
- int timeout_ms) override {
- return std::unique_ptr<Response>(
- MockCallMethodAndBlock(method_call, timeout_ms));
- }
+ MOCK_METHOD3(CallMethodAndBlockWithErrorDetails,
+ std::unique_ptr<Response>(MethodCall* method_call,
+ int timeout_ms,
+ ScopedDBusError* error));
+ 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));
diff --git a/chromium/dbus/mock_unittest.cc b/chromium/dbus/mock_unittest.cc
index 15bdf2759ad..7f3d759eaf4 100644
--- a/chromium/dbus/mock_unittest.cc
+++ b/chromium/dbus/mock_unittest.cc
@@ -45,10 +45,10 @@ class MockTest : public testing::Test {
// Set an expectation so mock_proxy's CallMethodAndBlock() will use
// CreateMockProxyResponse() to return responses.
- EXPECT_CALL(*mock_proxy_.get(), MockCallMethodAndBlock(_, _))
+ EXPECT_CALL(*mock_proxy_.get(), CallMethodAndBlock(_, _))
.WillRepeatedly(Invoke(this, &MockTest::CreateMockProxyResponse));
EXPECT_CALL(*mock_proxy_.get(),
- MockCallMethodAndBlockWithErrorDetails(_, _, _))
+ CallMethodAndBlockWithErrorDetails(_, _, _))
.WillRepeatedly(
Invoke(this, &MockTest::CreateMockProxyResponseWithErrorDetails));
@@ -91,8 +91,8 @@ class MockTest : public testing::Test {
private:
// Returns a response for the given method call. Used to implement
// CallMethodAndBlock() for |mock_proxy_|.
- Response* CreateMockProxyResponse(MethodCall* method_call,
- int timeout_ms) {
+ std::unique_ptr<Response> CreateMockProxyResponse(MethodCall* method_call,
+ int timeout_ms) {
if (method_call->GetInterface() == "org.chromium.TestInterface" &&
method_call->GetMember() == "Echo") {
MessageReader reader(method_call);
@@ -101,18 +101,18 @@ class MockTest : public testing::Test {
std::unique_ptr<Response> response = Response::CreateEmpty();
MessageWriter writer(response.get());
writer.AppendString(text_message);
- return response.release();
+ return response;
}
}
LOG(ERROR) << "Unexpected method call: " << method_call->ToString();
- return NULL;
+ return nullptr;
}
- Response* CreateMockProxyResponseWithErrorDetails(
+ std::unique_ptr<Response> CreateMockProxyResponseWithErrorDetails(
MethodCall* method_call, int timeout_ms, ScopedDBusError* error) {
dbus_set_error(error->get(), DBUS_ERROR_NOT_SUPPORTED, "Not implemented");
- return NULL;
+ return nullptr;
}
// Creates a response and runs the given response callback in the
@@ -121,19 +121,19 @@ class MockTest : public testing::Test {
MethodCall* method_call,
int timeout_ms,
ObjectProxy::ResponseCallback response_callback) {
- Response* response = CreateMockProxyResponse(method_call, timeout_ms);
+ 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, response));
+ response_callback, base::Passed(&response)));
}
// Runs the given response callback with the given response.
void RunResponseCallback(
ObjectProxy::ResponseCallback response_callback,
- Response* response) {
- response_callback.Run(response);
- delete response;
+ std::unique_ptr<Response> response) {
+ response_callback.Run(response.get());
}
};
diff --git a/chromium/dbus/object_manager.h b/chromium/dbus/object_manager.h
index 842a1378a26..c17f1408cda 100644
--- a/chromium/dbus/object_manager.h
+++ b/chromium/dbus/object_manager.h
@@ -211,12 +211,12 @@ public:
// Returns a ObjectProxy pointer for the given |object_path|. Unlike
// the equivalent method on Bus this will return NULL if the object
- // manager has not been informed of that object's existance.
+ // manager has not been informed of that object's existence.
ObjectProxy* GetObjectProxy(const ObjectPath& object_path);
// Returns a PropertySet* pointer for the given |object_path| and
// |interface_name|, or NULL if the object manager has not been informed of
- // that object's existance or the interface's properties. The caller should
+ // that object's existence or the interface's properties. The caller should
// cast the returned pointer to the appropriate type, e.g.:
// static_cast<Properties*>(GetProperties(object_path, my_interface));
PropertySet* GetProperties(const ObjectPath& object_path,
diff --git a/chromium/dbus/values_util_unittest.cc b/chromium/dbus/values_util_unittest.cc
index 0cc7d9164f8..a4854dc40f4 100644
--- a/chromium/dbus/values_util_unittest.cc
+++ b/chromium/dbus/values_util_unittest.cc
@@ -14,6 +14,7 @@
#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"
@@ -516,11 +517,11 @@ TEST(ValuesUtilTest, AppendDictionary) {
const double kDoubleValue = 4.9;
const std::string kStringValue = "fifty";
- base::ListValue* list_value = new base::ListValue();
+ auto list_value = base::MakeUnique<base::ListValue>();
list_value->AppendBoolean(kBoolValue);
list_value->AppendInteger(kInt32Value);
- base::DictionaryValue* dictionary_value = new base::DictionaryValue();
+ auto dictionary_value = base::MakeUnique<base::DictionaryValue>();
dictionary_value->SetBoolean(kKey1, kBoolValue);
dictionary_value->SetInteger(kKey2, kDoubleValue);
@@ -529,8 +530,8 @@ TEST(ValuesUtilTest, AppendDictionary) {
test_dictionary.SetInteger(kKey2, kInt32Value);
test_dictionary.SetDouble(kKey3, kDoubleValue);
test_dictionary.SetString(kKey4, kStringValue);
- test_dictionary.Set(kKey5, list_value); // takes ownership
- test_dictionary.Set(kKey6, dictionary_value); // takes ownership
+ test_dictionary.Set(kKey5, std::move(list_value));
+ test_dictionary.Set(kKey6, std::move(dictionary_value));
std::unique_ptr<Response> response(Response::CreateEmpty());
MessageWriter writer(response.get());
@@ -563,11 +564,11 @@ TEST(ValuesUtilTest, AppendDictionaryAsVariant) {
const double kDoubleValue = 4.9;
const std::string kStringValue = "fifty";
- base::ListValue* list_value = new base::ListValue();
+ auto list_value = base::MakeUnique<base::ListValue>();
list_value->AppendBoolean(kBoolValue);
list_value->AppendInteger(kInt32Value);
- base::DictionaryValue* dictionary_value = new base::DictionaryValue();
+ auto dictionary_value = base::MakeUnique<base::DictionaryValue>();
dictionary_value->SetBoolean(kKey1, kBoolValue);
dictionary_value->SetInteger(kKey2, kDoubleValue);
@@ -576,8 +577,8 @@ TEST(ValuesUtilTest, AppendDictionaryAsVariant) {
test_dictionary.SetInteger(kKey2, kInt32Value);
test_dictionary.SetDouble(kKey3, kDoubleValue);
test_dictionary.SetString(kKey4, kStringValue);
- test_dictionary.Set(kKey5, list_value); // takes ownership
- test_dictionary.Set(kKey6, dictionary_value); // takes ownership
+ test_dictionary.Set(kKey5, std::move(list_value));
+ test_dictionary.Set(kKey6, std::move(dictionary_value));
std::unique_ptr<Response> response(Response::CreateEmpty());
MessageWriter writer(response.get());