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

Side by Side Diff: dbus/bus.cc

Issue 9668018: dbus: remove service name from ExportedObject (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: pay more attention when fixing mock Created 8 years, 9 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 | Annotate | Revision Log
« 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"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 return iter->second; 226 return iter->second;
227 } 227 }
228 228
229 scoped_refptr<ObjectProxy> object_proxy = 229 scoped_refptr<ObjectProxy> object_proxy =
230 new ObjectProxy(this, service_name, object_path, options); 230 new ObjectProxy(this, service_name, object_path, options);
231 object_proxy_table_[key] = object_proxy; 231 object_proxy_table_[key] = object_proxy;
232 232
233 return object_proxy.get(); 233 return object_proxy.get();
234 } 234 }
235 235
236 ExportedObject* Bus::GetExportedObject(const std::string& service_name, 236 ExportedObject* Bus::GetExportedObject(const ObjectPath& object_path) {
237 const ObjectPath& object_path) {
238 AssertOnOriginThread(); 237 AssertOnOriginThread();
239 238
240 // Check if we already have the requested exported object. 239 // Check if we already have the requested exported object.
241 const std::string key = service_name + object_path.value(); 240 ExportedObjectTable::iterator iter = exported_object_table_.find(object_path);
242 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, object_path);
249 exported_object_table_[key] = exported_object; 247 exported_object_table_[object_path] = exported_object;
250 248
251 return exported_object.get(); 249 return exported_object.get();
252 } 250 }
253 251
254 bool Bus::Connect() { 252 bool Bus::Connect() {
255 // dbus_bus_get_private() and dbus_bus_get() are blocking calls. 253 // dbus_bus_get_private() and dbus_bus_get() are blocking calls.
256 AssertOnDBusThread(); 254 AssertOnDBusThread();
257 255
258 // Check if it's already initialized. 256 // Check if it's already initialized.
259 if (connection_) 257 if (connection_)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 this)); 330 this));
333 331
334 // Wait until the shutdown is complete on the D-Bus thread. 332 // Wait until the shutdown is complete on the D-Bus thread.
335 // The shutdown should not hang, but set timeout just in case. 333 // The shutdown should not hang, but set timeout just in case.
336 const int kTimeoutSecs = 3; 334 const int kTimeoutSecs = 3;
337 const base::TimeDelta timeout(base::TimeDelta::FromSeconds(kTimeoutSecs)); 335 const base::TimeDelta timeout(base::TimeDelta::FromSeconds(kTimeoutSecs));
338 const bool signaled = on_shutdown_.TimedWait(timeout); 336 const bool signaled = on_shutdown_.TimedWait(timeout);
339 LOG_IF(ERROR, !signaled) << "Failed to shutdown the bus"; 337 LOG_IF(ERROR, !signaled) << "Failed to shutdown the bus";
340 } 338 }
341 339
342 bool Bus::RequestOwnership(const std::string& service_name) { 340 void Bus::RequestOwnership(const std::string& service_name,
341 OnOwnershipCallback on_ownership_callback) {
342 AssertOnOriginThread();
343
344 PostTaskToDBusThread(FROM_HERE, base::Bind(
345 &Bus::RequestOwnershipInternal,
346 this, service_name, on_ownership_callback));
347 }
348
349 void Bus::RequestOwnershipInternal(const std::string& service_name,
350 OnOwnershipCallback on_ownership_callback) {
351 AssertOnDBusThread();
352
353 bool success = Connect();
354 if (success)
355 success = RequestOwnershipAndBlock(service_name);
356
357 PostTaskToOriginThread(FROM_HERE,
358 base::Bind(&Bus::OnOwnership,
359 this,
360 on_ownership_callback,
361 service_name,
362 success));
363 }
364
365 void Bus::OnOwnership(OnOwnershipCallback on_ownership_callback,
366 const std::string& service_name,
367 bool success) {
368 AssertOnOriginThread();
369
370 on_ownership_callback.Run(service_name, success);
371 }
372
373 bool Bus::RequestOwnershipAndBlock(const std::string& service_name) {
343 DCHECK(connection_); 374 DCHECK(connection_);
344 // dbus_bus_request_name() is a blocking call. 375 // dbus_bus_request_name() is a blocking call.
345 AssertOnDBusThread(); 376 AssertOnDBusThread();
346 377
347 // Check if we already own the service name. 378 // Check if we already own the service name.
348 if (owned_service_names_.find(service_name) != owned_service_names_.end()) { 379 if (owned_service_names_.find(service_name) != owned_service_names_.end()) {
349 return true; 380 return true;
350 } 381 }
351 382
352 ScopedDBusError error; 383 ScopedDBusError error;
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 } 788 }
758 789
759 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, 790 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection,
760 DBusDispatchStatus status, 791 DBusDispatchStatus status,
761 void* data) { 792 void* data) {
762 Bus* self = static_cast<Bus*>(data); 793 Bus* self = static_cast<Bus*>(data);
763 return self->OnDispatchStatusChanged(connection, status); 794 return self->OnDispatchStatusChanged(connection, status);
764 } 795 }
765 796
766 } // namespace dbus 797 } // 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