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| is provided, set Service.GUID to that. Otherwise if a GUID is |
| 347 // stored in a profile entry, use that. Otherwise leave it blank. Shill does |
| 348 // not enforce a valid guid, we do that at the NetworkStateHandler layer. |
| 349 std::string guid_to_set = guid; |
| 350 if (guid_to_set.empty()) { |
| 351 profile_properties.GetStringWithoutPathExpansion( |
| 352 shill::kGuidProperty, &guid_to_set); |
| 353 } |
| 354 if (!guid_to_set.empty()) { |
| 355 properties->SetWithoutPathExpansion(shill::kGuidProperty, |
| 356 new base::StringValue(guid_to_set)); |
| 357 } |
333 shill_property_util::SetSSID(name, properties); | 358 shill_property_util::SetSSID(name, properties); |
334 properties->SetWithoutPathExpansion( | 359 properties->SetWithoutPathExpansion( |
335 shill::kNameProperty, | 360 shill::kNameProperty, |
336 base::Value::CreateStringValue(name)); | 361 new base::StringValue(name)); |
337 properties->SetWithoutPathExpansion( | 362 properties->SetWithoutPathExpansion( |
338 shill::kDeviceProperty, | 363 shill::kDeviceProperty, |
339 base::Value::CreateStringValue(device_path)); | 364 new base::StringValue(device_path)); |
340 properties->SetWithoutPathExpansion( | 365 properties->SetWithoutPathExpansion( |
341 shill::kTypeProperty, | 366 shill::kTypeProperty, |
342 base::Value::CreateStringValue(type)); | 367 new base::StringValue(type)); |
343 properties->SetWithoutPathExpansion( | 368 properties->SetWithoutPathExpansion( |
344 shill::kStateProperty, | 369 shill::kStateProperty, |
345 base::Value::CreateStringValue(state)); | 370 new base::StringValue(state)); |
346 if (!ipconfig_path.empty()) { | 371 if (!ipconfig_path.empty()) { |
347 properties->SetWithoutPathExpansion( | 372 properties->SetWithoutPathExpansion( |
348 shill::kIPConfigProperty, | 373 shill::kIPConfigProperty, |
349 base::Value::CreateStringValue(ipconfig_path)); | 374 new base::StringValue(ipconfig_path)); |
| 375 } |
| 376 if (type == shill::kTypeWifi) { |
| 377 properties->SetWithoutPathExpansion( |
| 378 shill::kSecurityProperty, |
| 379 new base::StringValue(shill::kSecurityNone)); |
350 } | 380 } |
351 | 381 |
352 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 382 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
353 SortManagerServices(); | 383 SortManagerServices(); |
| 384 |
| 385 if (!profile_path.empty()) { |
| 386 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> |
| 387 UpdateService(profile_path, service_path); |
| 388 } |
354 } | 389 } |
355 | 390 |
356 void FakeShillServiceClient::RemoveService(const std::string& service_path) { | 391 void FakeShillServiceClient::RemoveService(const std::string& service_path) { |
357 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 392 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
358 RemoveManagerService(service_path); | 393 RemoveManagerService(service_path); |
359 | 394 |
360 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); | 395 stub_services_.RemoveWithoutPathExpansion(service_path, NULL); |
361 connect_behavior_.erase(service_path); | 396 connect_behavior_.erase(service_path); |
362 } | 397 } |
363 | 398 |
(...skipping 19 matching lines...) Expand all Loading... |
383 provider->SetWithoutPathExpansion(property, value.DeepCopy()); | 418 provider->SetWithoutPathExpansion(property, value.DeepCopy()); |
384 new_properties.SetWithoutPathExpansion(shill::kProviderProperty, provider); | 419 new_properties.SetWithoutPathExpansion(shill::kProviderProperty, provider); |
385 changed_property = shill::kProviderProperty; | 420 changed_property = shill::kProviderProperty; |
386 } else { | 421 } else { |
387 new_properties.SetWithoutPathExpansion(property, value.DeepCopy()); | 422 new_properties.SetWithoutPathExpansion(property, value.DeepCopy()); |
388 changed_property = property; | 423 changed_property = property; |
389 } | 424 } |
390 | 425 |
391 dict->MergeDictionary(&new_properties); | 426 dict->MergeDictionary(&new_properties); |
392 | 427 |
| 428 // Add or update the profile entry. |
| 429 if (property == shill::kProfileProperty) { |
| 430 std::string profile_path; |
| 431 if (value.GetAsString(&profile_path)) { |
| 432 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> |
| 433 AddService(profile_path, service_path); |
| 434 } else { |
| 435 LOG(ERROR) << "Profile value is not a String!"; |
| 436 } |
| 437 } else { |
| 438 std::string profile_path; |
| 439 if (dict->GetStringWithoutPathExpansion( |
| 440 shill::kProfileProperty, &profile_path) && !profile_path.empty()) { |
| 441 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> |
| 442 UpdateService(profile_path, service_path); |
| 443 } |
| 444 } |
| 445 |
393 // Notify the Manager if the state changed (affects DefaultService). | 446 // Notify the Manager if the state changed (affects DefaultService). |
394 if (property == shill::kStateProperty) { | 447 if (property == shill::kStateProperty) { |
395 std::string state; | 448 std::string state; |
396 value.GetAsString(&state); | 449 value.GetAsString(&state); |
397 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 450 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
398 ServiceStateChanged(service_path, state); | 451 ServiceStateChanged(service_path, state); |
399 } | 452 } |
400 | 453 |
401 // If the State changes, the sort order of Services may change and the | 454 // If the State changes, the sort order of Services may change and the |
402 // DefaultService property may change. | 455 // DefaultService property may change. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 base::DictionaryValue* properties; | 549 base::DictionaryValue* properties; |
497 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &properties)) | 550 if (!stub_services_.GetDictionaryWithoutPathExpansion(path, &properties)) |
498 NOTREACHED(); | 551 NOTREACHED(); |
499 | 552 |
500 std::string type; | 553 std::string type; |
501 properties->GetString(shill::kTypeProperty, &type); | 554 properties->GetString(shill::kTypeProperty, &type); |
502 if (type != service_type) | 555 if (type != service_type) |
503 continue; | 556 continue; |
504 properties->SetWithoutPathExpansion( | 557 properties->SetWithoutPathExpansion( |
505 shill::kStateProperty, | 558 shill::kStateProperty, |
506 base::Value::CreateStringValue(shill::kStateIdle)); | 559 new base::StringValue(shill::kStateIdle)); |
507 } | 560 } |
508 } | 561 } |
509 | 562 |
510 void FakeShillServiceClient::SetCellularActivated( | 563 void FakeShillServiceClient::SetCellularActivated( |
511 const dbus::ObjectPath& service_path, | 564 const dbus::ObjectPath& service_path, |
512 const ErrorCallback& error_callback) { | 565 const ErrorCallback& error_callback) { |
513 SetProperty(service_path, | 566 SetProperty(service_path, |
514 shill::kActivationStateProperty, | 567 shill::kActivationStateProperty, |
515 base::StringValue(shill::kActivationStateActivated), | 568 base::StringValue(shill::kActivationStateActivated), |
516 base::Bind(&base::DoNothing), | 569 base::Bind(&base::DoNothing), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 base::StringValue(shill::kErrorBadPassphrase))); | 610 base::StringValue(shill::kErrorBadPassphrase))); |
558 } else { | 611 } else { |
559 // Set Online. | 612 // Set Online. |
560 SetServiceProperty(service_path, | 613 SetServiceProperty(service_path, |
561 shill::kStateProperty, | 614 shill::kStateProperty, |
562 base::StringValue(shill::kStateOnline)); | 615 base::StringValue(shill::kStateOnline)); |
563 } | 616 } |
564 } | 617 } |
565 | 618 |
566 } // namespace chromeos | 619 } // namespace chromeos |
OLD | NEW |