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_manager_client.h" | 5 #include "chromeos/dbus/fake_shill_manager_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 shill::kStateProperty, | 93 shill::kStateProperty, |
94 base::StringValue(shill::kStatePortal)); | 94 base::StringValue(shill::kStatePortal)); |
95 } | 95 } |
96 | 96 |
97 const char* kTechnologyUnavailable = "unavailable"; | 97 const char* kTechnologyUnavailable = "unavailable"; |
98 const char* kNetworkActivated = "activated"; | 98 const char* kNetworkActivated = "activated"; |
99 const char* kNetworkDisabled = "disabled"; | 99 const char* kNetworkDisabled = "disabled"; |
100 | 100 |
101 } // namespace | 101 } // namespace |
102 | 102 |
| 103 // static |
| 104 const char FakeShillManagerClient::kFakeEthernetNetworkPath[] = "/service/eth1"; |
| 105 |
103 FakeShillManagerClient::FakeShillManagerClient() | 106 FakeShillManagerClient::FakeShillManagerClient() |
104 : interactive_delay_(0), | 107 : interactive_delay_(0), |
105 weak_ptr_factory_(this) { | 108 weak_ptr_factory_(this) { |
106 ParseCommandLineSwitch(); | 109 ParseCommandLineSwitch(); |
107 } | 110 } |
108 | 111 |
109 FakeShillManagerClient::~FakeShillManagerClient() {} | 112 FakeShillManagerClient::~FakeShillManagerClient() {} |
110 | 113 |
111 // ShillManagerClient overrides. | 114 // ShillManagerClient overrides. |
112 | 115 |
(...skipping 24 matching lines...) Expand all Loading... |
137 FROM_HERE, base::Bind( | 140 FROM_HERE, base::Bind( |
138 &FakeShillManagerClient::PassStubGeoNetworks, | 141 &FakeShillManagerClient::PassStubGeoNetworks, |
139 weak_ptr_factory_.GetWeakPtr(), | 142 weak_ptr_factory_.GetWeakPtr(), |
140 callback)); | 143 callback)); |
141 } | 144 } |
142 | 145 |
143 void FakeShillManagerClient::SetProperty(const std::string& name, | 146 void FakeShillManagerClient::SetProperty(const std::string& name, |
144 const base::Value& value, | 147 const base::Value& value, |
145 const base::Closure& callback, | 148 const base::Closure& callback, |
146 const ErrorCallback& error_callback) { | 149 const ErrorCallback& error_callback) { |
| 150 DVLOG(2) << "SetProperty: " << name; |
147 stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy()); | 151 stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy()); |
148 CallNotifyObserversPropertyChanged(name); | 152 CallNotifyObserversPropertyChanged(name); |
149 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 153 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
150 } | 154 } |
151 | 155 |
152 void FakeShillManagerClient::RequestScan(const std::string& type, | 156 void FakeShillManagerClient::RequestScan(const std::string& type, |
153 const base::Closure& callback, | 157 const base::Closure& callback, |
154 const ErrorCallback& error_callback) { | 158 const ErrorCallback& error_callback) { |
155 // For Stub purposes, default to a Wifi scan. | 159 // For Stub purposes, default to a Wifi scan. |
156 std::string device_type = shill::kTypeWifi; | 160 std::string device_type = shill::kTypeWifi; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 const base::DictionaryValue* existing_properties = | 252 const base::DictionaryValue* existing_properties = |
249 service_client->GetServiceProperties(service_path); | 253 service_client->GetServiceProperties(service_path); |
250 if (!existing_properties) { | 254 if (!existing_properties) { |
251 // Add a new service to the service client stub because none exists, yet. | 255 // Add a new service to the service client stub because none exists, yet. |
252 // This calls AddManagerService. | 256 // This calls AddManagerService. |
253 service_client->AddServiceWithIPConfig(service_path, | 257 service_client->AddServiceWithIPConfig(service_path, |
254 guid /* guid */, | 258 guid /* guid */, |
255 guid /* name */, | 259 guid /* name */, |
256 type, | 260 type, |
257 shill::kStateIdle, ipconfig_path, | 261 shill::kStateIdle, ipconfig_path, |
258 true /* visible */, | 262 true /* visible */); |
259 true /* watch */); | |
260 existing_properties = service_client->GetServiceProperties(service_path); | 263 existing_properties = service_client->GetServiceProperties(service_path); |
261 } | 264 } |
262 | 265 |
263 scoped_ptr<base::DictionaryValue> merged_properties( | 266 scoped_ptr<base::DictionaryValue> merged_properties( |
264 existing_properties->DeepCopy()); | 267 existing_properties->DeepCopy()); |
265 merged_properties->MergeDictionary(&properties); | 268 merged_properties->MergeDictionary(&properties); |
266 | 269 |
267 // Now set all the properties. | 270 // Now set all the properties. |
268 for (base::DictionaryValue::Iterator iter(*merged_properties); | 271 for (base::DictionaryValue::Iterator iter(*merged_properties); |
269 !iter.IsAtEnd(); iter.Advance()) { | 272 !iter.IsAtEnd(); iter.Advance()) { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 stub_properties_.Clear(); | 440 stub_properties_.Clear(); |
438 } | 441 } |
439 | 442 |
440 void FakeShillManagerClient::SetManagerProperty(const std::string& key, | 443 void FakeShillManagerClient::SetManagerProperty(const std::string& key, |
441 const base::Value& value) { | 444 const base::Value& value) { |
442 SetProperty(key, value, | 445 SetProperty(key, value, |
443 base::Bind(&base::DoNothing), base::Bind(&LogErrorCallback)); | 446 base::Bind(&base::DoNothing), base::Bind(&LogErrorCallback)); |
444 } | 447 } |
445 | 448 |
446 void FakeShillManagerClient::AddManagerService(const std::string& service_path, | 449 void FakeShillManagerClient::AddManagerService(const std::string& service_path, |
447 bool add_to_visible_list, | 450 bool add_to_visible_list) { |
448 bool add_to_watch_list) { | 451 DVLOG(2) << "AddManagerService: " << service_path |
| 452 << " Visible: " << add_to_visible_list; |
449 // Always add to ServiceCompleteListProperty. | 453 // Always add to ServiceCompleteListProperty. |
450 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent( | 454 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent( |
451 base::Value::CreateStringValue(service_path)); | 455 base::Value::CreateStringValue(service_path)); |
452 // If visible, add to Services and notify if new. | 456 // If visible, add to Services and notify if new. |
453 if (add_to_visible_list && | 457 if (add_to_visible_list && |
454 GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( | 458 GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( |
455 base::Value::CreateStringValue(service_path))) { | 459 base::Value::CreateStringValue(service_path))) { |
456 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | 460 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
457 } | 461 } |
458 if (add_to_watch_list) | |
459 AddServiceToWatchList(service_path); | |
460 } | 462 } |
461 | 463 |
462 void FakeShillManagerClient::RemoveManagerService( | 464 void FakeShillManagerClient::RemoveManagerService( |
463 const std::string& service_path, | 465 const std::string& service_path, |
464 bool remove_from_complete_list) { | 466 bool remove_from_complete_list) { |
| 467 DVLOG(2) << "RemoveManagerService: " << service_path; |
465 base::StringValue service_path_value(service_path); | 468 base::StringValue service_path_value(service_path); |
466 if (remove_from_complete_list) { | 469 if (remove_from_complete_list) { |
467 GetListProperty(shill::kServiceCompleteListProperty)->Remove( | 470 GetListProperty(shill::kServiceCompleteListProperty)->Remove( |
468 service_path_value, NULL); | 471 service_path_value, NULL); |
469 } | 472 } |
470 if (GetListProperty(shill::kServicesProperty)->Remove( | 473 if (GetListProperty(shill::kServicesProperty)->Remove( |
471 service_path_value, NULL)) { | 474 service_path_value, NULL)) { |
472 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | 475 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
473 } | 476 } |
474 if (GetListProperty(shill::kServiceWatchListProperty)->Remove( | |
475 service_path_value, NULL)) { | |
476 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); | |
477 } | |
478 } | 477 } |
479 | 478 |
480 void FakeShillManagerClient::ClearManagerServices() { | 479 void FakeShillManagerClient::ClearManagerServices() { |
| 480 DVLOG(1) << "ClearManagerServices"; |
481 GetListProperty(shill::kServiceCompleteListProperty)->Clear(); | 481 GetListProperty(shill::kServiceCompleteListProperty)->Clear(); |
482 GetListProperty(shill::kServicesProperty)->Clear(); | 482 GetListProperty(shill::kServicesProperty)->Clear(); |
483 GetListProperty(shill::kServiceWatchListProperty)->Clear(); | |
484 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | 483 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
485 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); | |
486 } | 484 } |
487 | 485 |
488 void FakeShillManagerClient::ServiceStateChanged( | 486 void FakeShillManagerClient::ServiceStateChanged( |
489 const std::string& service_path, | 487 const std::string& service_path, |
490 const std::string& state) { | 488 const std::string& state) { |
491 if (service_path == default_service_ && !IsConnectedState(state)) { | 489 if (service_path == default_service_ && !IsConnectedState(state)) { |
492 // Default service is no longer connected; clear. | 490 // Default service is no longer connected; clear. |
493 default_service_.clear(); | 491 default_service_.clear(); |
494 base::StringValue default_service_value(default_service_); | 492 base::StringValue default_service_value(default_service_); |
495 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); | 493 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); |
496 } | 494 } |
497 } | 495 } |
498 | 496 |
499 void FakeShillManagerClient::SortManagerServices() { | 497 void FakeShillManagerClient::SortManagerServices() { |
| 498 DVLOG(1) << "SortManagerServices"; |
500 SortServiceList(shill::kServicesProperty); | 499 SortServiceList(shill::kServicesProperty); |
501 SortServiceList(shill::kServiceCompleteListProperty); | 500 SortServiceList(shill::kServiceCompleteListProperty); |
502 } | 501 } |
503 | 502 |
504 void FakeShillManagerClient::SortServiceList(const std::string& property) { | 503 void FakeShillManagerClient::SortServiceList(const std::string& property) { |
505 static const char* ordered_types[] = { | 504 static const char* ordered_types[] = { |
506 shill::kTypeEthernet, | 505 shill::kTypeEthernet, |
507 shill::kTypeWifi, | 506 shill::kTypeWifi, |
508 shill::kTypeCellular, | 507 shill::kTypeCellular, |
509 shill::kTypeWimax, | 508 shill::kTypeWimax, |
510 shill::kTypeVPN | 509 shill::kTypeVPN |
511 }; | 510 }; |
512 | 511 |
513 base::ListValue* service_list = GetListProperty(property); | 512 base::ListValue* service_list = GetListProperty(property); |
| 513 scoped_ptr<base::ListValue> prev_service_list(service_list->DeepCopy()); |
514 std::vector<std::string> active_services; | 514 std::vector<std::string> active_services; |
515 std::vector<std::string> inactive_services; | 515 std::vector<std::string> inactive_services; |
516 if (service_list && !service_list->empty()) { | 516 if (service_list && !service_list->empty()) { |
517 for (size_t i = 0; i < arraysize(ordered_types); ++i) { | 517 for (size_t i = 0; i < arraysize(ordered_types); ++i) { |
518 AppendServicesForType(service_list, ordered_types[i], | 518 AppendServicesForType(service_list, ordered_types[i], |
519 &active_services, &inactive_services); | 519 &active_services, &inactive_services); |
520 } | 520 } |
521 service_list->Clear(); | 521 service_list->Clear(); |
522 for (size_t i = 0; i < active_services.size(); ++i) | 522 for (size_t i = 0; i < active_services.size(); ++i) |
523 service_list->AppendString(active_services[i]); | 523 service_list->AppendString(active_services[i]); |
524 for (size_t i = 0; i < inactive_services.size(); ++i) | 524 for (size_t i = 0; i < inactive_services.size(); ++i) |
525 service_list->AppendString(inactive_services[i]); | 525 service_list->AppendString(inactive_services[i]); |
526 } | 526 } |
527 | 527 |
528 if (property != shill::kServicesProperty) | 528 if (property != shill::kServicesProperty) |
529 return; | 529 return; |
530 | 530 |
531 CallNotifyObserversPropertyChanged(property); | 531 if (!service_list->Equals(prev_service_list.get())) |
| 532 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
532 | 533 |
533 // Set the first active service as the Default service. | 534 // Set the first active service as the Default service. |
534 std::string new_default_service; | 535 std::string new_default_service; |
535 if (!active_services.empty()) { | 536 if (!active_services.empty()) { |
536 ShillServiceClient::TestInterface* service_client = | 537 ShillServiceClient::TestInterface* service_client = |
537 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 538 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
538 std::string service_path = active_services[0]; | 539 std::string service_path = active_services[0]; |
539 const base::DictionaryValue* properties = | 540 const base::DictionaryValue* properties = |
540 service_client->GetServiceProperties(service_path); | 541 service_client->GetServiceProperties(service_path); |
541 if (!properties) { | 542 if (!properties) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 dbus_manager->GetShillDeviceClient()->GetTestInterface(); | 576 dbus_manager->GetShillDeviceClient()->GetTestInterface(); |
576 DCHECK(devices); | 577 DCHECK(devices); |
577 ShillIPConfigClient::TestInterface* ip_configs = | 578 ShillIPConfigClient::TestInterface* ip_configs = |
578 dbus_manager->GetShillIPConfigClient()->GetTestInterface(); | 579 dbus_manager->GetShillIPConfigClient()->GetTestInterface(); |
579 DCHECK(ip_configs); | 580 DCHECK(ip_configs); |
580 | 581 |
581 const std::string shared_profile = ShillProfileClient::GetSharedProfilePath(); | 582 const std::string shared_profile = ShillProfileClient::GetSharedProfilePath(); |
582 profiles->AddProfile(shared_profile, std::string()); | 583 profiles->AddProfile(shared_profile, std::string()); |
583 | 584 |
584 const bool add_to_visible = true; | 585 const bool add_to_visible = true; |
585 const bool add_to_watchlist = true; | |
586 | 586 |
587 bool enabled; | 587 bool enabled; |
588 std::string state; | 588 std::string state; |
589 | 589 |
590 // IPConfigs | 590 // IPConfigs |
591 base::DictionaryValue ipconfig_v4_dictionary; | 591 base::DictionaryValue ipconfig_v4_dictionary; |
592 ipconfig_v4_dictionary.SetStringWithoutPathExpansion( | 592 ipconfig_v4_dictionary.SetStringWithoutPathExpansion( |
593 shill::kAddressProperty, "0.0.0.0"); | 593 shill::kAddressProperty, "0.0.0.0"); |
594 ipconfig_v4_dictionary.SetStringWithoutPathExpansion( | 594 ipconfig_v4_dictionary.SetStringWithoutPathExpansion( |
595 shill::kGatewayProperty, "0.0.0.1"); | 595 shill::kGatewayProperty, "0.0.0.1"); |
(...skipping 17 matching lines...) Expand all Loading... |
613 "/device/eth1", shill::kTypeEthernet, "stub_eth_device1"); | 613 "/device/eth1", shill::kTypeEthernet, "stub_eth_device1"); |
614 devices->SetDeviceProperty("/device/eth1", | 614 devices->SetDeviceProperty("/device/eth1", |
615 shill::kAddressProperty, | 615 shill::kAddressProperty, |
616 base::StringValue("0123456789ab")); | 616 base::StringValue("0123456789ab")); |
617 base::ListValue eth_ip_configs; | 617 base::ListValue eth_ip_configs; |
618 eth_ip_configs.AppendString("ipconfig_v4_path"); | 618 eth_ip_configs.AppendString("ipconfig_v4_path"); |
619 eth_ip_configs.AppendString("ipconfig_v6_path"); | 619 eth_ip_configs.AppendString("ipconfig_v6_path"); |
620 devices->SetDeviceProperty("/device/eth1", | 620 devices->SetDeviceProperty("/device/eth1", |
621 shill::kIPConfigsProperty, | 621 shill::kIPConfigsProperty, |
622 eth_ip_configs); | 622 eth_ip_configs); |
623 services->AddService("eth1", "eth1", | 623 services->AddService(kFakeEthernetNetworkPath, "eth1", |
624 shill::kTypeEthernet, | 624 shill::kTypeEthernet, |
625 state, | 625 state, |
626 add_to_visible, add_to_watchlist); | 626 add_to_visible); |
627 profiles->AddService(shared_profile, "eth1"); | 627 profiles->AddService(shared_profile, kFakeEthernetNetworkPath); |
628 } | 628 } |
629 | 629 |
630 // Wifi | 630 // Wifi |
631 state = GetInitialStateForType(shill::kTypeWifi, &enabled); | 631 state = GetInitialStateForType(shill::kTypeWifi, &enabled); |
632 if (state != kTechnologyUnavailable) { | 632 if (state != kTechnologyUnavailable) { |
633 bool portaled = false; | 633 bool portaled = false; |
634 if (state == shill::kStatePortal) { | 634 if (state == shill::kStatePortal) { |
635 portaled = true; | 635 portaled = true; |
636 state = shill::kStateIdle; | 636 state = shill::kStateIdle; |
637 } | 637 } |
638 AddTechnology(shill::kTypeWifi, enabled); | 638 AddTechnology(shill::kTypeWifi, enabled); |
639 devices->AddDevice("/device/wifi1", shill::kTypeWifi, "stub_wifi_device1"); | 639 devices->AddDevice("/device/wifi1", shill::kTypeWifi, "stub_wifi_device1"); |
640 devices->SetDeviceProperty("/device/wifi1", | 640 devices->SetDeviceProperty("/device/wifi1", |
641 shill::kAddressProperty, | 641 shill::kAddressProperty, |
642 base::StringValue("23456789abc")); | 642 base::StringValue("23456789abc")); |
643 base::ListValue wifi_ip_configs; | 643 base::ListValue wifi_ip_configs; |
644 wifi_ip_configs.AppendString("ipconfig_v4_path"); | 644 wifi_ip_configs.AppendString("ipconfig_v4_path"); |
645 wifi_ip_configs.AppendString("ipconfig_v6_path"); | 645 wifi_ip_configs.AppendString("ipconfig_v6_path"); |
646 devices->SetDeviceProperty("/device/wifi1", | 646 devices->SetDeviceProperty("/device/wifi1", |
647 shill::kIPConfigsProperty, | 647 shill::kIPConfigsProperty, |
648 wifi_ip_configs); | 648 wifi_ip_configs); |
649 | 649 |
650 services->AddService("wifi1", | 650 services->AddService("/service/wifi1", |
651 "wifi1", | 651 "wifi1", |
652 shill::kTypeWifi, | 652 shill::kTypeWifi, |
653 state, | 653 state, |
654 add_to_visible, add_to_watchlist); | 654 add_to_visible); |
655 services->SetServiceProperty("wifi1", | 655 services->SetServiceProperty("/service/wifi1", |
656 shill::kSecurityProperty, | 656 shill::kSecurityProperty, |
657 base::StringValue(shill::kSecurityWep)); | 657 base::StringValue(shill::kSecurityWep)); |
658 profiles->AddService(shared_profile, "wifi1"); | 658 profiles->AddService(shared_profile, "/service/wifi1"); |
659 | 659 |
660 services->AddService("wifi2", | 660 services->AddService("/service/wifi2", |
661 "wifi2_PSK", | 661 "wifi2_PSK", |
662 shill::kTypeWifi, | 662 shill::kTypeWifi, |
663 shill::kStateIdle, | 663 shill::kStateIdle, |
664 add_to_visible, add_to_watchlist); | 664 add_to_visible); |
665 services->SetServiceProperty("wifi2", | 665 services->SetServiceProperty("/service/wifi2", |
666 shill::kSecurityProperty, | 666 shill::kSecurityProperty, |
667 base::StringValue(shill::kSecurityPsk)); | 667 base::StringValue(shill::kSecurityPsk)); |
668 | 668 |
669 base::FundamentalValue strength_value(80); | 669 base::FundamentalValue strength_value(80); |
670 services->SetServiceProperty( | 670 services->SetServiceProperty( |
671 "wifi2", shill::kSignalStrengthProperty, strength_value); | 671 "/service/wifi2", shill::kSignalStrengthProperty, strength_value); |
672 profiles->AddService(shared_profile, "wifi2"); | 672 profiles->AddService(shared_profile, "/service/wifi2"); |
673 | 673 |
674 if (portaled) { | 674 if (portaled) { |
675 const std::string kPortaledWifiPath = "portaled_wifi"; | 675 const std::string kPortaledWifiPath = "/service/portaled_wifi"; |
676 services->AddService(kPortaledWifiPath, | 676 services->AddService(kPortaledWifiPath, |
677 "Portaled Wifi", | 677 "Portaled Wifi", |
678 shill::kTypeWifi, | 678 shill::kTypeWifi, |
679 shill::kStatePortal, | 679 shill::kStatePortal, |
680 add_to_visible, add_to_watchlist); | 680 add_to_visible); |
681 services->SetServiceProperty(kPortaledWifiPath, | 681 services->SetServiceProperty(kPortaledWifiPath, |
682 shill::kSecurityProperty, | 682 shill::kSecurityProperty, |
683 base::StringValue(shill::kSecurityNone)); | 683 base::StringValue(shill::kSecurityNone)); |
684 services->SetConnectBehavior(kPortaledWifiPath, | 684 services->SetConnectBehavior(kPortaledWifiPath, |
685 base::Bind(&UpdatePortaledWifiState, | 685 base::Bind(&UpdatePortaledWifiState, |
686 "portaled_wifi")); | 686 "portaled_wifi")); |
687 services->SetServiceProperty(kPortaledWifiPath, | 687 services->SetServiceProperty(kPortaledWifiPath, |
688 shill::kConnectableProperty, | 688 shill::kConnectableProperty, |
689 base::FundamentalValue(true)); | 689 base::FundamentalValue(true)); |
690 profiles->AddService(shared_profile, kPortaledWifiPath); | 690 profiles->AddService(shared_profile, kPortaledWifiPath); |
691 } | 691 } |
692 } | 692 } |
693 | 693 |
694 // Wimax | 694 // Wimax |
695 state = GetInitialStateForType(shill::kTypeWimax, &enabled); | 695 state = GetInitialStateForType(shill::kTypeWimax, &enabled); |
696 if (state != kTechnologyUnavailable) { | 696 if (state != kTechnologyUnavailable) { |
697 AddTechnology(shill::kTypeWimax, enabled); | 697 AddTechnology(shill::kTypeWimax, enabled); |
698 devices->AddDevice( | 698 devices->AddDevice( |
699 "/device/wimax1", shill::kTypeWimax, "stub_wimax_device1"); | 699 "/device/wimax1", shill::kTypeWimax, "stub_wimax_device1"); |
700 | 700 |
701 services->AddService("wimax1", | 701 services->AddService("/service/wimax1", |
702 "wimax1", | 702 "wimax1", |
703 shill::kTypeWimax, | 703 shill::kTypeWimax, |
704 state, | 704 state, |
705 add_to_visible, add_to_watchlist); | 705 add_to_visible); |
706 services->SetServiceProperty( | 706 services->SetServiceProperty("/service/wimax1", |
707 "wimax1", shill::kConnectableProperty, base::FundamentalValue(true)); | 707 shill::kConnectableProperty, |
| 708 base::FundamentalValue(true)); |
708 } | 709 } |
709 | 710 |
710 // Cellular | 711 // Cellular |
711 state = GetInitialStateForType(shill::kTypeCellular, &enabled); | 712 state = GetInitialStateForType(shill::kTypeCellular, &enabled); |
712 if (state != kTechnologyUnavailable) { | 713 if (state != kTechnologyUnavailable) { |
713 bool activated = false; | 714 bool activated = false; |
714 if (state == kNetworkActivated) { | 715 if (state == kNetworkActivated) { |
715 activated = true; | 716 activated = true; |
716 state = shill::kStateIdle; | 717 state = shill::kStateIdle; |
717 } | 718 } |
718 AddTechnology(shill::kTypeCellular, enabled); | 719 AddTechnology(shill::kTypeCellular, enabled); |
719 devices->AddDevice( | 720 devices->AddDevice( |
720 "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1"); | 721 "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1"); |
721 devices->SetDeviceProperty("/device/cellular1", | 722 devices->SetDeviceProperty("/device/cellular1", |
722 shill::kCarrierProperty, | 723 shill::kCarrierProperty, |
723 base::StringValue(shill::kCarrierSprint)); | 724 base::StringValue(shill::kCarrierSprint)); |
724 | 725 |
725 services->AddService("cellular1", | 726 services->AddService("/service/cellular1", |
726 "cellular1", | 727 "cellular1", |
727 shill::kTypeCellular, | 728 shill::kTypeCellular, |
728 state, | 729 state, |
729 add_to_visible, add_to_watchlist); | 730 add_to_visible); |
730 base::StringValue technology_value(shill::kNetworkTechnologyGsm); | 731 base::StringValue technology_value(shill::kNetworkTechnologyGsm); |
731 services->SetServiceProperty( | 732 services->SetServiceProperty("/service/cellular1", |
732 "cellular1", shill::kNetworkTechnologyProperty, technology_value); | 733 shill::kNetworkTechnologyProperty, |
| 734 technology_value); |
733 | 735 |
734 if (activated) { | 736 if (activated) { |
735 services->SetServiceProperty( | 737 services->SetServiceProperty( |
736 "cellular1", | 738 "/service/cellular1", |
737 shill::kActivationStateProperty, | 739 shill::kActivationStateProperty, |
738 base::StringValue(shill::kActivationStateActivated)); | 740 base::StringValue(shill::kActivationStateActivated)); |
739 services->SetServiceProperty("cellular1", | 741 services->SetServiceProperty("/service/cellular1", |
740 shill::kConnectableProperty, | 742 shill::kConnectableProperty, |
741 base::FundamentalValue(true)); | 743 base::FundamentalValue(true)); |
742 } else { | 744 } else { |
743 services->SetServiceProperty( | 745 services->SetServiceProperty( |
744 "cellular1", | 746 "/service/cellular1", |
745 shill::kActivationStateProperty, | 747 shill::kActivationStateProperty, |
746 base::StringValue(shill::kActivationStateNotActivated)); | 748 base::StringValue(shill::kActivationStateNotActivated)); |
747 } | 749 } |
748 | 750 |
749 services->SetServiceProperty("cellular1", | 751 services->SetServiceProperty("/service/cellular1", |
750 shill::kRoamingStateProperty, | 752 shill::kRoamingStateProperty, |
751 base::StringValue(shill::kRoamingStateHome)); | 753 base::StringValue(shill::kRoamingStateHome)); |
752 } | 754 } |
753 | 755 |
754 // VPN | 756 // VPN |
755 state = GetInitialStateForType(shill::kTypeVPN, &enabled); | 757 state = GetInitialStateForType(shill::kTypeVPN, &enabled); |
756 if (state != kTechnologyUnavailable) { | 758 if (state != kTechnologyUnavailable) { |
757 // Set the "Provider" dictionary properties. Note: when setting these in | 759 // Set the "Provider" dictionary properties. Note: when setting these in |
758 // Shill, "Provider.Type", etc keys are used, but when reading the values | 760 // Shill, "Provider.Type", etc keys are used, but when reading the values |
759 // "Provider" . "Type", etc keys are used. Here we are setting the values | 761 // "Provider" . "Type", etc keys are used. Here we are setting the values |
760 // that will be read (by the UI, tests, etc). | 762 // that will be read (by the UI, tests, etc). |
761 base::DictionaryValue provider_properties; | 763 base::DictionaryValue provider_properties; |
762 provider_properties.SetString(shill::kTypeProperty, | 764 provider_properties.SetString(shill::kTypeProperty, |
763 shill::kProviderOpenVpn); | 765 shill::kProviderOpenVpn); |
764 provider_properties.SetString(shill::kHostProperty, "vpn_host"); | 766 provider_properties.SetString(shill::kHostProperty, "vpn_host"); |
765 | 767 |
766 services->AddService("vpn1", | 768 services->AddService("/service/vpn1", |
767 "vpn1", | 769 "vpn1", |
768 shill::kTypeVPN, | 770 shill::kTypeVPN, |
769 state, | 771 state, |
770 add_to_visible, add_to_watchlist); | 772 add_to_visible); |
771 services->SetServiceProperty( | 773 services->SetServiceProperty( |
772 "vpn1", shill::kProviderProperty, provider_properties); | 774 "/service/vpn1", shill::kProviderProperty, provider_properties); |
773 profiles->AddService(shared_profile, "vpn1"); | 775 profiles->AddService(shared_profile, "/service/vpn1"); |
774 | 776 |
775 services->AddService("vpn2", | 777 services->AddService("/service/vpn2", |
776 "vpn2", | 778 "vpn2", |
777 shill::kTypeVPN, | 779 shill::kTypeVPN, |
778 shill::kStateIdle, | 780 shill::kStateIdle, |
779 add_to_visible, add_to_watchlist); | 781 add_to_visible); |
780 services->SetServiceProperty( | 782 services->SetServiceProperty( |
781 "vpn2", shill::kProviderProperty, provider_properties); | 783 "/service/vpn2", shill::kProviderProperty, provider_properties); |
782 } | 784 } |
783 | 785 |
784 SortManagerServices(); | 786 SortManagerServices(); |
785 } | 787 } |
786 | 788 |
787 // Private methods | 789 // Private methods |
788 | 790 |
789 void FakeShillManagerClient::AddServiceToWatchList( | |
790 const std::string& service_path) { | |
791 // Remove and insert the service, moving it to the front of the watch list. | |
792 GetListProperty(shill::kServiceWatchListProperty)->Remove( | |
793 base::StringValue(service_path), NULL); | |
794 GetListProperty(shill::kServiceWatchListProperty)->Insert( | |
795 0, base::Value::CreateStringValue(service_path)); | |
796 CallNotifyObserversPropertyChanged( | |
797 shill::kServiceWatchListProperty); | |
798 } | |
799 | |
800 void FakeShillManagerClient::PassStubProperties( | 791 void FakeShillManagerClient::PassStubProperties( |
801 const DictionaryValueCallback& callback) const { | 792 const DictionaryValueCallback& callback) const { |
802 scoped_ptr<base::DictionaryValue> stub_properties( | 793 scoped_ptr<base::DictionaryValue> stub_properties( |
803 stub_properties_.DeepCopy()); | 794 stub_properties_.DeepCopy()); |
804 // Remove disabled services from the list. | 795 // Remove disabled services from the list. |
805 stub_properties->SetWithoutPathExpansion( | 796 stub_properties->SetWithoutPathExpansion( |
806 shill::kServicesProperty, | 797 shill::kServicesProperty, |
807 GetEnabledServiceList(shill::kServicesProperty)); | 798 GetEnabledServiceList(shill::kServicesProperty)); |
808 stub_properties->SetWithoutPathExpansion( | |
809 shill::kServiceWatchListProperty, | |
810 GetEnabledServiceList(shill::kServiceWatchListProperty)); | |
811 callback.Run(DBUS_METHOD_CALL_SUCCESS, *stub_properties); | 799 callback.Run(DBUS_METHOD_CALL_SUCCESS, *stub_properties); |
812 } | 800 } |
813 | 801 |
814 void FakeShillManagerClient::PassStubGeoNetworks( | 802 void FakeShillManagerClient::PassStubGeoNetworks( |
815 const DictionaryValueCallback& callback) const { | 803 const DictionaryValueCallback& callback) const { |
816 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); | 804 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); |
817 } | 805 } |
818 | 806 |
819 void FakeShillManagerClient::CallNotifyObserversPropertyChanged( | 807 void FakeShillManagerClient::CallNotifyObserversPropertyChanged( |
820 const std::string& property) { | 808 const std::string& property) { |
821 // Avoid unnecessary delayed task if we have no observers (e.g. during | 809 // Avoid unnecessary delayed task if we have no observers (e.g. during |
822 // initial setup). | 810 // initial setup). |
823 if (!observer_list_.might_have_observers()) | 811 if (!observer_list_.might_have_observers()) |
824 return; | 812 return; |
825 base::MessageLoop::current()->PostTask( | 813 base::MessageLoop::current()->PostTask( |
826 FROM_HERE, | 814 FROM_HERE, |
827 base::Bind(&FakeShillManagerClient::NotifyObserversPropertyChanged, | 815 base::Bind(&FakeShillManagerClient::NotifyObserversPropertyChanged, |
828 weak_ptr_factory_.GetWeakPtr(), | 816 weak_ptr_factory_.GetWeakPtr(), |
829 property)); | 817 property)); |
830 } | 818 } |
831 | 819 |
832 void FakeShillManagerClient::NotifyObserversPropertyChanged( | 820 void FakeShillManagerClient::NotifyObserversPropertyChanged( |
833 const std::string& property) { | 821 const std::string& property) { |
834 if (property == shill::kServicesProperty || | 822 DVLOG(1) << "NotifyObserversPropertyChanged: " << property; |
835 property == shill::kServiceWatchListProperty) { | 823 if (property == shill::kServicesProperty) { |
836 scoped_ptr<base::ListValue> services(GetEnabledServiceList(property)); | 824 scoped_ptr<base::ListValue> services(GetEnabledServiceList(property)); |
837 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, | 825 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, |
838 observer_list_, | 826 observer_list_, |
839 OnPropertyChanged(property, *(services.get()))); | 827 OnPropertyChanged(property, *(services.get()))); |
840 return; | 828 return; |
841 } | 829 } |
842 if (property == shill::kDevicesProperty) { | 830 if (property == shill::kDevicesProperty) { |
843 base::ListValue* devices = NULL; | 831 base::ListValue* devices = NULL; |
844 if (stub_properties_.GetListWithoutPathExpansion( | 832 if (stub_properties_.GetListWithoutPathExpansion( |
845 shill::kDevicesProperty, &devices)) { | 833 shill::kDevicesProperty, &devices)) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 GetListProperty(shill::kEnabledTechnologiesProperty); | 880 GetListProperty(shill::kEnabledTechnologiesProperty); |
893 if (enabled) | 881 if (enabled) |
894 enabled_list->AppendIfNotPresent(new base::StringValue(type)); | 882 enabled_list->AppendIfNotPresent(new base::StringValue(type)); |
895 else | 883 else |
896 enabled_list->Remove(base::StringValue(type), NULL); | 884 enabled_list->Remove(base::StringValue(type), NULL); |
897 CallNotifyObserversPropertyChanged( | 885 CallNotifyObserversPropertyChanged( |
898 shill::kEnabledTechnologiesProperty); | 886 shill::kEnabledTechnologiesProperty); |
899 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 887 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
900 // May affect available services | 888 // May affect available services |
901 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | 889 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
902 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); | |
903 } | 890 } |
904 | 891 |
905 base::ListValue* FakeShillManagerClient::GetEnabledServiceList( | 892 base::ListValue* FakeShillManagerClient::GetEnabledServiceList( |
906 const std::string& property) const { | 893 const std::string& property) const { |
907 base::ListValue* new_service_list = new base::ListValue; | 894 base::ListValue* new_service_list = new base::ListValue; |
908 const base::ListValue* service_list; | 895 const base::ListValue* service_list; |
909 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { | 896 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { |
910 ShillServiceClient::TestInterface* service_client = | 897 ShillServiceClient::TestInterface* service_client = |
911 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 898 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
912 for (base::ListValue::const_iterator iter = service_list->begin(); | 899 for (base::ListValue::const_iterator iter = service_list->begin(); |
(...skipping 17 matching lines...) Expand all Loading... |
930 } | 917 } |
931 | 918 |
932 void FakeShillManagerClient::ScanCompleted(const std::string& device_path, | 919 void FakeShillManagerClient::ScanCompleted(const std::string& device_path, |
933 const base::Closure& callback) { | 920 const base::Closure& callback) { |
934 if (!device_path.empty()) { | 921 if (!device_path.empty()) { |
935 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> | 922 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> |
936 SetDeviceProperty(device_path, | 923 SetDeviceProperty(device_path, |
937 shill::kScanningProperty, | 924 shill::kScanningProperty, |
938 base::FundamentalValue(false)); | 925 base::FundamentalValue(false)); |
939 } | 926 } |
| 927 DVLOG(2) << "ScanCompleted"; |
940 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | 928 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
941 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); | |
942 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 929 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
943 } | 930 } |
944 | 931 |
945 void FakeShillManagerClient::ParseCommandLineSwitch() { | 932 void FakeShillManagerClient::ParseCommandLineSwitch() { |
946 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 933 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
947 if (command_line->HasSwitch(switches::kShillStub)) { | 934 if (command_line->HasSwitch(switches::kShillStub)) { |
948 std::string option_str = | 935 std::string option_str = |
949 command_line->GetSwitchValueASCII(switches::kShillStub); | 936 command_line->GetSwitchValueASCII(switches::kShillStub); |
950 base::StringPairs string_pairs; | 937 base::StringPairs string_pairs; |
951 base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs); | 938 base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 *enabled = true; | 1038 *enabled = true; |
1052 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || | 1039 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || |
1053 (state == kNetworkActivated && type != shill::kTypeCellular)) { | 1040 (state == kNetworkActivated && type != shill::kTypeCellular)) { |
1054 LOG(WARNING) << "Invalid state: " << state << " for " << type; | 1041 LOG(WARNING) << "Invalid state: " << state << " for " << type; |
1055 return shill::kStateIdle; | 1042 return shill::kStateIdle; |
1056 } | 1043 } |
1057 return state; | 1044 return state; |
1058 } | 1045 } |
1059 | 1046 |
1060 } // namespace chromeos | 1047 } // namespace chromeos |
OLD | NEW |