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 #ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
6 #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/platform_thread.h" | 13 #include "base/platform_thread.h" |
14 #include "base/singleton.h" | 14 #include "base/singleton.h" |
15 #include "base/timer.h" | 15 #include "base/timer.h" |
16 #include "cros/chromeos_network.h" | 16 #include "cros/chromeos_network.h" |
17 | 17 |
18 namespace chromeos { | 18 namespace chromeos { |
19 | 19 |
| 20 // Cellular network is considered low data when less than 60 minues. |
| 21 static const int kCellularDataLowSecs = 60 * 60; |
| 22 |
| 23 // Cellular network is considered low data when less than 30 minues. |
| 24 static const int kCellularDataVeryLowSecs = 30 * 60; |
| 25 |
| 26 // Cellular network is considered low data when less than 100MB. |
| 27 static const int kCellularDataLowBytes = 100 * 1024 * 1024; |
| 28 |
| 29 // Cellular network is considered very low data when less than 50MB. |
| 30 static const int kCellularDataVeryLowBytes = 50 * 1024 * 1024; |
| 31 |
20 class Network { | 32 class Network { |
21 public: | 33 public: |
22 const std::string& service_path() const { return service_path_; } | 34 const std::string& service_path() const { return service_path_; } |
23 const std::string& device_path() const { return device_path_; } | 35 const std::string& device_path() const { return device_path_; } |
24 const std::string& ip_address() const { return ip_address_; } | 36 const std::string& ip_address() const { return ip_address_; } |
25 ConnectionType type() const { return type_; } | 37 ConnectionType type() const { return type_; } |
26 ConnectionState connection_state() const { return state_; } | 38 ConnectionState connection_state() const { return state_; } |
27 bool connecting() const { return state_ == STATE_ASSOCIATION || | 39 bool connecting() const { return state_ == STATE_ASSOCIATION || |
28 state_ == STATE_CONFIGURATION || state_ == STATE_CARRIER; } | 40 state_ == STATE_CONFIGURATION || state_ == STATE_CARRIER; } |
29 bool connected() const { return state_ == STATE_READY; } | 41 bool connected() const { return state_ == STATE_READY; } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 favorite_(false) {} | 123 favorite_(false) {} |
112 | 124 |
113 std::string name_; | 125 std::string name_; |
114 int strength_; | 126 int strength_; |
115 bool auto_connect_; | 127 bool auto_connect_; |
116 bool favorite_; | 128 bool favorite_; |
117 }; | 129 }; |
118 | 130 |
119 class CellularNetwork : public WirelessNetwork { | 131 class CellularNetwork : public WirelessNetwork { |
120 public: | 132 public: |
| 133 enum DataLeft { |
| 134 DATA_NORMAL, |
| 135 DATA_LOW, |
| 136 DATA_VERY_LOW, |
| 137 DATA_NONE |
| 138 }; |
| 139 |
121 CellularNetwork(); | 140 CellularNetwork(); |
122 explicit CellularNetwork(const ServiceInfo& service) | 141 explicit CellularNetwork(const ServiceInfo& service) |
123 : WirelessNetwork() { | 142 : WirelessNetwork() { |
124 ConfigureFromService(service); | 143 ConfigureFromService(service); |
125 } | 144 } |
126 | 145 |
127 // Starts device activation process. Returns false if the device state does | 146 // Starts device activation process. Returns false if the device state does |
128 // not permit activation. | 147 // not permit activation. |
129 bool StartActivation() const; | 148 bool StartActivation() const; |
130 const ActivationState activation_state() const { return activation_state_; } | 149 const ActivationState activation_state() const { return activation_state_; } |
(...skipping 12 matching lines...) Expand all Loading... |
143 const std::string& esn() const { return esn_; } | 162 const std::string& esn() const { return esn_; } |
144 const std::string& mdn() const { return mdn_; } | 163 const std::string& mdn() const { return mdn_; } |
145 const std::string& min() const { return min_; } | 164 const std::string& min() const { return min_; } |
146 const std::string& model_id() const { return model_id_; } | 165 const std::string& model_id() const { return model_id_; } |
147 const std::string& manufacturer() const { return manufacturer_; } | 166 const std::string& manufacturer() const { return manufacturer_; } |
148 const std::string& firmware_revision() const { return firmware_revision_; } | 167 const std::string& firmware_revision() const { return firmware_revision_; } |
149 const std::string& hardware_revision() const { return hardware_revision_; } | 168 const std::string& hardware_revision() const { return hardware_revision_; } |
150 const std::string& last_update() const { return last_update_; } | 169 const std::string& last_update() const { return last_update_; } |
151 const unsigned int prl_version() const { return prl_version_; } | 170 const unsigned int prl_version() const { return prl_version_; } |
152 bool is_gsm() const; | 171 bool is_gsm() const; |
| 172 DataLeft data_left() const; |
153 | 173 |
154 // WirelessNetwork overrides. | 174 // WirelessNetwork overrides. |
155 virtual void Clear(); | 175 virtual void Clear(); |
156 virtual void ConfigureFromService(const ServiceInfo& service); | 176 virtual void ConfigureFromService(const ServiceInfo& service); |
157 | 177 |
158 const CellularDataPlanList& GetDataPlans() const { | 178 const CellularDataPlanList& GetDataPlans() const { |
159 return data_plans_; | 179 return data_plans_; |
160 } | 180 } |
161 | 181 |
162 void SetDataPlans(CellularDataPlanList& data_plans) { | 182 void SetDataPlans(const CellularDataPlanList& data_plans) { |
163 data_plans_ = data_plans; | 183 data_plans_ = data_plans; |
164 } | 184 } |
165 // Return a string representation of network technology. | 185 // Return a string representation of network technology. |
166 std::string GetNetworkTechnologyString() const; | 186 std::string GetNetworkTechnologyString() const; |
167 // Return a string representation of activation state. | 187 // Return a string representation of activation state. |
168 std::string GetActivationStateString() const; | 188 std::string GetActivationStateString() const; |
169 // Return a string representation of roaming state. | 189 // Return a string representation of roaming state. |
170 std::string GetRoamingStateString() const; | 190 std::string GetRoamingStateString() const; |
171 | 191 |
172 protected: | 192 protected: |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 // This class handles the interaction with the ChromeOS network library APIs. | 316 // This class handles the interaction with the ChromeOS network library APIs. |
297 // Classes can add themselves as observers. Users can get an instance of the | 317 // Classes can add themselves as observers. Users can get an instance of the |
298 // library like this: chromeos::CrosLibrary::Get()->GetNetworkLibrary() | 318 // library like this: chromeos::CrosLibrary::Get()->GetNetworkLibrary() |
299 class NetworkLibrary { | 319 class NetworkLibrary { |
300 public: | 320 public: |
301 class Observer { | 321 class Observer { |
302 public: | 322 public: |
303 // Called when the network has changed. (wifi networks, and ethernet) | 323 // Called when the network has changed. (wifi networks, and ethernet) |
304 virtual void NetworkChanged(NetworkLibrary* obj) = 0; | 324 virtual void NetworkChanged(NetworkLibrary* obj) = 0; |
305 // Called when the cellular data plan has changed. | 325 // Called when the cellular data plan has changed. |
306 virtual void CellularDataPlanChanged(const std::string& service_path, | 326 virtual void CellularDataPlanChanged(NetworkLibrary* obj) {} |
307 const CellularDataPlanList& plans) {} | |
308 }; | 327 }; |
309 | 328 |
310 virtual ~NetworkLibrary() {} | 329 virtual ~NetworkLibrary() {} |
311 virtual void AddObserver(Observer* observer) = 0; | 330 virtual void AddObserver(Observer* observer) = 0; |
312 virtual void RemoveObserver(Observer* observer) = 0; | 331 virtual void RemoveObserver(Observer* observer) = 0; |
313 | 332 |
314 // Return the active Ethernet network (or a default structure if inactive). | 333 // Return the active Ethernet network (or a default structure if inactive). |
315 virtual const EthernetNetwork& ethernet_network() const = 0; | 334 virtual const EthernetNetwork& ethernet_network() const = 0; |
316 virtual bool ethernet_connecting() const = 0; | 335 virtual bool ethernet_connecting() const = 0; |
317 virtual bool ethernet_connected() const = 0; | 336 virtual bool ethernet_connected() const = 0; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 const std::string& password, | 400 const std::string& password, |
382 const std::string& identity, | 401 const std::string& identity, |
383 const std::string& certpath, | 402 const std::string& certpath, |
384 bool auto_connect) = 0; | 403 bool auto_connect) = 0; |
385 | 404 |
386 // Connect to the specified cellular network. | 405 // Connect to the specified cellular network. |
387 virtual void ConnectToCellularNetwork(CellularNetwork network) = 0; | 406 virtual void ConnectToCellularNetwork(CellularNetwork network) = 0; |
388 | 407 |
389 // Initiates cellular data plan refresh. Plan data will be passed through | 408 // Initiates cellular data plan refresh. Plan data will be passed through |
390 // Network::Observer::CellularDataPlanChanged callback. | 409 // Network::Observer::CellularDataPlanChanged callback. |
391 virtual void RefreshCellularDataPlans( | 410 virtual void RefreshCellularDataPlans(const CellularNetwork& network) = 0; |
392 const CellularNetwork& network) = 0; | |
393 | 411 |
394 // Disconnect from the specified wireless (either cellular or wifi) network. | 412 // Disconnect from the specified wireless (either cellular or wifi) network. |
395 virtual void DisconnectFromWirelessNetwork( | 413 virtual void DisconnectFromWirelessNetwork( |
396 const WirelessNetwork& network) = 0; | 414 const WirelessNetwork& network) = 0; |
397 | 415 |
398 // Save network information including passwords (wifi) and auto-connect. | 416 // Save network information including passwords (wifi) and auto-connect. |
399 virtual void SaveCellularNetwork(const CellularNetwork& network) = 0; | 417 virtual void SaveCellularNetwork(const CellularNetwork& network) = 0; |
400 virtual void SaveWifiNetwork(const WifiNetwork& network) = 0; | 418 virtual void SaveWifiNetwork(const WifiNetwork& network) = 0; |
401 | 419 |
402 // Forget the passed in wireless (either cellular or wifi) network. | 420 // Forget the passed in wireless (either cellular or wifi) network. |
(...skipping 30 matching lines...) Expand all Loading... |
433 virtual std::string GetHtmlInfo(int refresh) = 0; | 451 virtual std::string GetHtmlInfo(int refresh) = 0; |
434 | 452 |
435 // Factory function, creates a new instance and returns ownership. | 453 // Factory function, creates a new instance and returns ownership. |
436 // For normal usage, access the singleton via CrosLibrary::Get(). | 454 // For normal usage, access the singleton via CrosLibrary::Get(). |
437 static NetworkLibrary* GetImpl(bool stub); | 455 static NetworkLibrary* GetImpl(bool stub); |
438 }; | 456 }; |
439 | 457 |
440 } // namespace chromeos | 458 } // namespace chromeos |
441 | 459 |
442 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ | 460 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
OLD | NEW |