OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/object_manager.h" | 5 #include "dbus/object_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "dbus/bus.h" | 9 #include "dbus/bus.h" |
10 #include "dbus/message.h" | 10 #include "dbus/message.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 const ObjectPath& object_path) | 25 const ObjectPath& object_path) |
26 : bus_(bus), | 26 : bus_(bus), |
27 service_name_(service_name), | 27 service_name_(service_name), |
28 object_path_(object_path), | 28 object_path_(object_path), |
29 weak_ptr_factory_(this) { | 29 weak_ptr_factory_(this) { |
30 DVLOG(1) << "Creating ObjectManager for " << service_name_ | 30 DVLOG(1) << "Creating ObjectManager for " << service_name_ |
31 << " " << object_path_.value(); | 31 << " " << object_path_.value(); |
32 | 32 |
33 DCHECK(bus_); | 33 DCHECK(bus_); |
34 object_proxy_ = bus_->GetObjectProxy(service_name_, object_path_); | 34 object_proxy_ = bus_->GetObjectProxy(service_name_, object_path_); |
| 35 object_proxy_->SetNameOwnerChangedCallback( |
| 36 base::Bind(&ObjectManager::NameOwnerChanged, |
| 37 weak_ptr_factory_.GetWeakPtr())); |
35 | 38 |
36 object_proxy_->ConnectToSignal( | 39 object_proxy_->ConnectToSignal( |
37 kObjectManagerInterface, | 40 kObjectManagerInterface, |
38 kObjectManagerInterfacesAdded, | 41 kObjectManagerInterfacesAdded, |
39 base::Bind(&ObjectManager::InterfacesAddedReceived, | 42 base::Bind(&ObjectManager::InterfacesAddedReceived, |
40 weak_ptr_factory_.GetWeakPtr()), | 43 weak_ptr_factory_.GetWeakPtr()), |
41 base::Bind(&ObjectManager::InterfacesAddedConnected, | 44 base::Bind(&ObjectManager::InterfacesAddedConnected, |
42 weak_ptr_factory_.GetWeakPtr())); | 45 weak_ptr_factory_.GetWeakPtr())); |
43 | 46 |
44 object_proxy_->ConnectToSignal( | 47 object_proxy_->ConnectToSignal( |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } | 288 } |
286 | 289 |
287 object->properties_map.erase(piter); | 290 object->properties_map.erase(piter); |
288 | 291 |
289 if (object->properties_map.empty()) { | 292 if (object->properties_map.empty()) { |
290 object_map_.erase(oiter); | 293 object_map_.erase(oiter); |
291 delete object; | 294 delete object; |
292 } | 295 } |
293 } | 296 } |
294 | 297 |
| 298 void ObjectManager::NameOwnerChanged(const std::string& old_owner, |
| 299 const std::string& new_owner) { |
| 300 if (!old_owner.empty()) { |
| 301 ObjectMap::iterator iter = object_map_.begin(); |
| 302 while (iter != object_map_.end()) { |
| 303 ObjectMap::iterator tmp = iter; |
| 304 ++iter; |
| 305 |
| 306 // PropertiesMap is mutated by RemoveInterface, and also Object is |
| 307 // destroyed; easier to collect the object path and interface names |
| 308 // and remove them safely. |
| 309 const dbus::ObjectPath object_path = tmp->first; |
| 310 Object* object = tmp->second; |
| 311 std::vector<std::string> interfaces; |
| 312 |
| 313 for (Object::PropertiesMap::iterator piter = |
| 314 object->properties_map.begin(); |
| 315 piter != object->properties_map.end(); ++piter) |
| 316 interfaces.push_back(piter->first); |
| 317 |
| 318 for (std::vector<std::string>::iterator iiter = interfaces.begin(); |
| 319 iiter != interfaces.end(); ++iiter) |
| 320 RemoveInterface(object_path, *iiter); |
| 321 } |
| 322 |
| 323 } |
| 324 |
| 325 if (!new_owner.empty()) |
| 326 GetManagedObjects(); |
| 327 } |
| 328 |
295 } // namespace dbus | 329 } // namespace dbus |
OLD | NEW |