Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3334)

Unified Diff: dbus/object_manager.cc

Issue 177703006: dbus: Handle NameOwnerChanged in ObjectManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dbus/object_manager.h ('k') | dbus/object_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dbus/object_manager.cc
diff --git a/dbus/object_manager.cc b/dbus/object_manager.cc
index 038622859def71663e835118feb7f1b20615712b..d8eb569cf726ca61b114e95cb40b6115eddf2fff 100644
--- a/dbus/object_manager.cc
+++ b/dbus/object_manager.cc
@@ -32,6 +32,9 @@ ObjectManager::ObjectManager(Bus* bus,
DCHECK(bus_);
object_proxy_ = bus_->GetObjectProxy(service_name_, object_path_);
+ object_proxy_->SetNameOwnerChangedCallback(
+ base::Bind(&ObjectManager::NameOwnerChanged,
+ weak_ptr_factory_.GetWeakPtr()));
object_proxy_->ConnectToSignal(
kObjectManagerInterface,
@@ -292,4 +295,35 @@ void ObjectManager::RemoveInterface(const ObjectPath& object_path,
}
}
+void ObjectManager::NameOwnerChanged(const std::string& old_owner,
+ const std::string& new_owner) {
+ if (!old_owner.empty()) {
+ ObjectMap::iterator iter = object_map_.begin();
+ while (iter != object_map_.end()) {
+ ObjectMap::iterator tmp = iter;
+ ++iter;
+
+ // PropertiesMap is mutated by RemoveInterface, and also Object is
+ // destroyed; easier to collect the object path and interface names
+ // and remove them safely.
+ const dbus::ObjectPath object_path = tmp->first;
+ Object* object = tmp->second;
+ std::vector<std::string> interfaces;
+
+ for (Object::PropertiesMap::iterator piter =
+ object->properties_map.begin();
+ piter != object->properties_map.end(); ++piter)
+ interfaces.push_back(piter->first);
+
+ for (std::vector<std::string>::iterator iiter = interfaces.begin();
+ iiter != interfaces.end(); ++iiter)
+ RemoveInterface(object_path, *iiter);
+ }
+
+ }
+
+ if (!new_owner.empty())
+ GetManagedObjects();
+}
+
} // namespace dbus
« no previous file with comments | « dbus/object_manager.h ('k') | dbus/object_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698