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/shill_stub_helper.h" | 5 #include "chromeos/dbus/shill_stub_helper.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/strings/string_tokenizer.h" | 9 #include "base/strings/string_tokenizer.h" |
| 10 #include "chromeos/chromeos_switches.h" | 10 #include "chromeos/chromeos_switches.h" |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
| 12 #include "chromeos/dbus/shill_device_client.h" | 12 #include "chromeos/dbus/shill_device_client.h" |
| 13 #include "chromeos/dbus/shill_manager_client.h" | 13 #include "chromeos/dbus/shill_manager_client.h" |
| 14 #include "chromeos/dbus/shill_profile_client.h" | 14 #include "chromeos/dbus/shill_profile_client.h" |
| 15 #include "chromeos/dbus/shill_service_client.h" | 15 #include "chromeos/dbus/shill_service_client.h" |
| 16 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 17 | 17 |
| 18 namespace chromeos { | 18 namespace chromeos { |
| 19 namespace shill_stub_helper { | 19 namespace shill_stub_helper { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const char kDevicePathEthernet[] = "/device/eth1"; | 23 void UpdatePortalledWifiState(const std::string& service_path) { |
| 24 const char kDevicePathWifi[] = "/device/wifi1"; | |
| 25 const char kDevicePathCellular[] = "/device/cellular1"; | |
| 26 const char kDevicePathWimax[] = "/device/wimax1"; | |
| 27 | |
| 28 const char kStubPortalledWifiName[] = "Portalled Wifi"; | |
| 29 const char kStubPortalledWifiPath[] = "portalled_wifi"; | |
| 30 | |
| 31 void UpdatePortalledWifiState() { | |
| 32 ShillServiceClient::TestInterface* services = | 24 ShillServiceClient::TestInterface* services = |
| 33 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 25 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 34 | 26 |
| 35 services->SetServiceProperty(kStubPortalledWifiPath, | 27 services->SetServiceProperty(service_path, |
| 36 shill::kStateProperty, | 28 shill::kStateProperty, |
| 37 base::StringValue(shill::kStatePortal)); | 29 base::StringValue(shill::kStatePortal)); |
| 38 } | 30 } |
| 39 | 31 |
| 40 // Returns true if |network_type| is found in the comma separated list given | 32 // Returns true if |network_type| is found in the comma separated list given |
| 41 // with kEnabledStubNetworkTypes switch. | 33 // with kEnabledStubNetworkTypes switch. |
| 42 bool IsStubNetworkTypeEnabled(const std::string& network_type) { | 34 bool IsStubNetworkTypeEnabled(const std::string& network_type) { |
| 43 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 35 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 44 // If the switch is not present, enabled by default. | 36 // If the switch is not present, enabled by default. |
| 45 if (!command_line->HasSwitch(switches::kEnabledStubNetworkTypes)) | 37 if (!command_line->HasSwitch(switches::kEnabledStubNetworkTypes)) |
| 46 return true; | 38 return true; |
| 47 | 39 |
| 48 const std::string value = | 40 const std::string value = |
| 49 command_line->GetSwitchValueASCII(switches::kEnabledStubNetworkTypes); | 41 command_line->GetSwitchValueASCII(switches::kEnabledStubNetworkTypes); |
| 50 base::StringTokenizer tokenizer(value, ","); | 42 base::StringTokenizer tokenizer(value, ","); |
| 51 while (tokenizer.GetNext()) { | 43 while (tokenizer.GetNext()) { |
| 52 if (tokenizer.token() == network_type) | 44 if (tokenizer.token() == network_type) |
| 53 return true; | 45 return true; |
| 54 } | 46 } |
| 55 return false; | 47 return false; |
| 56 } | 48 } |
| 57 | 49 |
| 58 } // namespace | 50 } // namespace |
| 59 | 51 |
| 60 const char kSharedProfilePath[] = "/profile/default"; | |
| 61 | |
| 62 bool IsStubPortalledWifiEnabled(const std::string& path) { | |
| 63 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 64 chromeos::switches::kEnableStubPortalledWifi)) { | |
| 65 return false; | |
| 66 } | |
| 67 return path == kStubPortalledWifiPath; | |
| 68 } | |
| 69 | |
| 70 void SetupDefaultEnvironment() { | 52 void SetupDefaultEnvironment() { |
| 71 ShillServiceClient::TestInterface* services = | 53 ShillServiceClient::TestInterface* services = |
| 72 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 54 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 73 ShillProfileClient::TestInterface* profiles = | 55 ShillProfileClient::TestInterface* profiles = |
| 74 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); | 56 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); |
| 75 ShillManagerClient::TestInterface* manager = | 57 ShillManagerClient::TestInterface* manager = |
| 76 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); | 58 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); |
| 77 ShillDeviceClient::TestInterface* devices = | 59 ShillDeviceClient::TestInterface* devices = |
| 78 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | 60 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
| 79 if (!services || !profiles || !manager | !devices) | 61 if (!services || !profiles || !manager | !devices) |
| 80 return; | 62 return; |
| 81 | 63 |
| 82 // Stub Technologies. | 64 // Stub Technologies. |
| 83 manager->AddTechnology(shill::kTypeEthernet, true); | 65 manager->AddTechnology(shill::kTypeEthernet, true); |
| 84 manager->AddTechnology(shill::kTypeWifi, true); | 66 manager->AddTechnology(shill::kTypeWifi, true); |
| 85 manager->AddTechnology(shill::kTypeCellular, true); | 67 manager->AddTechnology(shill::kTypeCellular, true); |
| 86 manager->AddTechnology(shill::kTypeWimax, true); | 68 manager->AddTechnology(shill::kTypeWimax, true); |
| 87 | 69 |
| 88 profiles->AddProfile(kSharedProfilePath, std::string()); | 70 std::string shared_profile = ShillProfileClient::GetSharedProfilePath(); |
| 71 profiles->AddProfile(shared_profile, std::string()); | |
| 72 | |
| 73 devices->AddDevice("/device/eth1", shill::kTypeEthernet, "stub_eth_device1"); | |
| 74 devices->AddDevice("/device/wifi1", shill::kTypeWifi, "stub_wifi_device1"); | |
| 89 | 75 |
| 90 devices->AddDevice( | 76 devices->AddDevice( |
| 91 kDevicePathEthernet, shill::kTypeEthernet, "stub_eth_device1"); | 77 "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1"); |
| 92 devices->AddDevice(kDevicePathWifi, shill::kTypeWifi, "stub_wifi_device1"); | 78 devices->SetDeviceProperty("/device/cellular1", |
| 93 | |
| 94 devices->AddDevice( | |
| 95 kDevicePathCellular, shill::kTypeCellular, "stub_cellular_device1"); | |
| 96 devices->SetDeviceProperty(kDevicePathCellular, | |
| 97 shill::kCarrierProperty, | 79 shill::kCarrierProperty, |
| 98 base::StringValue(shill::kCarrierSprint)); | 80 base::StringValue(shill::kCarrierSprint)); |
| 99 | 81 |
| 100 devices->AddDevice(kDevicePathWimax, shill::kTypeWimax, "stub_wimax_device1"); | 82 devices->AddDevice("/device/wimax1", shill::kTypeWimax, "stub_wimax_device1"); |
| 101 | 83 |
| 102 const bool add_to_visible = true; | 84 const bool add_to_visible = true; |
| 103 const bool add_to_watchlist = true; | 85 const bool add_to_watchlist = true; |
| 104 | 86 |
| 105 // On real devices, service is not added for ethernet if cable is disconneted. | 87 // On real devices, service is not added for ethernet if cable is disconneted. |
| 106 if (IsStubNetworkTypeEnabled(shill::kTypeEthernet)) { | 88 if (IsStubNetworkTypeEnabled(shill::kTypeEthernet)) { |
| 107 services->AddService("eth1", "eth1", | 89 services->AddService("eth1", "eth1", |
| 108 shill::kTypeEthernet, | 90 shill::kTypeEthernet, |
| 109 shill::kStateOnline, | 91 shill::kStateOnline, |
| 110 add_to_visible, add_to_watchlist); | 92 add_to_visible, add_to_watchlist); |
| 111 profiles->AddService(kSharedProfilePath, "eth1"); | 93 profiles->AddService(shared_profile, "eth1"); |
| 112 } | 94 } |
| 113 | 95 |
| 114 // Wifi | 96 // Wifi |
| 115 | 97 |
| 116 services->AddService("wifi1", | 98 services->AddService("wifi1", |
| 117 "wifi1", | 99 "wifi1", |
| 118 shill::kTypeWifi, | 100 shill::kTypeWifi, |
| 119 IsStubNetworkTypeEnabled(shill::kTypeWifi) ? | 101 IsStubNetworkTypeEnabled(shill::kTypeWifi) ? |
| 120 shill::kStateOnline : shill::kStateIdle, | 102 shill::kStateOnline : shill::kStateIdle, |
| 121 add_to_visible, add_to_watchlist); | 103 add_to_visible, add_to_watchlist); |
| 122 services->SetServiceProperty("wifi1", | 104 services->SetServiceProperty("wifi1", |
| 123 shill::kSecurityProperty, | 105 shill::kSecurityProperty, |
| 124 base::StringValue(shill::kSecurityWep)); | 106 base::StringValue(shill::kSecurityWep)); |
| 125 profiles->AddService(kSharedProfilePath, "wifi1"); | 107 profiles->AddService(shared_profile, "wifi1"); |
| 126 | 108 |
| 127 services->AddService("wifi2", | 109 services->AddService("wifi2", |
| 128 "wifi2_PSK", | 110 "wifi2_PSK", |
| 129 shill::kTypeWifi, | 111 shill::kTypeWifi, |
| 130 shill::kStateIdle, | 112 shill::kStateIdle, |
| 131 add_to_visible, add_to_watchlist); | 113 add_to_visible, add_to_watchlist); |
| 132 services->SetServiceProperty("wifi2", | 114 services->SetServiceProperty("wifi2", |
| 133 shill::kSecurityProperty, | 115 shill::kSecurityProperty, |
| 134 base::StringValue(shill::kSecurityPsk)); | 116 base::StringValue(shill::kSecurityPsk)); |
| 135 base::FundamentalValue strength_value(80); | 117 base::FundamentalValue strength_value(80); |
| 136 services->SetServiceProperty( | 118 services->SetServiceProperty( |
| 137 "wifi2", shill::kSignalStrengthProperty, strength_value); | 119 "wifi2", shill::kSignalStrengthProperty, strength_value); |
| 138 profiles->AddService(kSharedProfilePath, "wifi2"); | 120 profiles->AddService(shared_profile, "wifi2"); |
| 139 | 121 |
| 140 if (CommandLine::ForCurrentProcess()->HasSwitch( | 122 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 141 chromeos::switches::kEnableStubPortalledWifi)) { | 123 chromeos::switches::kEnableStubPortalledWifi)) { |
| 142 services->AddService(kStubPortalledWifiPath, | 124 const std::string kPortaledWifiPath = "portalled_wifi"; |
|
pneubeck (no reviews)
2014/02/28 20:25:57
typo: Portaled -> Portalled
stevenjb
2014/02/28 20:29:00
Done.
| |
| 143 kStubPortalledWifiName, | 125 services->AddService(kPortaledWifiPath, |
| 126 "Portalled Wifi", | |
| 144 shill::kTypeWifi, | 127 shill::kTypeWifi, |
| 145 shill::kStatePortal, | 128 shill::kStatePortal, |
| 146 add_to_visible, add_to_watchlist); | 129 add_to_visible, add_to_watchlist); |
| 147 services->SetServiceProperty(kStubPortalledWifiPath, | 130 services->SetServiceProperty(kPortaledWifiPath, |
| 148 shill::kSecurityProperty, | 131 shill::kSecurityProperty, |
| 149 base::StringValue(shill::kSecurityNone)); | 132 base::StringValue(shill::kSecurityNone)); |
| 150 services->SetConnectBehavior(kStubPortalledWifiPath, | 133 services->SetConnectBehavior(kPortaledWifiPath, |
| 151 base::Bind(&UpdatePortalledWifiState)); | 134 base::Bind(&UpdatePortalledWifiState, |
| 152 services->SetServiceProperty(kStubPortalledWifiPath, | 135 kPortaledWifiPath)); |
| 136 services->SetServiceProperty(kPortaledWifiPath, | |
| 153 shill::kConnectableProperty, | 137 shill::kConnectableProperty, |
| 154 base::FundamentalValue(true)); | 138 base::FundamentalValue(true)); |
| 139 profiles->AddService(shared_profile, kPortaledWifiPath); | |
|
pneubeck (no reviews)
2014/02/28 20:25:57
was that missing before?
stevenjb
2014/02/28 20:29:00
Yes. It was causing warning spam in NetworkStateHa
| |
| 155 } | 140 } |
| 156 | 141 |
| 157 // Wimax | 142 // Wimax |
| 158 | 143 |
| 159 services->AddService("wimax1", | 144 services->AddService("wimax1", |
| 160 "wimax1", | 145 "wimax1", |
| 161 shill::kTypeWimax, | 146 shill::kTypeWimax, |
| 162 shill::kStateIdle, | 147 shill::kStateIdle, |
| 163 add_to_visible, add_to_watchlist); | 148 add_to_visible, add_to_watchlist); |
| 164 services->SetServiceProperty( | 149 services->SetServiceProperty( |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 193 provider_properties.SetString(shill::kHostProperty, "vpn_host"); | 178 provider_properties.SetString(shill::kHostProperty, "vpn_host"); |
| 194 | 179 |
| 195 services->AddService("vpn1", | 180 services->AddService("vpn1", |
| 196 "vpn1", | 181 "vpn1", |
| 197 shill::kTypeVPN, | 182 shill::kTypeVPN, |
| 198 IsStubNetworkTypeEnabled(shill::kTypeVPN) ? | 183 IsStubNetworkTypeEnabled(shill::kTypeVPN) ? |
| 199 shill::kStateOnline : shill::kStateIdle, | 184 shill::kStateOnline : shill::kStateIdle, |
| 200 add_to_visible, add_to_watchlist); | 185 add_to_visible, add_to_watchlist); |
| 201 services->SetServiceProperty( | 186 services->SetServiceProperty( |
| 202 "vpn1", shill::kProviderProperty, provider_properties); | 187 "vpn1", shill::kProviderProperty, provider_properties); |
| 203 profiles->AddService(kSharedProfilePath, "vpn1"); | 188 profiles->AddService(shared_profile, "vpn1"); |
| 204 | 189 |
| 205 services->AddService("vpn2", | 190 services->AddService("vpn2", |
| 206 "vpn2", | 191 "vpn2", |
| 207 shill::kTypeVPN, | 192 shill::kTypeVPN, |
| 208 shill::kStateIdle, | 193 shill::kStateIdle, |
| 209 add_to_visible, add_to_watchlist); | 194 add_to_visible, add_to_watchlist); |
| 210 services->SetServiceProperty( | 195 services->SetServiceProperty( |
| 211 "vpn2", shill::kProviderProperty, provider_properties); | 196 "vpn2", shill::kProviderProperty, provider_properties); |
| 212 | 197 |
| 213 manager->SortManagerServices(); | 198 manager->SortManagerServices(); |
| 214 } | 199 } |
| 215 | 200 |
| 216 std::string DevicePathForType(const std::string& type) { | |
| 217 if (type == shill::kTypeEthernet) | |
| 218 return kDevicePathEthernet; | |
| 219 if (type == shill::kTypeWifi) | |
| 220 return kDevicePathWifi; | |
| 221 if (type == shill::kTypeCellular) | |
| 222 return kDevicePathCellular; | |
| 223 if (type == shill::kTypeWimax) | |
| 224 return kDevicePathWimax; | |
| 225 return ""; | |
| 226 } | |
| 227 | |
| 228 } // namespace shill_stub_helper | 201 } // namespace shill_stub_helper |
| 229 } // namespace chromeos | 202 } // namespace chromeos |
| OLD | NEW |