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

Side by Side Diff: dbus/bus.cc

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

Powered by Google App Engine
This is Rietveld 408576698