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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 base::Bind(&ObjectProxy::ConnectToSignalInternal, | 178 base::Bind(&ObjectProxy::ConnectToSignalInternal, |
179 this, | 179 this, |
180 interface_name, | 180 interface_name, |
181 signal_name, | 181 signal_name, |
182 signal_callback), | 182 signal_callback), |
183 base::Bind(on_connected_callback, | 183 base::Bind(on_connected_callback, |
184 interface_name, | 184 interface_name, |
185 signal_name)); | 185 signal_name)); |
186 } | 186 } |
187 | 187 |
| 188 void ObjectProxy::SetNameOwnerChangedCallback( |
| 189 NameOwnerChangedCallback callback) { |
| 190 bus_->AssertOnOriginThread(); |
| 191 |
| 192 name_owner_changed_callback_ = callback; |
| 193 } |
| 194 |
188 void ObjectProxy::Detach() { | 195 void ObjectProxy::Detach() { |
189 bus_->AssertOnDBusThread(); | 196 bus_->AssertOnDBusThread(); |
190 | 197 |
191 if (filter_added_) { | 198 if (filter_added_) { |
192 if (!bus_->RemoveFilterFunction(&ObjectProxy::HandleMessageThunk, this)) { | 199 if (!bus_->RemoveFilterFunction(&ObjectProxy::HandleMessageThunk, this)) { |
193 LOG(ERROR) << "Failed to remove filter function"; | 200 LOG(ERROR) << "Failed to remove filter function"; |
194 } | 201 } |
195 } | 202 } |
196 | 203 |
197 for (std::set<std::string>::iterator iter = match_rules_.begin(); | 204 for (std::set<std::string>::iterator iter = match_rules_.begin(); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 | 407 |
401 // Try getting the current name owner. It's not guaranteed that we can get | 408 // Try getting the current name owner. It's not guaranteed that we can get |
402 // the name owner at this moment, as the service may not yet be started. If | 409 // the name owner at this moment, as the service may not yet be started. If |
403 // that's the case, we'll get the name owner via NameOwnerChanged signal, | 410 // that's the case, we'll get the name owner via NameOwnerChanged signal, |
404 // as soon as the service is started. | 411 // as soon as the service is started. |
405 UpdateNameOwnerAndBlock(); | 412 UpdateNameOwnerAndBlock(); |
406 | 413 |
407 return success; | 414 return success; |
408 } | 415 } |
409 | 416 |
410 void ObjectProxy::SetNameOwnerChangedCallback(SignalCallback callback) { | |
411 bus_->AssertOnOriginThread(); | |
412 | |
413 name_owner_changed_callback_ = callback; | |
414 } | |
415 | |
416 DBusHandlerResult ObjectProxy::HandleMessage( | 417 DBusHandlerResult ObjectProxy::HandleMessage( |
417 DBusConnection* connection, | 418 DBusConnection* connection, |
418 DBusMessage* raw_message) { | 419 DBusMessage* raw_message) { |
419 bus_->AssertOnDBusThread(); | 420 bus_->AssertOnDBusThread(); |
420 | 421 |
421 if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL) | 422 if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL) |
422 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 423 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
423 | 424 |
424 // 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 |
425 // reference so we can use it in Signal. | 426 // reference so we can use it in Signal. |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 if (signal->GetMember() == kNameOwnerChangedMember && | 614 if (signal->GetMember() == kNameOwnerChangedMember && |
614 signal->GetInterface() == kDBusSystemObjectInterface && | 615 signal->GetInterface() == kDBusSystemObjectInterface && |
615 signal->GetSender() == kDBusSystemObjectAddress) { | 616 signal->GetSender() == kDBusSystemObjectAddress) { |
616 MessageReader reader(signal.get()); | 617 MessageReader reader(signal.get()); |
617 std::string name, old_owner, new_owner; | 618 std::string name, old_owner, new_owner; |
618 if (reader.PopString(&name) && | 619 if (reader.PopString(&name) && |
619 reader.PopString(&old_owner) && | 620 reader.PopString(&old_owner) && |
620 reader.PopString(&new_owner) && | 621 reader.PopString(&new_owner) && |
621 name == service_name_) { | 622 name == service_name_) { |
622 service_name_owner_ = new_owner; | 623 service_name_owner_ = new_owner; |
623 if (!name_owner_changed_callback_.is_null()) { | 624 bus_->GetOriginTaskRunner()->PostTask( |
624 const base::TimeTicks start_time = base::TimeTicks::Now(); | 625 FROM_HERE, |
625 Signal* released_signal = signal.release(); | 626 base::Bind(&ObjectProxy::RunNameOwnerChangedCallback, |
626 std::vector<SignalCallback> callbacks; | 627 this, old_owner, new_owner)); |
627 callbacks.push_back(name_owner_changed_callback_); | |
628 bus_->GetOriginTaskRunner()->PostTask( | |
629 FROM_HERE, | |
630 base::Bind(&ObjectProxy::RunMethod, | |
631 this, | |
632 start_time, | |
633 callbacks, | |
634 released_signal)); | |
635 } | |
636 } | 628 } |
637 } | 629 } |
638 | 630 |
639 // Always return unhandled to let other object proxies handle the same | 631 // Always return unhandled to let other object proxies handle the same |
640 // signal. | 632 // signal. |
641 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 633 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
642 } | 634 } |
643 | 635 |
| 636 void ObjectProxy::RunNameOwnerChangedCallback(const std::string& old_owner, |
| 637 const std::string& new_owner) { |
| 638 bus_->AssertOnOriginThread(); |
| 639 if (!name_owner_changed_callback_.is_null()) |
| 640 name_owner_changed_callback_.Run(old_owner, new_owner); |
| 641 } |
| 642 |
644 } // namespace dbus | 643 } // namespace dbus |
OLD | NEW |