diff options
author | deymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-29 20:29:12 +0000 |
---|---|---|
committer | deymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-29 20:29:12 +0000 |
commit | 38ecdc8a47778b52d7404ce69088ff8b6b2b3725 (patch) | |
tree | fb7c268ddd833c274431d423ef13005648fde770 /dbus/bus.cc | |
parent | 34337d3460533c85315e3e72eb3b4186b8389f19 (diff) | |
download | chromium_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.cc')
-rw-r--r-- | dbus/bus.cc | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/dbus/bus.cc b/dbus/bus.cc index 30b6cc3..c7584fd 100644 --- a/dbus/bus.cc +++ b/dbus/bus.cc @@ -235,6 +235,46 @@ ObjectProxy* Bus::GetObjectProxyWithOptions(const std::string& service_name, return object_proxy.get(); } +bool Bus::RemoveObjectProxy(const std::string& service_name, + const ObjectPath& object_path, + const base::Closure& callback) { + return RemoveObjectProxyWithOptions(service_name, object_path, + ObjectProxy::DEFAULT_OPTIONS, + callback); +} + +bool Bus::RemoveObjectProxyWithOptions(const std::string& service_name, + const dbus::ObjectPath& object_path, + int options, + const base::Closure& callback) { + AssertOnOriginThread(); + + // Check if we have the requested object proxy. + const ObjectProxyTable::key_type key(service_name + object_path.value(), + options); + ObjectProxyTable::iterator iter = object_proxy_table_.find(key); + if (iter != object_proxy_table_.end()) { + // Object is present. Remove it now and Detach in the DBus thread. + PostTaskToDBusThread(FROM_HERE, base::Bind( + &Bus::RemoveObjectProxyInternal, + this, iter->second, callback)); + + object_proxy_table_.erase(iter); + return true; + } + return false; +} + +void Bus::RemoveObjectProxyInternal( + scoped_refptr<dbus::ObjectProxy> object_proxy, + const base::Closure& callback) { + AssertOnDBusThread(); + + object_proxy.get()->Detach(); + + PostTaskToOriginThread(FROM_HERE, callback); +} + ExportedObject* Bus::GetExportedObject(const ObjectPath& object_path) { AssertOnOriginThread(); @@ -410,21 +450,11 @@ void Bus::RequestOwnershipInternal(const std::string& service_name, success = RequestOwnershipAndBlock(service_name); PostTaskToOriginThread(FROM_HERE, - base::Bind(&Bus::OnOwnership, - this, - on_ownership_callback, + base::Bind(on_ownership_callback, service_name, success)); } -void Bus::OnOwnership(OnOwnershipCallback on_ownership_callback, - const std::string& service_name, - bool success) { - AssertOnOriginThread(); - - on_ownership_callback.Run(service_name, success); -} - bool Bus::RequestOwnershipAndBlock(const std::string& service_name) { DCHECK(connection_); // dbus_bus_request_name() is a blocking call. |