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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 401 |
402 void ObjectProxy::OnConnected(OnConnectedCallback on_connected_callback, | 402 void ObjectProxy::OnConnected(OnConnectedCallback on_connected_callback, |
403 const std::string& interface_name, | 403 const std::string& interface_name, |
404 const std::string& signal_name, | 404 const std::string& signal_name, |
405 bool success) { | 405 bool success) { |
406 bus_->AssertOnOriginThread(); | 406 bus_->AssertOnOriginThread(); |
407 | 407 |
408 on_connected_callback.Run(interface_name, signal_name, success); | 408 on_connected_callback.Run(interface_name, signal_name, success); |
409 } | 409 } |
410 | 410 |
| 411 void ObjectProxy::SetNameOwnerChangedCallback(SignalCallback callback) { |
| 412 bus_->AssertOnOriginThread(); |
| 413 |
| 414 name_owner_changed_callback_ = callback; |
| 415 } |
| 416 |
411 DBusHandlerResult ObjectProxy::HandleMessage( | 417 DBusHandlerResult ObjectProxy::HandleMessage( |
412 DBusConnection* connection, | 418 DBusConnection* connection, |
413 DBusMessage* raw_message) { | 419 DBusMessage* raw_message) { |
414 bus_->AssertOnDBusThread(); | 420 bus_->AssertOnDBusThread(); |
415 | 421 |
416 if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL) | 422 if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL) |
417 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 423 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
418 | 424 |
419 // raw_message will be unrefed on exit of the function. Increment the | 425 // raw_message will be unrefed on exit of the function. Increment the |
420 // reference so we can use it in Signal. | 426 // reference so we can use it in Signal. |
421 dbus_message_ref(raw_message); | 427 dbus_message_ref(raw_message); |
422 scoped_ptr<Signal> signal( | 428 scoped_ptr<Signal> signal( |
423 Signal::FromRawMessage(raw_message)); | 429 Signal::FromRawMessage(raw_message)); |
424 | 430 |
425 // Verify the signal comes from the object we're proxying for, this is | 431 // Verify the signal comes from the object we're proxying for, this is |
426 // our last chance to return DBUS_HANDLER_RESULT_NOT_YET_HANDLED and | 432 // our last chance to return DBUS_HANDLER_RESULT_NOT_YET_HANDLED and |
427 // allow other object proxies to handle instead. | 433 // allow other object proxies to handle instead. |
428 const dbus::ObjectPath path = signal->GetPath(); | 434 const dbus::ObjectPath path = signal->GetPath(); |
429 if (path != object_path_) { | 435 if (path != object_path_) { |
430 if (path.value() == kDbusSystemObjectPath && | 436 if (path.value() == kDbusSystemObjectPath && |
431 signal->GetMember() == "NameOwnerChanged") { | 437 signal->GetMember() == "NameOwnerChanged") { |
432 // Handle NameOwnerChanged separately | 438 // Handle NameOwnerChanged separately |
433 return HandleNameOwnerChanged(signal.get()); | 439 return HandleNameOwnerChanged(signal.Pass()); |
434 } | 440 } |
435 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 441 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
436 } | 442 } |
437 | 443 |
438 const std::string interface = signal->GetInterface(); | 444 const std::string interface = signal->GetInterface(); |
439 const std::string member = signal->GetMember(); | 445 const std::string member = signal->GetMember(); |
440 | 446 |
441 // Check if we know about the signal. | 447 // Check if we know about the signal. |
442 const std::string absolute_signal_name = GetAbsoluteSignalName( | 448 const std::string absolute_signal_name = GetAbsoluteSignalName( |
443 interface, member); | 449 interface, member); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 scoped_ptr<Response> response(Response::FromRawMessage(response_message)); | 618 scoped_ptr<Response> response(Response::FromRawMessage(response_message)); |
613 MessageReader reader(response.get()); | 619 MessageReader reader(response.get()); |
614 | 620 |
615 std::string new_service_name_owner; | 621 std::string new_service_name_owner; |
616 if (reader.PopString(&new_service_name_owner)) | 622 if (reader.PopString(&new_service_name_owner)) |
617 service_name_owner_ = new_service_name_owner; | 623 service_name_owner_ = new_service_name_owner; |
618 else | 624 else |
619 service_name_owner_.clear(); | 625 service_name_owner_.clear(); |
620 } | 626 } |
621 | 627 |
622 DBusHandlerResult ObjectProxy::HandleNameOwnerChanged(Signal* signal) { | 628 DBusHandlerResult ObjectProxy::HandleNameOwnerChanged( |
| 629 scoped_ptr<Signal> signal) { |
623 DCHECK(signal); | 630 DCHECK(signal); |
624 bus_->AssertOnDBusThread(); | 631 bus_->AssertOnDBusThread(); |
625 | 632 |
626 // Confirm the validity of the NameOwnerChanged signal. | 633 // Confirm the validity of the NameOwnerChanged signal. |
627 if (signal->GetMember() == "NameOwnerChanged" && | 634 if (signal->GetMember() == "NameOwnerChanged" && |
628 signal->GetInterface() == "org.freedesktop.DBus" && | 635 signal->GetInterface() == "org.freedesktop.DBus" && |
629 signal->GetSender() == "org.freedesktop.DBus") { | 636 signal->GetSender() == "org.freedesktop.DBus") { |
630 MessageReader reader(signal); | 637 MessageReader reader(signal.get()); |
631 std::string name, old_owner, new_owner; | 638 std::string name, old_owner, new_owner; |
632 if (reader.PopString(&name) && | 639 if (reader.PopString(&name) && |
633 reader.PopString(&old_owner) && | 640 reader.PopString(&old_owner) && |
634 reader.PopString(&new_owner) && | 641 reader.PopString(&new_owner) && |
635 name == service_name_) { | 642 name == service_name_) { |
636 service_name_owner_ = new_owner; | 643 service_name_owner_ = new_owner; |
| 644 if (!name_owner_changed_callback_.is_null()) { |
| 645 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 646 Signal* released_signal = signal.release(); |
| 647 bus_->PostTaskToOriginThread(FROM_HERE, |
| 648 base::Bind(&ObjectProxy::RunMethod, |
| 649 this, |
| 650 start_time, |
| 651 name_owner_changed_callback_, |
| 652 released_signal)); |
| 653 } |
637 return DBUS_HANDLER_RESULT_HANDLED; | 654 return DBUS_HANDLER_RESULT_HANDLED; |
638 } | 655 } |
639 } | 656 } |
640 | 657 |
641 // Untrusted or uninteresting signal | 658 // Untrusted or uninteresting signal |
642 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 659 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
643 } | 660 } |
644 | 661 |
645 } // namespace dbus | 662 } // namespace dbus |
OLD | NEW |