Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/fake_shill_service_client.h" | 5 #include "chromeos/dbus/fake_shill_service_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "chromeos/dbus/shill_device_client.h" | 14 #include "chromeos/dbus/shill_device_client.h" |
| 15 #include "chromeos/dbus/shill_manager_client.h" | 15 #include "chromeos/dbus/shill_manager_client.h" |
| 16 #include "chromeos/dbus/shill_profile_client.h" | |
| 16 #include "chromeos/dbus/shill_property_changed_observer.h" | 17 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 17 #include "chromeos/network/shill_property_util.h" | 18 #include "chromeos/network/shill_property_util.h" |
| 18 #include "dbus/bus.h" | 19 #include "dbus/bus.h" |
| 19 #include "dbus/message.h" | 20 #include "dbus/message.h" |
| 20 #include "dbus/object_path.h" | 21 #include "dbus/object_path.h" |
| 21 #include "third_party/cros_system_api/dbus/service_constants.h" | 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 22 | 23 |
| 23 namespace chromeos { | 24 namespace chromeos { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 } | 303 } |
| 303 | 304 |
| 304 // ShillServiceClient::TestInterface overrides. | 305 // ShillServiceClient::TestInterface overrides. |
| 305 | 306 |
| 306 void FakeShillServiceClient::AddService(const std::string& service_path, | 307 void FakeShillServiceClient::AddService(const std::string& service_path, |
| 307 const std::string& name, | 308 const std::string& name, |
| 308 const std::string& type, | 309 const std::string& type, |
| 309 const std::string& state, | 310 const std::string& state, |
| 310 bool add_to_visible_list, | 311 bool add_to_visible_list, |
| 311 bool add_to_watch_list) { | 312 bool add_to_watch_list) { |
| 312 AddServiceWithIPConfig(service_path, name, type, state, "", | 313 AddServiceWithIPConfig(service_path, "" /* guid */, name, |
| 314 type, state, "" /* ipconfig_path */, | |
| 313 add_to_visible_list, add_to_watch_list); | 315 add_to_visible_list, add_to_watch_list); |
| 314 } | 316 } |
| 315 | 317 |
| 316 void FakeShillServiceClient::AddServiceWithIPConfig( | 318 void FakeShillServiceClient::AddServiceWithIPConfig( |
| 317 const std::string& service_path, | 319 const std::string& service_path, |
| 320 const std::string& guid, | |
| 318 const std::string& name, | 321 const std::string& name, |
| 319 const std::string& type, | 322 const std::string& type, |
| 320 const std::string& state, | 323 const std::string& state, |
| 321 const std::string& ipconfig_path, | 324 const std::string& ipconfig_path, |
| 322 bool add_to_visible_list, | 325 bool add_to_visible_list, |
| 323 bool add_to_watch_list) { | 326 bool add_to_watch_list) { |
| 324 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 327 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 325 AddManagerService(service_path, add_to_visible_list, add_to_watch_list); | 328 AddManagerService(service_path, add_to_visible_list, add_to_watch_list); |
| 326 std::string device_path = | 329 std::string device_path = |
| 327 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> | 330 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> |
| 328 GetDevicePathForType(type); | 331 GetDevicePathForType(type); |
| 329 | 332 |
| 330 base::DictionaryValue* properties = | 333 base::DictionaryValue* properties = |
| 331 GetModifiableServiceProperties(service_path, true); | 334 GetModifiableServiceProperties(service_path, true); |
| 332 connect_behavior_.erase(service_path); | 335 connect_behavior_.erase(service_path); |
| 336 | |
| 337 std::string profile_path; | |
| 338 base::DictionaryValue profile_properties; | |
| 339 if (DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> | |
| 340 GetService(service_path, &profile_path, &profile_properties)) { | |
| 341 properties->SetWithoutPathExpansion( | |
| 342 shill::kProfileProperty, | |
| 343 new base::StringValue(profile_path)); | |
| 344 } | |
| 345 | |
| 346 if (!guid.empty()) { | |
| 347 // If |guid| is not provided, leave it blank. Shill does not enforce a | |
|
pneubeck (no reviews)
2014/05/14 08:12:17
move the comment in front of the if, since it appl
stevenjb
2014/05/14 17:08:10
Done.
| |
| 348 // valid guid, we do that at the NetworkStateHandler layer. | |
| 349 properties->SetWithoutPathExpansion( | |
| 350 shill::kGuidProperty, | |
| 351 new base::StringValue(guid)); | |
| 352 } else { | |
| 353 std::string profile_guid; | |
| 354 if (profile_properties.GetStringWithoutPathExpansion( | |
|
pneubeck (no reviews)
2014/05/14 08:12:17
optional nit: IMO clearer, if profile_guid would b
stevenjb
2014/05/14 17:08:10
We can't use 'guid' here since it's const, but I'l
| |
| 355 shill::kGuidProperty, &profile_guid)) { | |
| 356 properties->SetWithoutPathExpansion( | |
| 357 shill::kGuidProperty, | |
| 358 new base::StringValue(profile_guid)); | |
| 359 } | |
| 360 } | |
| 333 shill_property_util::SetSSID(name, properties); | 361 shill_property_util::SetSSID(name, properties); |
| 334 properties->SetWithoutPathExpansion( | 362 properties->SetWithoutPathExpansion( |
| 335 shill::kNameProperty, | 363 shill::kNameProperty, |
| 336 base::Value::CreateStringValue(name)); | 364 new base::StringValue(name)); |
| 337 properties->SetWithoutPathExpansion( | 365 properties->SetWithoutPathExpansion( |
| 338 shill::kDeviceProperty, | 366 shill::kDeviceProperty, |
| 339 base::Value::CreateStringValue(device_path)); | 367 new base::StringValue(device_path)); |
| 340 properties->SetWithoutPathExpansion( | 368 properties->SetWithoutPathExpansion( |
| 341 shill::kTypeProperty, | 369 shill::kTypeProperty, |
| 342 base::Value::CreateStringValue(type)); | 370 new base::StringValue(type)); |
| 343 properties->SetWithoutPathExpansion( | 371 properties->SetWithoutPathExpansion( |
| 344 shill::kStateProperty, | 372 shill::kStateProperty, |
| 345 base::Value::CreateStringValue(state)); | 373 new base::StringValue(state)); |
| 346 if (!ipconfig_path.empty()) { | 374 if (!ipconfig_path.empty()) { |
| 347 properties->SetWithoutPathExpansion( | 375 properties->SetWithoutPathExpansion( |
| 348 shill::kIPConfigProperty, | 376 shill::kIPConfigProperty, |
| 349 base::Value::CreateStringValue(ipconfig_path)); | 377 new base::StringValue(ipconfig_path)); |
| 378 } | |
| 379 if (type == shill::kTypeWifi) { | |
| 380 properties->SetWithoutPathExpansion( | |
| 381 shill::kSecurityProperty, | |
| 382 new base::StringValue(shill::kSecurityNone)); | |
| 350 } | 383 } |
| 351 | 384 |
| 352 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 385 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 353 SortManagerServices(); | 386 SortManagerServices(); |
| 387 | |
| 388 if (!profile_path.empty()) { | |
| 389 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> | |
| 390 UpdateService(profile_path, service_path); | |
| 391 } | |
| 354 } | 392 } |
| 355 | 393 |
| 356 void FakeShillServiceClient::RemoveService(const std::string& service_path) { | 394 void FakeShillServiceClient::RemoveService(const std::string& service_path) { |
| 357 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 395 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 358 RemoveManagerService(service_path); | 396 RemoveManagerService(service_path); |
| 359 | 397 |
| 360 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); | 398 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); |
| 361 connect_behavior_.erase(service_path); | 399 connect_behavior_.erase(service_path); |
| 362 } | 400 } |
| 363 | 401 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 383 provider->SetWithoutPathExpansion(property, value.DeepCopy()); | 421 provider->SetWithoutPathExpansion(property, value.DeepCopy()); |
| 384 new_properties.SetWithoutPathExpansion(shill::kProviderProperty, provider); | 422 new_properties.SetWithoutPathExpansion(shill::kProviderProperty, provider); |
| 385 changed_property = shill::kProviderProperty; | 423 changed_property = shill::kProviderProperty; |
| 386 } else { | 424 } else { |
| 387 new_properties.SetWithoutPathExpansion(property, value.DeepCopy()); | 425 new_properties.SetWithoutPathExpansion(property, value.DeepCopy()); |
| 388 changed_property = property; | 426 changed_property = property; |
| 389 } | 427 } |
| 390 | 428 |
| 391 dict->MergeDictionary(&new_properties); | 429 dict->MergeDictionary(&new_properties); |
| 392 | 430 |
| 431 // Add or update the profile entry. | |
| 432 if (property == shill::kProfileProperty) { | |
| 433 std::string profile_path; | |
| 434 if (value.GetAsString(&profile_path)) { | |
| 435 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> | |
| 436 AddService(profile_path, service_path); | |
| 437 } else { | |
| 438 LOG(ERROR) << "Profile value is not a String!"; | |
| 439 } | |
| 440 } else { | |
| 441 std::string profile_path; | |
| 442 if (dict->GetStringWithoutPathExpansion( | |
| 443 shill::kProfileProperty, &profile_path) && !profile_path.empty()) { | |
| 444 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> | |
| 445 UpdateService(profile_path, service_path); | |
| 446 } | |
| 447 } | |
| 448 | |
| 393 // Notify the Manager if the state changed (affects DefaultService). | 449 // Notify the Manager if the state changed (affects DefaultService). |
| 394 if (property == shill::kStateProperty) { | 450 if (property == shill::kStateProperty) { |
| 395 std::string state; | 451 std::string state; |
| 396 value.GetAsString(&state); | 452 value.GetAsString(&state); |
| 397 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 453 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 398 ServiceStateChanged(service_path, state); | 454 ServiceStateChanged(service_path, state); |
| 399 } | 455 } |
| 400 | 456 |
| 401 // If the State changes, the sort order of Services may change and the | 457 // If the State changes, the sort order of Services may change and the |
| 402 // DefaultService property may change. | 458 // DefaultService property may change. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 base::DictionaryValue* properties; | 552 base::DictionaryValue* properties; |
| 497 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &properties)) | 553 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &properties)) |
| 498 NOTREACHED(); | 554 NOTREACHED(); |
| 499 | 555 |
| 500 std::string type; | 556 std::string type; |
| 501 properties->GetString(shill::kTypeProperty, &type); | 557 properties->GetString(shill::kTypeProperty, &type); |
| 502 if (type != service_type) | 558 if (type != service_type) |
| 503 continue; | 559 continue; |
| 504 properties->SetWithoutPathExpansion( | 560 properties->SetWithoutPathExpansion( |
| 505 shill::kStateProperty, | 561 shill::kStateProperty, |
| 506 base::Value::CreateStringValue(shill::kStateIdle)); | 562 new base::StringValue(shill::kStateIdle)); |
| 507 } | 563 } |
| 508 } | 564 } |
| 509 | 565 |
| 510 void FakeShillServiceClient::SetCellularActivated( | 566 void FakeShillServiceClient::SetCellularActivated( |
| 511 const dbus::ObjectPath& service_path, | 567 const dbus::ObjectPath& service_path, |
| 512 const ErrorCallback& error_callback) { | 568 const ErrorCallback& error_callback) { |
| 513 SetProperty(service_path, | 569 SetProperty(service_path, |
| 514 shill::kActivationStateProperty, | 570 shill::kActivationStateProperty, |
| 515 base::StringValue(shill::kActivationStateActivated), | 571 base::StringValue(shill::kActivationStateActivated), |
| 516 base::Bind(&base::DoNothing), | 572 base::Bind(&base::DoNothing), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 base::StringValue(shill::kErrorBadPassphrase))); | 613 base::StringValue(shill::kErrorBadPassphrase))); |
| 558 } else { | 614 } else { |
| 559 // Set Online. | 615 // Set Online. |
| 560 SetServiceProperty(service_path, | 616 SetServiceProperty(service_path, |
| 561 shill::kStateProperty, | 617 shill::kStateProperty, |
| 562 base::StringValue(shill::kStateOnline)); | 618 base::StringValue(shill::kStateOnline)); |
| 563 } | 619 } |
| 564 } | 620 } |
| 565 | 621 |
| 566 } // namespace chromeos | 622 } // namespace chromeos |
| OLD | NEW |