| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "dbus/bus.h" | 5 #include "dbus/bus.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 base::MessageLoop message_loop; | 130 base::MessageLoop message_loop; |
| 131 | 131 |
| 132 // Start the D-Bus thread. | 132 // Start the D-Bus thread. |
| 133 base::Thread::Options thread_options; | 133 base::Thread::Options thread_options; |
| 134 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 134 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 135 base::Thread dbus_thread("D-Bus thread"); | 135 base::Thread dbus_thread("D-Bus thread"); |
| 136 dbus_thread.StartWithOptions(thread_options); | 136 dbus_thread.StartWithOptions(thread_options); |
| 137 | 137 |
| 138 // Create the bus. | 138 // Create the bus. |
| 139 Bus::Options options; | 139 Bus::Options options; |
| 140 options.dbus_task_runner = dbus_thread.message_loop_proxy(); | 140 options.dbus_task_runner = dbus_thread.task_runner(); |
| 141 scoped_refptr<Bus> bus = new Bus(options); | 141 scoped_refptr<Bus> bus = new Bus(options); |
| 142 ASSERT_FALSE(bus->shutdown_completed()); | 142 ASSERT_FALSE(bus->shutdown_completed()); |
| 143 | 143 |
| 144 // Try to remove a non existant object proxy should return false. | 144 // Try to remove a non existant object proxy should return false. |
| 145 ASSERT_FALSE( | 145 ASSERT_FALSE( |
| 146 bus->RemoveObjectProxy("org.chromium.TestService", | 146 bus->RemoveObjectProxy("org.chromium.TestService", |
| 147 ObjectPath("/org/chromium/TestObject"), | 147 ObjectPath("/org/chromium/TestObject"), |
| 148 base::Bind(&base::DoNothing))); | 148 base::Bind(&base::DoNothing))); |
| 149 | 149 |
| 150 ObjectProxy* object_proxy1 = | 150 ObjectProxy* object_proxy1 = |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 210 |
| 211 TEST(BusTest, UnregisterExportedObject) { | 211 TEST(BusTest, UnregisterExportedObject) { |
| 212 // Start the D-Bus thread. | 212 // Start the D-Bus thread. |
| 213 base::Thread::Options thread_options; | 213 base::Thread::Options thread_options; |
| 214 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 214 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 215 base::Thread dbus_thread("D-Bus thread"); | 215 base::Thread dbus_thread("D-Bus thread"); |
| 216 dbus_thread.StartWithOptions(thread_options); | 216 dbus_thread.StartWithOptions(thread_options); |
| 217 | 217 |
| 218 // Create the bus. | 218 // Create the bus. |
| 219 Bus::Options options; | 219 Bus::Options options; |
| 220 options.dbus_task_runner = dbus_thread.message_loop_proxy(); | 220 options.dbus_task_runner = dbus_thread.task_runner(); |
| 221 scoped_refptr<Bus> bus = new Bus(options); | 221 scoped_refptr<Bus> bus = new Bus(options); |
| 222 ASSERT_FALSE(bus->shutdown_completed()); | 222 ASSERT_FALSE(bus->shutdown_completed()); |
| 223 | 223 |
| 224 ExportedObject* object_proxy1 = | 224 ExportedObject* object_proxy1 = |
| 225 bus->GetExportedObject(ObjectPath("/org/chromium/TestObject")); | 225 bus->GetExportedObject(ObjectPath("/org/chromium/TestObject")); |
| 226 ASSERT_TRUE(object_proxy1); | 226 ASSERT_TRUE(object_proxy1); |
| 227 | 227 |
| 228 // Increment the reference count to the object proxy to avoid destroying it | 228 // Increment the reference count to the object proxy to avoid destroying it |
| 229 // calling UnregisterExportedObject. This ensures the dbus::ExportedObject is | 229 // calling UnregisterExportedObject. This ensures the dbus::ExportedObject is |
| 230 // not freed from memory. See http://crbug.com/137846 for details. | 230 // not freed from memory. See http://crbug.com/137846 for details. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 260 | 260 |
| 261 TEST(BusTest, ShutdownAndBlockWithDBusThread) { | 261 TEST(BusTest, ShutdownAndBlockWithDBusThread) { |
| 262 // Start the D-Bus thread. | 262 // Start the D-Bus thread. |
| 263 base::Thread::Options thread_options; | 263 base::Thread::Options thread_options; |
| 264 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 264 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 265 base::Thread dbus_thread("D-Bus thread"); | 265 base::Thread dbus_thread("D-Bus thread"); |
| 266 dbus_thread.StartWithOptions(thread_options); | 266 dbus_thread.StartWithOptions(thread_options); |
| 267 | 267 |
| 268 // Create the bus. | 268 // Create the bus. |
| 269 Bus::Options options; | 269 Bus::Options options; |
| 270 options.dbus_task_runner = dbus_thread.message_loop_proxy(); | 270 options.dbus_task_runner = dbus_thread.task_runner(); |
| 271 scoped_refptr<Bus> bus = new Bus(options); | 271 scoped_refptr<Bus> bus = new Bus(options); |
| 272 ASSERT_FALSE(bus->shutdown_completed()); | 272 ASSERT_FALSE(bus->shutdown_completed()); |
| 273 | 273 |
| 274 // Shut down synchronously. | 274 // Shut down synchronously. |
| 275 bus->ShutdownOnDBusThreadAndBlock(); | 275 bus->ShutdownOnDBusThreadAndBlock(); |
| 276 EXPECT_TRUE(bus->shutdown_completed()); | 276 EXPECT_TRUE(bus->shutdown_completed()); |
| 277 dbus_thread.Stop(); | 277 dbus_thread.Stop(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 TEST(BusTest, DoubleAddAndRemoveMatch) { | 280 TEST(BusTest, DoubleAddAndRemoveMatch) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 bus->UnlistenForServiceOwnerChange("org.chromium.TestService", callback1); | 388 bus->UnlistenForServiceOwnerChange("org.chromium.TestService", callback1); |
| 389 bus->UnlistenForServiceOwnerChange("org.chromium.TestService", callback2); | 389 bus->UnlistenForServiceOwnerChange("org.chromium.TestService", callback2); |
| 390 base::RunLoop().RunUntilIdle(); | 390 base::RunLoop().RunUntilIdle(); |
| 391 | 391 |
| 392 // Shut down synchronously. | 392 // Shut down synchronously. |
| 393 bus->ShutdownAndBlock(); | 393 bus->ShutdownAndBlock(); |
| 394 EXPECT_TRUE(bus->shutdown_completed()); | 394 EXPECT_TRUE(bus->shutdown_completed()); |
| 395 } | 395 } |
| 396 | 396 |
| 397 } // namespace dbus | 397 } // namespace dbus |
| OLD | NEW |