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