diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-07-12 14:07:37 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-07-17 10:29:26 +0000 |
commit | ec02ee4181c49b61fce1c8fb99292dbb8139cc90 (patch) | |
tree | 25cde714b2b71eb639d1cd53f5a22e9ba76e14ef /chromium/dbus | |
parent | bb09965444b5bb20b096a291445170876225268d (diff) | |
download | qtwebengine-chromium-ec02ee4181c49b61fce1c8fb99292dbb8139cc90.tar.gz |
BASELINE: Update Chromium to 59.0.3071.134
Change-Id: Id02ef6fb2204c5fd21668a1c3e6911c83b17585a
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/dbus')
-rw-r--r-- | chromium/dbus/bus.cc | 68 | ||||
-rw-r--r-- | chromium/dbus/bus_unittest.cc | 9 | ||||
-rw-r--r-- | chromium/dbus/message.cc | 5 | ||||
-rw-r--r-- | chromium/dbus/object_proxy_unittest.cc | 9 | ||||
-rw-r--r-- | chromium/dbus/values_util.cc | 6 | ||||
-rw-r--r-- | chromium/dbus/values_util_unittest.cc | 16 |
6 files changed, 55 insertions, 58 deletions
diff --git a/chromium/dbus/bus.cc b/chromium/dbus/bus.cc index a86971736f7..3d77d0fe45a 100644 --- a/chromium/dbus/bus.cc +++ b/chromium/dbus/bus.cc @@ -6,9 +6,11 @@ #include <stddef.h> +#include <memory> + #include "base/bind.h" +#include "base/files/file_descriptor_watcher_posix.h" #include "base/logging.h" -#include "base/message_loop/message_loop.h" #include "base/stl_util.h" #include "base/strings/stringprintf.h" #include "base/threading/thread.h" @@ -42,14 +44,13 @@ const char kServiceNameOwnerChangeMatchRule[] = // The class is used for watching the file descriptor used for D-Bus // communication. -class Watch : public base::MessagePumpLibevent::Watcher { +class Watch { public: - explicit Watch(DBusWatch* watch) - : raw_watch_(watch), file_descriptor_watcher_(FROM_HERE) { + explicit Watch(DBusWatch* watch) : raw_watch_(watch) { dbus_watch_set_data(raw_watch_, this, NULL); } - ~Watch() override { dbus_watch_set_data(raw_watch_, NULL, NULL); } + ~Watch() { dbus_watch_set_data(raw_watch_, NULL, NULL); } // Returns true if the underlying file descriptor is ready to be watched. bool IsReadyToBeWatched() { @@ -59,44 +60,38 @@ class Watch : public base::MessagePumpLibevent::Watcher { // Starts watching the underlying file descriptor. void StartWatching() { const int file_descriptor = dbus_watch_get_unix_fd(raw_watch_); - const int flags = dbus_watch_get_flags(raw_watch_); - - base::MessageLoopForIO::Mode mode = base::MessageLoopForIO::WATCH_READ; - if ((flags & DBUS_WATCH_READABLE) && (flags & DBUS_WATCH_WRITABLE)) - mode = base::MessageLoopForIO::WATCH_READ_WRITE; - else if (flags & DBUS_WATCH_READABLE) - mode = base::MessageLoopForIO::WATCH_READ; - else if (flags & DBUS_WATCH_WRITABLE) - mode = base::MessageLoopForIO::WATCH_WRITE; - else - NOTREACHED(); - - const bool persistent = true; // Watch persistently. - const bool success = base::MessageLoopForIO::current()->WatchFileDescriptor( - file_descriptor, persistent, mode, &file_descriptor_watcher_, this); - CHECK(success) << "Unable to allocate memory"; + const unsigned int flags = dbus_watch_get_flags(raw_watch_); + + // Using base::Unretained(this) is safe because watches are automatically + // canceled when |read_watcher_| and |write_watcher_| are destroyed. + if (flags & DBUS_WATCH_READABLE) { + read_watcher_ = base::FileDescriptorWatcher::WatchReadable( + file_descriptor, + base::Bind(&Watch::OnFileReady, base::Unretained(this), + DBUS_WATCH_READABLE)); + } + if (flags & DBUS_WATCH_WRITABLE) { + write_watcher_ = base::FileDescriptorWatcher::WatchWritable( + file_descriptor, + base::Bind(&Watch::OnFileReady, base::Unretained(this), + DBUS_WATCH_WRITABLE)); + } } // Stops watching the underlying file descriptor. void StopWatching() { - file_descriptor_watcher_.StopWatchingFileDescriptor(); + read_watcher_.reset(); + write_watcher_.reset(); } private: - // Implement MessagePumpLibevent::Watcher. - void OnFileCanReadWithoutBlocking(int file_descriptor) override { - const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_READABLE); - CHECK(success) << "Unable to allocate memory"; - } - - // Implement MessagePumpLibevent::Watcher. - void OnFileCanWriteWithoutBlocking(int file_descriptor) override { - const bool success = dbus_watch_handle(raw_watch_, DBUS_WATCH_WRITABLE); - CHECK(success) << "Unable to allocate memory"; + void OnFileReady(unsigned int flags) { + CHECK(dbus_watch_handle(raw_watch_, flags)) << "Unable to allocate memory"; } DBusWatch* raw_watch_; - base::MessagePumpLibevent::FileDescriptorWatcher file_descriptor_watcher_; + std::unique_ptr<base::FileDescriptorWatcher::Controller> read_watcher_; + std::unique_ptr<base::FileDescriptorWatcher::Controller> write_watcher_; }; // The class is used for monitoring the timeout used for D-Bus method @@ -1048,13 +1043,10 @@ void Bus::OnToggleWatch(DBusWatch* raw_watch) { AssertOnDBusThread(); Watch* watch = static_cast<Watch*>(dbus_watch_get_data(raw_watch)); - if (watch->IsReadyToBeWatched()) { + if (watch->IsReadyToBeWatched()) watch->StartWatching(); - } else { - // It's safe to call this if StartWatching() wasn't called, per - // message_pump_libevent.h. + else watch->StopWatching(); - } } dbus_bool_t Bus::OnAddTimeout(DBusTimeout* raw_timeout) { diff --git a/chromium/dbus/bus_unittest.cc b/chromium/dbus/bus_unittest.cc index 84bbb783f39..71101e69682 100644 --- a/chromium/dbus/bus_unittest.cc +++ b/chromium/dbus/bus_unittest.cc @@ -5,6 +5,7 @@ #include "dbus/bus.h" #include "base/bind.h" +#include "base/files/file_descriptor_watcher_posix.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/message_loop/message_loop.h" @@ -318,9 +319,11 @@ TEST(BusTest, DoubleAddAndRemoveMatch) { } TEST(BusTest, ListenForServiceOwnerChange) { - // Setup the current thread's MessageLoop. Must be of TYPE_IO for the - // listeners to work. - base::MessageLoop message_loop(base::MessageLoop::TYPE_IO); + base::MessageLoopForIO message_loop; + + // This enables FileDescriptorWatcher, which is required by dbus::Watch. + base::FileDescriptorWatcher file_descriptor_watcher(&message_loop); + RunLoopWithExpectedCount run_loop_state; // Create the bus. diff --git a/chromium/dbus/message.cc b/chromium/dbus/message.cc index c8663f72ad6..b33345ec236 100644 --- a/chromium/dbus/message.cc +++ b/chromium/dbus/message.cc @@ -13,12 +13,7 @@ #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "dbus/object_path.h" - -#if defined(USE_SYSTEM_PROTOBUF) -#include <google/protobuf/message_lite.h> -#else #include "third_party/protobuf/src/google/protobuf/message_lite.h" -#endif namespace { diff --git a/chromium/dbus/object_proxy_unittest.cc b/chromium/dbus/object_proxy_unittest.cc index 189ef9074a0..5e3d3e2e9d1 100644 --- a/chromium/dbus/object_proxy_unittest.cc +++ b/chromium/dbus/object_proxy_unittest.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "dbus/object_proxy.h" #include "base/bind.h" +#include "base/files/file_descriptor_watcher_posix.h" #include "base/memory/ref_counted.h" #include "base/run_loop.h" #include "dbus/bus.h" -#include "dbus/object_proxy.h" #include "dbus/test_service.h" #include "testing/gtest/include/gtest/gtest.h" @@ -15,6 +16,8 @@ namespace { class ObjectProxyTest : public testing::Test { protected: + ObjectProxyTest() : file_descriptor_watcher_(&message_loop_) {} + void SetUp() override { Bus::Options bus_options; bus_options.bus_type = Bus::SESSION; @@ -25,6 +28,10 @@ class ObjectProxyTest : public testing::Test { void TearDown() override { bus_->ShutdownAndBlock(); } base::MessageLoopForIO message_loop_; + + // This enables FileDescriptorWatcher, which is required by dbus::Watch. + base::FileDescriptorWatcher file_descriptor_watcher_; + scoped_refptr<Bus> bus_; }; diff --git a/chromium/dbus/values_util.cc b/chromium/dbus/values_util.cc index 58b2b9ed7f7..e57380d1fa7 100644 --- a/chromium/dbus/values_util.cc +++ b/chromium/dbus/values_util.cc @@ -159,13 +159,13 @@ std::unique_ptr<base::Value> PopDataAsValue(MessageReader* reader) { 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: { @@ -282,7 +282,7 @@ void AppendValueData(MessageWriter* writer, const base::Value& value) { dbus::MessageWriter array_writer(NULL); writer->OpenArray("v", &array_writer); for (const auto& value : *list) { - AppendValueDataAsVariant(&array_writer, *value); + AppendValueDataAsVariant(&array_writer, value); } writer->CloseContainer(&array_writer); break; diff --git a/chromium/dbus/values_util_unittest.cc b/chromium/dbus/values_util_unittest.cc index 38d94f824b1..13c496bb145 100644 --- a/chromium/dbus/values_util_unittest.cc +++ b/chromium/dbus/values_util_unittest.cc @@ -100,17 +100,17 @@ TEST(ValuesUtilTest, PopBasicTypes) { // Pop a string. value = PopDataAsValue(&reader); ASSERT_TRUE(value.get() != NULL); - expected_value.reset(new base::StringValue(kStringValue)); + expected_value.reset(new base::Value(kStringValue)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop an empty string. value = PopDataAsValue(&reader); ASSERT_TRUE(value.get() != NULL); - expected_value.reset(new base::StringValue(kEmptyStringValue)); + expected_value.reset(new base::Value(kEmptyStringValue)); EXPECT_TRUE(value->Equals(expected_value.get())); // Pop an object path. value = PopDataAsValue(&reader); ASSERT_TRUE(value.get() != NULL); - expected_value.reset(new base::StringValue(kObjectPathValue.value())); + expected_value.reset(new base::Value(kObjectPathValue.value())); EXPECT_TRUE(value->Equals(expected_value.get())); } @@ -148,7 +148,7 @@ TEST(ValuesUtilTest, PopVariant) { // Pop a string. value = PopDataAsValue(&reader); ASSERT_TRUE(value.get() != NULL); - expected_value.reset(new base::StringValue(kStringValue)); + expected_value.reset(new base::Value(kStringValue)); EXPECT_TRUE(value->Equals(expected_value.get())); } @@ -391,7 +391,7 @@ TEST(ValuesUtilTest, AppendBasicTypes) { const base::Value kBoolValue(false); const base::Value kIntegerValue(42); const base::Value kDoubleValue(4.2); - const base::StringValue kStringValue("string"); + const base::Value kStringValue("string"); std::unique_ptr<Response> response(Response::CreateEmpty()); MessageWriter writer(response.get()); @@ -420,7 +420,7 @@ TEST(ValuesUtilTest, AppendBasicTypesAsVariant) { const base::Value kBoolValue(false); const base::Value kIntegerValue(42); const base::Value kDoubleValue(4.2); - const base::StringValue kStringValue("string"); + const base::Value kStringValue("string"); std::unique_ptr<Response> response(Response::CreateEmpty()); MessageWriter writer(response.get()); @@ -449,7 +449,7 @@ TEST(ValuesUtilTest, AppendValueDataBasicTypes) { const base::Value kBoolValue(false); const base::Value kIntegerValue(42); const base::Value kDoubleValue(4.2); - const base::StringValue kStringValue("string"); + const base::Value kStringValue("string"); std::unique_ptr<Response> response(Response::CreateEmpty()); MessageWriter writer(response.get()); @@ -478,7 +478,7 @@ TEST(ValuesUtilTest, AppendValueDataAsVariantBasicTypes) { const base::Value kBoolValue(false); const base::Value kIntegerValue(42); const base::Value kDoubleValue(4.2); - const base::StringValue kStringValue("string"); + const base::Value kStringValue("string"); std::unique_ptr<Response> response(Response::CreateEmpty()); MessageWriter writer(response.get()); |