Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: chrome/browser/chromeos/dbus/bluetooth_manager_client.cc

Issue 9363045: Revert 121920 - dbus: add ObjectPath type (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/chromeos/dbus/bluetooth_manager_client.h" 5 #include "chrome/browser/chromeos/dbus/bluetooth_manager_client.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 "chrome/browser/chromeos/system/runtime_environment.h" 9 #include "chrome/browser/chromeos/system/runtime_environment.h"
10 #include "dbus/bus.h" 10 #include "dbus/bus.h"
11 #include "dbus/message.h" 11 #include "dbus/message.h"
12 #include "dbus/object_path.h"
13 #include "dbus/object_proxy.h" 12 #include "dbus/object_proxy.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h" 13 #include "third_party/cros_system_api/dbus/service_constants.h"
15 14
16 namespace chromeos { 15 namespace chromeos {
17 16
18 // The BluetoothManagerClient implementation used in production. 17 // The BluetoothManagerClient implementation used in production.
19 class BluetoothManagerClientImpl : public BluetoothManagerClient { 18 class BluetoothManagerClientImpl : public BluetoothManagerClient {
20 public: 19 public:
21 explicit BluetoothManagerClientImpl(dbus::Bus* bus) 20 explicit BluetoothManagerClientImpl(dbus::Bus* bus)
22 : weak_ptr_factory_(this), 21 : weak_ptr_factory_(this),
23 bluetooth_manager_proxy_(NULL) { 22 bluetooth_manager_proxy_(NULL) {
24 VLOG(1) << "Creating BluetoothManagerClientImpl"; 23 VLOG(1) << "Creating BluetoothManagerClientImpl";
25 24
26 DCHECK(bus); 25 DCHECK(bus);
27 26
28 bluetooth_manager_proxy_ = bus->GetObjectProxy( 27 bluetooth_manager_proxy_ = bus->GetObjectProxy(
29 bluetooth_manager::kBluetoothManagerServiceName, 28 bluetooth_manager::kBluetoothManagerServiceName,
30 dbus::ObjectPath(bluetooth_manager::kBluetoothManagerServicePath)); 29 bluetooth_manager::kBluetoothManagerServicePath);
31 30
32 bluetooth_manager_proxy_->ConnectToSignal( 31 bluetooth_manager_proxy_->ConnectToSignal(
33 bluetooth_manager::kBluetoothManagerInterface, 32 bluetooth_manager::kBluetoothManagerInterface,
34 bluetooth_manager::kAdapterAddedSignal, 33 bluetooth_manager::kAdapterAddedSignal,
35 base::Bind(&BluetoothManagerClientImpl::AdapterAddedReceived, 34 base::Bind(&BluetoothManagerClientImpl::AdapterAddedReceived,
36 weak_ptr_factory_.GetWeakPtr()), 35 weak_ptr_factory_.GetWeakPtr()),
37 base::Bind(&BluetoothManagerClientImpl::AdapterAddedConnected, 36 base::Bind(&BluetoothManagerClientImpl::AdapterAddedConnected,
38 weak_ptr_factory_.GetWeakPtr())); 37 weak_ptr_factory_.GetWeakPtr()));
39 38
40 bluetooth_manager_proxy_->ConnectToSignal( 39 bluetooth_manager_proxy_->ConnectToSignal(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, 84 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
86 base::Bind(&BluetoothManagerClientImpl::OnDefaultAdapter, 85 base::Bind(&BluetoothManagerClientImpl::OnDefaultAdapter,
87 weak_ptr_factory_.GetWeakPtr(), callback)); 86 weak_ptr_factory_.GetWeakPtr(), callback));
88 } 87 }
89 88
90 private: 89 private:
91 // Called by dbus:: when an AdapterAdded signal is received. 90 // Called by dbus:: when an AdapterAdded signal is received.
92 void AdapterAddedReceived(dbus::Signal* signal) { 91 void AdapterAddedReceived(dbus::Signal* signal) {
93 DCHECK(signal); 92 DCHECK(signal);
94 dbus::MessageReader reader(signal); 93 dbus::MessageReader reader(signal);
95 dbus::ObjectPath object_path; 94 std::string object_path;
96 if (!reader.PopObjectPath(&object_path)) { 95 if (!reader.PopObjectPath(&object_path)) {
97 LOG(ERROR) << "AdapterAdded signal has incorrect parameters: " 96 LOG(ERROR) << "AdapterAdded signal has incorrect parameters: "
98 << signal->ToString(); 97 << signal->ToString();
99 return; 98 return;
100 } 99 }
101 VLOG(1) << "Adapter added: " << object_path.value(); 100 VLOG(1) << "Adapter added: " << object_path;
102 FOR_EACH_OBSERVER(Observer, observers_, AdapterAdded(object_path)); 101 FOR_EACH_OBSERVER(Observer, observers_, AdapterAdded(object_path));
103 } 102 }
104 103
105 // Called by dbus:: when the AdapterAdded signal is initially connected. 104 // Called by dbus:: when the AdapterAdded signal is initially connected.
106 void AdapterAddedConnected(const std::string& interface_name, 105 void AdapterAddedConnected(const std::string& interface_name,
107 const std::string& signal_name, 106 const std::string& signal_name,
108 bool success) { 107 bool success) {
109 LOG_IF(WARNING, !success) << "Failed to connect to AdapterAdded signal."; 108 LOG_IF(WARNING, !success) << "Failed to connect to AdapterAdded signal.";
110 } 109 }
111 110
112 // Called by dbus:: when an AdapterRemoved signal is received. 111 // Called by dbus:: when an AdapterRemoved signal is received.
113 void AdapterRemovedReceived(dbus::Signal* signal) { 112 void AdapterRemovedReceived(dbus::Signal* signal) {
114 DCHECK(signal); 113 DCHECK(signal);
115 dbus::MessageReader reader(signal); 114 dbus::MessageReader reader(signal);
116 dbus::ObjectPath object_path; 115 std::string object_path;
117 if (!reader.PopObjectPath(&object_path)) { 116 if (!reader.PopObjectPath(&object_path)) {
118 LOG(ERROR) << "AdapterRemoved signal has incorrect parameters: " 117 LOG(ERROR) << "AdapterRemoved signal has incorrect parameters: "
119 << signal->ToString(); 118 << signal->ToString();
120 return; 119 return;
121 } 120 }
122 VLOG(1) << "Adapter removed: " << object_path.value(); 121 VLOG(1) << "Adapter removed: " << object_path;
123 FOR_EACH_OBSERVER(Observer, observers_, AdapterRemoved(object_path)); 122 FOR_EACH_OBSERVER(Observer, observers_, AdapterRemoved(object_path));
124 } 123 }
125 124
126 // Called by dbus:: when the AdapterRemoved signal is initially connected. 125 // Called by dbus:: when the AdapterRemoved signal is initially connected.
127 void AdapterRemovedConnected(const std::string& interface_name, 126 void AdapterRemovedConnected(const std::string& interface_name,
128 const std::string& signal_name, 127 const std::string& signal_name,
129 bool success) { 128 bool success) {
130 LOG_IF(WARNING, !success) << "Failed to connect to AdapterRemoved signal."; 129 LOG_IF(WARNING, !success) << "Failed to connect to AdapterRemoved signal.";
131 } 130 }
132 131
133 // Called by dbus:: when a DefaultAdapterChanged signal is received. 132 // Called by dbus:: when a DefaultAdapterChanged signal is received.
134 void DefaultAdapterChangedReceived(dbus::Signal* signal) { 133 void DefaultAdapterChangedReceived(dbus::Signal* signal) {
135 DCHECK(signal); 134 DCHECK(signal);
136 dbus::MessageReader reader(signal); 135 dbus::MessageReader reader(signal);
137 dbus::ObjectPath object_path; 136 std::string adapter;
138 if (!reader.PopObjectPath(&object_path)) { 137 if (!reader.PopObjectPath(&adapter)) {
139 LOG(ERROR) << "DefaultAdapterChanged signal has incorrect parameters: " 138 LOG(ERROR) << "DefaultAdapterChanged signal has incorrect parameters: "
140 << signal->ToString(); 139 << signal->ToString();
141 return; 140 return;
142 } 141 }
143 VLOG(1) << "Default adapter changed: " << object_path.value(); 142 VLOG(1) << "Default adapter changed: " << adapter;
144 FOR_EACH_OBSERVER(Observer, observers_, DefaultAdapterChanged(object_path)); 143 FOR_EACH_OBSERVER(Observer, observers_, DefaultAdapterChanged(adapter));
145 } 144 }
146 145
147 // Called by dbus:: when the DefaultAdapterChanged signal is initially 146 // Called by dbus:: when the DefaultAdapterChanged signal is initially
148 // connected. 147 // connected.
149 void DefaultAdapterChangedConnected(const std::string& interface_name, 148 void DefaultAdapterChangedConnected(const std::string& interface_name,
150 const std::string& signal_name, 149 const std::string& signal_name,
151 bool success) { 150 bool success) {
152 LOG_IF(WARNING, !success) 151 LOG_IF(WARNING, !success)
153 << "Failed to connect to DefaultAdapterChanged signal."; 152 << "Failed to connect to DefaultAdapterChanged signal.";
154 } 153 }
155 154
156 // Called when a response for DefaultAdapter() is received. 155 // Called when a response for DefaultAdapter() is received.
157 void OnDefaultAdapter(const DefaultAdapterCallback& callback, 156 void OnDefaultAdapter(const DefaultAdapterCallback& callback,
158 dbus::Response* response) { 157 dbus::Response* response) {
159 // Parse response. 158 // Parse response.
160 bool success = false; 159 bool success = false;
161 dbus::ObjectPath adapter; 160 std::string adapter;
162 if (response != NULL) { 161 if (response != NULL) {
163 dbus::MessageReader reader(response); 162 dbus::MessageReader reader(response);
164 if (!reader.PopObjectPath(&adapter)) { 163 if (!reader.PopObjectPath(&adapter)) {
165 LOG(ERROR) << "DefaultAdapter response has incorrect parameters: " 164 LOG(ERROR) << "DefaultAdapter response has incorrect parameters: "
166 << response->ToString(); 165 << response->ToString();
167 } else { 166 } else {
168 success = true; 167 success = true;
169 LOG(INFO) << "OnDefaultAdapter: " << adapter.value(); 168 LOG(INFO) << "OnDefaultAdapter: " << adapter;
170 } 169 }
171 } else { 170 } else {
172 LOG(ERROR) << "Failed to get default adapter."; 171 LOG(ERROR) << "Failed to get default adapter.";
173 } 172 }
174 173
175 // Notify client. 174 // Notify client.
176 callback.Run(adapter, success); 175 callback.Run(adapter, success);
177 } 176 }
178 177
179 // Weak pointer factory for generating 'this' pointers that might live longer 178 // Weak pointer factory for generating 'this' pointers that might live longer
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 214
216 BluetoothManagerClient* BluetoothManagerClient::Create(dbus::Bus* bus) { 215 BluetoothManagerClient* BluetoothManagerClient::Create(dbus::Bus* bus) {
217 if (system::runtime_environment::IsRunningOnChromeOS()) { 216 if (system::runtime_environment::IsRunningOnChromeOS()) {
218 return new BluetoothManagerClientImpl(bus); 217 return new BluetoothManagerClientImpl(bus);
219 } else { 218 } else {
220 return new BluetoothManagerClientStubImpl(); 219 return new BluetoothManagerClientStubImpl();
221 } 220 }
222 } 221 }
223 222
224 } // namespace chromeos 223 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/dbus/bluetooth_manager_client.h ('k') | chrome/browser/chromeos/dbus/cros_dbus_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698