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 // TODO(satorux): | 5 // TODO(satorux): |
6 // - Handle "disconnected" signal. | 6 // - Handle "disconnected" signal. |
7 | 7 |
8 #include "dbus/bus.h" | 8 #include "dbus/bus.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
17 #include "base/time.h" | 17 #include "base/time.h" |
18 #include "dbus/exported_object.h" | 18 #include "dbus/exported_object.h" |
19 #include "dbus/object_path.h" | |
20 #include "dbus/object_proxy.h" | 19 #include "dbus/object_proxy.h" |
21 #include "dbus/scoped_dbus_error.h" | 20 #include "dbus/scoped_dbus_error.h" |
22 | 21 |
23 namespace dbus { | 22 namespace dbus { |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
27 // The class is used for watching the file descriptor used for D-Bus | 26 // The class is used for watching the file descriptor used for D-Bus |
28 // communication. | 27 // communication. |
29 class Watch : public base::MessagePumpLibevent::Watcher { | 28 class Watch : public base::MessagePumpLibevent::Watcher { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 DCHECK(filter_functions_added_.empty()); | 200 DCHECK(filter_functions_added_.empty()); |
202 DCHECK(registered_object_paths_.empty()); | 201 DCHECK(registered_object_paths_.empty()); |
203 DCHECK_EQ(0, num_pending_watches_); | 202 DCHECK_EQ(0, num_pending_watches_); |
204 // TODO(satorux): This check fails occasionally in browser_tests for tests | 203 // TODO(satorux): This check fails occasionally in browser_tests for tests |
205 // that run very quickly. Perhaps something does not have time to clean up. | 204 // that run very quickly. Perhaps something does not have time to clean up. |
206 // Despite the check failing, the tests seem to run fine. crosbug.com/23416 | 205 // Despite the check failing, the tests seem to run fine. crosbug.com/23416 |
207 // DCHECK_EQ(0, num_pending_timeouts_); | 206 // DCHECK_EQ(0, num_pending_timeouts_); |
208 } | 207 } |
209 | 208 |
210 ObjectProxy* Bus::GetObjectProxy(const std::string& service_name, | 209 ObjectProxy* Bus::GetObjectProxy(const std::string& service_name, |
211 const ObjectPath& object_path) { | 210 const std::string& object_path) { |
212 return GetObjectProxyWithOptions(service_name, object_path, | 211 return GetObjectProxyWithOptions(service_name, object_path, |
213 ObjectProxy::DEFAULT_OPTIONS); | 212 ObjectProxy::DEFAULT_OPTIONS); |
214 } | 213 } |
215 | 214 |
216 ObjectProxy* Bus::GetObjectProxyWithOptions(const std::string& service_name, | 215 ObjectProxy* Bus::GetObjectProxyWithOptions(const std::string& service_name, |
217 const dbus::ObjectPath& object_path, | 216 const std::string& object_path, |
218 int options) { | 217 int options) { |
219 AssertOnOriginThread(); | 218 AssertOnOriginThread(); |
220 | 219 |
221 // Check if we already have the requested object proxy. | 220 // Check if we already have the requested object proxy. |
222 const ObjectProxyTable::key_type key(service_name + object_path.value(), | 221 const ObjectProxyTable::key_type key(service_name + object_path, options); |
223 options); | |
224 ObjectProxyTable::iterator iter = object_proxy_table_.find(key); | 222 ObjectProxyTable::iterator iter = object_proxy_table_.find(key); |
225 if (iter != object_proxy_table_.end()) { | 223 if (iter != object_proxy_table_.end()) { |
226 return iter->second; | 224 return iter->second; |
227 } | 225 } |
228 | 226 |
229 scoped_refptr<ObjectProxy> object_proxy = | 227 scoped_refptr<ObjectProxy> object_proxy = |
230 new ObjectProxy(this, service_name, object_path, options); | 228 new ObjectProxy(this, service_name, object_path, options); |
231 object_proxy_table_[key] = object_proxy; | 229 object_proxy_table_[key] = object_proxy; |
232 | 230 |
233 return object_proxy.get(); | 231 return object_proxy.get(); |
234 } | 232 } |
235 | 233 |
236 ExportedObject* Bus::GetExportedObject(const std::string& service_name, | 234 ExportedObject* Bus::GetExportedObject(const std::string& service_name, |
237 const ObjectPath& object_path) { | 235 const std::string& object_path) { |
238 AssertOnOriginThread(); | 236 AssertOnOriginThread(); |
239 | 237 |
240 // Check if we already have the requested exported object. | 238 // Check if we already have the requested exported object. |
241 const std::string key = service_name + object_path.value(); | 239 const std::string key = service_name + object_path; |
242 ExportedObjectTable::iterator iter = exported_object_table_.find(key); | 240 ExportedObjectTable::iterator iter = exported_object_table_.find(key); |
243 if (iter != exported_object_table_.end()) { | 241 if (iter != exported_object_table_.end()) { |
244 return iter->second; | 242 return iter->second; |
245 } | 243 } |
246 | 244 |
247 scoped_refptr<ExportedObject> exported_object = | 245 scoped_refptr<ExportedObject> exported_object = |
248 new ExportedObject(this, service_name, object_path); | 246 new ExportedObject(this, service_name, object_path); |
249 exported_object_table_[key] = exported_object; | 247 exported_object_table_[key] = exported_object; |
250 | 248 |
251 return exported_object.get(); | 249 return exported_object.get(); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 | 514 |
517 if (match_rules_added_.find(match_rule) == match_rules_added_.end()) { | 515 if (match_rules_added_.find(match_rule) == match_rules_added_.end()) { |
518 LOG(ERROR) << "Requested to remove an unknown match rule: " << match_rule; | 516 LOG(ERROR) << "Requested to remove an unknown match rule: " << match_rule; |
519 return; | 517 return; |
520 } | 518 } |
521 | 519 |
522 dbus_bus_remove_match(connection_, match_rule.c_str(), error); | 520 dbus_bus_remove_match(connection_, match_rule.c_str(), error); |
523 match_rules_added_.erase(match_rule); | 521 match_rules_added_.erase(match_rule); |
524 } | 522 } |
525 | 523 |
526 bool Bus::TryRegisterObjectPath(const ObjectPath& object_path, | 524 bool Bus::TryRegisterObjectPath(const std::string& object_path, |
527 const DBusObjectPathVTable* vtable, | 525 const DBusObjectPathVTable* vtable, |
528 void* user_data, | 526 void* user_data, |
529 DBusError* error) { | 527 DBusError* error) { |
530 DCHECK(connection_); | 528 DCHECK(connection_); |
531 AssertOnDBusThread(); | 529 AssertOnDBusThread(); |
532 | 530 |
533 if (registered_object_paths_.find(object_path) != | 531 if (registered_object_paths_.find(object_path) != |
534 registered_object_paths_.end()) { | 532 registered_object_paths_.end()) { |
535 LOG(ERROR) << "Object path already registered: " << object_path.value(); | 533 LOG(ERROR) << "Object path already registered: " << object_path; |
536 return false; | 534 return false; |
537 } | 535 } |
538 | 536 |
539 const bool success = dbus_connection_try_register_object_path( | 537 const bool success = dbus_connection_try_register_object_path( |
540 connection_, | 538 connection_, |
541 object_path.value().c_str(), | 539 object_path.c_str(), |
542 vtable, | 540 vtable, |
543 user_data, | 541 user_data, |
544 error); | 542 error); |
545 if (success) | 543 if (success) |
546 registered_object_paths_.insert(object_path); | 544 registered_object_paths_.insert(object_path); |
547 return success; | 545 return success; |
548 } | 546 } |
549 | 547 |
550 void Bus::UnregisterObjectPath(const ObjectPath& object_path) { | 548 void Bus::UnregisterObjectPath(const std::string& object_path) { |
551 DCHECK(connection_); | 549 DCHECK(connection_); |
552 AssertOnDBusThread(); | 550 AssertOnDBusThread(); |
553 | 551 |
554 if (registered_object_paths_.find(object_path) == | 552 if (registered_object_paths_.find(object_path) == |
555 registered_object_paths_.end()) { | 553 registered_object_paths_.end()) { |
556 LOG(ERROR) << "Requested to unregister an unknown object path: " | 554 LOG(ERROR) << "Requested to unregister an unknown object path: " |
557 << object_path.value(); | 555 << object_path; |
558 return; | 556 return; |
559 } | 557 } |
560 | 558 |
561 const bool success = dbus_connection_unregister_object_path( | 559 const bool success = dbus_connection_unregister_object_path( |
562 connection_, | 560 connection_, |
563 object_path.value().c_str()); | 561 object_path.c_str()); |
564 CHECK(success) << "Unable to allocate memory"; | 562 CHECK(success) << "Unable to allocate memory"; |
565 registered_object_paths_.erase(object_path); | 563 registered_object_paths_.erase(object_path); |
566 } | 564 } |
567 | 565 |
568 void Bus::ShutdownOnDBusThreadAndBlockInternal() { | 566 void Bus::ShutdownOnDBusThreadAndBlockInternal() { |
569 AssertOnDBusThread(); | 567 AssertOnDBusThread(); |
570 | 568 |
571 ShutdownAndBlock(); | 569 ShutdownAndBlock(); |
572 on_shutdown_.Signal(); | 570 on_shutdown_.Signal(); |
573 } | 571 } |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 } | 755 } |
758 | 756 |
759 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, | 757 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, |
760 DBusDispatchStatus status, | 758 DBusDispatchStatus status, |
761 void* data) { | 759 void* data) { |
762 Bus* self = static_cast<Bus*>(data); | 760 Bus* self = static_cast<Bus*>(data); |
763 return self->OnDispatchStatusChanged(connection, status); | 761 return self->OnDispatchStatusChanged(connection, status); |
764 } | 762 } |
765 | 763 |
766 } // namespace dbus | 764 } // namespace dbus |
OLD | NEW |