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