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