| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_stub.h" | 5 #include "chromeos/dbus/shill_service_client_stub.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
| 8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chromeos/chromeos_switches.h" |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 12 #include "chromeos/dbus/shill_manager_client.h" | 14 #include "chromeos/dbus/shill_manager_client.h" |
| 13 #include "chromeos/dbus/shill_property_changed_observer.h" | 15 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 14 #include "dbus/bus.h" | 16 #include "dbus/bus.h" |
| 15 #include "dbus/message.h" | 17 #include "dbus/message.h" |
| 16 #include "dbus/object_proxy.h" | 18 #include "dbus/object_proxy.h" |
| 17 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 18 | 20 |
| 19 namespace chromeos { | 21 namespace chromeos { |
| 20 | 22 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 240 |
| 239 ShillServiceClient::TestInterface* ShillServiceClientStub::GetTestInterface() { | 241 ShillServiceClient::TestInterface* ShillServiceClientStub::GetTestInterface() { |
| 240 return this; | 242 return this; |
| 241 } | 243 } |
| 242 | 244 |
| 243 // ShillServiceClient::TestInterface overrides. | 245 // ShillServiceClient::TestInterface overrides. |
| 244 | 246 |
| 245 void ShillServiceClientStub::AddService(const std::string& service_path, | 247 void ShillServiceClientStub::AddService(const std::string& service_path, |
| 246 const std::string& name, | 248 const std::string& name, |
| 247 const std::string& type, | 249 const std::string& type, |
| 248 const std::string& state) { | 250 const std::string& state, |
| 249 base::DictionaryValue* properties = GetServiceProperties(service_path); | 251 bool add_to_watch_list) { |
| 252 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 253 AddService(service_path, add_to_watch_list); |
| 254 |
| 255 base::DictionaryValue* properties = |
| 256 GetModifiableServiceProperties(service_path); |
| 250 properties->SetWithoutPathExpansion( | 257 properties->SetWithoutPathExpansion( |
| 251 flimflam::kSSIDProperty, | 258 flimflam::kSSIDProperty, |
| 252 base::Value::CreateStringValue(service_path)); | 259 base::Value::CreateStringValue(service_path)); |
| 253 properties->SetWithoutPathExpansion( | 260 properties->SetWithoutPathExpansion( |
| 254 flimflam::kNameProperty, | 261 flimflam::kNameProperty, |
| 255 base::Value::CreateStringValue(name)); | 262 base::Value::CreateStringValue(name)); |
| 256 properties->SetWithoutPathExpansion( | 263 properties->SetWithoutPathExpansion( |
| 257 flimflam::kTypeProperty, | 264 flimflam::kTypeProperty, |
| 258 base::Value::CreateStringValue(type)); | 265 base::Value::CreateStringValue(type)); |
| 259 properties->SetWithoutPathExpansion( | 266 properties->SetWithoutPathExpansion( |
| 260 flimflam::kStateProperty, | 267 flimflam::kStateProperty, |
| 261 base::Value::CreateStringValue(state)); | 268 base::Value::CreateStringValue(state)); |
| 262 } | 269 } |
| 263 | 270 |
| 264 void ShillServiceClientStub::RemoveService(const std::string& service_path) { | 271 void ShillServiceClientStub::RemoveService(const std::string& service_path) { |
| 272 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 273 RemoveService(service_path); |
| 274 |
| 265 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); | 275 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); |
| 266 } | 276 } |
| 267 | 277 |
| 268 void ShillServiceClientStub::SetServiceProperty(const std::string& service_path, | 278 void ShillServiceClientStub::SetServiceProperty(const std::string& service_path, |
| 269 const std::string& property, | 279 const std::string& property, |
| 270 const base::Value& value) { | 280 const base::Value& value) { |
| 271 SetProperty(dbus::ObjectPath(service_path), property, value, | 281 SetProperty(dbus::ObjectPath(service_path), property, value, |
| 272 base::Bind(&base::DoNothing), | 282 base::Bind(&base::DoNothing), |
| 273 base::Bind(&ErrorFunction)); | 283 base::Bind(&ErrorFunction)); |
| 274 } | 284 } |
| 275 | 285 |
| 286 const base::DictionaryValue* ShillServiceClientStub::GetServiceProperties( |
| 287 const std::string& service_path) const { |
| 288 const base::DictionaryValue* properties = NULL; |
| 289 stub_services_.GetDictionaryWithoutPathExpansion(service_path, &properties); |
| 290 return properties; |
| 291 } |
| 292 |
| 276 void ShillServiceClientStub::ClearServices() { | 293 void ShillServiceClientStub::ClearServices() { |
| 277 stub_services_.Clear(); | 294 stub_services_.Clear(); |
| 278 } | 295 } |
| 279 | 296 |
| 280 void ShillServiceClientStub::SetDefaultProperties() { | 297 void ShillServiceClientStub::SetDefaultProperties() { |
| 281 // Add stub services. Note: names match Manager stub impl. | 298 const bool add_to_watchlist = true; |
| 282 AddService("stub_ethernet", "eth0", | 299 |
| 283 flimflam::kTypeEthernet, | 300 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 284 flimflam::kStateOnline); | 301 chromeos::switches::kDisableStubEthernet)) { |
| 302 AddService("stub_ethernet", "eth0", |
| 303 flimflam::kTypeEthernet, |
| 304 flimflam::kStateOnline, |
| 305 add_to_watchlist); |
| 306 } |
| 285 | 307 |
| 286 AddService("stub_wifi1", "wifi1", | 308 AddService("stub_wifi1", "wifi1", |
| 287 flimflam::kTypeWifi, | 309 flimflam::kTypeWifi, |
| 288 flimflam::kStateOnline); | 310 flimflam::kStateOnline, |
| 311 add_to_watchlist); |
| 289 | 312 |
| 290 AddService("stub_wifi2", "wifi2_PSK", | 313 AddService("stub_wifi2", "wifi2_PSK", |
| 291 flimflam::kTypeWifi, | 314 flimflam::kTypeWifi, |
| 292 flimflam::kStateIdle); | 315 flimflam::kStateIdle, |
| 316 add_to_watchlist); |
| 293 base::StringValue psk_value(flimflam::kSecurityPsk); | 317 base::StringValue psk_value(flimflam::kSecurityPsk); |
| 294 SetServiceProperty("stub_wifi2", | 318 SetServiceProperty("stub_wifi2", |
| 295 flimflam::kSecurityProperty, | 319 flimflam::kSecurityProperty, |
| 296 psk_value); | 320 psk_value); |
| 297 base::FundamentalValue strength_value(80); | 321 base::FundamentalValue strength_value(80); |
| 298 SetServiceProperty("stub_wifi2", | 322 SetServiceProperty("stub_wifi2", |
| 299 flimflam::kSignalStrengthProperty, | 323 flimflam::kSignalStrengthProperty, |
| 300 strength_value); | 324 strength_value); |
| 301 | 325 |
| 302 AddService("stub_cellular1", "cellular1", | 326 AddService("stub_cellular1", "cellular1", |
| 303 flimflam::kTypeCellular, | 327 flimflam::kTypeCellular, |
| 304 flimflam::kStateIdle); | 328 flimflam::kStateIdle, |
| 329 add_to_watchlist); |
| 305 base::StringValue technology_value(flimflam::kNetworkTechnologyGsm); | 330 base::StringValue technology_value(flimflam::kNetworkTechnologyGsm); |
| 306 SetServiceProperty("stub_cellular1", | 331 SetServiceProperty("stub_cellular1", |
| 307 flimflam::kNetworkTechnologyProperty, | 332 flimflam::kNetworkTechnologyProperty, |
| 308 technology_value); | 333 technology_value); |
| 334 base::StringValue activation_value(flimflam::kActivationStateActivated); |
| 335 SetServiceProperty("stub_cellular1", |
| 336 flimflam::kActivationStateProperty, |
| 337 activation_value); |
| 309 } | 338 } |
| 310 | 339 |
| 311 void ShillServiceClientStub::PassStubServiceProperties( | 340 void ShillServiceClientStub::PassStubServiceProperties( |
| 312 const dbus::ObjectPath& service_path, | 341 const dbus::ObjectPath& service_path, |
| 313 const DictionaryValueCallback& callback) { | 342 const DictionaryValueCallback& callback) { |
| 314 base::DictionaryValue* dict = NULL; | 343 base::DictionaryValue* dict = NULL; |
| 315 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 344 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
| 316 service_path.value(), &dict)) { | 345 service_path.value(), &dict)) { |
| 317 base::DictionaryValue empty_dictionary; | 346 base::DictionaryValue empty_dictionary; |
| 318 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); | 347 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 334 if (!dict->GetWithoutPathExpansion(property, &value)) { | 363 if (!dict->GetWithoutPathExpansion(property, &value)) { |
| 335 LOG(ERROR) << "Notify for unknown property: " | 364 LOG(ERROR) << "Notify for unknown property: " |
| 336 << path << " : " << property; | 365 << path << " : " << property; |
| 337 return; | 366 return; |
| 338 } | 367 } |
| 339 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, | 368 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, |
| 340 GetObserverList(service_path), | 369 GetObserverList(service_path), |
| 341 OnPropertyChanged(property, *value)); | 370 OnPropertyChanged(property, *value)); |
| 342 } | 371 } |
| 343 | 372 |
| 344 base::DictionaryValue* ShillServiceClientStub::GetServiceProperties( | 373 base::DictionaryValue* ShillServiceClientStub::GetModifiableServiceProperties( |
| 345 const std::string& service_path) { | 374 const std::string& service_path) { |
| 346 base::DictionaryValue* properties = NULL; | 375 base::DictionaryValue* properties = NULL; |
| 347 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 376 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
| 348 service_path, &properties)) { | 377 service_path, &properties)) { |
| 349 properties = new base::DictionaryValue; | 378 properties = new base::DictionaryValue; |
| 350 stub_services_.Set(service_path, properties); | 379 stub_services_.Set(service_path, properties); |
| 351 } | 380 } |
| 352 return properties; | 381 return properties; |
| 353 } | 382 } |
| 354 | 383 |
| 355 ShillServiceClientStub::PropertyObserverList& | 384 ShillServiceClientStub::PropertyObserverList& |
| 356 ShillServiceClientStub::GetObserverList(const dbus::ObjectPath& device_path) { | 385 ShillServiceClientStub::GetObserverList(const dbus::ObjectPath& device_path) { |
| 357 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = | 386 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = |
| 358 observer_list_.find(device_path); | 387 observer_list_.find(device_path); |
| 359 if (iter != observer_list_.end()) | 388 if (iter != observer_list_.end()) |
| 360 return *(iter->second); | 389 return *(iter->second); |
| 361 PropertyObserverList* observer_list = new PropertyObserverList(); | 390 PropertyObserverList* observer_list = new PropertyObserverList(); |
| 362 observer_list_[device_path] = observer_list; | 391 observer_list_[device_path] = observer_list; |
| 363 return *observer_list; | 392 return *observer_list; |
| 364 } | 393 } |
| 365 | 394 |
| 366 } // namespace chromeos | 395 } // namespace chromeos |
| OLD | NEW |