| 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 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 prl_version_ = service.device_info->PRL_version; | 257 prl_version_ = service.device_info->PRL_version; |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 bool CellularNetwork::is_gsm() const { | 261 bool CellularNetwork::is_gsm() const { |
| 262 return network_technology_ != NETWORK_TECHNOLOGY_EVDO && | 262 return network_technology_ != NETWORK_TECHNOLOGY_EVDO && |
| 263 network_technology_ != NETWORK_TECHNOLOGY_1XRTT && | 263 network_technology_ != NETWORK_TECHNOLOGY_1XRTT && |
| 264 network_technology_ != NETWORK_TECHNOLOGY_UNKNOWN; | 264 network_technology_ != NETWORK_TECHNOLOGY_UNKNOWN; |
| 265 } | 265 } |
| 266 | 266 |
| 267 CellularNetwork::DataLeft CellularNetwork::data_left() const { | |
| 268 if (data_plans_.empty()) | |
| 269 return DATA_NORMAL; | |
| 270 CellularDataPlan plan = data_plans_[0]; | |
| 271 if (plan.plan_type == CELLULAR_DATA_PLAN_UNLIMITED) { | |
| 272 int64 remaining = plan.plan_end_time - plan.update_time; | |
| 273 if (remaining <= 0) | |
| 274 return DATA_NONE; | |
| 275 else if (remaining <= kCellularDataVeryLowSecs) | |
| 276 return DATA_VERY_LOW; | |
| 277 else if (remaining <= kCellularDataLowSecs) | |
| 278 return DATA_LOW; | |
| 279 else | |
| 280 return DATA_NORMAL; | |
| 281 } else if (plan.plan_type == CELLULAR_DATA_PLAN_METERED_PAID || | |
| 282 plan.plan_type == CELLULAR_DATA_PLAN_METERED_BASE) { | |
| 283 int64 remaining = plan.plan_data_bytes - plan.data_bytes_used; | |
| 284 if (remaining <= 0) | |
| 285 return DATA_NONE; | |
| 286 else if (remaining <= kCellularDataVeryLowBytes) | |
| 287 return DATA_VERY_LOW; | |
| 288 else if (remaining <= kCellularDataLowBytes) | |
| 289 return DATA_LOW; | |
| 290 else | |
| 291 return DATA_NORMAL; | |
| 292 } | |
| 293 return DATA_NORMAL; | |
| 294 } | |
| 295 | |
| 296 std::string CellularNetwork::GetNetworkTechnologyString() const { | 267 std::string CellularNetwork::GetNetworkTechnologyString() const { |
| 297 // No need to localize these cellular technology abbreviations. | 268 // No need to localize these cellular technology abbreviations. |
| 298 switch (network_technology_) { | 269 switch (network_technology_) { |
| 299 case NETWORK_TECHNOLOGY_1XRTT: | 270 case NETWORK_TECHNOLOGY_1XRTT: |
| 300 return "1xRTT"; | 271 return "1xRTT"; |
| 301 break; | 272 break; |
| 302 case NETWORK_TECHNOLOGY_EVDO: | 273 case NETWORK_TECHNOLOGY_EVDO: |
| 303 return "EVDO"; | 274 return "EVDO"; |
| 304 break; | 275 break; |
| 305 case NETWORK_TECHNOLOGY_GPRS: | 276 case NETWORK_TECHNOLOGY_GPRS: |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 test_plan.plan_start_time = | 989 test_plan.plan_start_time = |
| 1019 (base::Time::Now() - base::TimeDelta::FromDays(15)).ToInternalValue() / | 990 (base::Time::Now() - base::TimeDelta::FromDays(15)).ToInternalValue() / |
| 1020 base::Time::kMicrosecondsPerSecond; | 991 base::Time::kMicrosecondsPerSecond; |
| 1021 test_plan.plan_end_time = | 992 test_plan.plan_end_time = |
| 1022 (base::Time::Now() + base::TimeDelta::FromDays(12)).ToInternalValue() / | 993 (base::Time::Now() + base::TimeDelta::FromDays(12)).ToInternalValue() / |
| 1023 base::Time::kMicrosecondsPerSecond; | 994 base::Time::kMicrosecondsPerSecond; |
| 1024 test_plan.plan_data_bytes = 20LL * 1024LL * 1024LL * 1024LL; | 995 test_plan.plan_data_bytes = 20LL * 1024LL * 1024LL * 1024LL; |
| 1025 test_plan.plan_type = CELLULAR_DATA_PLAN_METERED_PAID; | 996 test_plan.plan_type = CELLULAR_DATA_PLAN_METERED_PAID; |
| 1026 test_plan.update_time = base::Time::Now().ToInternalValue() / | 997 test_plan.update_time = base::Time::Now().ToInternalValue() / |
| 1027 base::Time::kMicrosecondsPerSecond; | 998 base::Time::kMicrosecondsPerSecond; |
| 1028 chromeos::CellularDataPlanList test_plans; | 999 cellular_data_plans_.push_back(test_plan); |
| 1029 test_plans.push_back(test_plan); | |
| 1030 cellular_.SetDataPlans(test_plans); | |
| 1031 } | 1000 } |
| 1032 | 1001 |
| 1033 void UpdateSystemInfo() { | 1002 void UpdateSystemInfo() { |
| 1034 if (CrosLibrary::Get()->EnsureLoaded()) { | 1003 if (CrosLibrary::Get()->EnsureLoaded()) { |
| 1035 UpdateNetworkStatus(); | 1004 UpdateNetworkStatus(); |
| 1036 } | 1005 } |
| 1037 } | 1006 } |
| 1038 | 1007 |
| 1039 WifiNetwork* GetWifiNetworkByName(const std::string& name) { | 1008 WifiNetwork* GetWifiNetworkByName(const std::string& name) { |
| 1040 for (size_t i = 0; i < wifi_networks_.size(); ++i) { | 1009 for (size_t i = 0; i < wifi_networks_.size(); ++i) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 } | 1048 } |
| 1080 | 1049 |
| 1081 EnableNetworkDevice(device, enable); | 1050 EnableNetworkDevice(device, enable); |
| 1082 } | 1051 } |
| 1083 | 1052 |
| 1084 void NotifyNetworkChanged() { | 1053 void NotifyNetworkChanged() { |
| 1085 FOR_EACH_OBSERVER(Observer, observers_, NetworkChanged(this)); | 1054 FOR_EACH_OBSERVER(Observer, observers_, NetworkChanged(this)); |
| 1086 } | 1055 } |
| 1087 | 1056 |
| 1088 void NotifyCellularDataPlanChanged() { | 1057 void NotifyCellularDataPlanChanged() { |
| 1089 FOR_EACH_OBSERVER(Observer, observers_, CellularDataPlanChanged(this)); | 1058 FOR_EACH_OBSERVER(Observer, observers_, |
| 1059 CellularDataPlanChanged(cellular_.service_path(), |
| 1060 cellular_data_plans_)); |
| 1090 } | 1061 } |
| 1091 | 1062 |
| 1092 void UpdateNetworkStatus() { | 1063 void UpdateNetworkStatus() { |
| 1093 // Make sure we run on UI thread. | 1064 // Make sure we run on UI thread. |
| 1094 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 1065 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 1095 BrowserThread::PostTask( | 1066 BrowserThread::PostTask( |
| 1096 BrowserThread::UI, FROM_HERE, | 1067 BrowserThread::UI, FROM_HERE, |
| 1097 NewRunnableMethod(this, | 1068 NewRunnableMethod(this, |
| 1098 &NetworkLibraryImpl::UpdateNetworkStatus)); | 1069 &NetworkLibraryImpl::UpdateNetworkStatus)); |
| 1099 return; | 1070 return; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 available_devices_ = system->available_technologies; | 1106 available_devices_ = system->available_technologies; |
| 1136 enabled_devices_ = system->enabled_technologies; | 1107 enabled_devices_ = system->enabled_technologies; |
| 1137 connected_devices_ = system->connected_technologies; | 1108 connected_devices_ = system->connected_technologies; |
| 1138 offline_mode_ = system->offline_mode; | 1109 offline_mode_ = system->offline_mode; |
| 1139 | 1110 |
| 1140 NotifyNetworkChanged(); | 1111 NotifyNetworkChanged(); |
| 1141 FreeSystemInfo(system); | 1112 FreeSystemInfo(system); |
| 1142 } | 1113 } |
| 1143 | 1114 |
| 1144 void UpdateCellularDataPlan(const CellularDataPlanList& data_plans) { | 1115 void UpdateCellularDataPlan(const CellularDataPlanList& data_plans) { |
| 1145 cellular_.SetDataPlans(data_plans); | 1116 cellular_data_plans_ = data_plans; |
| 1146 NotifyCellularDataPlanChanged(); | 1117 NotifyCellularDataPlanChanged(); |
| 1147 } | 1118 } |
| 1148 | 1119 |
| 1149 ObserverList<Observer> observers_; | 1120 ObserverList<Observer> observers_; |
| 1150 | 1121 |
| 1151 // The network status connection for monitoring network status changes. | 1122 // The network status connection for monitoring network status changes. |
| 1152 MonitorNetworkConnection network_status_connection_; | 1123 MonitorNetworkConnection network_status_connection_; |
| 1153 | 1124 |
| 1154 // For monitoring data plan changes to the connected cellular network. | 1125 // For monitoring data plan changes to the connected cellular network. |
| 1155 DataPlanUpdateMonitor data_plan_monitor_; | 1126 DataPlanUpdateMonitor data_plan_monitor_; |
| 1156 | 1127 |
| 1157 // The ethernet network. | 1128 // The ethernet network. |
| 1158 EthernetNetwork ethernet_; | 1129 EthernetNetwork ethernet_; |
| 1159 | 1130 |
| 1160 // The list of available wifi networks. | 1131 // The list of available wifi networks. |
| 1161 WifiNetworkVector wifi_networks_; | 1132 WifiNetworkVector wifi_networks_; |
| 1162 | 1133 |
| 1163 // The current connected (or connecting) wifi network. | 1134 // The current connected (or connecting) wifi network. |
| 1164 WifiNetwork wifi_; | 1135 WifiNetwork wifi_; |
| 1165 | 1136 |
| 1166 // The remembered wifi networks. | 1137 // The remembered wifi networks. |
| 1167 WifiNetworkVector remembered_wifi_networks_; | 1138 WifiNetworkVector remembered_wifi_networks_; |
| 1168 | 1139 |
| 1169 // The list of available cellular networks. | 1140 // The list of available cellular networks. |
| 1170 CellularNetworkVector cellular_networks_; | 1141 CellularNetworkVector cellular_networks_; |
| 1171 | 1142 |
| 1172 // The current connected (or connecting) cellular network. | 1143 // The current connected (or connecting) cellular network. |
| 1173 CellularNetwork cellular_; | 1144 CellularNetwork cellular_; |
| 1174 | 1145 |
| 1146 // The data plan for the current cellular network. |
| 1147 CellularDataPlanList cellular_data_plans_; |
| 1148 |
| 1175 // The remembered cellular networks. | 1149 // The remembered cellular networks. |
| 1176 CellularNetworkVector remembered_cellular_networks_; | 1150 CellularNetworkVector remembered_cellular_networks_; |
| 1177 | 1151 |
| 1178 // The current available network devices. Bitwise flag of ConnectionTypes. | 1152 // The current available network devices. Bitwise flag of ConnectionTypes. |
| 1179 int available_devices_; | 1153 int available_devices_; |
| 1180 | 1154 |
| 1181 // The current enabled network devices. Bitwise flag of ConnectionTypes. | 1155 // The current enabled network devices. Bitwise flag of ConnectionTypes. |
| 1182 int enabled_devices_; | 1156 int enabled_devices_; |
| 1183 | 1157 |
| 1184 // The current connected network devices. Bitwise flag of ConnectionTypes. | 1158 // The current connected network devices. Bitwise flag of ConnectionTypes. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 return new NetworkLibraryStubImpl(); | 1259 return new NetworkLibraryStubImpl(); |
| 1286 else | 1260 else |
| 1287 return new NetworkLibraryImpl(); | 1261 return new NetworkLibraryImpl(); |
| 1288 } | 1262 } |
| 1289 | 1263 |
| 1290 } // namespace chromeos | 1264 } // namespace chromeos |
| 1291 | 1265 |
| 1292 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 1266 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 1293 // won't be deleted until it's last InvokeLater is run. | 1267 // won't be deleted until it's last InvokeLater is run. |
| 1294 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); | 1268 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImpl); |
| OLD | NEW |