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

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

Issue 10949030: This converts the Shill clients to allow propagation of shill errors (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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
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/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 29 matching lines...) Expand all
40 } 40 }
41 41
42 // The ShillServiceClient implementation. 42 // The ShillServiceClient implementation.
43 class ShillServiceClientImpl : public ShillServiceClient { 43 class ShillServiceClientImpl : public ShillServiceClient {
44 public: 44 public:
45 explicit ShillServiceClientImpl(dbus::Bus* bus) 45 explicit ShillServiceClientImpl(dbus::Bus* bus)
46 : bus_(bus), 46 : bus_(bus),
47 helpers_deleter_(&helpers_) { 47 helpers_deleter_(&helpers_) {
48 } 48 }
49 49
50 // ShillServiceClient override. 50 /////////////////////////////////////
51 virtual void SetPropertyChangedHandler( 51 // ShillServiceClient overrides.
52 virtual void AddPropertyChangedObserver(
52 const dbus::ObjectPath& service_path, 53 const dbus::ObjectPath& service_path,
53 const PropertyChangedHandler& handler) OVERRIDE { 54 PropertyChangedObserver* observer) OVERRIDE {
54 GetHelper(service_path)->SetPropertyChangedHandler(handler); 55 GetHelper(service_path)->AddPropertyChangedObserver(observer);
55 } 56 }
56 57
57 // ShillServiceClient override. 58 virtual void RemovePropertyChangedObserver(
58 virtual void ResetPropertyChangedHandler( 59 const dbus::ObjectPath& service_path,
59 const dbus::ObjectPath& service_path) OVERRIDE { 60 PropertyChangedObserver* observer) OVERRIDE {
60 GetHelper(service_path)->ResetPropertyChangedHandler(); 61 GetHelper(service_path)->RemovePropertyChangedObserver(observer);
61 } 62 }
62 63
63 // ShillServiceClient override.
64 virtual void GetProperties(const dbus::ObjectPath& service_path, 64 virtual void GetProperties(const dbus::ObjectPath& service_path,
65 const DictionaryValueCallback& callback) OVERRIDE { 65 const DictionaryValueCallback& callback) OVERRIDE {
66 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 66 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
67 flimflam::kGetPropertiesFunction); 67 flimflam::kGetPropertiesFunction);
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.
75 virtual void SetProperty(const dbus::ObjectPath& service_path, 74 virtual void SetProperty(const dbus::ObjectPath& service_path,
76 const std::string& name, 75 const std::string& name,
77 const base::Value& value, 76 const base::Value& value,
78 const VoidDBusMethodCallback& callback) OVERRIDE { 77 const base::Closure& callback,
78 const ErrorCallback& error_callback) OVERRIDE {
79 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 79 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
80 flimflam::kSetPropertyFunction); 80 flimflam::kSetPropertyFunction);
81 dbus::MessageWriter writer(&method_call); 81 dbus::MessageWriter writer(&method_call);
82 writer.AppendString(name); 82 writer.AppendString(name);
83 ShillClientHelper::AppendValueDataAsVariant(&writer, value); 83 ShillClientHelper::AppendValueDataAsVariant(&writer, value);
84 GetHelper(service_path)->CallVoidMethod(&method_call, callback); 84 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call,
85 callback,
86 error_callback);
85 } 87 }
86 88
87 // ShillServiceClient override.
88 virtual void ClearProperty(const dbus::ObjectPath& service_path, 89 virtual void ClearProperty(const dbus::ObjectPath& service_path,
89 const std::string& name, 90 const std::string& name,
90 const VoidDBusMethodCallback& callback) OVERRIDE { 91 const base::Closure& callback,
92 const ErrorCallback& error_callback) OVERRIDE {
91 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 93 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
92 flimflam::kClearPropertyFunction); 94 flimflam::kClearPropertyFunction);
93 dbus::MessageWriter writer(&method_call); 95 dbus::MessageWriter writer(&method_call);
94 writer.AppendString(name); 96 writer.AppendString(name);
95 GetHelper(service_path)->CallVoidMethod(&method_call, callback); 97 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call,
98 callback,
99 error_callback);
96 } 100 }
97 101
98 // ShillServiceClient override.
99 virtual void Connect(const dbus::ObjectPath& service_path, 102 virtual void Connect(const dbus::ObjectPath& service_path,
100 const base::Closure& callback, 103 const base::Closure& callback,
101 const ErrorCallback& error_callback) OVERRIDE { 104 const ErrorCallback& error_callback) OVERRIDE {
102 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 105 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
103 flimflam::kConnectFunction); 106 flimflam::kConnectFunction);
104 GetHelper(service_path)->CallVoidMethodWithErrorCallback( 107 GetHelper(service_path)->CallVoidMethodWithErrorCallback(
105 &method_call, callback, error_callback); 108 &method_call, callback, error_callback);
106 } 109 }
107 110
108 // ShillServiceClient override.
109 virtual void Disconnect(const dbus::ObjectPath& service_path, 111 virtual void Disconnect(const dbus::ObjectPath& service_path,
110 const VoidDBusMethodCallback& callback) OVERRIDE { 112 const base::Closure& callback,
113 const ErrorCallback& error_callback) OVERRIDE {
111 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 114 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
112 flimflam::kDisconnectFunction); 115 flimflam::kDisconnectFunction);
113 GetHelper(service_path)->CallVoidMethod(&method_call, callback); 116 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call,
117 callback,
118 error_callback);
114 } 119 }
115 120
116 // ShillServiceClient override.
117 virtual void Remove(const dbus::ObjectPath& service_path, 121 virtual void Remove(const dbus::ObjectPath& service_path,
118 const VoidDBusMethodCallback& callback) OVERRIDE { 122 const base::Closure& callback,
123 const ErrorCallback& error_callback) OVERRIDE {
119 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 124 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
120 flimflam::kRemoveServiceFunction); 125 flimflam::kRemoveServiceFunction);
121 GetHelper(service_path)->CallVoidMethod(&method_call, callback); 126 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call,
127 callback,
128 error_callback);
122 } 129 }
123 130
124 // ShillServiceClient override.
125 virtual void ActivateCellularModem( 131 virtual void ActivateCellularModem(
126 const dbus::ObjectPath& service_path, 132 const dbus::ObjectPath& service_path,
127 const std::string& carrier, 133 const std::string& carrier,
128 const VoidDBusMethodCallback& callback) OVERRIDE { 134 const base::Closure& callback,
135 const ErrorCallback& error_callback) OVERRIDE {
129 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 136 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
130 flimflam::kActivateCellularModemFunction); 137 flimflam::kActivateCellularModemFunction);
131 dbus::MessageWriter writer(&method_call); 138 dbus::MessageWriter writer(&method_call);
132 writer.AppendString(carrier); 139 writer.AppendString(carrier);
133 GetHelper(service_path)->CallVoidMethod(&method_call, callback); 140 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call,
141 callback,
142 error_callback);
134 } 143 }
135 144
136 // ShillServiceClient override.
137 virtual bool CallActivateCellularModemAndBlock( 145 virtual bool CallActivateCellularModemAndBlock(
138 const dbus::ObjectPath& service_path, 146 const dbus::ObjectPath& service_path,
139 const std::string& carrier) OVERRIDE { 147 const std::string& carrier) OVERRIDE {
140 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, 148 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface,
141 flimflam::kActivateCellularModemFunction); 149 flimflam::kActivateCellularModemFunction);
142 dbus::MessageWriter writer(&method_call); 150 dbus::MessageWriter writer(&method_call);
143 writer.AppendString(carrier); 151 writer.AppendString(carrier);
144 return GetHelper(service_path)->CallVoidMethodAndBlock(&method_call); 152 return GetHelper(service_path)->CallVoidMethodAndBlock(&method_call);
145 } 153 }
146 154
(...skipping 22 matching lines...) Expand all
169 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientImpl); 177 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientImpl);
170 }; 178 };
171 179
172 // A stub implementation of ShillServiceClient. 180 // A stub implementation of ShillServiceClient.
173 class ShillServiceClientStubImpl : public ShillServiceClient { 181 class ShillServiceClientStubImpl : public ShillServiceClient {
174 public: 182 public:
175 ShillServiceClientStubImpl() : weak_ptr_factory_(this) {} 183 ShillServiceClientStubImpl() : weak_ptr_factory_(this) {}
176 184
177 virtual ~ShillServiceClientStubImpl() {} 185 virtual ~ShillServiceClientStubImpl() {}
178 186
179 // ShillServiceClient override. 187 ///////////////////////////////////
180 virtual void SetPropertyChangedHandler( 188 // ShillServiceClient overrides.
189 virtual void AddPropertyChangedObserver(
181 const dbus::ObjectPath& service_path, 190 const dbus::ObjectPath& service_path,
182 const PropertyChangedHandler& handler) OVERRIDE {} 191 PropertyChangedObserver* observer) OVERRIDE {}
183 192
184 // ShillServiceClient override. 193 virtual void RemovePropertyChangedObserver(
185 virtual void ResetPropertyChangedHandler( 194 const dbus::ObjectPath& service_path,
186 const dbus::ObjectPath& service_path) OVERRIDE {} 195 PropertyChangedObserver* observer) OVERRIDE {}
187 196
188 // ShillServiceClient override.
189 virtual void GetProperties(const dbus::ObjectPath& service_path, 197 virtual void GetProperties(const dbus::ObjectPath& service_path,
190 const DictionaryValueCallback& callback) OVERRIDE { 198 const DictionaryValueCallback& callback) OVERRIDE {
191 MessageLoop::current()->PostTask( 199 MessageLoop::current()->PostTask(
192 FROM_HERE, 200 FROM_HERE,
193 base::Bind(&ShillServiceClientStubImpl::PassEmptyDictionaryValue, 201 base::Bind(&ShillServiceClientStubImpl::PassEmptyDictionaryValue,
194 weak_ptr_factory_.GetWeakPtr(), 202 weak_ptr_factory_.GetWeakPtr(),
195 callback)); 203 callback));
196 } 204 }
197 205
198 // ShillServiceClient override.
199 virtual void SetProperty(const dbus::ObjectPath& service_path, 206 virtual void SetProperty(const dbus::ObjectPath& service_path,
200 const std::string& name, 207 const std::string& name,
201 const base::Value& value, 208 const base::Value& value,
202 const VoidDBusMethodCallback& callback) OVERRIDE { 209 const base::Closure& callback,
203 PostSuccessVoidCallback(callback); 210 const ErrorCallback& error_callback) OVERRIDE {
211 PostClosure(callback);
204 } 212 }
205 213
206 // ShillServiceClient override.
207 virtual void ClearProperty(const dbus::ObjectPath& service_path, 214 virtual void ClearProperty(const dbus::ObjectPath& service_path,
208 const std::string& name, 215 const std::string& name,
209 const VoidDBusMethodCallback& callback) OVERRIDE { 216 const base::Closure& callback,
210 PostSuccessVoidCallback(callback); 217 const ErrorCallback& error_callback) OVERRIDE {
218 PostClosure(callback);
211 } 219 }
212 220
213 // ShillServiceClient override.
214 virtual void Connect(const dbus::ObjectPath& service_path, 221 virtual void Connect(const dbus::ObjectPath& service_path,
215 const base::Closure& callback, 222 const base::Closure& callback,
216 const ErrorCallback& error_callback) OVERRIDE { 223 const ErrorCallback& error_callback) OVERRIDE {
217 MessageLoop::current()->PostTask(FROM_HERE, callback); 224 MessageLoop::current()->PostTask(FROM_HERE, callback);
218 } 225 }
219 226
220 // ShillServiceClient override.
221 virtual void Disconnect(const dbus::ObjectPath& service_path, 227 virtual void Disconnect(const dbus::ObjectPath& service_path,
222 const VoidDBusMethodCallback& callback) OVERRIDE { 228 const base::Closure& callback,
223 PostSuccessVoidCallback(callback); 229 const ErrorCallback& error_callback) OVERRIDE {
230 PostClosure(callback);
224 } 231 }
225 232
226 // ShillServiceClient override.
227 virtual void Remove(const dbus::ObjectPath& service_path, 233 virtual void Remove(const dbus::ObjectPath& service_path,
228 const VoidDBusMethodCallback& callback) OVERRIDE { 234 const base::Closure& callback,
229 PostSuccessVoidCallback(callback); 235 const ErrorCallback& error_callback) OVERRIDE {
236 PostClosure(callback);
230 } 237 }
231 238
232 // ShillServiceClient override.
233 virtual void ActivateCellularModem( 239 virtual void ActivateCellularModem(
234 const dbus::ObjectPath& service_path, 240 const dbus::ObjectPath& service_path,
235 const std::string& carrier, 241 const std::string& carrier,
236 const VoidDBusMethodCallback& callback) OVERRIDE { 242 const base::Closure& callback,
237 PostSuccessVoidCallback(callback); 243 const ErrorCallback& error_callback) OVERRIDE {
244 PostClosure(callback);
238 } 245 }
239 246
240 // ShillServiceClient override.
241 virtual bool CallActivateCellularModemAndBlock( 247 virtual bool CallActivateCellularModemAndBlock(
242 const dbus::ObjectPath& service_path, 248 const dbus::ObjectPath& service_path,
243 const std::string& carrier) OVERRIDE { 249 const std::string& carrier) OVERRIDE {
244 return true; 250 return true;
245 } 251 }
246 252
247 private: 253 private:
248 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { 254 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const {
249 base::DictionaryValue dictionary; 255 base::DictionaryValue dictionary;
250 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); 256 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary);
251 } 257 }
252 258
253 // Posts a task to run a void callback with success status code. 259 // Posts a task to run a closure.
254 void PostSuccessVoidCallback(const VoidDBusMethodCallback& callback) { 260 void PostClosure(const base::Closure& callback) {
hashimoto 2012/09/21 11:52:01 Since this method became very simple, we no longer
Greg Spencer (Chromium) 2012/09/21 22:03:47 Removed.
255 MessageLoop::current()->PostTask(FROM_HERE, 261 MessageLoop::current()->PostTask(FROM_HERE, callback);
256 base::Bind(callback,
257 DBUS_METHOD_CALL_SUCCESS));
258 } 262 }
259 263
260 // Note: This should remain the last member so it'll be destroyed and 264 // Note: This should remain the last member so it'll be destroyed and
261 // invalidate its weak pointers before any other members are destroyed. 265 // invalidate its weak pointers before any other members are destroyed.
262 base::WeakPtrFactory<ShillServiceClientStubImpl> weak_ptr_factory_; 266 base::WeakPtrFactory<ShillServiceClientStubImpl> weak_ptr_factory_;
263 267
264 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientStubImpl); 268 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientStubImpl);
265 }; 269 };
266 270
267 } // namespace 271 } // namespace
268 272
269 ShillServiceClient::ShillServiceClient() {} 273 ShillServiceClient::ShillServiceClient() {}
270 274
271 ShillServiceClient::~ShillServiceClient() {} 275 ShillServiceClient::~ShillServiceClient() {}
272 276
273 // static 277 // static
274 ShillServiceClient* ShillServiceClient::Create( 278 ShillServiceClient* ShillServiceClient::Create(
275 DBusClientImplementationType type, 279 DBusClientImplementationType type,
276 dbus::Bus* bus) { 280 dbus::Bus* bus) {
277 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 281 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
278 return new ShillServiceClientImpl(bus); 282 return new ShillServiceClientImpl(bus);
279 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 283 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
280 return new ShillServiceClientStubImpl(); 284 return new ShillServiceClientStubImpl();
281 } 285 }
282 286
283 } // namespace chromeos 287 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698