Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: chromeos/dbus/fake_shill_manager_client.cc

Issue 181413006: Replace misc. network stub flags with more flexible ones (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/fake_shill_manager_client.h ('k') | chromeos/dbus/fake_shill_service_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h"
10 #include "base/values.h" 13 #include "base/values.h"
11 #include "chromeos/chromeos_switches.h" 14 #include "chromeos/chromeos_switches.h"
12 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/shill_device_client.h" 16 #include "chromeos/dbus/shill_device_client.h"
14 #include "chromeos/dbus/shill_profile_client.h" 17 #include "chromeos/dbus/shill_profile_client.h"
15 #include "chromeos/dbus/shill_property_changed_observer.h" 18 #include "chromeos/dbus/shill_property_changed_observer.h"
16 #include "chromeos/dbus/shill_service_client.h" 19 #include "chromeos/dbus/shill_service_client.h"
17 #include "dbus/bus.h" 20 #include "dbus/bus.h"
18 #include "dbus/message.h" 21 #include "dbus/message.h"
19 #include "dbus/object_path.h" 22 #include "dbus/object_path.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 void LogErrorCallback(const std::string& error_name, 79 void LogErrorCallback(const std::string& error_name,
77 const std::string& error_message) { 80 const std::string& error_message) {
78 LOG(ERROR) << error_name << ": " << error_message; 81 LOG(ERROR) << error_name << ": " << error_message;
79 } 82 }
80 83
81 bool IsConnectedState(const std::string& state) { 84 bool IsConnectedState(const std::string& state) {
82 return state == shill::kStateOnline || state == shill::kStatePortal || 85 return state == shill::kStateOnline || state == shill::kStatePortal ||
83 state == shill::kStateReady; 86 state == shill::kStateReady;
84 } 87 }
85 88
89 void UpdatePortaledWifiState(const std::string& service_path) {
90 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface()
91 ->SetServiceProperty(service_path,
92 shill::kStateProperty,
93 base::StringValue(shill::kStatePortal));
94 }
95
96 const char* kTechnologyUnavailable = "unavailable";
97 const char* kNetworkActivated = "activated";
98 const char* kNetworkDisabled = "disabled";
99
86 } // namespace 100 } // namespace
87 101
88 FakeShillManagerClient::FakeShillManagerClient() 102 FakeShillManagerClient::FakeShillManagerClient()
89 : weak_ptr_factory_(this) { 103 : interactive_delay_(0),
104 weak_ptr_factory_(this) {
105 ParseCommandLineSwitch();
90 } 106 }
91 107
92 FakeShillManagerClient::~FakeShillManagerClient() {} 108 FakeShillManagerClient::~FakeShillManagerClient() {}
93 109
94 // ShillManagerClient overrides. 110 // ShillManagerClient overrides.
95 111
96 void FakeShillManagerClient::Init(dbus::Bus* bus) {} 112 void FakeShillManagerClient::Init(dbus::Bus* bus) {}
97 113
98 void FakeShillManagerClient::AddPropertyChangedObserver( 114 void FakeShillManagerClient::AddPropertyChangedObserver(
99 ShillPropertyChangedObserver* observer) { 115 ShillPropertyChangedObserver* observer) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 const base::Closure& callback, 152 const base::Closure& callback,
137 const ErrorCallback& error_callback) { 153 const ErrorCallback& error_callback) {
138 // For Stub purposes, default to a Wifi scan. 154 // For Stub purposes, default to a Wifi scan.
139 std::string device_type = shill::kTypeWifi; 155 std::string device_type = shill::kTypeWifi;
140 if (!type.empty()) 156 if (!type.empty())
141 device_type = type; 157 device_type = type;
142 ShillDeviceClient::TestInterface* device_client = 158 ShillDeviceClient::TestInterface* device_client =
143 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); 159 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
144 std::string device_path = device_client->GetDevicePathForType(device_type); 160 std::string device_path = device_client->GetDevicePathForType(device_type);
145 if (!device_path.empty()) { 161 if (!device_path.empty()) {
146 device_client->SetDeviceProperty(device_path, 162 device_client->SetDeviceProperty(
147 shill::kScanningProperty, 163 device_path, shill::kScanningProperty, base::FundamentalValue(true));
148 base::FundamentalValue(true));
149 }
150 const int kScanDurationSeconds = 3;
151 int scan_duration_seconds = kScanDurationSeconds;
152 if (!CommandLine::ForCurrentProcess()->HasSwitch(
153 chromeos::switches::kEnableStubInteractive)) {
154 scan_duration_seconds = 0;
155 } 164 }
156 base::MessageLoop::current()->PostDelayedTask( 165 base::MessageLoop::current()->PostDelayedTask(
157 FROM_HERE, 166 FROM_HERE,
158 base::Bind(&FakeShillManagerClient::ScanCompleted, 167 base::Bind(&FakeShillManagerClient::ScanCompleted,
159 weak_ptr_factory_.GetWeakPtr(), device_path, callback), 168 weak_ptr_factory_.GetWeakPtr(),
160 base::TimeDelta::FromSeconds(scan_duration_seconds)); 169 device_path,
170 callback),
171 base::TimeDelta::FromSeconds(interactive_delay_));
161 } 172 }
162 173
163 void FakeShillManagerClient::EnableTechnology( 174 void FakeShillManagerClient::EnableTechnology(
164 const std::string& type, 175 const std::string& type,
165 const base::Closure& callback, 176 const base::Closure& callback,
166 const ErrorCallback& error_callback) { 177 const ErrorCallback& error_callback) {
167 base::ListValue* enabled_list = NULL; 178 base::ListValue* enabled_list = NULL;
168 if (!stub_properties_.GetListWithoutPathExpansion( 179 if (!stub_properties_.GetListWithoutPathExpansion(
169 shill::kEnabledTechnologiesProperty, &enabled_list)) { 180 shill::kAvailableTechnologiesProperty, &enabled_list)) {
170 base::MessageLoop::current()->PostTask(FROM_HERE, callback); 181 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
171 base::MessageLoop::current()->PostTask( 182 base::MessageLoop::current()->PostTask(
172 FROM_HERE, 183 FROM_HERE,
173 base::Bind(error_callback, "StubError", "Property not found")); 184 base::Bind(error_callback, "StubError", "Property not found"));
174 return; 185 return;
175 } 186 }
176 if (CommandLine::ForCurrentProcess()->HasSwitch( 187 base::MessageLoop::current()->PostDelayedTask(
177 chromeos::switches::kEnableStubInteractive)) { 188 FROM_HERE,
178 const int kEnableTechnologyDelaySeconds = 3; 189 base::Bind(&FakeShillManagerClient::SetTechnologyEnabled,
179 base::MessageLoop::current()->PostDelayedTask( 190 weak_ptr_factory_.GetWeakPtr(),
180 FROM_HERE, 191 type,
181 base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, 192 callback,
182 weak_ptr_factory_.GetWeakPtr(), type, callback, true), 193 true),
183 base::TimeDelta::FromSeconds(kEnableTechnologyDelaySeconds)); 194 base::TimeDelta::FromSeconds(interactive_delay_));
184 } else {
185 SetTechnologyEnabled(type, callback, true);
186 }
187 } 195 }
188 196
189 void FakeShillManagerClient::DisableTechnology( 197 void FakeShillManagerClient::DisableTechnology(
190 const std::string& type, 198 const std::string& type,
191 const base::Closure& callback, 199 const base::Closure& callback,
192 const ErrorCallback& error_callback) { 200 const ErrorCallback& error_callback) {
193 base::ListValue* enabled_list = NULL; 201 base::ListValue* enabled_list = NULL;
194 if (!stub_properties_.GetListWithoutPathExpansion( 202 if (!stub_properties_.GetListWithoutPathExpansion(
195 shill::kEnabledTechnologiesProperty, &enabled_list)) { 203 shill::kAvailableTechnologiesProperty, &enabled_list)) {
196 base::MessageLoop::current()->PostTask( 204 base::MessageLoop::current()->PostTask(
197 FROM_HERE, 205 FROM_HERE,
198 base::Bind(error_callback, "StubError", "Property not found")); 206 base::Bind(error_callback, "StubError", "Property not found"));
199 return; 207 return;
200 } 208 }
201 if (CommandLine::ForCurrentProcess()->HasSwitch( 209 base::MessageLoop::current()->PostDelayedTask(
202 chromeos::switches::kEnableStubInteractive)) { 210 FROM_HERE,
203 const int kDisableTechnologyDelaySeconds = 3; 211 base::Bind(&FakeShillManagerClient::SetTechnologyEnabled,
204 base::MessageLoop::current()->PostDelayedTask( 212 weak_ptr_factory_.GetWeakPtr(),
205 FROM_HERE, 213 type,
206 base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, 214 callback,
207 weak_ptr_factory_.GetWeakPtr(), type, callback, false), 215 false),
208 base::TimeDelta::FromSeconds(kDisableTechnologyDelaySeconds)); 216 base::TimeDelta::FromSeconds(interactive_delay_));
209 } else {
210 SetTechnologyEnabled(type, callback, false);
211 }
212 } 217 }
213 218
214 void FakeShillManagerClient::ConfigureService( 219 void FakeShillManagerClient::ConfigureService(
215 const base::DictionaryValue& properties, 220 const base::DictionaryValue& properties,
216 const ObjectPathCallback& callback, 221 const ObjectPathCallback& callback,
217 const ErrorCallback& error_callback) { 222 const ErrorCallback& error_callback) {
218 ShillServiceClient::TestInterface* service_client = 223 ShillServiceClient::TestInterface* service_client =
219 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); 224 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
220 225
221 std::string guid; 226 std::string guid;
222 std::string type; 227 std::string type;
223 if (!properties.GetString(shill::kGuidProperty, &guid) || 228 if (!properties.GetString(shill::kGuidProperty, &guid) ||
224 !properties.GetString(shill::kTypeProperty, &type)) { 229 !properties.GetString(shill::kTypeProperty, &type)) {
225 LOG(ERROR) << "ConfigureService requies GUID and Type to be defined"; 230 LOG(ERROR) << "ConfigureService requires GUID and Type to be defined";
226 // If the properties aren't filled out completely, then just return an empty 231 // If the properties aren't filled out completely, then just return an empty
227 // object path. 232 // object path.
228 base::MessageLoop::current()->PostTask( 233 base::MessageLoop::current()->PostTask(
229 FROM_HERE, base::Bind(callback, dbus::ObjectPath())); 234 FROM_HERE, base::Bind(callback, dbus::ObjectPath()));
230 return; 235 return;
231 } 236 }
232 237
233 // For the purposes of this stub, we're going to assume that the GUID property 238 // For the purposes of this stub, we're going to assume that the GUID property
234 // is set to the service path because we don't want to re-implement Shill's 239 // is set to the service path because we don't want to re-implement Shill's
235 // property matching magic here. 240 // property matching magic here.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 const ErrorCallback& error_callback) { 314 const ErrorCallback& error_callback) {
310 base::MessageLoop::current()->PostTask( 315 base::MessageLoop::current()->PostTask(
311 FROM_HERE, base::Bind(callback, "encrypted_credentials")); 316 FROM_HERE, base::Bind(callback, "encrypted_credentials"));
312 } 317 }
313 318
314 void FakeShillManagerClient::VerifyAndEncryptData( 319 void FakeShillManagerClient::VerifyAndEncryptData(
315 const VerificationProperties& properties, 320 const VerificationProperties& properties,
316 const std::string& data, 321 const std::string& data,
317 const StringCallback& callback, 322 const StringCallback& callback,
318 const ErrorCallback& error_callback) { 323 const ErrorCallback& error_callback) {
319 base::MessageLoop::current()->PostTask(FROM_HERE, 324 base::MessageLoop::current()->PostTask(
320 base::Bind(callback, "encrypted_data")); 325 FROM_HERE, base::Bind(callback, "encrypted_data"));
321 } 326 }
322 327
323 void FakeShillManagerClient::ConnectToBestServices( 328 void FakeShillManagerClient::ConnectToBestServices(
324 const base::Closure& callback, 329 const base::Closure& callback,
325 const ErrorCallback& error_callback) { 330 const ErrorCallback& error_callback) {
326 } 331 }
327 332
328 ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() { 333 ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() {
329 return this; 334 return this;
330 } 335 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 } 395 }
391 } else { 396 } else {
392 if (GetListProperty(shill::kUninitializedTechnologiesProperty)->Remove( 397 if (GetListProperty(shill::kUninitializedTechnologiesProperty)->Remove(
393 base::StringValue(type), NULL)) { 398 base::StringValue(type), NULL)) {
394 CallNotifyObserversPropertyChanged( 399 CallNotifyObserversPropertyChanged(
395 shill::kUninitializedTechnologiesProperty); 400 shill::kUninitializedTechnologiesProperty);
396 } 401 }
397 } 402 }
398 } 403 }
399 404
405 void FakeShillManagerClient::AddGeoNetwork(
406 const std::string& technology,
407 const base::DictionaryValue& network) {
408 base::ListValue* list_value = NULL;
409 if (!stub_geo_networks_.GetListWithoutPathExpansion(technology,
410 &list_value)) {
411 list_value = new base::ListValue;
412 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value);
413 }
414 list_value->Append(network.DeepCopy());
415 }
416
417 void FakeShillManagerClient::AddProfile(const std::string& profile_path) {
418 const char* key = shill::kProfilesProperty;
419 if (GetListProperty(key)
420 ->AppendIfNotPresent(new base::StringValue(profile_path))) {
421 CallNotifyObserversPropertyChanged(key);
422 }
423 }
424
400 void FakeShillManagerClient::ClearProperties() { 425 void FakeShillManagerClient::ClearProperties() {
401 stub_properties_.Clear(); 426 stub_properties_.Clear();
402 } 427 }
403 428
404 void FakeShillManagerClient::SetManagerProperty(const std::string& key, 429 void FakeShillManagerClient::SetManagerProperty(const std::string& key,
405 const base::Value& value) { 430 const base::Value& value) {
406 SetProperty(key, value, 431 SetProperty(key, value,
407 base::Bind(&base::DoNothing), base::Bind(&LogErrorCallback)); 432 base::Bind(&base::DoNothing), base::Bind(&LogErrorCallback));
408 } 433 }
409 434
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 new_default_service = service_path; 531 new_default_service = service_path;
507 } 532 }
508 } 533 }
509 if (default_service_ != new_default_service) { 534 if (default_service_ != new_default_service) {
510 default_service_ = new_default_service; 535 default_service_ = new_default_service;
511 base::StringValue default_service_value(default_service_); 536 base::StringValue default_service_value(default_service_);
512 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); 537 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value);
513 } 538 }
514 } 539 }
515 540
516 void FakeShillManagerClient::AddGeoNetwork( 541
517 const std::string& technology, 542 int FakeShillManagerClient::GetInteractiveDelay() const {
518 const base::DictionaryValue& network) { 543 return interactive_delay_;
519 base::ListValue* list_value = NULL;
520 if (!stub_geo_networks_.GetListWithoutPathExpansion(
521 technology, &list_value)) {
522 list_value = new base::ListValue;
523 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value);
524 }
525 list_value->Append(network.DeepCopy());
526 } 544 }
527 545
528 void FakeShillManagerClient::AddProfile(const std::string& profile_path) { 546 void FakeShillManagerClient::SetupDefaultEnvironment() {
529 const char* key = shill::kProfilesProperty; 547 DBusThreadManager* dbus_manager = DBusThreadManager::Get();
530 if (GetListProperty(key)->AppendIfNotPresent( 548 ShillServiceClient::TestInterface* services =
531 new base::StringValue(profile_path))) { 549 dbus_manager->GetShillServiceClient()->GetTestInterface();
532 CallNotifyObserversPropertyChanged(key); 550 ShillProfileClient::TestInterface* profiles =
551 dbus_manager->GetShillProfileClient()->GetTestInterface();
552 ShillDeviceClient::TestInterface* devices =
553 dbus_manager->GetShillDeviceClient()->GetTestInterface();
554 if (!services || !profiles || !devices)
555 return;
556
557 const std::string shared_profile = ShillProfileClient::GetSharedProfilePath();
558 profiles->AddProfile(shared_profile, std::string());
559
560 const bool add_to_visible = true;
561 const bool add_to_watchlist = true;
562
563 bool enabled;
564 std::string state;
565
566 // Ethernet
567 state = GetInitialStateForType(shill::kTypeEthernet, &enabled);
568 if (state == shill::kStateOnline) {
569 AddTechnology(shill::kTypeEthernet, enabled);
570 devices->AddDevice(
571 "/device/eth1", shill::kTypeEthernet, "stub_eth_device1");
572 services->AddService("eth1", "eth1",
573 shill::kTypeEthernet,
574 state,
575 add_to_visible, add_to_watchlist);
576 profiles->AddService(shared_profile, "eth1");
533 } 577 }
578
579 // Wifi
580 state = GetInitialStateForType(shill::kTypeWifi, &enabled);
581 if (state != kTechnologyUnavailable) {
582 bool portaled = false;
583 if (state == shill::kStatePortal) {
584 portaled = true;
585 state = shill::kStateIdle;
586 }
587 AddTechnology(shill::kTypeWifi, enabled);
588 devices->AddDevice("/device/wifi1", shill::kTypeWifi, "stub_wifi_device1");
589
590 services->AddService("wifi1",
591 "wifi1",
592 shill::kTypeWifi,
593 state,
594 add_to_visible, add_to_watchlist);
595 services->SetServiceProperty("wifi1",
596 shill::kSecurityProperty,
597 base::StringValue(shill::kSecurityWep));
598 profiles->AddService(shared_profile, "wifi1");
599
600 services->AddService("wifi2",
601 "wifi2_PSK",
602 shill::kTypeWifi,
603 shill::kStateIdle,
604 add_to_visible, add_to_watchlist);
605 services->SetServiceProperty("wifi2",
606 shill::kSecurityProperty,
607 base::StringValue(shill::kSecurityPsk));
608
609 base::FundamentalValue strength_value(80);
610 services->SetServiceProperty(
611 "wifi2", shill::kSignalStrengthProperty, strength_value);
612 profiles->AddService(shared_profile, "wifi2");
613
614 if (portaled) {
615 const std::string kPortaledWifiPath = "portaled_wifi";
616 services->AddService(kPortaledWifiPath,
617 "Portaled Wifi",
618 shill::kTypeWifi,
619 shill::kStatePortal,
620 add_to_visible, add_to_watchlist);
621 services->SetServiceProperty(kPortaledWifiPath,
622 shill::kSecurityProperty,
623 base::StringValue(shill::kSecurityNone));
624 services->SetConnectBehavior(kPortaledWifiPath,
625 base::Bind(&UpdatePortaledWifiState,
626 "portaled_wifi"));
627 services->SetServiceProperty(kPortaledWifiPath,
628 shill::kConnectableProperty,
629 base::FundamentalValue(true));
630 profiles->AddService(shared_profile, kPortaledWifiPath);
631 }
632 }
633
634 // Wimax
635 state = GetInitialStateForType(shill::kTypeWimax, &enabled);
636 if (state != kTechnologyUnavailable) {
637 AddTechnology(shill::kTypeWimax, enabled);
638 devices->AddDevice(
639 "/device/wimax1", shill::kTypeWimax, "stub_wimax_device1");
640
641 services->AddService("wimax1",
642 "wimax1",
643 shill::kTypeWimax,
644 state,
645 add_to_visible, add_to_watchlist);
646 services->SetServiceProperty(
647 "wimax1", shill::kConnectableProperty, base::FundamentalValue(true));
648 }
649
650 // Cellular
651 state = GetInitialStateForType(shill::kTypeCellular, &enabled);
652 if (state != kTechnologyUnavailable) {
653 bool activated = false;
654 if (state == kNetworkActivated) {
655 activated = true;
656 state = shill::kStateIdle;
657 }
658 AddTechnology(shill::kTypeCellular, enabled);
659 devices->AddDevice(
660 "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1");
661 devices->SetDeviceProperty("/device/cellular1",
662 shill::kCarrierProperty,
663 base::StringValue(shill::kCarrierSprint));
664
665 services->AddService("cellular1",
666 "cellular1",
667 shill::kTypeCellular,
668 state,
669 add_to_visible, add_to_watchlist);
670 base::StringValue technology_value(shill::kNetworkTechnologyGsm);
671 services->SetServiceProperty(
672 "cellular1", shill::kNetworkTechnologyProperty, technology_value);
673
674 if (activated) {
675 services->SetServiceProperty(
676 "cellular1",
677 shill::kActivationStateProperty,
678 base::StringValue(shill::kActivationStateActivated));
679 services->SetServiceProperty("cellular1",
680 shill::kConnectableProperty,
681 base::FundamentalValue(true));
682 } else {
683 services->SetServiceProperty(
684 "cellular1",
685 shill::kActivationStateProperty,
686 base::StringValue(shill::kActivationStateNotActivated));
687 }
688
689 services->SetServiceProperty("cellular1",
690 shill::kRoamingStateProperty,
691 base::StringValue(shill::kRoamingStateHome));
692 }
693
694 // VPN
695 state = GetInitialStateForType(shill::kTypeVPN, &enabled);
696 if (state != kTechnologyUnavailable) {
697 // Set the "Provider" dictionary properties. Note: when setting these in
698 // Shill, "Provider.Type", etc keys are used, but when reading the values
699 // "Provider" . "Type", etc keys are used. Here we are setting the values
700 // that will be read (by the UI, tests, etc).
701 base::DictionaryValue provider_properties;
702 provider_properties.SetString(shill::kTypeProperty,
703 shill::kProviderOpenVpn);
704 provider_properties.SetString(shill::kHostProperty, "vpn_host");
705
706 services->AddService("vpn1",
707 "vpn1",
708 shill::kTypeVPN,
709 state,
710 add_to_visible, add_to_watchlist);
711 services->SetServiceProperty(
712 "vpn1", shill::kProviderProperty, provider_properties);
713 profiles->AddService(shared_profile, "vpn1");
714
715 services->AddService("vpn2",
716 "vpn2",
717 shill::kTypeVPN,
718 shill::kStateIdle,
719 add_to_visible, add_to_watchlist);
720 services->SetServiceProperty(
721 "vpn2", shill::kProviderProperty, provider_properties);
722 }
723
724 SortManagerServices();
534 } 725 }
535 726
727 // Private methods
728
536 void FakeShillManagerClient::AddServiceToWatchList( 729 void FakeShillManagerClient::AddServiceToWatchList(
537 const std::string& service_path) { 730 const std::string& service_path) {
538 // Remove and insert the service, moving it to the front of the watch list. 731 // Remove and insert the service, moving it to the front of the watch list.
539 GetListProperty(shill::kServiceWatchListProperty)->Remove( 732 GetListProperty(shill::kServiceWatchListProperty)->Remove(
540 base::StringValue(service_path), NULL); 733 base::StringValue(service_path), NULL);
541 GetListProperty(shill::kServiceWatchListProperty)->Insert( 734 GetListProperty(shill::kServiceWatchListProperty)->Insert(
542 0, base::Value::CreateStringValue(service_path)); 735 0, base::Value::CreateStringValue(service_path));
543 CallNotifyObserversPropertyChanged( 736 CallNotifyObserversPropertyChanged(
544 shill::kServiceWatchListProperty); 737 shill::kServiceWatchListProperty);
545 } 738 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 if (technologies->Find(type_value) != technologies->end()) 821 if (technologies->Find(type_value) != technologies->end())
629 enabled = true; 822 enabled = true;
630 } 823 }
631 return enabled; 824 return enabled;
632 } 825 }
633 826
634 void FakeShillManagerClient::SetTechnologyEnabled( 827 void FakeShillManagerClient::SetTechnologyEnabled(
635 const std::string& type, 828 const std::string& type,
636 const base::Closure& callback, 829 const base::Closure& callback,
637 bool enabled) { 830 bool enabled) {
638 base::ListValue* enabled_list = NULL; 831 base::ListValue* enabled_list =
639 stub_properties_.GetListWithoutPathExpansion( 832 GetListProperty(shill::kEnabledTechnologiesProperty);
640 shill::kEnabledTechnologiesProperty, &enabled_list);
641 DCHECK(enabled_list);
642 if (enabled) 833 if (enabled)
643 enabled_list->AppendIfNotPresent(new base::StringValue(type)); 834 enabled_list->AppendIfNotPresent(new base::StringValue(type));
644 else 835 else
645 enabled_list->Remove(base::StringValue(type), NULL); 836 enabled_list->Remove(base::StringValue(type), NULL);
646 CallNotifyObserversPropertyChanged( 837 CallNotifyObserversPropertyChanged(
647 shill::kEnabledTechnologiesProperty); 838 shill::kEnabledTechnologiesProperty);
648 base::MessageLoop::current()->PostTask(FROM_HERE, callback); 839 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
649 // May affect available services 840 // May affect available services
650 CallNotifyObserversPropertyChanged(shill::kServicesProperty); 841 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
651 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); 842 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> 877 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()->
687 SetDeviceProperty(device_path, 878 SetDeviceProperty(device_path,
688 shill::kScanningProperty, 879 shill::kScanningProperty,
689 base::FundamentalValue(false)); 880 base::FundamentalValue(false));
690 } 881 }
691 CallNotifyObserversPropertyChanged(shill::kServicesProperty); 882 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
692 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); 883 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty);
693 base::MessageLoop::current()->PostTask(FROM_HERE, callback); 884 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
694 } 885 }
695 886
887 void FakeShillManagerClient::ParseCommandLineSwitch() {
888 CommandLine* command_line = CommandLine::ForCurrentProcess();
889 if (command_line->HasSwitch(switches::kShillStub)) {
890 std::string option_str =
891 command_line->GetSwitchValueASCII(switches::kShillStub);
892 base::StringPairs string_pairs;
893 base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs);
894 for (base::StringPairs::iterator iter = string_pairs.begin();
895 iter != string_pairs.end(); ++iter) {
896 ParseOption((*iter).first, (*iter).second);
897 }
898 return;
899 }
900 // Default setup
901 SetInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline);
902 SetInitialNetworkState(shill::kTypeWifi, shill::kStateOnline);
903 SetInitialNetworkState(shill::kTypeCellular, shill::kStateIdle);
904 SetInitialNetworkState(shill::kTypeVPN, shill::kStateIdle);
905 }
906
907 bool FakeShillManagerClient::ParseOption(const std::string& arg0,
908 const std::string& arg1) {
909 if (arg0 == "interactive") {
910 int seconds = 3;
911 if (!arg1.empty())
912 base::StringToInt(arg1, &seconds);
913 interactive_delay_ = seconds;
914 return true;
915 }
916 return SetInitialNetworkState(arg0, arg1);
917 }
918
919 bool FakeShillManagerClient::SetInitialNetworkState(std::string type_arg,
920 std::string state_arg) {
921 std::string state;
922 state_arg = StringToLowerASCII(state_arg);
923 if (state_arg.empty() || state_arg == "1" || state_arg == "on" ||
924 state_arg == "enabled" || state_arg == "connected" ||
925 state_arg == "online") {
926 // Enabled and connected (default value)
927 state = shill::kStateOnline;
928 } else if (state_arg == "0" || state_arg == "off" ||
929 state_arg == "inactive" || state_arg == shill::kStateIdle) {
930 // Technology enabled, services are created but are not connected.
931 state = shill::kStateIdle;
932 } else if (state_arg == "disabled" || state_arg == "disconnect") {
933 // Technology disabled but available, services created but not connected.
934 state = kNetworkDisabled;
935 } else if (state_arg == "none" || state_arg == "offline") {
936 // Technology not available, do not create services.
937 state = kTechnologyUnavailable;
938 } else if (state_arg == "portal") {
939 // Technology is enabled, a service is connected and in Portal state.
940 state = shill::kStatePortal;
941 } else if (state_arg == "active" || state_arg == "activated") {
942 // Technology is enabled, a service is connected and Activated.
943 state = kNetworkActivated;
944 } else {
945 LOG(ERROR) << "Unrecognized initial state: " << state_arg;
946 return false;
947 }
948
949 type_arg = StringToLowerASCII(type_arg);
950 // Special cases
951 if (type_arg == "wireless") {
952 shill_initial_state_map_[shill::kTypeWifi] = state;
953 shill_initial_state_map_[shill::kTypeCellular] = state;
954 return true;
955 }
956 // Convenience synonyms.
957 if (type_arg == "eth")
958 type_arg = shill::kTypeEthernet;
959
960 if (type_arg != shill::kTypeEthernet &&
961 type_arg != shill::kTypeWifi &&
962 type_arg != shill::kTypeCellular &&
963 type_arg != shill::kTypeWimax &&
964 type_arg != shill::kTypeVPN) {
965 LOG(WARNING) << "Unrecognized Shill network type: " << type_arg;
966 return false;
967 }
968
969 // Unconnected or disabled ethernet is the same as unavailable.
970 if (type_arg == shill::kTypeEthernet &&
971 (state == shill::kStateIdle || state == kNetworkDisabled)) {
972 state = kTechnologyUnavailable;
973 }
974
975 shill_initial_state_map_[type_arg] = state;
976 return true;
977 }
978
979 std::string FakeShillManagerClient::GetInitialStateForType(
980 const std::string& type,
981 bool* enabled) {
982 std::map<std::string, std::string>::const_iterator iter =
983 shill_initial_state_map_.find(type);
984 if (iter == shill_initial_state_map_.end()) {
985 *enabled = false;
986 return kTechnologyUnavailable;
987 }
988 std::string state = iter->second;
989 if (state == kNetworkDisabled) {
990 *enabled = false;
991 return shill::kStateIdle;
992 }
993 *enabled = true;
994 if ((state == shill::kStatePortal && type != shill::kTypeWifi) ||
995 (state == kNetworkActivated && type != shill::kTypeCellular)) {
996 LOG(WARNING) << "Invalid state: " << state << " for " << type;
997 return shill::kStateIdle;
998 }
999 return state;
1000 }
1001
696 } // namespace chromeos 1002 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_shill_manager_client.h ('k') | chromeos/dbus/fake_shill_service_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698