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

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

Issue 11192024: Add chromeos::NetworkStateManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase with dbus tests in trunk Created 8 years, 1 month 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/shill_device_client.h" 5 #include "chromeos/dbus/shill_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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 ShillDeviceClientStubImpl() : weak_ptr_factory_(this) { 225 ShillDeviceClientStubImpl() : weak_ptr_factory_(this) {
226 SetDefaultProperties(); 226 SetDefaultProperties();
227 } 227 }
228 228
229 virtual ~ShillDeviceClientStubImpl() {} 229 virtual ~ShillDeviceClientStubImpl() {}
230 230
231 // ShillDeviceClient overrides. 231 // ShillDeviceClient overrides.
232 232
233 virtual void AddPropertyChangedObserver( 233 virtual void AddPropertyChangedObserver(
234 const dbus::ObjectPath& device_path, 234 const dbus::ObjectPath& device_path,
235 ShillPropertyChangedObserver* observer) OVERRIDE {} 235 ShillPropertyChangedObserver* observer) OVERRIDE {
236 observer_list_.AddObserver(observer);
hashimoto 2012/11/05 04:03:03 You might need to change the type of observer_list
stevenjb 2012/11/05 22:42:35 Good catch, fixed.
237 }
236 238
237 virtual void RemovePropertyChangedObserver( 239 virtual void RemovePropertyChangedObserver(
238 const dbus::ObjectPath& device_path, 240 const dbus::ObjectPath& device_path,
239 ShillPropertyChangedObserver* observer) OVERRIDE {} 241 ShillPropertyChangedObserver* observer) OVERRIDE {
242 observer_list_.RemoveObserver(observer);
243 }
240 244
241 virtual void GetProperties(const dbus::ObjectPath& device_path, 245 virtual void GetProperties(const dbus::ObjectPath& device_path,
242 const DictionaryValueCallback& callback) OVERRIDE { 246 const DictionaryValueCallback& callback) OVERRIDE {
243 MessageLoop::current()->PostTask( 247 MessageLoop::current()->PostTask(
244 FROM_HERE, 248 FROM_HERE,
245 base::Bind(&ShillDeviceClientStubImpl::PassStubDeviceProperties, 249 base::Bind(&ShillDeviceClientStubImpl::PassStubDeviceProperties,
246 weak_ptr_factory_.GetWeakPtr(), 250 weak_ptr_factory_.GetWeakPtr(),
247 device_path, callback)); 251 device_path, callback));
248 } 252 }
249 253
(...skipping 20 matching lines...) Expand all
270 std::string error_name("org.chromium.flimflam.Error.Failure"); 274 std::string error_name("org.chromium.flimflam.Error.Failure");
271 std::string error_message("Failed"); 275 std::string error_message("Failed");
272 MessageLoop::current()->PostTask(FROM_HERE, 276 MessageLoop::current()->PostTask(FROM_HERE,
273 base::Bind(error_callback, 277 base::Bind(error_callback,
274 error_name, 278 error_name,
275 error_message)); 279 error_message));
276 return; 280 return;
277 } 281 }
278 device_properties->Set(name, value.DeepCopy()); 282 device_properties->Set(name, value.DeepCopy());
279 MessageLoop::current()->PostTask(FROM_HERE, callback); 283 MessageLoop::current()->PostTask(FROM_HERE, callback);
284 MessageLoop::current()->PostTask(
285 FROM_HERE,
286 base::Bind(&ShillDeviceClientStubImpl::NotifyObserversPropertyChanged,
287 weak_ptr_factory_.GetWeakPtr(), device_path, name));
280 } 288 }
281 289
282 virtual void ClearProperty(const dbus::ObjectPath& device_path, 290 virtual void ClearProperty(const dbus::ObjectPath& device_path,
283 const std::string& name, 291 const std::string& name,
284 const VoidDBusMethodCallback& callback) OVERRIDE { 292 const VoidDBusMethodCallback& callback) OVERRIDE {
285 base::DictionaryValue* device_properties = NULL; 293 base::DictionaryValue* device_properties = NULL;
286 if (!stub_devices_.GetDictionary(device_path.value(), &device_properties)) { 294 if (!stub_devices_.GetDictionary(device_path.value(), &device_properties)) {
287 PostVoidCallback(callback, DBUS_METHOD_CALL_FAILURE); 295 PostVoidCallback(callback, DBUS_METHOD_CALL_FAILURE);
288 return; 296 return;
289 } 297 }
290 device_properties->Remove(name, NULL); 298 device_properties->Remove(name, NULL);
291 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS); 299 PostVoidCallback(callback, DBUS_METHOD_CALL_SUCCESS);
hashimoto 2012/11/05 04:03:03 Is there no need to notify observers about the cle
stevenjb 2012/11/05 22:42:35 The dbus impl calls ShillClientHelper::CallVoidMet
292 } 300 }
293 301
294 virtual void AddIPConfig( 302 virtual void AddIPConfig(
295 const dbus::ObjectPath& device_path, 303 const dbus::ObjectPath& device_path,
296 const std::string& method, 304 const std::string& method,
297 const ObjectPathDBusMethodCallback& callback) OVERRIDE { 305 const ObjectPathDBusMethodCallback& callback) OVERRIDE {
298 MessageLoop::current()->PostTask(FROM_HERE, 306 MessageLoop::current()->PostTask(FROM_HERE,
299 base::Bind(callback, 307 base::Bind(callback,
300 DBUS_METHOD_CALL_SUCCESS, 308 DBUS_METHOD_CALL_SUCCESS,
301 dbus::ObjectPath())); 309 dbus::ObjectPath()));
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 callback.Run(DBUS_METHOD_CALL_SUCCESS, *device_properties); 414 callback.Run(DBUS_METHOD_CALL_SUCCESS, *device_properties);
407 } 415 }
408 416
409 // Posts a task to run a void callback with status code |status|. 417 // Posts a task to run a void callback with status code |status|.
410 void PostVoidCallback(const VoidDBusMethodCallback& callback, 418 void PostVoidCallback(const VoidDBusMethodCallback& callback,
411 DBusMethodCallStatus status) { 419 DBusMethodCallStatus status) {
412 MessageLoop::current()->PostTask(FROM_HERE, 420 MessageLoop::current()->PostTask(FROM_HERE,
413 base::Bind(callback, status)); 421 base::Bind(callback, status));
414 } 422 }
415 423
424 void NotifyObserversPropertyChanged(const dbus::ObjectPath& device_path,
425 const std::string& property) {
426 base::DictionaryValue* dict = NULL;
427 std::string path = device_path.value();
428 if (!stub_devices_.GetDictionaryWithoutPathExpansion(path, &dict)) {
429 LOG(ERROR) << "Notify for unknown service: " << path;
430 return;
431 }
432 base::Value* value = NULL;
433 if (!dict->GetWithoutPathExpansion(property, &value)) {
434 LOG(ERROR) << "Notify for unknown property: "
435 << path << " : " << property;
436 return;
437 }
438 FOR_EACH_OBSERVER(ShillPropertyChangedObserver,
439 observer_list_,
440 OnPropertyChanged(property, *value));
441 }
442
416 base::DictionaryValue* GetDeviceProperties(const std::string& device_path) { 443 base::DictionaryValue* GetDeviceProperties(const std::string& device_path) {
417 base::DictionaryValue* properties = NULL; 444 base::DictionaryValue* properties = NULL;
418 if (!stub_devices_.GetDictionaryWithoutPathExpansion( 445 if (!stub_devices_.GetDictionaryWithoutPathExpansion(
419 device_path, &properties)) { 446 device_path, &properties)) {
420 properties = new base::DictionaryValue; 447 properties = new base::DictionaryValue;
421 stub_devices_.Set(device_path, properties); 448 stub_devices_.Set(device_path, properties);
422 } 449 }
423 return properties; 450 return properties;
424 } 451 }
425 452
426 // Dictionary of <device_name, Dictionary>. 453 // Dictionary of <device_name, Dictionary>.
427 base::DictionaryValue stub_devices_; 454 base::DictionaryValue stub_devices_;
455 ObserverList<ShillPropertyChangedObserver> observer_list_;
428 456
429 // Note: This should remain the last member so it'll be destroyed and 457 // Note: This should remain the last member so it'll be destroyed and
430 // invalidate its weak pointers before any other members are destroyed. 458 // invalidate its weak pointers before any other members are destroyed.
431 base::WeakPtrFactory<ShillDeviceClientStubImpl> weak_ptr_factory_; 459 base::WeakPtrFactory<ShillDeviceClientStubImpl> weak_ptr_factory_;
432 460
433 DISALLOW_COPY_AND_ASSIGN(ShillDeviceClientStubImpl); 461 DISALLOW_COPY_AND_ASSIGN(ShillDeviceClientStubImpl);
434 }; 462 };
435 463
436 } // namespace 464 } // namespace
437 465
438 ShillDeviceClient::ShillDeviceClient() {} 466 ShillDeviceClient::ShillDeviceClient() {}
439 467
440 ShillDeviceClient::~ShillDeviceClient() {} 468 ShillDeviceClient::~ShillDeviceClient() {}
441 469
442 // static 470 // static
443 ShillDeviceClient* ShillDeviceClient::Create( 471 ShillDeviceClient* ShillDeviceClient::Create(
444 DBusClientImplementationType type, 472 DBusClientImplementationType type,
445 dbus::Bus* bus) { 473 dbus::Bus* bus) {
446 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) 474 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
447 return new ShillDeviceClientImpl(bus); 475 return new ShillDeviceClientImpl(bus);
448 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); 476 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
449 return new ShillDeviceClientStubImpl(); 477 return new ShillDeviceClientStubImpl();
450 } 478 }
451 479
452 } // namespace chromeos 480 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698