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 flimflam::kGetPropertiesFunction); | 68 flimflam::kGetPropertiesFunction); |
69 GetHelper(service_path)->CallDictionaryValueMethodWithErrorCallback( | 69 GetHelper(service_path)->CallDictionaryValueMethodWithErrorCallback( |
70 &method_call, | 70 &method_call, |
71 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS), | 71 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS), |
72 base::Bind(&OnGetPropertiesError, service_path, callback)); | 72 base::Bind(&OnGetPropertiesError, service_path, callback)); |
73 } | 73 } |
74 | 74 |
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 virtual void ClearProperty(const dbus::ObjectPath& service_path, | 90 virtual void ClearProperty(const dbus::ObjectPath& service_path, |
88 const std::string& name, | 91 const std::string& name, |
89 const VoidDBusMethodCallback& callback) OVERRIDE { | 92 const base::Closure& callback, |
| 93 const ErrorCallback& error_callback) OVERRIDE { |
90 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 94 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
91 flimflam::kClearPropertyFunction); | 95 flimflam::kClearPropertyFunction); |
92 dbus::MessageWriter writer(&method_call); | 96 dbus::MessageWriter writer(&method_call); |
93 writer.AppendString(name); | 97 writer.AppendString(name); |
94 GetHelper(service_path)->CallVoidMethod(&method_call, callback); | 98 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call, |
| 99 callback, |
| 100 error_callback); |
95 } | 101 } |
96 | 102 |
97 virtual void Connect(const dbus::ObjectPath& service_path, | 103 virtual void Connect(const dbus::ObjectPath& service_path, |
98 const base::Closure& callback, | 104 const base::Closure& callback, |
99 const ErrorCallback& error_callback) OVERRIDE { | 105 const ErrorCallback& error_callback) OVERRIDE { |
100 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 106 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
101 flimflam::kConnectFunction); | 107 flimflam::kConnectFunction); |
102 GetHelper(service_path)->CallVoidMethodWithErrorCallback( | 108 GetHelper(service_path)->CallVoidMethodWithErrorCallback( |
103 &method_call, callback, error_callback); | 109 &method_call, callback, error_callback); |
104 } | 110 } |
105 | 111 |
106 virtual void Disconnect(const dbus::ObjectPath& service_path, | 112 virtual void Disconnect(const dbus::ObjectPath& service_path, |
107 const VoidDBusMethodCallback& callback) OVERRIDE { | 113 const base::Closure& callback, |
| 114 const ErrorCallback& error_callback) OVERRIDE { |
108 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 115 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
109 flimflam::kDisconnectFunction); | 116 flimflam::kDisconnectFunction); |
110 GetHelper(service_path)->CallVoidMethod(&method_call, callback); | 117 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call, |
| 118 callback, |
| 119 error_callback); |
111 } | 120 } |
112 | 121 |
113 virtual void Remove(const dbus::ObjectPath& service_path, | 122 virtual void Remove(const dbus::ObjectPath& service_path, |
114 const VoidDBusMethodCallback& callback) OVERRIDE { | 123 const base::Closure& callback, |
| 124 const ErrorCallback& error_callback) OVERRIDE { |
115 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 125 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
116 flimflam::kRemoveServiceFunction); | 126 flimflam::kRemoveServiceFunction); |
117 GetHelper(service_path)->CallVoidMethod(&method_call, callback); | 127 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call, |
| 128 callback, |
| 129 error_callback); |
118 } | 130 } |
119 | 131 |
120 virtual void ActivateCellularModem( | 132 virtual void ActivateCellularModem( |
121 const dbus::ObjectPath& service_path, | 133 const dbus::ObjectPath& service_path, |
122 const std::string& carrier, | 134 const std::string& carrier, |
123 const VoidDBusMethodCallback& callback) OVERRIDE { | 135 const base::Closure& callback, |
| 136 const ErrorCallback& error_callback) OVERRIDE { |
124 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 137 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
125 flimflam::kActivateCellularModemFunction); | 138 flimflam::kActivateCellularModemFunction); |
126 dbus::MessageWriter writer(&method_call); | 139 dbus::MessageWriter writer(&method_call); |
127 writer.AppendString(carrier); | 140 writer.AppendString(carrier); |
128 GetHelper(service_path)->CallVoidMethod(&method_call, callback); | 141 GetHelper(service_path)->CallVoidMethodWithErrorCallback(&method_call, |
| 142 callback, |
| 143 error_callback); |
129 } | 144 } |
130 | 145 |
131 virtual bool CallActivateCellularModemAndBlock( | 146 virtual bool CallActivateCellularModemAndBlock( |
132 const dbus::ObjectPath& service_path, | 147 const dbus::ObjectPath& service_path, |
133 const std::string& carrier) OVERRIDE { | 148 const std::string& carrier) OVERRIDE { |
134 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, | 149 dbus::MethodCall method_call(flimflam::kFlimflamServiceInterface, |
135 flimflam::kActivateCellularModemFunction); | 150 flimflam::kActivateCellularModemFunction); |
136 dbus::MessageWriter writer(&method_call); | 151 dbus::MessageWriter writer(&method_call); |
137 writer.AppendString(carrier); | 152 writer.AppendString(carrier); |
138 return GetHelper(service_path)->CallVoidMethodAndBlock(&method_call); | 153 return GetHelper(service_path)->CallVoidMethodAndBlock(&method_call); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 MessageLoop::current()->PostTask( | 200 MessageLoop::current()->PostTask( |
186 FROM_HERE, | 201 FROM_HERE, |
187 base::Bind(&ShillServiceClientStubImpl::PassEmptyDictionaryValue, | 202 base::Bind(&ShillServiceClientStubImpl::PassEmptyDictionaryValue, |
188 weak_ptr_factory_.GetWeakPtr(), | 203 weak_ptr_factory_.GetWeakPtr(), |
189 callback)); | 204 callback)); |
190 } | 205 } |
191 | 206 |
192 virtual void SetProperty(const dbus::ObjectPath& service_path, | 207 virtual void SetProperty(const dbus::ObjectPath& service_path, |
193 const std::string& name, | 208 const std::string& name, |
194 const base::Value& value, | 209 const base::Value& value, |
195 const VoidDBusMethodCallback& callback) OVERRIDE { | 210 const base::Closure& callback, |
196 PostSuccessVoidCallback(callback); | 211 const ErrorCallback& error_callback) OVERRIDE { |
| 212 MessageLoop::current()->PostTask(FROM_HERE, callback); |
197 } | 213 } |
198 | 214 |
199 virtual void ClearProperty(const dbus::ObjectPath& service_path, | 215 virtual void ClearProperty(const dbus::ObjectPath& service_path, |
200 const std::string& name, | 216 const std::string& name, |
201 const VoidDBusMethodCallback& callback) OVERRIDE { | 217 const base::Closure& callback, |
202 PostSuccessVoidCallback(callback); | 218 const ErrorCallback& error_callback) OVERRIDE { |
| 219 MessageLoop::current()->PostTask(FROM_HERE, callback); |
203 } | 220 } |
204 | 221 |
205 virtual void Connect(const dbus::ObjectPath& service_path, | 222 virtual void Connect(const dbus::ObjectPath& service_path, |
206 const base::Closure& callback, | 223 const base::Closure& callback, |
207 const ErrorCallback& error_callback) OVERRIDE { | 224 const ErrorCallback& error_callback) OVERRIDE { |
208 MessageLoop::current()->PostTask(FROM_HERE, callback); | 225 MessageLoop::current()->PostTask(FROM_HERE, callback); |
209 } | 226 } |
210 | 227 |
211 virtual void Disconnect(const dbus::ObjectPath& service_path, | 228 virtual void Disconnect(const dbus::ObjectPath& service_path, |
212 const VoidDBusMethodCallback& callback) OVERRIDE { | 229 const base::Closure& callback, |
213 PostSuccessVoidCallback(callback); | 230 const ErrorCallback& error_callback) OVERRIDE { |
| 231 MessageLoop::current()->PostTask(FROM_HERE, callback); |
214 } | 232 } |
215 | 233 |
216 virtual void Remove(const dbus::ObjectPath& service_path, | 234 virtual void Remove(const dbus::ObjectPath& service_path, |
217 const VoidDBusMethodCallback& callback) OVERRIDE { | 235 const base::Closure& callback, |
218 PostSuccessVoidCallback(callback); | 236 const ErrorCallback& error_callback) OVERRIDE { |
| 237 MessageLoop::current()->PostTask(FROM_HERE, callback); |
219 } | 238 } |
220 | 239 |
221 virtual void ActivateCellularModem( | 240 virtual void ActivateCellularModem( |
222 const dbus::ObjectPath& service_path, | 241 const dbus::ObjectPath& service_path, |
223 const std::string& carrier, | 242 const std::string& carrier, |
224 const VoidDBusMethodCallback& callback) OVERRIDE { | 243 const base::Closure& callback, |
225 PostSuccessVoidCallback(callback); | 244 const ErrorCallback& error_callback) OVERRIDE { |
| 245 MessageLoop::current()->PostTask(FROM_HERE, callback); |
226 } | 246 } |
227 | 247 |
228 virtual bool CallActivateCellularModemAndBlock( | 248 virtual bool CallActivateCellularModemAndBlock( |
229 const dbus::ObjectPath& service_path, | 249 const dbus::ObjectPath& service_path, |
230 const std::string& carrier) OVERRIDE { | 250 const std::string& carrier) OVERRIDE { |
231 return true; | 251 return true; |
232 } | 252 } |
233 | 253 |
234 private: | 254 private: |
235 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { | 255 void PassEmptyDictionaryValue(const DictionaryValueCallback& callback) const { |
236 base::DictionaryValue dictionary; | 256 base::DictionaryValue dictionary; |
237 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); | 257 callback.Run(DBUS_METHOD_CALL_SUCCESS, dictionary); |
238 } | 258 } |
239 | 259 |
240 // Posts a task to run a void callback with success status code. | |
241 void PostSuccessVoidCallback(const VoidDBusMethodCallback& callback) { | |
242 MessageLoop::current()->PostTask(FROM_HERE, | |
243 base::Bind(callback, | |
244 DBUS_METHOD_CALL_SUCCESS)); | |
245 } | |
246 | |
247 // Note: This should remain the last member so it'll be destroyed and | 260 // Note: This should remain the last member so it'll be destroyed and |
248 // invalidate its weak pointers before any other members are destroyed. | 261 // invalidate its weak pointers before any other members are destroyed. |
249 base::WeakPtrFactory<ShillServiceClientStubImpl> weak_ptr_factory_; | 262 base::WeakPtrFactory<ShillServiceClientStubImpl> weak_ptr_factory_; |
250 | 263 |
251 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientStubImpl); | 264 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientStubImpl); |
252 }; | 265 }; |
253 | 266 |
254 } // namespace | 267 } // namespace |
255 | 268 |
256 ShillServiceClient::ShillServiceClient() {} | 269 ShillServiceClient::ShillServiceClient() {} |
257 | 270 |
258 ShillServiceClient::~ShillServiceClient() {} | 271 ShillServiceClient::~ShillServiceClient() {} |
259 | 272 |
260 // static | 273 // static |
261 ShillServiceClient* ShillServiceClient::Create( | 274 ShillServiceClient* ShillServiceClient::Create( |
262 DBusClientImplementationType type, | 275 DBusClientImplementationType type, |
263 dbus::Bus* bus) { | 276 dbus::Bus* bus) { |
264 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 277 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
265 return new ShillServiceClientImpl(bus); | 278 return new ShillServiceClientImpl(bus); |
266 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 279 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
267 return new ShillServiceClientStubImpl(); | 280 return new ShillServiceClientStubImpl(); |
268 } | 281 } |
269 | 282 |
270 } // namespace chromeos | 283 } // namespace chromeos |
OLD | NEW |