summaryrefslogtreecommitdiffstats
path: root/dbus/bus_unittest.cc
diff options
context:
space:
mode:
authordeymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-29 20:29:12 +0000
committerdeymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-29 20:29:12 +0000
commit38ecdc8a47778b52d7404ce69088ff8b6b2b3725 (patch)
treefb7c268ddd833c274431d423ef13005648fde770 /dbus/bus_unittest.cc
parent34337d3460533c85315e3e72eb3b4186b8389f19 (diff)
downloadchromium_src-38ecdc8a47778b52d7404ce69088ff8b6b2b3725.zip
chromium_src-38ecdc8a47778b52d7404ce69088ff8b6b2b3725.tar.gz
chromium_src-38ecdc8a47778b52d7404ce69088ff8b6b2b3725.tar.bz2
D-Bus: ObjectProxy remove function for Bus object.
This implements a remove function for an ObjectProxy owned by a bus object. Although the Bus object removes all the objects at shutdown, this functions permits to reduce the memory usage for objects no longer needed and reduce the number of dbus matching rules used in the bus connection. BUG=chromium:170182 TEST=BusTest.RemoveObjectProxy (run out/Debug/dbus_unittests) Review URL: https://chromiumcodereview.appspot.com/12022004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179400 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'dbus/bus_unittest.cc')
-rw-r--r--dbus/bus_unittest.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/dbus/bus_unittest.cc b/dbus/bus_unittest.cc
index bc155e7..0f57db1 100644
--- a/dbus/bus_unittest.cc
+++ b/dbus/bus_unittest.cc
@@ -84,6 +84,65 @@ TEST(BusTest, GetObjectProxyIgnoreUnknownService) {
bus->ShutdownAndBlock();
}
+TEST(BusTest, RemoveObjectProxy) {
+ // Setup the current thread's MessageLoop.
+ MessageLoop message_loop;
+
+ // Start the D-Bus thread.
+ base::Thread::Options thread_options;
+ thread_options.message_loop_type = MessageLoop::TYPE_IO;
+ base::Thread dbus_thread("D-Bus thread");
+ dbus_thread.StartWithOptions(thread_options);
+
+ // Create the bus.
+ dbus::Bus::Options options;
+ options.dbus_thread_message_loop_proxy = dbus_thread.message_loop_proxy();
+ scoped_refptr<dbus::Bus> bus = new dbus::Bus(options);
+ ASSERT_FALSE(bus->shutdown_completed());
+
+ // Try to remove a non existant object proxy should return false.
+ ASSERT_FALSE(
+ bus->RemoveObjectProxy("org.chromium.TestService",
+ dbus::ObjectPath("/org/chromium/TestObject"),
+ base::Bind(&base::DoNothing)));
+
+ dbus::ObjectProxy* object_proxy1 =
+ bus->GetObjectProxy("org.chromium.TestService",
+ dbus::ObjectPath("/org/chromium/TestObject"));
+ ASSERT_TRUE(object_proxy1);
+
+ // Increment the reference count to the object proxy to avoid destroying it
+ // while removing the object.
+ object_proxy1->AddRef();
+
+ // Remove the object from the bus. This will invalidate any other usage of
+ // object_proxy1 other than destroy it. We keep this object for a comparison
+ // at a later time.
+ ASSERT_TRUE(
+ bus->RemoveObjectProxy("org.chromium.TestService",
+ dbus::ObjectPath("/org/chromium/TestObject"),
+ base::Bind(&base::DoNothing)));
+
+ // This should return a different object because the first object was removed
+ // from the bus, but not deleted from memory.
+ dbus::ObjectProxy* object_proxy2 =
+ bus->GetObjectProxy("org.chromium.TestService",
+ dbus::ObjectPath("/org/chromium/TestObject"));
+ ASSERT_TRUE(object_proxy2);
+
+ // Compare the new object with the first object. The first object still exists
+ // thanks to the increased reference.
+ EXPECT_NE(object_proxy1, object_proxy2);
+
+ // Release object_proxy1.
+ object_proxy1->Release();
+
+ // Shut down synchronously.
+ bus->ShutdownOnDBusThreadAndBlock();
+ EXPECT_TRUE(bus->shutdown_completed());
+ dbus_thread.Stop();
+}
+
TEST(BusTest, GetExportedObject) {
dbus::Bus::Options options;
scoped_refptr<dbus::Bus> bus = new dbus::Bus(options);