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

Side by Side Diff: dbus/object_proxy.cc

Issue 9808001: dbus: don't fail when reconnecting object signals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | « no previous file | no next file » | 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 #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.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 delete data; 274 delete data;
275 } 275 }
276 276
277 void ObjectProxy::ConnectToSignalInternal( 277 void ObjectProxy::ConnectToSignalInternal(
278 const std::string& interface_name, 278 const std::string& interface_name,
279 const std::string& signal_name, 279 const std::string& signal_name,
280 SignalCallback signal_callback, 280 SignalCallback signal_callback,
281 OnConnectedCallback on_connected_callback) { 281 OnConnectedCallback on_connected_callback) {
282 bus_->AssertOnDBusThread(); 282 bus_->AssertOnDBusThread();
283 283
284 // Check if the object is already connected to the signal.
285 const std::string absolute_signal_name = 284 const std::string absolute_signal_name =
286 GetAbsoluteSignalName(interface_name, signal_name); 285 GetAbsoluteSignalName(interface_name, signal_name);
287 if (method_table_.find(absolute_signal_name) != method_table_.end()) {
288 LOG(ERROR) << "The object proxy is already connected to "
289 << absolute_signal_name;
290 return;
291 }
292 286
293 // Will become true, if everything is successful. 287 // Will become true, if everything is successful.
294 bool success = false; 288 bool success = false;
295 289
296 if (bus_->Connect() && bus_->SetUpAsyncOperations()) { 290 if (bus_->Connect() && bus_->SetUpAsyncOperations()) {
297 // We should add the filter only once. Otherwise, HandleMessage() will 291 // We should add the filter only once. Otherwise, HandleMessage() will
298 // be called more than once. 292 // be called more than once.
299 if (!filter_added_) { 293 if (!filter_added_) {
300 if (bus_->AddFilterFunction(&ObjectProxy::HandleMessageThunk, this)) { 294 if (bus_->AddFilterFunction(&ObjectProxy::HandleMessageThunk, this)) {
301 filter_added_ = true; 295 filter_added_ = true;
302 } else { 296 } else {
303 LOG(ERROR) << "Failed to add filter function"; 297 LOG(ERROR) << "Failed to add filter function";
304 } 298 }
305 } 299 }
306 // Add a match rule so the signal goes through HandleMessage(). 300 // Add a match rule so the signal goes through HandleMessage().
307 const std::string match_rule = 301 const std::string match_rule =
308 base::StringPrintf("type='signal', interface='%s', path='%s'", 302 base::StringPrintf("type='signal', interface='%s', path='%s'",
309 interface_name.c_str(), 303 interface_name.c_str(),
310 object_path_.value().c_str()); 304 object_path_.value().c_str());
311 305
312 // Add the match rule if we don't have it. 306 // Add the match rule if we don't have it.
313 if (match_rules_.find(match_rule) == match_rules_.end()) { 307 if (match_rules_.find(match_rule) == match_rules_.end()) {
satorux1 2012/03/21 16:20:28 When reconnecting to the same signal, match_rules_
keybuk 2012/03/21 16:22:41 exactly, which is what you want - there's already
314 ScopedDBusError error; 308 ScopedDBusError error;
315 bus_->AddMatch(match_rule, error.get());; 309 bus_->AddMatch(match_rule, error.get());;
316 if (error.is_set()) { 310 if (error.is_set()) {
317 LOG(ERROR) << "Failed to add match rule: " << match_rule; 311 LOG(ERROR) << "Failed to add match rule: " << match_rule;
318 } else { 312 } else {
319 // Store the match rule, so that we can remove this in Detach(). 313 // Store the match rule, so that we can remove this in Detach().
320 match_rules_.insert(match_rule); 314 match_rules_.insert(match_rule);
321 // Add the signal callback to the method table. 315 // Add the signal callback to the method table.
322 method_table_[absolute_signal_name] = signal_callback; 316 method_table_[absolute_signal_name] = signal_callback;
satorux1 2012/03/21 04:59:40 if method_table_[absolute_signal_name] is already
keybuk 2012/03/21 14:51:29 Yes, that's the intent of this patch
satorux1 2012/03/21 16:20:28 I see I see. Could you document this behavior in o
keybuk 2012/03/21 16:22:41 yup
keybuk 2012/03/21 21:26:28 Done.
323 success = true; 317 success = true;
324 } 318 }
325 } else { 319 } else {
326 // We already have the match rule. 320 // We already have the match rule.
327 method_table_[absolute_signal_name] = signal_callback; 321 method_table_[absolute_signal_name] = signal_callback;
328 success = true; 322 success = true;
329 } 323 }
330 } 324 }
331 325
332 // Run on_connected_callback in the origin thread. 326 // Run on_connected_callback in the origin thread.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 void ObjectProxy::LogMethodCallFailure( 423 void ObjectProxy::LogMethodCallFailure(
430 const base::StringPiece& error_name, 424 const base::StringPiece& error_name,
431 const base::StringPiece& error_message) const { 425 const base::StringPiece& error_message) const {
432 if (ignore_service_unknown_errors_ && error_name == kErrorServiceUnknown) 426 if (ignore_service_unknown_errors_ && error_name == kErrorServiceUnknown)
433 return; 427 return;
434 LOG(ERROR) << "Failed to call method: " << error_name 428 LOG(ERROR) << "Failed to call method: " << error_name
435 << ": " << error_message; 429 << ": " << error_message;
436 } 430 }
437 431
438 } // namespace dbus 432 } // namespace dbus
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698