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_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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 } | 191 } |
| 192 | 192 |
| 193 virtual ~ShillServiceClientStubImpl() { | 193 virtual ~ShillServiceClientStubImpl() { |
| 194 } | 194 } |
| 195 | 195 |
| 196 // ShillServiceClient overrides. | 196 // ShillServiceClient overrides. |
| 197 | 197 |
| 198 virtual void AddPropertyChangedObserver( | 198 virtual void AddPropertyChangedObserver( |
| 199 const dbus::ObjectPath& service_path, | 199 const dbus::ObjectPath& service_path, |
| 200 ShillPropertyChangedObserver* observer) OVERRIDE { | 200 ShillPropertyChangedObserver* observer) OVERRIDE { |
| 201 observer_list_.AddObserver(observer); | 201 observer_list_.AddObserver(observer); |
|
hashimoto
2012/11/05 04:03:03
You might want to prepare observer lists for each
stevenjb
2012/11/05 22:42:35
Done.
| |
| 202 } | 202 } |
| 203 | 203 |
| 204 virtual void RemovePropertyChangedObserver( | 204 virtual void RemovePropertyChangedObserver( |
| 205 const dbus::ObjectPath& service_path, | 205 const dbus::ObjectPath& service_path, |
| 206 ShillPropertyChangedObserver* observer) OVERRIDE { | 206 ShillPropertyChangedObserver* observer) OVERRIDE { |
| 207 observer_list_.RemoveObserver(observer); | 207 observer_list_.RemoveObserver(observer); |
| 208 } | 208 } |
| 209 | 209 |
| 210 virtual void GetProperties(const dbus::ObjectPath& service_path, | 210 virtual void GetProperties(const dbus::ObjectPath& service_path, |
| 211 const DictionaryValueCallback& callback) OVERRIDE { | 211 const DictionaryValueCallback& callback) OVERRIDE { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 | 284 |
| 285 virtual ShillServiceClient::TestInterface* GetTestInterface() OVERRIDE { | 285 virtual ShillServiceClient::TestInterface* GetTestInterface() OVERRIDE { |
| 286 return this; | 286 return this; |
| 287 } | 287 } |
| 288 | 288 |
| 289 // ShillServiceClient::TestInterface overrides. | 289 // ShillServiceClient::TestInterface overrides. |
| 290 | 290 |
| 291 virtual void AddService(const std::string& service_path, | 291 virtual void AddService(const std::string& service_path, |
| 292 const std::string& name, | 292 const std::string& name, |
| 293 const std::string& type, | 293 const std::string& type, |
| 294 const std::string& state, | 294 const std::string& state) OVERRIDE { |
| 295 const std::string& security) OVERRIDE { | |
| 296 base::DictionaryValue* properties = GetServiceProperties(service_path); | 295 base::DictionaryValue* properties = GetServiceProperties(service_path); |
| 297 properties->SetWithoutPathExpansion( | 296 properties->SetWithoutPathExpansion( |
| 298 flimflam::kSSIDProperty, | 297 flimflam::kSSIDProperty, |
| 299 base::Value::CreateStringValue(service_path)); | 298 base::Value::CreateStringValue(service_path)); |
| 300 properties->SetWithoutPathExpansion( | 299 properties->SetWithoutPathExpansion( |
| 301 flimflam::kNameProperty, | 300 flimflam::kNameProperty, |
| 302 base::Value::CreateStringValue(name)); | 301 base::Value::CreateStringValue(name)); |
| 303 properties->SetWithoutPathExpansion( | 302 properties->SetWithoutPathExpansion( |
| 304 flimflam::kTypeProperty, | 303 flimflam::kTypeProperty, |
| 305 base::Value::CreateStringValue(type)); | 304 base::Value::CreateStringValue(type)); |
| 306 properties->SetWithoutPathExpansion( | 305 properties->SetWithoutPathExpansion( |
| 307 flimflam::kStateProperty, | 306 flimflam::kStateProperty, |
| 308 base::Value::CreateStringValue(state)); | 307 base::Value::CreateStringValue(state)); |
| 309 properties->SetWithoutPathExpansion( | |
| 310 flimflam::kSecurityProperty, | |
| 311 base::Value::CreateStringValue(security)); | |
| 312 } | 308 } |
| 313 | 309 |
| 314 virtual void RemoveService(const std::string& service_path) { | 310 virtual void RemoveService(const std::string& service_path) { |
| 315 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); | 311 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); |
| 316 } | 312 } |
| 317 | 313 |
| 318 virtual void SetServiceProperty(const std::string& service_path, | 314 virtual void SetServiceProperty(const std::string& service_path, |
| 319 const std::string& property, | 315 const std::string& property, |
| 320 const base::Value& value) OVERRIDE { | 316 const base::Value& value) OVERRIDE { |
| 321 SetProperty(dbus::ObjectPath(service_path), property, value, | 317 SetProperty(dbus::ObjectPath(service_path), property, value, |
| 322 base::Bind(&base::DoNothing), ErrorCallback()); | 318 base::Bind(&base::DoNothing), |
| 319 base::Bind(&ShillServiceClientStubImpl::ErrorFunction)); | |
| 323 } | 320 } |
| 324 | 321 |
| 325 virtual void ClearServices() OVERRIDE { | 322 virtual void ClearServices() OVERRIDE { |
| 326 stub_services_.Clear(); | 323 stub_services_.Clear(); |
| 327 } | 324 } |
| 328 | 325 |
| 329 private: | 326 private: |
| 330 void SetDefaultProperties() { | 327 void SetDefaultProperties() { |
| 331 // Add stub services. Note: names match Manager stub impl. | 328 // Add stub services. Note: names match Manager stub impl. |
| 332 AddService("stub_ethernet", "eth0", | 329 AddService("stub_ethernet", "eth0", |
| 333 flimflam::kTypeEthernet, | 330 flimflam::kTypeEthernet, |
| 334 flimflam::kStateOnline, | 331 flimflam::kStateOnline); |
| 335 flimflam::kSecurityNone); | 332 |
| 336 AddService("stub_wifi1", "wifi1", | 333 AddService("stub_wifi1", "wifi1", |
| 337 flimflam::kTypeWifi, | 334 flimflam::kTypeWifi, |
| 338 flimflam::kStateOnline, | 335 flimflam::kStateOnline); |
| 339 flimflam::kSecurityNone); | 336 |
| 340 AddService("stub_wifi2", "wifi2_PSK", | 337 AddService("stub_wifi2", "wifi2_PSK", |
| 341 flimflam::kTypeWifi, | 338 flimflam::kTypeWifi, |
| 342 flimflam::kStateIdle, | 339 flimflam::kStateIdle); |
| 343 flimflam::kSecurityPsk); | 340 base::StringValue psk_value(flimflam::kSecurityPsk); |
| 341 SetServiceProperty("stub_wifi2", | |
| 342 flimflam::kSecurityProperty, | |
| 343 psk_value); | |
| 344 | |
| 344 AddService("stub_cellular1", "cellular1", | 345 AddService("stub_cellular1", "cellular1", |
| 345 flimflam::kTypeCellular, | 346 flimflam::kTypeCellular, |
| 346 flimflam::kStateIdle, | 347 flimflam::kStateIdle); |
| 347 flimflam::kSecurityNone); | |
| 348 base::StringValue technology_value(flimflam::kNetworkTechnologyGsm); | 348 base::StringValue technology_value(flimflam::kNetworkTechnologyGsm); |
| 349 SetServiceProperty("stub_cellular1", | 349 SetServiceProperty("stub_cellular1", |
| 350 flimflam::kNetworkTechnologyProperty, | 350 flimflam::kNetworkTechnologyProperty, |
| 351 technology_value); | 351 technology_value); |
| 352 } | 352 } |
| 353 | 353 |
| 354 void PassStubDictionaryValue(const dbus::ObjectPath& service_path, | 354 void PassStubDictionaryValue(const dbus::ObjectPath& service_path, |
| 355 const DictionaryValueCallback& callback) { | 355 const DictionaryValueCallback& callback) { |
| 356 base::DictionaryValue* dict = NULL; | 356 base::DictionaryValue* dict = NULL; |
| 357 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 357 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 385 base::DictionaryValue* GetServiceProperties(const std::string& service_path) { | 385 base::DictionaryValue* GetServiceProperties(const std::string& service_path) { |
| 386 base::DictionaryValue* properties = NULL; | 386 base::DictionaryValue* properties = NULL; |
| 387 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 387 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
| 388 service_path, &properties)) { | 388 service_path, &properties)) { |
| 389 properties = new base::DictionaryValue; | 389 properties = new base::DictionaryValue; |
| 390 stub_services_.Set(service_path, properties); | 390 stub_services_.Set(service_path, properties); |
| 391 } | 391 } |
| 392 return properties; | 392 return properties; |
| 393 } | 393 } |
| 394 | 394 |
| 395 static void ErrorFunction(const std::string& error_name, | |
| 396 const std::string& error_message) { | |
| 397 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; | |
| 398 } | |
| 395 | 399 |
| 396 base::DictionaryValue stub_services_; | 400 base::DictionaryValue stub_services_; |
| 397 ObserverList<ShillPropertyChangedObserver> observer_list_; | 401 ObserverList<ShillPropertyChangedObserver> observer_list_; |
| 398 | 402 |
| 399 // Note: This should remain the last member so it'll be destroyed and | 403 // Note: This should remain the last member so it'll be destroyed and |
| 400 // invalidate its weak pointers before any other members are destroyed. | 404 // invalidate its weak pointers before any other members are destroyed. |
| 401 base::WeakPtrFactory<ShillServiceClientStubImpl> weak_ptr_factory_; | 405 base::WeakPtrFactory<ShillServiceClientStubImpl> weak_ptr_factory_; |
| 402 | 406 |
| 403 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientStubImpl); | 407 DISALLOW_COPY_AND_ASSIGN(ShillServiceClientStubImpl); |
| 404 }; | 408 }; |
| 405 | 409 |
| 406 } // namespace | 410 } // namespace |
| 407 | 411 |
| 408 ShillServiceClient::ShillServiceClient() {} | 412 ShillServiceClient::ShillServiceClient() {} |
| 409 | 413 |
| 410 ShillServiceClient::~ShillServiceClient() {} | 414 ShillServiceClient::~ShillServiceClient() {} |
| 411 | 415 |
| 412 // static | 416 // static |
| 413 ShillServiceClient* ShillServiceClient::Create( | 417 ShillServiceClient* ShillServiceClient::Create( |
| 414 DBusClientImplementationType type, | 418 DBusClientImplementationType type, |
| 415 dbus::Bus* bus) { | 419 dbus::Bus* bus) { |
| 416 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 420 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 417 return new ShillServiceClientImpl(bus); | 421 return new ShillServiceClientImpl(bus); |
| 418 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 422 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 419 return new ShillServiceClientStubImpl(); | 423 return new ShillServiceClientStubImpl(); |
| 420 } | 424 } |
| 421 | 425 |
| 422 } // namespace chromeos | 426 } // namespace chromeos |
| OLD | NEW |