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

Side by Side Diff: dbus/bus.cc

Issue 7702001: Reuse existing object proxies and exported objects, if these exist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-upload Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // - Collect metrics (ex. # of method calls, method call time, etc.) 7 // - Collect metrics (ex. # of method calls, method call time, etc.)
8 8
9 #include "dbus/bus.h" 9 #include "dbus/bus.h"
10 10
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 DCHECK(filter_functions_added_.empty()); 205 DCHECK(filter_functions_added_.empty());
206 DCHECK(registered_object_paths_.empty()); 206 DCHECK(registered_object_paths_.empty());
207 DCHECK_EQ(0, num_pending_watches_); 207 DCHECK_EQ(0, num_pending_watches_);
208 DCHECK_EQ(0, num_pending_timeouts_); 208 DCHECK_EQ(0, num_pending_timeouts_);
209 } 209 }
210 210
211 ObjectProxy* Bus::GetObjectProxy(const std::string& service_name, 211 ObjectProxy* Bus::GetObjectProxy(const std::string& service_name,
212 const std::string& object_path) { 212 const std::string& object_path) {
213 AssertOnOriginThread(); 213 AssertOnOriginThread();
214 214
215 // Check if we already have the requested object proxy.
216 const std::string key = service_name + object_path;
217 ObjectProxyTable::iterator iter = object_proxy_table_.find(key);
218 if (iter != object_proxy_table_.end()) {
219 return iter->second;
220 }
221
215 scoped_refptr<ObjectProxy> object_proxy = 222 scoped_refptr<ObjectProxy> object_proxy =
216 new ObjectProxy(this, service_name, object_path); 223 new ObjectProxy(this, service_name, object_path);
217 object_proxies_.push_back(object_proxy); 224 object_proxy_table_[key] = object_proxy;
218 225
219 return object_proxy; 226 return object_proxy.get();
220 } 227 }
221 228
222 ExportedObject* Bus::GetExportedObject(const std::string& service_name, 229 ExportedObject* Bus::GetExportedObject(const std::string& service_name,
223 const std::string& object_path) { 230 const std::string& object_path) {
224 AssertOnOriginThread(); 231 AssertOnOriginThread();
225 232
233 // Check if we already have the requested exported object.
234 const std::string key = service_name + object_path;
235 ExportedObjectTable::iterator iter = exported_object_table_.find(key);
236 if (iter != exported_object_table_.end()) {
237 return iter->second;
238 }
239
226 scoped_refptr<ExportedObject> exported_object = 240 scoped_refptr<ExportedObject> exported_object =
227 new ExportedObject(this, service_name, object_path); 241 new ExportedObject(this, service_name, object_path);
228 exported_objects_.push_back(exported_object); 242 exported_object_table_[key] = exported_object;
229 243
230 return exported_object; 244 return exported_object.get();
231 } 245 }
232 246
233 bool Bus::Connect() { 247 bool Bus::Connect() {
234 // dbus_bus_get_private() and dbus_bus_get() are blocking calls. 248 // dbus_bus_get_private() and dbus_bus_get() are blocking calls.
235 AssertOnDBusThread(); 249 AssertOnDBusThread();
236 250
237 // Check if it's already initialized. 251 // Check if it's already initialized.
238 if (connection_) 252 if (connection_)
239 return true; 253 return true;
240 254
(...skipping 12 matching lines...) Expand all
253 // We shouldn't exit on the disconnected signal. 267 // We shouldn't exit on the disconnected signal.
254 dbus_connection_set_exit_on_disconnect(connection_, false); 268 dbus_connection_set_exit_on_disconnect(connection_, false);
255 269
256 return true; 270 return true;
257 } 271 }
258 272
259 void Bus::ShutdownAndBlock() { 273 void Bus::ShutdownAndBlock() {
260 AssertOnDBusThread(); 274 AssertOnDBusThread();
261 275
262 // Unregister the exported objects. 276 // Unregister the exported objects.
263 for (size_t i = 0; i < exported_objects_.size(); ++i) { 277 for (ExportedObjectTable::iterator iter = exported_object_table_.begin();
264 exported_objects_[i]->Unregister(); 278 iter != exported_object_table_.end(); ++iter) {
279 iter->second->Unregister();
265 } 280 }
266 281
267 // Release all service names. 282 // Release all service names.
268 for (std::set<std::string>::iterator iter = owned_service_names_.begin(); 283 for (std::set<std::string>::iterator iter = owned_service_names_.begin();
269 iter != owned_service_names_.end();) { 284 iter != owned_service_names_.end();) {
270 // This is a bit tricky but we should increment the iter here as 285 // This is a bit tricky but we should increment the iter here as
271 // ReleaseOwnership() may remove |service_name| from the set. 286 // ReleaseOwnership() may remove |service_name| from the set.
272 const std::string& service_name = *iter++; 287 const std::string& service_name = *iter++;
273 ReleaseOwnership(service_name); 288 ReleaseOwnership(service_name);
274 } 289 }
275 if (!owned_service_names_.empty()) { 290 if (!owned_service_names_.empty()) {
276 LOG(ERROR) << "Failed to release all service names. # of services left: " 291 LOG(ERROR) << "Failed to release all service names. # of services left: "
277 << owned_service_names_.size(); 292 << owned_service_names_.size();
278 } 293 }
279 294
280 // Detach from the remote objects. 295 // Detach from the remote objects.
281 for (size_t i = 0; i < object_proxies_.size(); ++i) { 296 for (ObjectProxyTable::iterator iter = object_proxy_table_.begin();
282 object_proxies_[i]->Detach(); 297 iter != object_proxy_table_.end(); ++iter) {
298 iter->second->Detach();
283 } 299 }
284 300
285 // Private connection should be closed. 301 // Private connection should be closed.
286 if (connection_ && connection_type_ == PRIVATE) { 302 if (connection_ && connection_type_ == PRIVATE) {
287 dbus_connection_close(connection_); 303 dbus_connection_close(connection_);
288 } 304 }
289 // dbus_connection_close() won't unref. 305 // dbus_connection_close() won't unref.
290 dbus_connection_unref(connection_); 306 dbus_connection_unref(connection_);
291 307
292 connection_ = NULL; 308 connection_ = NULL;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 error); 512 error);
497 if (success) 513 if (success)
498 registered_object_paths_.insert(object_path); 514 registered_object_paths_.insert(object_path);
499 return success; 515 return success;
500 } 516 }
501 517
502 void Bus::UnregisterObjectPath(const std::string& object_path) { 518 void Bus::UnregisterObjectPath(const std::string& object_path) {
503 DCHECK(connection_); 519 DCHECK(connection_);
504 AssertOnDBusThread(); 520 AssertOnDBusThread();
505 521
506 DCHECK(registered_object_paths_.find(object_path) != 522 if (registered_object_paths_.find(object_path) ==
507 registered_object_paths_.end()) 523 registered_object_paths_.end()) {
508 << "Requested to unregister an unknown object path: " << object_path; 524 LOG(ERROR) << "Requested to unregister an unknown object path: "
525 << object_path;
526 }
509 527
510 const bool success = dbus_connection_unregister_object_path( 528 const bool success = dbus_connection_unregister_object_path(
511 connection_, 529 connection_,
512 object_path.c_str()); 530 object_path.c_str());
513 CHECK(success) << "Unable to allocate memory"; 531 CHECK(success) << "Unable to allocate memory";
514 registered_object_paths_.erase(object_path); 532 registered_object_paths_.erase(object_path);
515 } 533 }
516 534
517 void Bus::ShutdownInternal(OnShutdownCallback callback) { 535 void Bus::ShutdownInternal(OnShutdownCallback callback) {
518 AssertOnDBusThread(); 536 AssertOnDBusThread();
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 } 707 }
690 708
691 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection, 709 void Bus::OnDispatchStatusChangedThunk(DBusConnection* connection,
692 DBusDispatchStatus status, 710 DBusDispatchStatus status,
693 void* data) { 711 void* data) {
694 Bus* self = static_cast<Bus*>(data); 712 Bus* self = static_cast<Bus*>(data);
695 return self->OnDispatchStatusChanged(connection, status); 713 return self->OnDispatchStatusChanged(connection, status);
696 } 714 }
697 715
698 } // namespace dbus 716 } // 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