OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/cros/network_library.h" | 5 #include "chrome/browser/chromeos/cros/network_library.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 namespace chromeos { | 31 namespace chromeos { |
32 | 32 |
33 namespace { | 33 namespace { |
34 // TODO(ers) These string constants and Parse functions are copied | 34 // TODO(ers) These string constants and Parse functions are copied |
35 // straight out of libcros:chromeos_network.cc. Fix this by moving | 35 // straight out of libcros:chromeos_network.cc. Fix this by moving |
36 // all handling of properties into libcros. | 36 // all handling of properties into libcros. |
37 // Network service properties we are interested in monitoring | 37 // Network service properties we are interested in monitoring |
| 38 static const char* kConnectableProperty = "Connectable"; |
38 static const char* kIsActiveProperty = "IsActive"; | 39 static const char* kIsActiveProperty = "IsActive"; |
39 static const char* kStateProperty = "State"; | 40 static const char* kStateProperty = "State"; |
40 static const char* kSignalStrengthProperty = "Strength"; | 41 static const char* kSignalStrengthProperty = "Strength"; |
41 static const char* kActivationStateProperty = "Cellular.ActivationState"; | 42 static const char* kActivationStateProperty = "Cellular.ActivationState"; |
42 static const char* kNetworkTechnologyProperty = "Cellular.NetworkTechnology"; | 43 static const char* kNetworkTechnologyProperty = "Cellular.NetworkTechnology"; |
43 static const char* kPaymentURLProperty = "Cellular.OlpUrl"; | 44 static const char* kPaymentURLProperty = "Cellular.OlpUrl"; |
44 static const char* kRestrictedPoolProperty = "Cellular.RestrictedPool"; | 45 static const char* kRestrictedPoolProperty = "Cellular.RestrictedPool"; |
45 static const char* kRoamingStateProperty = "Cellular.RoamingState"; | 46 static const char* kRoamingStateProperty = "Cellular.RoamingState"; |
46 | 47 |
47 // Connman state options. | 48 // Connman state options. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 //////////////////////////////////////////////////////////////////////////////// | 213 //////////////////////////////////////////////////////////////////////////////// |
213 // Network | 214 // Network |
214 | 215 |
215 Network::Network(const Network& network) { | 216 Network::Network(const Network& network) { |
216 service_path_ = network.service_path(); | 217 service_path_ = network.service_path(); |
217 device_path_ = network.device_path(); | 218 device_path_ = network.device_path(); |
218 ip_address_ = network.ip_address(); | 219 ip_address_ = network.ip_address(); |
219 type_ = network.type(); | 220 type_ = network.type(); |
220 state_ = network.state(); | 221 state_ = network.state(); |
221 error_ = network.error(); | 222 error_ = network.error(); |
| 223 connectable_ = network.connectable(); |
| 224 is_active_ = network.is_active(); |
222 } | 225 } |
223 | 226 |
224 void Network::Clear() { | 227 void Network::Clear() { |
225 state_ = STATE_UNKNOWN; | |
226 error_ = ERROR_UNKNOWN; | |
227 service_path_.clear(); | 228 service_path_.clear(); |
228 device_path_.clear(); | 229 device_path_.clear(); |
229 ip_address_.clear(); | 230 ip_address_.clear(); |
| 231 type_ = TYPE_UNKNOWN; |
| 232 state_ = STATE_UNKNOWN; |
| 233 error_ = ERROR_UNKNOWN; |
| 234 connectable_ = true; |
230 is_active_ = false; | 235 is_active_ = false; |
231 } | 236 } |
232 | 237 |
233 Network::Network(const ServiceInfo* service) { | 238 Network::Network(const ServiceInfo* service) { |
234 type_ = service->type; | 239 type_ = service->type; |
235 state_ = service->state; | 240 state_ = service->state; |
236 error_ = service->error; | 241 error_ = service->error; |
237 service_path_ = SafeString(service->service_path); | 242 service_path_ = SafeString(service->service_path); |
238 device_path_ = SafeString(service->device_path); | 243 device_path_ = SafeString(service->device_path); |
| 244 connectable_ = service->connectable; |
239 is_active_ = service->is_active; | 245 is_active_ = service->is_active; |
240 ip_address_.clear(); | 246 ip_address_.clear(); |
241 // If connected, get ip config. | 247 // If connected, get ip config. |
242 if (EnsureCrosLoaded() && connected() && service->device_path) { | 248 if (EnsureCrosLoaded() && connected() && service->device_path) { |
243 IPConfigStatus* ipconfig_status = ListIPConfigs(service->device_path); | 249 IPConfigStatus* ipconfig_status = ListIPConfigs(service->device_path); |
244 if (ipconfig_status) { | 250 if (ipconfig_status) { |
245 for (int i = 0; i < ipconfig_status->size; i++) { | 251 for (int i = 0; i < ipconfig_status->size; i++) { |
246 IPConfig ipconfig = ipconfig_status->ips[i]; | 252 IPConfig ipconfig = ipconfig_status->ips[i]; |
247 if (strlen(ipconfig.address) > 0) | 253 if (strlen(ipconfig.address) > 0) |
248 ip_address_ = ipconfig.address; | 254 ip_address_ = ipconfig.address; |
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1417 wifi2->set_strength(70); | 1423 wifi2->set_strength(70); |
1418 wifi2->set_connected(true); | 1424 wifi2->set_connected(true); |
1419 wifi2->set_encryption(SECURITY_WEP); | 1425 wifi2->set_encryption(SECURITY_WEP); |
1420 wifi_networks_.push_back(wifi2); | 1426 wifi_networks_.push_back(wifi2); |
1421 | 1427 |
1422 WifiNetwork* wifi3 = new WifiNetwork(); | 1428 WifiNetwork* wifi3 = new WifiNetwork(); |
1423 wifi3->set_service_path("fw3"); | 1429 wifi3->set_service_path("fw3"); |
1424 wifi3->set_name("Fake Wifi 3"); | 1430 wifi3->set_name("Fake Wifi 3"); |
1425 wifi3->set_strength(50); | 1431 wifi3->set_strength(50); |
1426 wifi3->set_connected(false); | 1432 wifi3->set_connected(false); |
1427 wifi3->set_encryption(SECURITY_WEP); | 1433 wifi3->set_encryption(SECURITY_8021X); |
| 1434 wifi3->set_connectable(false); |
1428 wifi_networks_.push_back(wifi3); | 1435 wifi_networks_.push_back(wifi3); |
1429 | 1436 |
1430 wifi_ = wifi2; | 1437 wifi_ = wifi2; |
1431 | 1438 |
1432 STLDeleteElements(&cellular_networks_); | 1439 STLDeleteElements(&cellular_networks_); |
1433 cellular_networks_.clear(); | 1440 cellular_networks_.clear(); |
1434 | 1441 |
1435 CellularNetwork* cellular1 = new CellularNetwork(); | 1442 CellularNetwork* cellular1 = new CellularNetwork(); |
1436 cellular1->set_service_path("fc1"); | 1443 cellular1->set_service_path("fc1"); |
1437 cellular1->set_name("Fake Cellular 1"); | 1444 cellular1->set_name("Fake Cellular 1"); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 if (value->GetAsString(&stringval)) | 1641 if (value->GetAsString(&stringval)) |
1635 cellular->set_network_technology( | 1642 cellular->set_network_technology( |
1636 ParseNetworkTechnology(stringval)); | 1643 ParseNetworkTechnology(stringval)); |
1637 } else if (strcmp(key, kRoamingStateProperty) == 0) { | 1644 } else if (strcmp(key, kRoamingStateProperty) == 0) { |
1638 if (value->GetAsString(&stringval)) | 1645 if (value->GetAsString(&stringval)) |
1639 cellular->set_roaming_state(ParseRoamingState(stringval)); | 1646 cellular->set_roaming_state(ParseRoamingState(stringval)); |
1640 } | 1647 } |
1641 } | 1648 } |
1642 network = wireless; | 1649 network = wireless; |
1643 } | 1650 } |
1644 if (strcmp(key, kIsActiveProperty) == 0) { | 1651 if (strcmp(key, kConnectableProperty) == 0) { |
| 1652 if (value->GetAsBoolean(&boolval)) |
| 1653 network->set_connectable(boolval); |
| 1654 } else if (strcmp(key, kIsActiveProperty) == 0) { |
1645 if (value->GetAsBoolean(&boolval)) | 1655 if (value->GetAsBoolean(&boolval)) |
1646 network->set_active(boolval); | 1656 network->set_active(boolval); |
1647 } else if (strcmp(key, kStateProperty) == 0) { | 1657 } else if (strcmp(key, kStateProperty) == 0) { |
1648 if (value->GetAsString(&stringval)) | 1658 if (value->GetAsString(&stringval)) |
1649 network->set_state(ParseState(stringval)); | 1659 network->set_state(ParseState(stringval)); |
1650 } | 1660 } |
1651 NotifyNetworkChanged(network); | 1661 NotifyNetworkChanged(network); |
1652 } | 1662 } |
1653 | 1663 |
1654 void UpdateCellularDataPlan(const CellularDataPlanList* data_plans) { | 1664 void UpdateCellularDataPlan(const CellularDataPlanList* data_plans) { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1839 return new NetworkLibraryStubImpl(); | 1849 return new NetworkLibraryStubImpl(); |
1840 else | 1850 else |
1841 return new NetworkLibraryImpl(); | 1851 return new NetworkLibraryImpl(); |
1842 } | 1852 } |
1843 | 1853 |
1844 } // namespace chromeos | 1854 } // namespace chromeos |
1845 | 1855 |
1846 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 1856 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
1847 // won't be deleted until it's last InvokeLater is run. | 1857 // won't be deleted until it's last InvokeLater is run. |
1848 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); | 1858 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); |
OLD | NEW |