Chromium Code Reviews| 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_manager_client.h" | 5 #include "chromeos/dbus/shill_manager_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/values.h" | 10 #include "base/values.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 flimflam::kGetPropertiesFunction); | 75 flimflam::kGetPropertiesFunction); |
| 76 helper_.CallDictionaryValueMethod(&method_call, callback); | 76 helper_.CallDictionaryValueMethod(&method_call, callback); |
| 77 } | 77 } |
| 78 | 78 |
| 79 virtual base::DictionaryValue* CallGetPropertiesAndBlock() OVERRIDE { | 79 virtual base::DictionaryValue* CallGetPropertiesAndBlock() OVERRIDE { |
| 80 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, | 80 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, |
| 81 flimflam::kGetPropertiesFunction); | 81 flimflam::kGetPropertiesFunction); |
| 82 return helper_.CallDictionaryValueMethodAndBlock(&method_call); | 82 return helper_.CallDictionaryValueMethodAndBlock(&method_call); |
| 83 } | 83 } |
| 84 | 84 |
| 85 virtual void GetNetworksForGeolocation( | |
| 86 const DictionaryValueCallback& callback) OVERRIDE { | |
| 87 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, | |
| 88 shill::kGetNetworksForGeolocation); | |
| 89 helper_.CallDictionaryValueMethod(&method_call, callback); | |
| 90 } | |
| 91 | |
| 85 virtual void SetProperty(const std::string& name, | 92 virtual void SetProperty(const std::string& name, |
| 86 const base::Value& value, | 93 const base::Value& value, |
| 87 const base::Closure& callback, | 94 const base::Closure& callback, |
| 88 const ErrorCallback& error_callback) OVERRIDE { | 95 const ErrorCallback& error_callback) OVERRIDE { |
| 89 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, | 96 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, |
| 90 flimflam::kSetPropertyFunction); | 97 flimflam::kSetPropertyFunction); |
| 91 dbus::MessageWriter writer(&method_call); | 98 dbus::MessageWriter writer(&method_call); |
| 92 writer.AppendString(name); | 99 writer.AppendString(name); |
| 93 ShillClientHelper::AppendValueDataAsVariant(&writer, value); | 100 ShillClientHelper::AppendValueDataAsVariant(&writer, value); |
| 94 helper_.CallVoidMethodWithErrorCallback(&method_call, | 101 helper_.CallVoidMethodWithErrorCallback(&method_call, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 FROM_HERE, base::Bind( | 221 FROM_HERE, base::Bind( |
| 215 &ShillManagerClientStubImpl::PassStubProperties, | 222 &ShillManagerClientStubImpl::PassStubProperties, |
| 216 weak_ptr_factory_.GetWeakPtr(), | 223 weak_ptr_factory_.GetWeakPtr(), |
| 217 callback)); | 224 callback)); |
| 218 } | 225 } |
| 219 | 226 |
| 220 virtual base::DictionaryValue* CallGetPropertiesAndBlock() OVERRIDE { | 227 virtual base::DictionaryValue* CallGetPropertiesAndBlock() OVERRIDE { |
| 221 return stub_properties_.DeepCopy(); | 228 return stub_properties_.DeepCopy(); |
| 222 } | 229 } |
| 223 | 230 |
| 231 virtual void GetNetworksForGeolocation( | |
| 232 const DictionaryValueCallback& callback) OVERRIDE { | |
| 233 if (callback.is_null()) | |
| 234 return; | |
| 235 MessageLoop::current()->PostTask( | |
| 236 FROM_HERE, base::Bind( | |
| 237 &ShillManagerClientStubImpl::PassStubGeoNetworks, | |
| 238 weak_ptr_factory_.GetWeakPtr(), | |
| 239 callback)); | |
| 240 } | |
| 241 | |
| 224 virtual void SetProperty(const std::string& name, | 242 virtual void SetProperty(const std::string& name, |
| 225 const base::Value& value, | 243 const base::Value& value, |
| 226 const base::Closure& callback, | 244 const base::Closure& callback, |
| 227 const ErrorCallback& error_callback) OVERRIDE { | 245 const ErrorCallback& error_callback) OVERRIDE { |
| 228 stub_properties_.Set(name, value.DeepCopy()); | 246 stub_properties_.Set(name, value.DeepCopy()); |
| 229 if (callback.is_null()) | 247 if (callback.is_null()) |
| 230 return; | 248 return; |
| 231 MessageLoop::current()->PostTask(FROM_HERE, callback); | 249 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 232 } | 250 } |
| 233 | 251 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 } | 339 } |
| 322 | 340 |
| 323 virtual void RemoveDevice(const std::string& device_path) OVERRIDE { | 341 virtual void RemoveDevice(const std::string& device_path) OVERRIDE { |
| 324 base::StringValue device_path_value(device_path); | 342 base::StringValue device_path_value(device_path); |
| 325 if (GetListProperty(flimflam::kDevicesProperty)->Remove( | 343 if (GetListProperty(flimflam::kDevicesProperty)->Remove( |
| 326 device_path_value, NULL)) { | 344 device_path_value, NULL)) { |
| 327 CallNotifyObserversPropertyChanged(flimflam::kDevicesProperty, 0); | 345 CallNotifyObserversPropertyChanged(flimflam::kDevicesProperty, 0); |
| 328 } | 346 } |
| 329 } | 347 } |
| 330 | 348 |
| 349 virtual void ResetDevices() OVERRIDE { | |
| 350 stub_properties_.Remove(flimflam::kDevicesProperty, NULL); | |
| 351 } | |
| 352 | |
| 331 virtual void AddService(const std::string& service_path, | 353 virtual void AddService(const std::string& service_path, |
| 332 bool add_to_watch_list) OVERRIDE { | 354 bool add_to_watch_list) OVERRIDE { |
| 333 if (GetListProperty(flimflam::kServicesProperty)->AppendIfNotPresent( | 355 if (GetListProperty(flimflam::kServicesProperty)->AppendIfNotPresent( |
| 334 base::Value::CreateStringValue(service_path))) { | 356 base::Value::CreateStringValue(service_path))) { |
| 335 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 357 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 336 } | 358 } |
| 337 if (add_to_watch_list) | 359 if (add_to_watch_list) |
| 338 AddServiceToWatchList(service_path); | 360 AddServiceToWatchList(service_path); |
| 339 } | 361 } |
| 340 | 362 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 type_value, NULL)) { | 416 type_value, NULL)) { |
| 395 CallNotifyObserversPropertyChanged( | 417 CallNotifyObserversPropertyChanged( |
| 396 flimflam::kEnabledTechnologiesProperty, 0); | 418 flimflam::kEnabledTechnologiesProperty, 0); |
| 397 } | 419 } |
| 398 } | 420 } |
| 399 | 421 |
| 400 virtual void ClearProperties() OVERRIDE { | 422 virtual void ClearProperties() OVERRIDE { |
| 401 stub_properties_.Clear(); | 423 stub_properties_.Clear(); |
| 402 } | 424 } |
| 403 | 425 |
| 426 virtual void AddGeoNetwork(const std::string& technology, | |
| 427 const base::DictionaryValue& network) OVERRIDE { | |
| 428 base::ListValue* list_value = NULL; | |
| 429 if (!stub_geo_networks_.GetListWithoutPathExpansion( | |
| 430 technology, &list_value)) { | |
| 431 list_value = new base::ListValue; | |
| 432 stub_geo_networks_.Set(technology, list_value); | |
| 433 } | |
| 434 list_value->Append(network.DeepCopy()); | |
| 435 } | |
| 436 | |
| 404 private: | 437 private: |
| 405 void AddServiceToWatchList(const std::string& service_path) { | 438 void AddServiceToWatchList(const std::string& service_path) { |
| 406 if (GetListProperty( | 439 if (GetListProperty( |
| 407 flimflam::kServiceWatchListProperty)->AppendIfNotPresent( | 440 flimflam::kServiceWatchListProperty)->AppendIfNotPresent( |
| 408 base::Value::CreateStringValue(service_path))) { | 441 base::Value::CreateStringValue(service_path))) { |
| 409 CallNotifyObserversPropertyChanged( | 442 CallNotifyObserversPropertyChanged( |
| 410 flimflam::kServiceWatchListProperty, 0); | 443 flimflam::kServiceWatchListProperty, 0); |
| 411 } | 444 } |
| 412 } | 445 } |
| 413 | 446 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 425 // Stub Technologies | 458 // Stub Technologies |
| 426 AddTechnology(flimflam::kTypeEthernet, true); | 459 AddTechnology(flimflam::kTypeEthernet, true); |
| 427 AddTechnology(flimflam::kTypeWifi, true); | 460 AddTechnology(flimflam::kTypeWifi, true); |
| 428 AddTechnology(flimflam::kTypeCellular, true); | 461 AddTechnology(flimflam::kTypeCellular, true); |
| 429 } | 462 } |
| 430 | 463 |
| 431 void PassStubProperties(const DictionaryValueCallback& callback) const { | 464 void PassStubProperties(const DictionaryValueCallback& callback) const { |
| 432 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_properties_); | 465 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_properties_); |
| 433 } | 466 } |
| 434 | 467 |
| 468 void PassStubGeoNetworks(const DictionaryValueCallback& callback) const { | |
| 469 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); | |
| 470 } | |
| 471 | |
| 435 void CallNotifyObserversPropertyChanged(const std::string& property, | 472 void CallNotifyObserversPropertyChanged(const std::string& property, |
| 436 int delay_ms) { | 473 int delay_ms) { |
| 437 // Avoid unnecessary delayed task if we have no observers (e.g. during | 474 // Avoid unnecessary delayed task if we have no observers (e.g. during |
| 438 // initial setup). | 475 // initial setup). |
| 439 if (observer_list_.size() == 0) | 476 if (observer_list_.size() == 0) |
| 440 return; | 477 return; |
| 441 MessageLoop::current()->PostDelayedTask( | 478 MessageLoop::current()->PostDelayedTask( |
| 442 FROM_HERE, | 479 FROM_HERE, |
| 443 base::Bind(&ShillManagerClientStubImpl::NotifyObserversPropertyChanged, | 480 base::Bind(&ShillManagerClientStubImpl::NotifyObserversPropertyChanged, |
| 444 weak_ptr_factory_.GetWeakPtr(), | 481 weak_ptr_factory_.GetWeakPtr(), |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 460 base::ListValue* GetListProperty(const std::string& property) { | 497 base::ListValue* GetListProperty(const std::string& property) { |
| 461 base::ListValue* list_property = NULL; | 498 base::ListValue* list_property = NULL; |
| 462 if (!stub_properties_.GetListWithoutPathExpansion( | 499 if (!stub_properties_.GetListWithoutPathExpansion( |
| 463 property, &list_property)) { | 500 property, &list_property)) { |
| 464 list_property = new base::ListValue; | 501 list_property = new base::ListValue; |
| 465 stub_properties_.Set(property, list_property); | 502 stub_properties_.Set(property, list_property); |
| 466 } | 503 } |
| 467 return list_property; | 504 return list_property; |
| 468 } | 505 } |
| 469 | 506 |
| 507 // Dictionary of name -> value | |
|
gauravsh
2013/01/14 06:19:59
redundant comment
stevenjb
2013/01/14 19:38:48
I added the comment because it's not actually obvi
| |
| 470 base::DictionaryValue stub_properties_; | 508 base::DictionaryValue stub_properties_; |
| 509 // Dictionary of technology -> list of property dictionaries | |
| 510 base::DictionaryValue stub_geo_networks_; | |
| 511 | |
| 471 ObserverList<ShillPropertyChangedObserver> observer_list_; | 512 ObserverList<ShillPropertyChangedObserver> observer_list_; |
| 472 | 513 |
| 473 // Note: This should remain the last member so it'll be destroyed and | 514 // Note: This should remain the last member so it'll be destroyed and |
| 474 // invalidate its weak pointers before any other members are destroyed. | 515 // invalidate its weak pointers before any other members are destroyed. |
| 475 base::WeakPtrFactory<ShillManagerClientStubImpl> weak_ptr_factory_; | 516 base::WeakPtrFactory<ShillManagerClientStubImpl> weak_ptr_factory_; |
| 476 | 517 |
| 477 DISALLOW_COPY_AND_ASSIGN(ShillManagerClientStubImpl); | 518 DISALLOW_COPY_AND_ASSIGN(ShillManagerClientStubImpl); |
| 478 }; | 519 }; |
| 479 | 520 |
| 480 } // namespace | 521 } // namespace |
| 481 | 522 |
| 482 ShillManagerClient::ShillManagerClient() {} | 523 ShillManagerClient::ShillManagerClient() {} |
| 483 | 524 |
| 484 ShillManagerClient::~ShillManagerClient() {} | 525 ShillManagerClient::~ShillManagerClient() {} |
| 485 | 526 |
| 486 // static | 527 // static |
| 487 ShillManagerClient* ShillManagerClient::Create( | 528 ShillManagerClient* ShillManagerClient::Create( |
| 488 DBusClientImplementationType type, | 529 DBusClientImplementationType type, |
| 489 dbus::Bus* bus) { | 530 dbus::Bus* bus) { |
| 490 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 531 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 491 return new ShillManagerClientImpl(bus); | 532 return new ShillManagerClientImpl(bus); |
| 492 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 533 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 493 return new ShillManagerClientStubImpl(); | 534 return new ShillManagerClientStubImpl(); |
| 494 } | 535 } |
| 495 | 536 |
| 496 } // namespace chromeos | 537 } // namespace chromeos |
| OLD | NEW |