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/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 void Bus::AssertOnDBusThread() { | 829 void Bus::AssertOnDBusThread() { |
830 base::ThreadRestrictions::AssertIOAllowed(); | 830 base::ThreadRestrictions::AssertIOAllowed(); |
831 | 831 |
832 if (dbus_task_runner_.get()) { | 832 if (dbus_task_runner_.get()) { |
833 DCHECK(dbus_task_runner_->RunsTasksOnCurrentThread()); | 833 DCHECK(dbus_task_runner_->RunsTasksOnCurrentThread()); |
834 } else { | 834 } else { |
835 AssertOnOriginThread(); | 835 AssertOnOriginThread(); |
836 } | 836 } |
837 } | 837 } |
838 | 838 |
| 839 std::string Bus::GetServiceOwnerAndBlock(const std::string& service_name, |
| 840 GetServiceOwnerOption options) { |
| 841 AssertOnDBusThread(); |
| 842 |
| 843 MethodCall get_name_owner_call("org.freedesktop.DBus", "GetNameOwner"); |
| 844 MessageWriter writer(&get_name_owner_call); |
| 845 writer.AppendString(service_name); |
| 846 VLOG(1) << "Method call: " << get_name_owner_call.ToString(); |
| 847 |
| 848 const ObjectPath obj_path("/org/freedesktop/DBus"); |
| 849 if (!get_name_owner_call.SetDestination("org.freedesktop.DBus") || |
| 850 !get_name_owner_call.SetPath(obj_path)) { |
| 851 if (options == REPORT_ERRORS) |
| 852 LOG(ERROR) << "Failed to get name owner."; |
| 853 return ""; |
| 854 } |
| 855 |
| 856 ScopedDBusError error; |
| 857 DBusMessage* response_message = |
| 858 SendWithReplyAndBlock(get_name_owner_call.raw_message(), |
| 859 ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 860 error.get()); |
| 861 if (!response_message) { |
| 862 if (options == REPORT_ERRORS) { |
| 863 LOG(ERROR) << "Failed to get name owner. Got " << error.name() << ": " |
| 864 << error.message(); |
| 865 } |
| 866 return ""; |
| 867 } |
| 868 |
| 869 scoped_ptr<Response> response(Response::FromRawMessage(response_message)); |
| 870 MessageReader reader(response.get()); |
| 871 |
| 872 std::string service_owner; |
| 873 if (!reader.PopString(&service_owner)) |
| 874 service_owner.clear(); |
| 875 return service_owner; |
| 876 } |
| 877 |
| 878 void Bus::GetServiceOwner(const std::string& service_name, |
| 879 const GetServiceOwnerCallback& callback) { |
| 880 AssertOnOriginThread(); |
| 881 |
| 882 PostTaskToDBusThread( |
| 883 FROM_HERE, |
| 884 base::Bind(&Bus::GetServiceOwnerInternal, this, service_name, callback)); |
| 885 } |
| 886 |
| 887 void Bus::GetServiceOwnerInternal(const std::string& service_name, |
| 888 const GetServiceOwnerCallback& callback) { |
| 889 AssertOnDBusThread(); |
| 890 |
| 891 std::string service_owner; |
| 892 if (Connect()) |
| 893 service_owner = GetServiceOwnerAndBlock(service_name, REPORT_ERRORS); |
| 894 PostTaskToOriginThread(FROM_HERE, base::Bind(callback, service_owner)); |
| 895 } |
| 896 |
839 dbus_bool_t Bus::OnAddWatch(DBusWatch* raw_watch) { | 897 dbus_bool_t Bus::OnAddWatch(DBusWatch* raw_watch) { |
840 AssertOnDBusThread(); | 898 AssertOnDBusThread(); |
841 | 899 |
842 // watch will be deleted when raw_watch is removed in OnRemoveWatch(). | 900 // watch will be deleted when raw_watch is removed in OnRemoveWatch(). |
843 Watch* watch = new Watch(raw_watch); | 901 Watch* watch = new Watch(raw_watch); |
844 if (watch->IsReadyToBeWatched()) { | 902 if (watch->IsReadyToBeWatched()) { |
845 watch->StartWatching(); | 903 watch->StartWatching(); |
846 } | 904 } |
847 ++num_pending_watches_; | 905 ++num_pending_watches_; |
848 return true; | 906 return true; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 kDisconnectedSignal)) { | 1032 kDisconnectedSignal)) { |
975 Bus* self = static_cast<Bus*>(data); | 1033 Bus* self = static_cast<Bus*>(data); |
976 self->AssertOnDBusThread(); | 1034 self->AssertOnDBusThread(); |
977 self->OnConnectionDisconnected(connection); | 1035 self->OnConnectionDisconnected(connection); |
978 return DBUS_HANDLER_RESULT_HANDLED; | 1036 return DBUS_HANDLER_RESULT_HANDLED; |
979 } | 1037 } |
980 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 1038 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
981 } | 1039 } |
982 | 1040 |
983 } // namespace dbus | 1041 } // namespace dbus |
OLD | NEW |