Chromium Code Reviews| 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/logging.h" | 8 #include "base/logging.h" | 
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" | 
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" | 
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 const base::Closure& callback) { | 260 const base::Closure& callback) { | 
| 261 AssertOnOriginThread(); | 261 AssertOnOriginThread(); | 
| 262 | 262 | 
| 263 // Check if we have the requested object proxy. | 263 // Check if we have the requested object proxy. | 
| 264 const ObjectProxyTable::key_type key(service_name + object_path.value(), | 264 const ObjectProxyTable::key_type key(service_name + object_path.value(), | 
| 265 options); | 265 options); | 
| 266 ObjectProxyTable::iterator iter = object_proxy_table_.find(key); | 266 ObjectProxyTable::iterator iter = object_proxy_table_.find(key); | 
| 267 if (iter != object_proxy_table_.end()) { | 267 if (iter != object_proxy_table_.end()) { | 
| 268 scoped_refptr<ObjectProxy> object_proxy = iter->second; | 268 scoped_refptr<ObjectProxy> object_proxy = iter->second; | 
| 269 object_proxy_table_.erase(iter); | 269 object_proxy_table_.erase(iter); | 
| 270 // Object is present. Remove it now and Detach in the DBus thread. | 270 // Object is present. Remove it now and Detach on the DBus thread. | 
| 271 GetDBusTaskRunner()->PostTask( | 271 GetDBusTaskRunner()->PostTask( | 
| 272 FROM_HERE, | 272 FROM_HERE, | 
| 273 base::Bind(&Bus::RemoveObjectProxyInternal, | 273 base::Bind(&Bus::RemoveObjectProxyInternal, | 
| 274 this, object_proxy, callback)); | 274 this, object_proxy, callback)); | 
| 275 return true; | 275 return true; | 
| 276 } | 276 } | 
| 277 return false; | 277 return false; | 
| 278 } | 278 } | 
| 279 | 279 | 
| 280 void Bus::RemoveObjectProxyInternal(scoped_refptr<ObjectProxy> object_proxy, | 280 void Bus::RemoveObjectProxyInternal(scoped_refptr<ObjectProxy> object_proxy, | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 } | 344 } | 
| 345 | 345 | 
| 346 scoped_refptr<ObjectManager> object_manager = | 346 scoped_refptr<ObjectManager> object_manager = | 
| 347 new ObjectManager(this, service_name, object_path); | 347 new ObjectManager(this, service_name, object_path); | 
| 348 object_manager_table_[key] = object_manager; | 348 object_manager_table_[key] = object_manager; | 
| 349 | 349 | 
| 350 return object_manager.get(); | 350 return object_manager.get(); | 
| 351 } | 351 } | 
| 352 | 352 | 
| 353 void Bus::RemoveObjectManager(const std::string& service_name, | 353 void Bus::RemoveObjectManager(const std::string& service_name, | 
| 354 const ObjectPath& object_path) { | 354 const ObjectPath& object_path, | 
| 355 const base::Closure& callback) { | |
| 355 AssertOnOriginThread(); | 356 AssertOnOriginThread(); | 
| 
 
satorux1
2014/08/28 04:00:01
add: DCHECK(!callback.is_null()); to make it clear
 
armansito
2014/08/28 15:37:59
Done.
 
 | |
| 356 | 357 | 
| 357 const ObjectManagerTable::key_type key(service_name + object_path.value()); | 358 const ObjectManagerTable::key_type key(service_name + object_path.value()); | 
| 358 ObjectManagerTable::iterator iter = object_manager_table_.find(key); | 359 ObjectManagerTable::iterator iter = object_manager_table_.find(key); | 
| 359 if (iter == object_manager_table_.end()) | 360 if (iter == object_manager_table_.end()) | 
| 360 return; | 361 return; | 
| 361 | 362 | 
| 363 // ObjectManager is present. Remove it now and CleanUp in the DBus thread. | |
| 
 
satorux1
2014/08/28 04:00:01
in -> on ?
 
armansito
2014/08/28 15:37:59
Done.
 
 | |
| 362 scoped_refptr<ObjectManager> object_manager = iter->second; | 364 scoped_refptr<ObjectManager> object_manager = iter->second; | 
| 363 object_manager_table_.erase(iter); | 365 object_manager_table_.erase(iter); | 
| 366 | |
| 367 GetDBusTaskRunner()->PostTask( | |
| 368 FROM_HERE, | |
| 369 base::Bind(&Bus::RemoveObjectManagerInternal, | |
| 370 this, object_manager, callback)); | |
| 371 } | |
| 372 | |
| 373 void Bus::RemoveObjectManagerInternal( | |
| 374 scoped_refptr<dbus::ObjectManager> object_manager, | |
| 375 const base::Closure& callback) { | |
| 376 AssertOnDBusThread(); | |
| 377 DCHECK(object_manager.get()); | |
| 378 | |
| 379 object_manager->CleanUp(); | |
| 380 | |
| 381 GetOriginTaskRunner()->PostTask(FROM_HERE, callback); | |
| 364 } | 382 } | 
| 365 | 383 | 
| 366 void Bus::GetManagedObjects() { | 384 void Bus::GetManagedObjects() { | 
| 367 for (ObjectManagerTable::iterator iter = object_manager_table_.begin(); | 385 for (ObjectManagerTable::iterator iter = object_manager_table_.begin(); | 
| 368 iter != object_manager_table_.end(); ++iter) { | 386 iter != object_manager_table_.end(); ++iter) { | 
| 369 iter->second->GetManagedObjects(); | 387 iter->second->GetManagedObjects(); | 
| 370 } | 388 } | 
| 371 } | 389 } | 
| 372 | 390 | 
| 373 bool Bus::Connect() { | 391 bool Bus::Connect() { | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 LOG(ERROR) << "Failed to release all service names. # of services left: " | 471 LOG(ERROR) << "Failed to release all service names. # of services left: " | 
| 454 << owned_service_names_.size(); | 472 << owned_service_names_.size(); | 
| 455 } | 473 } | 
| 456 | 474 | 
| 457 // Detach from the remote objects. | 475 // Detach from the remote objects. | 
| 458 for (ObjectProxyTable::iterator iter = object_proxy_table_.begin(); | 476 for (ObjectProxyTable::iterator iter = object_proxy_table_.begin(); | 
| 459 iter != object_proxy_table_.end(); ++iter) { | 477 iter != object_proxy_table_.end(); ++iter) { | 
| 460 iter->second->Detach(); | 478 iter->second->Detach(); | 
| 461 } | 479 } | 
| 462 | 480 | 
| 481 // Clean up the object managers. | |
| 482 for (ObjectManagerTable::iterator iter = object_manager_table_.begin(); | |
| 483 iter != object_manager_table_.end(); ++iter) { | |
| 484 iter->second->CleanUp(); | |
| 485 } | |
| 486 | |
| 463 // Release object proxies and exported objects here. We should do this | 487 // Release object proxies and exported objects here. We should do this | 
| 464 // here rather than in the destructor to avoid memory leaks due to | 488 // here rather than in the destructor to avoid memory leaks due to | 
| 465 // cyclic references. | 489 // cyclic references. | 
| 466 object_proxy_table_.clear(); | 490 object_proxy_table_.clear(); | 
| 467 exported_object_table_.clear(); | 491 exported_object_table_.clear(); | 
| 468 | 492 | 
| 469 // Private connection should be closed. | 493 // Private connection should be closed. | 
| 470 if (connection_) { | 494 if (connection_) { | 
| 471 // Remove Disconnected watcher. | 495 // Remove Disconnected watcher. | 
| 472 ScopedDBusError error; | 496 ScopedDBusError error; | 
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1189 kNameOwnerChangedSignal)) { | 1213 kNameOwnerChangedSignal)) { | 
| 1190 Bus* self = static_cast<Bus*>(data); | 1214 Bus* self = static_cast<Bus*>(data); | 
| 1191 self->OnServiceOwnerChanged(message); | 1215 self->OnServiceOwnerChanged(message); | 
| 1192 } | 1216 } | 
| 1193 // Always return unhandled to let others, e.g. ObjectProxies, handle the same | 1217 // Always return unhandled to let others, e.g. ObjectProxies, handle the same | 
| 1194 // signal. | 1218 // signal. | 
| 1195 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 1219 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 
| 1196 } | 1220 } | 
| 1197 | 1221 | 
| 1198 } // namespace dbus | 1222 } // namespace dbus | 
| OLD | NEW |