OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 const int kNetworkNotifyDelayMs = 50; | 96 const int kNetworkNotifyDelayMs = 50; |
97 | 97 |
98 // How long we should remember that cellular plan payment was received. | 98 // How long we should remember that cellular plan payment was received. |
99 const int kRecentPlanPaymentHours = 6; | 99 const int kRecentPlanPaymentHours = 6; |
100 | 100 |
101 // Default value of the SIM unlock retries count. It is updated to the real | 101 // Default value of the SIM unlock retries count. It is updated to the real |
102 // retries count once cellular device with SIM card is initialized. | 102 // retries count once cellular device with SIM card is initialized. |
103 // If cellular device doesn't have SIM card, then retries are never used. | 103 // If cellular device doesn't have SIM card, then retries are never used. |
104 const int kDefaultSimUnlockRetriesCount = 999; | 104 const int kDefaultSimUnlockRetriesCount = 999; |
105 | 105 |
106 // List of cellular operators names that should have data roaming always enabled | |
107 // to be able to connect to any network. | |
108 const char* kAlwaysInRoamingOperators[] = { | |
109 "CUBIC" | |
110 }; | |
111 | |
106 //////////////////////////////////////////////////////////////////////////////// | 112 //////////////////////////////////////////////////////////////////////////////// |
107 // Misc. | 113 // Misc. |
108 | 114 |
109 // Safe string constructor since we can't rely on non NULL pointers | 115 // Safe string constructor since we can't rely on non NULL pointers |
110 // for string values from libcros. | 116 // for string values from libcros. |
111 static std::string SafeString(const char* s) { | 117 static std::string SafeString(const char* s) { |
112 return s ? std::string(s) : std::string(); | 118 return s ? std::string(s) : std::string(); |
113 } | 119 } |
114 | 120 |
115 // Erase the memory used by a string, then clear it. | 121 // Erase the memory used by a string, then clear it. |
(...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1367 virtual std::string GetCellularHomeCarrierId() const OVERRIDE; | 1373 virtual std::string GetCellularHomeCarrierId() const OVERRIDE; |
1368 | 1374 |
1369 // virtual ChangePin implemented in derived classes. | 1375 // virtual ChangePin implemented in derived classes. |
1370 // virtual ChangeRequiredPin implemented in derived classes. | 1376 // virtual ChangeRequiredPin implemented in derived classes. |
1371 // virtual EnterPin implemented in derived classes. | 1377 // virtual EnterPin implemented in derived classes. |
1372 // virtual UnblockPin implemented in derived classes. | 1378 // virtual UnblockPin implemented in derived classes. |
1373 | 1379 |
1374 // virtual RequestCellularScan implemented in derived classes. | 1380 // virtual RequestCellularScan implemented in derived classes. |
1375 // virtual RequestCellularRegister implemented in derived classes. | 1381 // virtual RequestCellularRegister implemented in derived classes. |
1376 // virtual SetCellularDataRoamingAllowed implemented in derived classes. | 1382 // virtual SetCellularDataRoamingAllowed implemented in derived classes. |
1383 // virtual IsCellularAlwaysInRoaming implemented in derived classes. | |
1377 // virtual RequestNetworkScan implemented in derived classes. | 1384 // virtual RequestNetworkScan implemented in derived classes. |
1378 // virtual GetWifiAccessPoints implemented in derived classes. | 1385 // virtual GetWifiAccessPoints implemented in derived classes. |
1379 | 1386 |
1380 virtual bool HasProfileType(NetworkProfileType type) const OVERRIDE; | 1387 virtual bool HasProfileType(NetworkProfileType type) const OVERRIDE; |
1381 virtual void SetNetworkProfile(const std::string& service_path, | 1388 virtual void SetNetworkProfile(const std::string& service_path, |
1382 NetworkProfileType type) OVERRIDE; | 1389 NetworkProfileType type) OVERRIDE; |
1383 virtual bool CanConnectToNetwork(const Network* network) const OVERRIDE; | 1390 virtual bool CanConnectToNetwork(const Network* network) const OVERRIDE; |
1384 | 1391 |
1385 // Connect to an existing network. | 1392 // Connect to an existing network. |
1386 virtual void ConnectToWifiNetwork(WifiNetwork* wifi) OVERRIDE; | 1393 virtual void ConnectToWifiNetwork(WifiNetwork* wifi) OVERRIDE; |
(...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2948 virtual void ChangePin(const std::string& old_pin, | 2955 virtual void ChangePin(const std::string& old_pin, |
2949 const std::string& new_pin) OVERRIDE; | 2956 const std::string& new_pin) OVERRIDE; |
2950 virtual void ChangeRequirePin(bool require_pin, | 2957 virtual void ChangeRequirePin(bool require_pin, |
2951 const std::string& pin) OVERRIDE; | 2958 const std::string& pin) OVERRIDE; |
2952 virtual void EnterPin(const std::string& pin) OVERRIDE; | 2959 virtual void EnterPin(const std::string& pin) OVERRIDE; |
2953 virtual void UnblockPin(const std::string& puk, | 2960 virtual void UnblockPin(const std::string& puk, |
2954 const std::string& new_pin) OVERRIDE; | 2961 const std::string& new_pin) OVERRIDE; |
2955 virtual void RequestCellularScan() OVERRIDE; | 2962 virtual void RequestCellularScan() OVERRIDE; |
2956 virtual void RequestCellularRegister(const std::string& network_id) OVERRIDE; | 2963 virtual void RequestCellularRegister(const std::string& network_id) OVERRIDE; |
2957 virtual void SetCellularDataRoamingAllowed(bool new_value) OVERRIDE; | 2964 virtual void SetCellularDataRoamingAllowed(bool new_value) OVERRIDE; |
2965 virtual bool IsCellularAlwaysInRoaming() OVERRIDE; | |
2958 virtual void RequestNetworkScan() OVERRIDE; | 2966 virtual void RequestNetworkScan() OVERRIDE; |
2959 virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) OVERRIDE; | 2967 virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) OVERRIDE; |
2960 | 2968 |
2961 virtual void DisconnectFromNetwork(const Network* network) OVERRIDE; | 2969 virtual void DisconnectFromNetwork(const Network* network) OVERRIDE; |
2962 virtual void CallEnableNetworkDeviceType( | 2970 virtual void CallEnableNetworkDeviceType( |
2963 ConnectionType device, bool enable) OVERRIDE; | 2971 ConnectionType device, bool enable) OVERRIDE; |
2964 virtual void EnableOfflineMode(bool enable) OVERRIDE; | 2972 virtual void EnableOfflineMode(bool enable) OVERRIDE; |
2965 | 2973 |
2966 virtual NetworkIPConfigVector GetIPConfigs( | 2974 virtual NetworkIPConfigVector GetIPConfigs( |
2967 const std::string& device_path, | 2975 const std::string& device_path, |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3204 | 3212 |
3205 void NetworkLibraryImplCros::UpdateNetworkDeviceStatus( | 3213 void NetworkLibraryImplCros::UpdateNetworkDeviceStatus( |
3206 const std::string& path, const std::string& key, const Value& value) { | 3214 const std::string& path, const std::string& key, const Value& value) { |
3207 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3215 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3208 NetworkDevice* device = FindNetworkDeviceByPath(path); | 3216 NetworkDevice* device = FindNetworkDeviceByPath(path); |
3209 if (device) { | 3217 if (device) { |
3210 VLOG(2) << "UpdateNetworkDeviceStatus: " << device->name() << "." << key; | 3218 VLOG(2) << "UpdateNetworkDeviceStatus: " << device->name() << "." << key; |
3211 PropertyIndex index = PROPERTY_INDEX_UNKNOWN; | 3219 PropertyIndex index = PROPERTY_INDEX_UNKNOWN; |
3212 if (device->UpdateStatus(key, value, &index)) { | 3220 if (device->UpdateStatus(key, value, &index)) { |
3213 if (index == PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING) { | 3221 if (index == PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING) { |
3214 bool settings_value = | 3222 if (!device->data_roaming_allowed() && IsCellularAlwaysInRoaming()) { |
3215 UserCrosSettingsProvider::cached_data_roaming_enabled(); | 3223 SetCellularDataRoamingAllowed(true); |
3216 if (device->data_roaming_allowed() != settings_value) { | 3224 } else { |
3217 // Switch back to signed settings value. | 3225 bool settings_value = |
3218 SetCellularDataRoamingAllowed(settings_value); | 3226 UserCrosSettingsProvider::cached_data_roaming_enabled(); |
3219 return; | 3227 if (device->data_roaming_allowed() != settings_value) { |
3228 // Switch back to signed settings value. | |
3229 SetCellularDataRoamingAllowed(settings_value); | |
3230 return; | |
3231 } | |
3220 } | 3232 } |
3221 } | 3233 } |
3222 } else { | 3234 } else { |
3223 VLOG(1) << "UpdateNetworkDeviceStatus: Failed to update: " | 3235 VLOG(1) << "UpdateNetworkDeviceStatus: Failed to update: " |
3224 << path << "." << key; | 3236 << path << "." << key; |
3225 } | 3237 } |
3226 // Notify only observers on device property change. | 3238 // Notify only observers on device property change. |
3227 NotifyNetworkDeviceChanged(device, index); | 3239 NotifyNetworkDeviceChanged(device, index); |
3228 // If a device's power state changes, new properties may become defined. | 3240 // If a device's power state changes, new properties may become defined. |
3229 if (index == PROPERTY_INDEX_POWERED) | 3241 if (index == PROPERTY_INDEX_POWERED) |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3469 NOTREACHED() << "Calling SetCellularDataRoamingAllowed method " | 3481 NOTREACHED() << "Calling SetCellularDataRoamingAllowed method " |
3470 "w/o cellular device."; | 3482 "w/o cellular device."; |
3471 return; | 3483 return; |
3472 } | 3484 } |
3473 scoped_ptr<Value> value(Value::CreateBooleanValue(new_value)); | 3485 scoped_ptr<Value> value(Value::CreateBooleanValue(new_value)); |
3474 chromeos::SetNetworkDeviceProperty(cellular->device_path().c_str(), | 3486 chromeos::SetNetworkDeviceProperty(cellular->device_path().c_str(), |
3475 kCellularAllowRoamingProperty, | 3487 kCellularAllowRoamingProperty, |
3476 value.get()); | 3488 value.get()); |
3477 } | 3489 } |
3478 | 3490 |
3491 bool NetworkLibraryImplCros::IsCellularAlwaysInRoaming() { | |
3492 const NetworkDevice* cellular = FindCellularDevice(); | |
3493 if (!cellular) { | |
3494 NOTREACHED() << "Calling IsCellularAlwaysInRoaming method " | |
3495 "w/o cellular device."; | |
3496 return false; | |
3497 } | |
3498 const std::string& home_provider = cellular->home_provider(); | |
Nikita (slow)
2011/08/25 11:32:46
home_provider_name()
network.home_provider_ is no
Dmitry Polukhin
2011/08/25 12:39:27
Done. Thanks for catching it!
| |
3499 for (size_t i = 0; i < arraysize(kAlwaysInRoamingOperators); i++) { | |
Nikita (slow)
2011/08/25 11:59:17
optional optimization proposal: Cache result of th
| |
3500 if (home_provider == kAlwaysInRoamingOperators[i]) | |
3501 return true; | |
3502 } | |
3503 return false; | |
3504 } | |
3505 | |
3479 void NetworkLibraryImplCros::RequestNetworkScan() { | 3506 void NetworkLibraryImplCros::RequestNetworkScan() { |
3480 if (wifi_enabled()) { | 3507 if (wifi_enabled()) { |
3481 wifi_scanning_ = true; // Cleared when updates are received. | 3508 wifi_scanning_ = true; // Cleared when updates are received. |
3482 chromeos::RequestNetworkScan(kTypeWifi); | 3509 chromeos::RequestNetworkScan(kTypeWifi); |
3483 } | 3510 } |
3484 if (cellular_network()) | 3511 if (cellular_network()) |
3485 cellular_network()->RefreshDataPlansIfNeeded(); | 3512 cellular_network()->RefreshDataPlansIfNeeded(); |
3486 // Make sure all Manager info is up to date. This will also update | 3513 // Make sure all Manager info is up to date. This will also update |
3487 // remembered networks and visible services. | 3514 // remembered networks and visible services. |
3488 chromeos::RequestNetworkManagerInfo(&NetworkManagerUpdate, this); | 3515 chromeos::RequestNetworkManagerInfo(&NetworkManagerUpdate, this); |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4293 virtual void ChangeRequirePin(bool require_pin, | 4320 virtual void ChangeRequirePin(bool require_pin, |
4294 const std::string& pin) OVERRIDE; | 4321 const std::string& pin) OVERRIDE; |
4295 virtual void EnterPin(const std::string& pin) OVERRIDE; | 4322 virtual void EnterPin(const std::string& pin) OVERRIDE; |
4296 virtual void UnblockPin(const std::string& puk, | 4323 virtual void UnblockPin(const std::string& puk, |
4297 const std::string& new_pin) OVERRIDE; | 4324 const std::string& new_pin) OVERRIDE; |
4298 | 4325 |
4299 virtual void RequestCellularScan() OVERRIDE {} | 4326 virtual void RequestCellularScan() OVERRIDE {} |
4300 virtual void RequestCellularRegister( | 4327 virtual void RequestCellularRegister( |
4301 const std::string& network_id) OVERRIDE {} | 4328 const std::string& network_id) OVERRIDE {} |
4302 virtual void SetCellularDataRoamingAllowed(bool new_value) OVERRIDE {} | 4329 virtual void SetCellularDataRoamingAllowed(bool new_value) OVERRIDE {} |
4330 virtual bool IsCellularAlwaysInRoaming() OVERRIDE { return false; } | |
4303 virtual void RequestNetworkScan() OVERRIDE {} | 4331 virtual void RequestNetworkScan() OVERRIDE {} |
4304 | 4332 |
4305 virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) OVERRIDE; | 4333 virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) OVERRIDE; |
4306 | 4334 |
4307 virtual void DisconnectFromNetwork(const Network* network) OVERRIDE; | 4335 virtual void DisconnectFromNetwork(const Network* network) OVERRIDE; |
4308 | 4336 |
4309 virtual void CallEnableNetworkDeviceType( | 4337 virtual void CallEnableNetworkDeviceType( |
4310 ConnectionType device, bool enable) OVERRIDE {} | 4338 ConnectionType device, bool enable) OVERRIDE {} |
4311 virtual void EnableOfflineMode(bool enable) OVERRIDE { | 4339 virtual void EnableOfflineMode(bool enable) OVERRIDE { |
4312 offline_mode_ = enable; | 4340 offline_mode_ = enable; |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4612 return network_library; | 4640 return network_library; |
4613 } | 4641 } |
4614 | 4642 |
4615 ///////////////////////////////////////////////////////////////////////////// | 4643 ///////////////////////////////////////////////////////////////////////////// |
4616 | 4644 |
4617 } // namespace chromeos | 4645 } // namespace chromeos |
4618 | 4646 |
4619 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 4647 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
4620 // won't be deleted until its last InvokeLater is run. | 4648 // won't be deleted until its last InvokeLater is run. |
4621 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); | 4649 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); |
OLD | NEW |