| 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 #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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 // If the D-Bus thread is not used, just call the callback on the | 488 // If the D-Bus thread is not used, just call the callback on the |
| 489 // current thread. Transfer the ownership of |signal| to RunMethod(). | 489 // current thread. Transfer the ownership of |signal| to RunMethod(). |
| 490 Signal* released_signal = signal.release(); | 490 Signal* released_signal = signal.release(); |
| 491 RunMethod(start_time, iter->second, released_signal); | 491 RunMethod(start_time, iter->second, released_signal); |
| 492 } | 492 } |
| 493 | 493 |
| 494 return DBUS_HANDLER_RESULT_HANDLED; | 494 return DBUS_HANDLER_RESULT_HANDLED; |
| 495 } | 495 } |
| 496 | 496 |
| 497 void ObjectProxy::RunMethod(base::TimeTicks start_time, | 497 void ObjectProxy::RunMethod(base::TimeTicks start_time, |
| 498 SignalCallback signal_callback, | 498 std::vector<SignalCallback> signal_callbacks, |
| 499 Signal* signal) { | 499 Signal* signal) { |
| 500 bus_->AssertOnOriginThread(); | 500 bus_->AssertOnOriginThread(); |
| 501 | 501 |
| 502 signal_callback.Run(signal); | 502 for (std::vector<SignalCallback>::iterator iter = signal_callbacks.begin(); |
| 503 iter != signal_callbacks.end(); ++iter) |
| 504 iter->Run(signal); |
| 505 |
| 503 // Delete the message on the D-Bus thread. See comments in | 506 // Delete the message on the D-Bus thread. See comments in |
| 504 // RunResponseCallback(). | 507 // RunResponseCallback(). |
| 505 bus_->PostTaskToDBusThread( | 508 bus_->PostTaskToDBusThread( |
| 506 FROM_HERE, | 509 FROM_HERE, |
| 507 base::Bind(&base::DeletePointer<dbus::Signal>, signal)); | 510 base::Bind(&base::DeletePointer<dbus::Signal>, signal)); |
| 508 | 511 |
| 509 // Record time spent for handling the signal. | 512 // Record time spent for handling the signal. |
| 510 UMA_HISTOGRAM_TIMES("DBus.SignalHandleTime", | 513 UMA_HISTOGRAM_TIMES("DBus.SignalHandleTime", |
| 511 base::TimeTicks::Now() - start_time); | 514 base::TimeTicks::Now() - start_time); |
| 512 } | 515 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 ScopedDBusError error; | 564 ScopedDBusError error; |
| 562 bus_->AddMatch(match_rule, error.get()); | 565 bus_->AddMatch(match_rule, error.get()); |
| 563 if (error.is_set()) { | 566 if (error.is_set()) { |
| 564 LOG(ERROR) << "Failed to add match rule \"" << match_rule << "\". Got " << | 567 LOG(ERROR) << "Failed to add match rule \"" << match_rule << "\". Got " << |
| 565 error.name() << ": " << error.message(); | 568 error.name() << ": " << error.message(); |
| 566 return false; | 569 return false; |
| 567 } else { | 570 } else { |
| 568 // Store the match rule, so that we can remove this in Detach(). | 571 // Store the match rule, so that we can remove this in Detach(). |
| 569 match_rules_.insert(match_rule); | 572 match_rules_.insert(match_rule); |
| 570 // Add the signal callback to the method table. | 573 // Add the signal callback to the method table. |
| 571 method_table_[absolute_signal_name] = signal_callback; | 574 method_table_[absolute_signal_name].push_back(signal_callback); |
| 572 return true; | 575 return true; |
| 573 } | 576 } |
| 574 } else { | 577 } else { |
| 575 // We already have the match rule. | 578 // We already have the match rule. |
| 576 method_table_[absolute_signal_name] = signal_callback; | 579 method_table_[absolute_signal_name].push_back(signal_callback); |
| 577 return true; | 580 return true; |
| 578 } | 581 } |
| 579 } | 582 } |
| 580 | 583 |
| 581 bool ObjectProxy::AddMatchRuleWithoutCallback( | 584 bool ObjectProxy::AddMatchRuleWithoutCallback( |
| 582 const std::string& match_rule, | 585 const std::string& match_rule, |
| 583 const std::string& absolute_signal_name) { | 586 const std::string& absolute_signal_name) { |
| 584 DCHECK(!match_rule.empty()); | 587 DCHECK(!match_rule.empty()); |
| 585 DCHECK(!absolute_signal_name.empty()); | 588 DCHECK(!absolute_signal_name.empty()); |
| 586 bus_->AssertOnDBusThread(); | 589 bus_->AssertOnDBusThread(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 MessageReader reader(signal.get()); | 650 MessageReader reader(signal.get()); |
| 648 std::string name, old_owner, new_owner; | 651 std::string name, old_owner, new_owner; |
| 649 if (reader.PopString(&name) && | 652 if (reader.PopString(&name) && |
| 650 reader.PopString(&old_owner) && | 653 reader.PopString(&old_owner) && |
| 651 reader.PopString(&new_owner) && | 654 reader.PopString(&new_owner) && |
| 652 name == service_name_) { | 655 name == service_name_) { |
| 653 service_name_owner_ = new_owner; | 656 service_name_owner_ = new_owner; |
| 654 if (!name_owner_changed_callback_.is_null()) { | 657 if (!name_owner_changed_callback_.is_null()) { |
| 655 const base::TimeTicks start_time = base::TimeTicks::Now(); | 658 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 656 Signal* released_signal = signal.release(); | 659 Signal* released_signal = signal.release(); |
| 660 std::vector<SignalCallback> callbacks; |
| 661 callbacks.push_back(name_owner_changed_callback_); |
| 657 bus_->PostTaskToOriginThread(FROM_HERE, | 662 bus_->PostTaskToOriginThread(FROM_HERE, |
| 658 base::Bind(&ObjectProxy::RunMethod, | 663 base::Bind(&ObjectProxy::RunMethod, |
| 659 this, | 664 this, |
| 660 start_time, | 665 start_time, |
| 661 name_owner_changed_callback_, | 666 callbacks, |
| 662 released_signal)); | 667 released_signal)); |
| 663 } | 668 } |
| 664 } | 669 } |
| 665 } | 670 } |
| 666 | 671 |
| 667 // Always return unhandled to let other object proxies handle the same | 672 // Always return unhandled to let other object proxies handle the same |
| 668 // signal. | 673 // signal. |
| 669 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 674 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 670 } | 675 } |
| 671 | 676 |
| 672 } // namespace dbus | 677 } // namespace dbus |
| OLD | NEW |