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 "chromeos/dbus/shill_service_client.h" | 5 #include "chromeos/dbus/shill_service_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/chromeos/chromeos_version.h" | 8 #include "base/chromeos/chromeos_version.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 GetHelper(service_path)->CallDictionaryValueMethodWithErrorCallback( | 68 GetHelper(service_path)->CallDictionaryValueMethodWithErrorCallback( |
69 &method_call, | 69 &method_call, |
70 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS), | 70 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS), |
71 base::Bind(&OnGetPropertiesError, service_path, callback)); | 71 base::Bind(&OnGetPropertiesError, service_path, callback)); |
72 } | 72 } |
73 | 73 |
74 // ShillServiceClient override. | 74 // ShillServiceClient override. |
75 virtual void SetProperty(const dbus::ObjectPath& service_path, | 75 virtual void SetProperty(const dbus::ObjectPath& service_path, |
76 const std::string& name, | 76 const std::string& name, |
77 const base::Value& value, | 77 const base::Value& value, |
78 const VoidDBusMethodCallback& callback) OVERRIDE { | 78 const base::Closure& callback, |
79 const ErrorCallback& error_callback) OVERRIDE { | |
79 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 80 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
80 flimflam::kSetPropertyFunction); | 81 flimflam::kSetPropertyFunction); |
81 dbus::MessageWriter writer(&method_call); | 82 dbus::MessageWriter writer(&method_call); |
82 writer.AppendString(name); | 83 writer.AppendString(name); |
83 ShillClientHelper::AppendValueDataAsVariant(&writer, value); | 84 ShillClientHelper::AppendValueDataAsVariant(&writer, value); |
84 GetHelper(service_path)->CallVoidMethod(&method_call, callback); | 85 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call, |
86 callback, | |
87 error_callback); | |
85 } | 88 } |
86 | 89 |
87 // ShillServiceClient override. | 90 // ShillServiceClient override. |
88 virtual void ClearProperty(const dbus::ObjectPath& service_path, | 91 virtual void ClearProperty(const dbus::ObjectPath& service_path, |
89 const std::string& name, | 92 const std::string& name, |
90 const VoidDBusMethodCallback& callback) OVERRIDE { | 93 const base::Closure& callback, |
94 const ErrorCallback& error_callback) OVERRIDE { | |
91 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 95 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
92 flimflam::kClearPropertyFunction); | 96 flimflam::kClearPropertyFunction); |
93 dbus::MessageWriter writer(&method_call); | 97 dbus::MessageWriter writer(&method_call); |
94 writer.AppendString(name); | 98 writer.AppendString(name); |
95 GetHelper(service_path)->CallVoidMethod(&method_call, callback); | 99 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call, |
100 callback, | |
101 error_callback); | |
96 } | 102 } |
97 | 103 |
98 // ShillServiceClient override. | 104 // ShillServiceClient override. |
99 virtual void Connect(const dbus::ObjectPath& service_path, | 105 virtual void Connect(const dbus::ObjectPath& service_path, |
100 const base::Closure& callback, | 106 const base::Closure& callback, |
101 const ErrorCallback& error_callback) OVERRIDE { | 107 const ErrorCallback& error_callback) OVERRIDE { |
102 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 108 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
103 flimflam::kConnectFunction); | 109 flimflam::kConnectFunction); |
104 GetHelper(service_path)->CallVoidMethodWithErrorCallback( | 110 GetHelper(service_path)->CallVoidMethodWithErrorCallback( |
105 &method_call, callback, error_callback); | 111 &method_call, callback, error_callback); |
106 } | 112 } |
107 | 113 |
108 // ShillServiceClient override. | 114 // ShillServiceClient override. |
109 virtual void Disconnect(const dbus::ObjectPath& service_path, | 115 virtual void Disconnect(const dbus::ObjectPath& service_path, |
110 const VoidDBusMethodCallback& callback) OVERRIDE { | 116 const base::Closure& callback, |
117 const ErrorCallback& error_callback) OVERRIDE { | |
111 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 118 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
112 flimflam::kDisconnectFunction); | 119 flimflam::kDisconnectFunction); |
113 GetHelper(service_path)->CallVoidMethod(&method_call, callback); | 120 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call, |
121 callback, | |
122 error_callback); | |
114 } | 123 } |
115 | 124 |
116 // ShillServiceClient override. | 125 // ShillServiceClient override. |
117 virtual void Remove(const dbus::ObjectPath& service_path, | 126 virtual void Remove(const dbus::ObjectPath& service_path, |
118 const VoidDBusMethodCallback& callback) OVERRIDE { | 127 const base::Closure& callback, |
128 const ErrorCallback& error_callback) OVERRIDE { | |
119 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 129 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
120 flimflam::kRemoveServiceFunction); | 130 flimflam::kRemoveServiceFunction); |
121 GetHelper(service_path)->CallVoidMethod(&method_call, callback); | 131 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call, |
132 callback, | |
133 error_callback); | |
122 } | 134 } |
123 | 135 |
124 // ShillServiceClient override. | 136 // ShillServiceClient override. |
125 virtual void ActivateCellularModem( | 137 virtual void ActivateCellularModem( |
126 const dbus::ObjectPath& service_path, | 138 const dbus::ObjectPath& service_path, |
127 const std::string& carrier, | 139 const std::string& carrier, |
128 const VoidDBusMethodCallback& callback) OVERRIDE { | 140 const base::Closure& callback, |
141 const ErrorCallback& error_callback) OVERRIDE { | |
129 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 142 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
130 flimflam::kActivateCellularModemFunction); | 143 flimflam::kActivateCellularModemFunction); |
131 dbus::MessageWriter writer(&method_call); | 144 dbus::MessageWriter writer(&method_call); |
132 writer.AppendString(carrier); | 145 writer.AppendString(carrier); |
133 GetHelper(service_path)->CallVoidMethod(&method_call, callback); | 146 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call, |
147 callback, | |
148 error_callback); | |
134 } | 149 } |
135 | 150 |
136 // ShillServiceClient override. | 151 // ShillServiceClient override. |
137 virtual bool CallActivateCellularModemAndBlock( | 152 virtual bool CallActivateCellularModemAndBlock( |
138 const dbus::ObjectPath& service_path, | 153 const dbus::ObjectPath& service_path, |
139 const std::string& carrier) OVERRIDE { | 154 const std::string& carrier) OVERRIDE { |
140 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 155 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
141 flimflam::kActivateCellularModemFunction); | 156 flimflam::kActivateCellularModemFunction); |
142 dbus::MessageWriter writer(&method_call); | 157 dbus::MessageWriter writer(&method_call); |
143 writer.AppendString(carrier); | 158 writer.AppendString(carrier); |
(...skipping 25 matching lines...) Expand all Loading... | |
169 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientImpl); | 184 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientImpl); |
170 }; | 185 }; |
171 | 186 |
172 // A stub implementation of ShillServiceClient. | 187 // A stub implementation of ShillServiceClient. |
173 class ShillServiceClientStubImpl : public ShillServiceClient { | 188 class ShillServiceClientStubImpl : public ShillServiceClient { |
174 public: | 189 public: |
175 ShillServiceClientStubImpl() : weak_ptr_factory_(this) {} | 190 ShillServiceClientStubImpl() : weak_ptr_factory_(this) {} |
176 | 191 |
177 virtual ~ShillServiceClientStubImpl() {} | 192 virtual ~ShillServiceClientStubImpl() {} |
178 | 193 |
179 // ShillServiceClient override. | 194 // ShillServiceClient override |
hashimoto
2012/09/24 02:28:56
nit: Revert this line to make it easy to merge cha
Greg Spencer (Chromium)
2012/09/24 21:50:54
Done.
| |
180 virtual void SetPropertyChangedHandler( | 195 virtual void SetPropertyChangedHandler( |
181 const dbus::ObjectPath& service_path, | 196 const dbus::ObjectPath& service_path, |
182 const PropertyChangedHandler& handler) OVERRIDE {} | 197 const PropertyChangedHandler& handler) OVERRIDE {} |
183 | 198 |
184 // ShillServiceClient override. | 199 // ShillServiceClient override. |
185 virtual void ResetPropertyChangedHandler( | 200 virtual void ResetPropertyChangedHandler( |
186 const dbus::ObjectPath& service_path) OVERRIDE {} | 201 const dbus::ObjectPath& service_path) OVERRIDE {} |
187 | 202 |
188 // ShillServiceClient override. | 203 // ShillServiceClient override. |
189 virtual void GetProperties(const dbus::ObjectPath& service_path, | 204 virtual void GetProperties(const dbus::ObjectPath& service_path, |
190 const DictionaryValueCallback& callback) OVERRIDE { | 205 const DictionaryValueCallback& callback) OVERRIDE { |
191 MessageLoop::current()->PostTask( | 206 MessageLoop::current()->PostTask( |
192 FROM_HERE, | 207 FROM_HERE, |
193 base::Bind(&ShillServiceClientStubImpl::PassEmptyDictionaryValue, | 208 base::Bind(&ShillServiceClientStubImpl::PassEmptyDictionaryValue, |
194 weak_ptr_factory_.GetWeakPtr(), | 209 weak_ptr_factory_.GetWeakPtr(), |
195 callback)); | 210 callback)); |
196 } | 211 } |
197 | 212 |
198 // ShillServiceClient override. | 213 // ShillServiceClient override. |
199 virtual void SetProperty(const dbus::ObjectPath& service_path, | 214 virtual void SetProperty(const dbus::ObjectPath& service_path, |
200 const std::string& name, | 215 const std::string& name, |
201 const base::Value& value, | 216 const base::Value& value, |
202 const VoidDBusMethodCallback& callback) OVERRIDE { | 217 const base::Closure& callback, |
203 PostSuccessVoidCallback(callback); | 218 const ErrorCallback& error_callback) OVERRIDE { |
219 MessageLoop::current()->PostTask(FROM_HERE, callback); | |
204 } | 220 } |
205 | 221 |
206 // ShillServiceClient override. | 222 // ShillServiceClient override. |
207 virtual void ClearProperty(const dbus::ObjectPath& service_path, | 223 virtual void ClearProperty(const dbus::ObjectPath& service_path, |
208 const std::string& name, | 224 const std::string& name, |
209 const VoidDBusMethodCallback& callback) OVERRIDE { | 225 const base::Closure& callback, |
210 PostSuccessVoidCallback(callback); | 226 const ErrorCallback& error_callback) OVERRIDE { |
227 MessageLoop::current()->PostTask(FROM_HERE, callback); | |
211 } | 228 } |
212 | 229 |
213 // ShillServiceClient override. | 230 // ShillServiceClient override. |
214 virtual void Connect(const dbus::ObjectPath& service_path, | 231 virtual void Connect(const dbus::ObjectPath& service_path, |
215 const base::Closure& callback, | 232 const base::Closure& callback, |
216 const ErrorCallback& error_callback) OVERRIDE { | 233 const ErrorCallback& error_callback) OVERRIDE { |
217 MessageLoop::current()->PostTask(FROM_HERE, callback); | 234 MessageLoop::current()->PostTask(FROM_HERE, callback); |
218 } | 235 } |
219 | 236 |
220 // ShillServiceClient override. | 237 // ShillServiceClient override. |
221 virtual void Disconnect(const dbus::ObjectPath& service_path, | 238 virtual void Disconnect(const dbus::ObjectPath& service_path, |
222 const VoidDBusMethodCallback& callback) OVERRIDE { | 239 const base::Closure& callback, |
223 PostSuccessVoidCallback(callback); | 240 const ErrorCallback& error_callback) OVERRIDE { |
241 MessageLoop::current()->PostTask(FROM_HERE, callback); | |
224 } | 242 } |
225 | 243 |
226 // ShillServiceClient override. | 244 // ShillServiceClient override. |
227 virtual void Remove(const dbus::ObjectPath& service_path, | 245 virtual void Remove(const dbus::ObjectPath& service_path, |
228 const VoidDBusMethodCallback& callback) OVERRIDE { | 246 const base::Closure& callback, |
229 PostSuccessVoidCallback(callback); | 247 const ErrorCallback& error_callback) OVERRIDE { |
248 MessageLoop::current()->PostTask(FROM_HERE, callback); | |
230 } | 249 } |
231 | 250 |
232 // ShillServiceClient override. | 251 // ShillServiceClient override. |
233 virtual void ActivateCellularModem( | 252 virtual void ActivateCellularModem( |
234 const dbus::ObjectPath& service_path, | 253 const dbus::ObjectPath& service_path, |
235 const std::string& carrier, | 254 const std::string& carrier, |
236 const VoidDBusMethodCallback& callback) OVERRIDE { | 255 const base::Closure& callback, |
237 PostSuccessVoidCallback(callback); | 256 const ErrorCallback& error_callback) OVERRIDE { |
257 MessageLoop::current()->PostTask(FROM_HERE, callback); | |
238 } | 258 } |
239 | 259 |
240 // ShillServiceClient override. | 260 // ShillServiceClient override. |
241 virtual bool CallActivateCellularModemAndBlock( | 261 virtual bool CallActivateCellularModemAndBlock( |
242 const dbus::ObjectPath& service_path, | 262 const dbus::ObjectPath& service_path, |
243 const std::string& carrier) OVERRIDE { | 263 const std::string& carrier) OVERRIDE { |
244 return true; | 264 return true; |
245 } | 265 } |
246 | 266 |
247 private: | 267 private: |
248 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { | 268 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { |
249 base::DictionaryValue dictionary; | 269 base::DictionaryValue dictionary; |
250 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); | 270 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); |
251 } | 271 } |
252 | 272 |
253 // Posts a task to run a void callback with success status code. | |
254 void PostSuccessVoidCallback(const VoidDBusMethodCallback& callback) { | |
255 MessageLoop::current()->PostTask(FROM_HERE, | |
256 base::Bind(callback, | |
257 DBUS_METHOD_CALL_SUCCESS)); | |
258 } | |
259 | |
260 // Note: This should remain the last member so it'll be destroyed and | 273 // Note: This should remain the last member so it'll be destroyed and |
261 // invalidate its weak pointers before any other members are destroyed. | 274 // invalidate its weak pointers before any other members are destroyed. |
262 base::WeakPtrFactory<ShillServiceClientStubImpl> weak_ptr_factory_; | 275 base::WeakPtrFactory<ShillServiceClientStubImpl> weak_ptr_factory_; |
263 | 276 |
264 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientStubImpl); | 277 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientStubImpl); |
265 }; | 278 }; |
266 | 279 |
267 } // namespace | 280 } // namespace |
268 | 281 |
269 ShillServiceClient::ShillServiceClient() {} | 282 ShillServiceClient::ShillServiceClient() {} |
270 | 283 |
271 ShillServiceClient::~ShillServiceClient() {} | 284 ShillServiceClient::~ShillServiceClient() {} |
272 | 285 |
273 // static | 286 // static |
274 ShillServiceClient* ShillServiceClient::Create( | 287 ShillServiceClient* ShillServiceClient::Create( |
275 DBusClientImplementationType type, | 288 DBusClientImplementationType type, |
276 dbus::Bus* bus) { | 289 dbus::Bus* bus) { |
277 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 290 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
278 return new ShillServiceClientImpl(bus); | 291 return new ShillServiceClientImpl(bus); |
279 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 292 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
280 return new ShillServiceClientStubImpl(); | 293 return new ShillServiceClientStubImpl(); |
281 } | 294 } |
282 | 295 |
283 } // namespace chromeos | 296 } // namespace chromeos |
OLD | NEW |