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

Side by Side Diff: chromeos/dbus/flimflam_device_client.cc

Issue 10170020: Rework chromeos::FlimflamDevice/ServiceClient with CallMethodWithErrorCallback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 8 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 "chromeos/dbus/flimflam_device_client.h" 5 #include "chromeos/dbus/flimflam_device_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 flimflam::kAddIPConfigFunction); 108 flimflam::kAddIPConfigFunction);
109 dbus::MessageWriter writer(&method_call); 109 dbus::MessageWriter writer(&method_call);
110 writer.AppendString(method); 110 writer.AppendString(method);
111 return GetHelper(device_path)->CallObjectPathMethodAndBlock(&method_call); 111 return GetHelper(device_path)->CallObjectPathMethodAndBlock(&method_call);
112 } 112 }
113 113
114 // FlimflamProfileClient override. 114 // FlimflamProfileClient override.
115 virtual void RequirePin(const dbus::ObjectPath& device_path, 115 virtual void RequirePin(const dbus::ObjectPath& device_path,
116 const std::string& pin, 116 const std::string& pin,
117 bool require, 117 bool require,
118 const VoidCallback& callback) OVERRIDE { 118 const base::Closure& callback,
119 const ErrorCallback& error_callback) OVERRIDE {
119 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, 120 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
120 flimflam::kRequirePinFunction); 121 flimflam::kRequirePinFunction);
121 dbus::MessageWriter writer(&method_call); 122 dbus::MessageWriter writer(&method_call);
122 writer.AppendString(pin); 123 writer.AppendString(pin);
123 writer.AppendBool(require); 124 writer.AppendBool(require);
124 GetHelper(device_path)->CallVoidMethod(&method_call, callback); 125 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
126 &method_call, callback, error_callback);
125 } 127 }
126 128
127 // FlimflamProfileClient override. 129 // FlimflamProfileClient override.
128 virtual void EnterPin(const dbus::ObjectPath& device_path, 130 virtual void EnterPin(const dbus::ObjectPath& device_path,
129 const std::string& pin, 131 const std::string& pin,
130 const VoidCallback& callback) OVERRIDE { 132 const base::Closure& callback,
133 const ErrorCallback& error_callback) OVERRIDE {
131 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, 134 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
132 flimflam::kEnterPinFunction); 135 flimflam::kEnterPinFunction);
133 dbus::MessageWriter writer(&method_call); 136 dbus::MessageWriter writer(&method_call);
134 writer.AppendString(pin); 137 writer.AppendString(pin);
135 GetHelper(device_path)->CallVoidMethod(&method_call, callback); 138 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
139 &method_call, callback, error_callback);
136 } 140 }
137 141
138 // FlimflamProfileClient override. 142 // FlimflamProfileClient override.
139 virtual void UnblockPin(const dbus::ObjectPath& device_path, 143 virtual void UnblockPin(const dbus::ObjectPath& device_path,
140 const std::string& puk, 144 const std::string& puk,
141 const std::string& pin, 145 const std::string& pin,
142 const VoidCallback& callback) OVERRIDE { 146 const base::Closure& callback,
147 const ErrorCallback& error_callback) OVERRIDE {
143 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, 148 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
144 flimflam::kUnblockPinFunction); 149 flimflam::kUnblockPinFunction);
145 dbus::MessageWriter writer(&method_call); 150 dbus::MessageWriter writer(&method_call);
146 writer.AppendString(puk); 151 writer.AppendString(puk);
147 writer.AppendString(pin); 152 writer.AppendString(pin);
148 GetHelper(device_path)->CallVoidMethod(&method_call, callback); 153 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
154 &method_call, callback, error_callback);
149 } 155 }
150 156
151 // FlimflamProfileClient override. 157 // FlimflamProfileClient override.
152 virtual void ChangePin(const dbus::ObjectPath& device_path, 158 virtual void ChangePin(const dbus::ObjectPath& device_path,
153 const std::string& old_pin, 159 const std::string& old_pin,
154 const std::string& new_pin, 160 const std::string& new_pin,
155 const VoidCallback& callback) OVERRIDE { 161 const base::Closure& callback,
162 const ErrorCallback& error_callback) OVERRIDE {
156 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, 163 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
157 flimflam::kChangePinFunction); 164 flimflam::kChangePinFunction);
158 dbus::MessageWriter writer(&method_call); 165 dbus::MessageWriter writer(&method_call);
159 writer.AppendString(old_pin); 166 writer.AppendString(old_pin);
160 writer.AppendString(new_pin); 167 writer.AppendString(new_pin);
161 GetHelper(device_path)->CallVoidMethod(&method_call, callback); 168 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
169 &method_call, callback, error_callback);
162 } 170 }
163 171
164 // FlimflamProfileClient override. 172 // FlimflamProfileClient override.
165 virtual void Register(const dbus::ObjectPath& device_path, 173 virtual void Register(const dbus::ObjectPath& device_path,
166 const std::string& network_id, 174 const std::string& network_id,
167 const VoidCallback& callback) OVERRIDE { 175 const base::Closure& callback,
176 const ErrorCallback& error_callback) OVERRIDE {
168 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface, 177 dbus::MethodCall method_call(flimflam::kFlimflamDeviceInterface,
169 flimflam::kRegisterFunction); 178 flimflam::kRegisterFunction);
170 dbus::MessageWriter writer(&method_call); 179 dbus::MessageWriter writer(&method_call);
171 writer.AppendString(network_id); 180 writer.AppendString(network_id);
172 GetHelper(device_path)->CallVoidMethod(&method_call, callback); 181 GetHelper(device_path)->CallVoidMethodWithErrorCallback(
182 &method_call, callback, error_callback);
173 } 183 }
174 184
175 private: 185 private:
176 typedef std::map<std::string, FlimflamClientHelper*> HelperMap; 186 typedef std::map<std::string, FlimflamClientHelper*> HelperMap;
177 187
178 // Returns the corresponding FlimflamClientHelper for the profile. 188 // Returns the corresponding FlimflamClientHelper for the profile.
179 FlimflamClientHelper* GetHelper(const dbus::ObjectPath& device_path) { 189 FlimflamClientHelper* GetHelper(const dbus::ObjectPath& device_path) {
180 HelperMap::iterator it = helpers_.find(device_path.value()); 190 HelperMap::iterator it = helpers_.find(device_path.value());
181 if (it != helpers_.end()) 191 if (it != helpers_.end())
182 return it->second; 192 return it->second;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 virtual dbus::ObjectPath CallAddIPConfigAndBlock( 274 virtual dbus::ObjectPath CallAddIPConfigAndBlock(
265 const dbus::ObjectPath& device_path, 275 const dbus::ObjectPath& device_path,
266 const std::string& method) OVERRIDE { 276 const std::string& method) OVERRIDE {
267 return dbus::ObjectPath(); 277 return dbus::ObjectPath();
268 } 278 }
269 279
270 // FlimflamDeviceClient override. 280 // FlimflamDeviceClient override.
271 virtual void RequirePin(const dbus::ObjectPath& device_path, 281 virtual void RequirePin(const dbus::ObjectPath& device_path,
272 const std::string& pin, 282 const std::string& pin,
273 bool require, 283 bool require,
274 const VoidCallback& callback) OVERRIDE { 284 const base::Closure& callback,
275 PostSuccessVoidCallback(callback); 285 const ErrorCallback& error_callback) OVERRIDE {
286 MessageLoop::current()->PostTask(FROM_HERE, callback);
276 } 287 }
277 288
278 // FlimflamDeviceClient override. 289 // FlimflamDeviceClient override.
279 virtual void EnterPin(const dbus::ObjectPath& device_path, 290 virtual void EnterPin(const dbus::ObjectPath& device_path,
280 const std::string& pin, 291 const std::string& pin,
281 const VoidCallback& callback) OVERRIDE { 292 const base::Closure& callback,
282 PostSuccessVoidCallback(callback); 293 const ErrorCallback& error_callback) OVERRIDE {
294 MessageLoop::current()->PostTask(FROM_HERE, callback);
283 } 295 }
284 296
285 // FlimflamDeviceClient override. 297 // FlimflamDeviceClient override.
286 virtual void UnblockPin(const dbus::ObjectPath& device_path, 298 virtual void UnblockPin(const dbus::ObjectPath& device_path,
287 const std::string& puk, 299 const std::string& puk,
288 const std::string& pin, 300 const std::string& pin,
289 const VoidCallback& callback) OVERRIDE { 301 const base::Closure& callback,
290 PostSuccessVoidCallback(callback); 302 const ErrorCallback& error_callback) OVERRIDE {
303 MessageLoop::current()->PostTask(FROM_HERE, callback);
291 } 304 }
292 305
293 // FlimflamDeviceClient override. 306 // FlimflamDeviceClient override.
294 virtual void ChangePin(const dbus::ObjectPath& device_path, 307 virtual void ChangePin(const dbus::ObjectPath& device_path,
295 const std::string& old_pin, 308 const std::string& old_pin,
296 const std::string& new_pin, 309 const std::string& new_pin,
297 const VoidCallback& callback) OVERRIDE { 310 const base::Closure& callback,
298 PostSuccessVoidCallback(callback); 311 const ErrorCallback& error_callback) OVERRIDE {
312 MessageLoop::current()->PostTask(FROM_HERE, callback);
299 } 313 }
300 314
301 // FlimflamDeviceClient override. 315 // FlimflamDeviceClient override.
302 virtual void Register(const dbus::ObjectPath& device_path, 316 virtual void Register(const dbus::ObjectPath& device_path,
303 const std::string& network_id, 317 const std::string& network_id,
304 const VoidCallback& callback) OVERRIDE { 318 const base::Closure& callback,
305 PostSuccessVoidCallback(callback); 319 const ErrorCallback& error_callback) OVERRIDE {
320 MessageLoop::current()->PostTask(FROM_HERE, callback);
306 } 321 }
307 322
308 private: 323 private:
309 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { 324 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const {
310 base::DictionaryValue dictionary; 325 base::DictionaryValue dictionary;
311 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); 326 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary);
312 } 327 }
313 328
314 // Posts a task to run a void callback with success status code. 329 // Posts a task to run a void callback with success status code.
315 void PostSuccessVoidCallback(const VoidCallback& callback) { 330 void PostSuccessVoidCallback(const VoidCallback& callback) {
(...skipping 17 matching lines...) Expand all
333 FlimflamDeviceClient* FlimflamDeviceClient::Create( 348 FlimflamDeviceClient* FlimflamDeviceClient::Create(
334 DBusClientImplementationType type, 349 DBusClientImplementationType type,
335 dbus::Bus* bus) { 350 dbus::Bus* bus) {
336 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 351 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
337 return new FlimflamDeviceClientImpl(bus); 352 return new FlimflamDeviceClientImpl(bus);
338 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 353 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
339 return new FlimflamDeviceClientStubImpl(); 354 return new FlimflamDeviceClientStubImpl();
340 } 355 }
341 356
342 } // namespace chromeos 357 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/flimflam_device_client.h ('k') | chromeos/dbus/flimflam_device_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698