| 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> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 bool connecting() const { return state_ == STATE_ASSOCIATION || | 41 bool connecting() const { return state_ == STATE_ASSOCIATION || |
| 42 state_ == STATE_CONFIGURATION || state_ == STATE_CARRIER; } | 42 state_ == STATE_CONFIGURATION || state_ == STATE_CARRIER; } |
| 43 bool configuring() const { return state_ == STATE_CONFIGURATION; } | 43 bool configuring() const { return state_ == STATE_CONFIGURATION; } |
| 44 bool connected() const { return state_ == STATE_READY; } | 44 bool connected() const { return state_ == STATE_READY; } |
| 45 bool connecting_or_connected() const { return connecting() || connected(); } | 45 bool connecting_or_connected() const { return connecting() || connected(); } |
| 46 bool failed() const { return state_ == STATE_FAILURE; } | 46 bool failed() const { return state_ == STATE_FAILURE; } |
| 47 bool failed_or_disconnected() const { return failed() || | 47 bool failed_or_disconnected() const { return failed() || |
| 48 state_ == STATE_IDLE; } | 48 state_ == STATE_IDLE; } |
| 49 ConnectionError error() const { return error_; } | 49 ConnectionError error() const { return error_; } |
| 50 ConnectionState state() const { return state_; } | 50 ConnectionState state() const { return state_; } |
| 51 | 51 // Is this the active network, i.e, the one through which |
| 52 void set_service_path(const std::string& service_path) { | 52 // network traffic is being routed? A network can be connected, |
| 53 service_path_ = service_path; } | 53 // but not be carrying traffic. |
| 54 void set_connecting(bool connecting) { state_ = (connecting ? | 54 bool is_active() const { return is_active_; } |
| 55 STATE_ASSOCIATION : STATE_IDLE); } | |
| 56 void set_connected(bool connected) { state_ = (connected ? | |
| 57 STATE_READY : STATE_IDLE); } | |
| 58 | 55 |
| 59 // Clear the fields. | 56 // Clear the fields. |
| 60 virtual void Clear(); | 57 virtual void Clear(); |
| 61 | 58 |
| 62 // Return a string representation of the state code. | 59 // Return a string representation of the state code. |
| 63 std::string GetStateString() const; | 60 std::string GetStateString() const; |
| 64 | 61 |
| 65 // Return a string representation of the error code. | 62 // Return a string representation of the error code. |
| 66 std::string GetErrorString() const; | 63 std::string GetErrorString() const; |
| 67 | 64 |
| 68 protected: | 65 protected: |
| 69 Network() | 66 Network() |
| 70 : type_(TYPE_UNKNOWN), | 67 : type_(TYPE_UNKNOWN), |
| 71 state_(STATE_UNKNOWN), | 68 state_(STATE_UNKNOWN), |
| 72 error_(ERROR_UNKNOWN) {} | 69 error_(ERROR_UNKNOWN), |
| 70 is_active_(false) {} |
| 73 explicit Network(const Network& network); | 71 explicit Network(const Network& network); |
| 74 explicit Network(const ServiceInfo* service); | 72 explicit Network(const ServiceInfo* service); |
| 75 virtual ~Network() {} | 73 virtual ~Network() {} |
| 76 | 74 |
| 77 std::string service_path_; | 75 std::string service_path_; |
| 78 std::string device_path_; | 76 std::string device_path_; |
| 79 std::string ip_address_; | 77 std::string ip_address_; |
| 80 ConnectionType type_; | 78 ConnectionType type_; |
| 81 ConnectionState state_; | 79 ConnectionState state_; |
| 82 ConnectionError error_; | 80 ConnectionError error_; |
| 81 bool is_active_; |
| 82 |
| 83 private: |
| 84 void set_service_path(const std::string& service_path) { |
| 85 service_path_ = service_path; } |
| 86 void set_connecting(bool connecting) { state_ = (connecting ? |
| 87 STATE_ASSOCIATION : STATE_IDLE); } |
| 88 void set_connected(bool connected) { state_ = (connected ? |
| 89 STATE_READY : STATE_IDLE); } |
| 90 void set_state(ConnectionState state) { state_ = state; } |
| 91 void set_active(bool is_active) { is_active_ = is_active; } |
| 92 |
| 93 friend class NetworkLibraryImpl; |
| 83 }; | 94 }; |
| 84 | 95 |
| 85 class EthernetNetwork : public Network { | 96 class EthernetNetwork : public Network { |
| 86 public: | 97 public: |
| 87 EthernetNetwork() : Network() { | 98 EthernetNetwork() : Network() { |
| 88 type_ = TYPE_ETHERNET; | 99 type_ = TYPE_ETHERNET; |
| 89 } | 100 } |
| 90 | 101 |
| 91 explicit EthernetNetwork(const EthernetNetwork& network) | 102 explicit EthernetNetwork(const EthernetNetwork& network) |
| 92 : Network(network) { | 103 : Network(network) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 112 return a->service_path().compare(path) == 0; | 123 return a->service_path().compare(path) == 0; |
| 113 } | 124 } |
| 114 const std::string& path; | 125 const std::string& path; |
| 115 }; | 126 }; |
| 116 | 127 |
| 117 const std::string& name() const { return name_; } | 128 const std::string& name() const { return name_; } |
| 118 int strength() const { return strength_; } | 129 int strength() const { return strength_; } |
| 119 bool auto_connect() const { return auto_connect_; } | 130 bool auto_connect() const { return auto_connect_; } |
| 120 bool favorite() const { return favorite_; } | 131 bool favorite() const { return favorite_; } |
| 121 | 132 |
| 122 void set_name(const std::string& name) { name_ = name; } | |
| 123 void set_strength(int strength) { strength_ = strength; } | |
| 124 void set_auto_connect(bool auto_connect) { auto_connect_ = auto_connect; } | 133 void set_auto_connect(bool auto_connect) { auto_connect_ = auto_connect; } |
| 125 void set_favorite(bool favorite) { favorite_ = favorite; } | 134 void set_favorite(bool favorite) { favorite_ = favorite; } |
| 126 | 135 |
| 127 // Network overrides. | 136 // Network overrides. |
| 128 virtual void Clear(); | 137 virtual void Clear(); |
| 129 | 138 |
| 130 protected: | 139 protected: |
| 131 WirelessNetwork() | 140 WirelessNetwork() |
| 132 : Network(), | 141 : Network(), |
| 133 strength_(0), | 142 strength_(0), |
| 134 auto_connect_(false), | 143 auto_connect_(false), |
| 135 favorite_(false) {} | 144 favorite_(false) {} |
| 136 explicit WirelessNetwork(const WirelessNetwork& network); | 145 explicit WirelessNetwork(const WirelessNetwork& network); |
| 137 explicit WirelessNetwork(const ServiceInfo* service); | 146 explicit WirelessNetwork(const ServiceInfo* service); |
| 138 | 147 |
| 139 std::string name_; | 148 std::string name_; |
| 140 int strength_; | 149 int strength_; |
| 141 bool auto_connect_; | 150 bool auto_connect_; |
| 142 bool favorite_; | 151 bool favorite_; |
| 152 |
| 153 private: |
| 154 void set_name(const std::string& name) { name_ = name; } |
| 155 void set_strength(int strength) { strength_ = strength; } |
| 156 |
| 157 friend class NetworkLibraryImpl; |
| 143 }; | 158 }; |
| 144 | 159 |
| 145 class CellularNetwork : public WirelessNetwork { | 160 class CellularNetwork : public WirelessNetwork { |
| 146 public: | 161 public: |
| 147 enum DataLeft { | 162 enum DataLeft { |
| 148 DATA_NORMAL, | 163 DATA_NORMAL, |
| 149 DATA_LOW, | 164 DATA_LOW, |
| 150 DATA_VERY_LOW, | 165 DATA_VERY_LOW, |
| 151 DATA_NONE | 166 DATA_NONE |
| 152 }; | 167 }; |
| 153 | 168 |
| 154 CellularNetwork(); | 169 CellularNetwork(); |
| 155 explicit CellularNetwork(const CellularNetwork& network); | 170 explicit CellularNetwork(const CellularNetwork& network); |
| 156 explicit CellularNetwork(const ServiceInfo* service); | 171 explicit CellularNetwork(const ServiceInfo* service); |
| 157 | 172 |
| 158 // Starts device activation process. Returns false if the device state does | 173 // Starts device activation process. Returns false if the device state does |
| 159 // not permit activation. | 174 // not permit activation. |
| 160 bool StartActivation() const; | 175 bool StartActivation() const; |
| 161 void set_activation_state(ActivationState state) { | |
| 162 activation_state_ = state; | |
| 163 } | |
| 164 const ActivationState activation_state() const { return activation_state_; } | 176 const ActivationState activation_state() const { return activation_state_; } |
| 165 const NetworkTechnology network_technology() const { | 177 const NetworkTechnology network_technology() const { |
| 166 return network_technology_; | 178 return network_technology_; |
| 167 } | 179 } |
| 168 const NetworkRoamingState roaming_state() const { return roaming_state_; } | 180 const NetworkRoamingState roaming_state() const { return roaming_state_; } |
| 169 bool restricted_pool() const { return restricted_pool_; } | 181 bool restricted_pool() const { return restricted_pool_; } |
| 170 const std::string& service_name() const { return service_name_; } | 182 const std::string& service_name() const { return service_name_; } |
| 171 const std::string& operator_name() const { return operator_name_; } | 183 const std::string& operator_name() const { return operator_name_; } |
| 172 const std::string& operator_code() const { return operator_code_; } | 184 const std::string& operator_code() const { return operator_code_; } |
| 173 const std::string& payment_url() const { return payment_url_; } | 185 const std::string& payment_url() const { return payment_url_; } |
| 174 void set_payment_url(const std::string& url) { | |
| 175 payment_url_ = url; | |
| 176 } | |
| 177 const std::string& meid() const { return meid_; } | 186 const std::string& meid() const { return meid_; } |
| 178 const std::string& imei() const { return imei_; } | 187 const std::string& imei() const { return imei_; } |
| 179 const std::string& imsi() const { return imsi_; } | 188 const std::string& imsi() const { return imsi_; } |
| 180 const std::string& esn() const { return esn_; } | 189 const std::string& esn() const { return esn_; } |
| 181 const std::string& mdn() const { return mdn_; } | 190 const std::string& mdn() const { return mdn_; } |
| 182 const std::string& min() const { return min_; } | 191 const std::string& min() const { return min_; } |
| 183 const std::string& model_id() const { return model_id_; } | 192 const std::string& model_id() const { return model_id_; } |
| 184 const std::string& manufacturer() const { return manufacturer_; } | 193 const std::string& manufacturer() const { return manufacturer_; } |
| 185 const std::string& firmware_revision() const { return firmware_revision_; } | 194 const std::string& firmware_revision() const { return firmware_revision_; } |
| 186 const std::string& hardware_revision() const { return hardware_revision_; } | 195 const std::string& hardware_revision() const { return hardware_revision_; } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 std::string esn_; | 236 std::string esn_; |
| 228 std::string mdn_; | 237 std::string mdn_; |
| 229 std::string min_; | 238 std::string min_; |
| 230 std::string model_id_; | 239 std::string model_id_; |
| 231 std::string manufacturer_; | 240 std::string manufacturer_; |
| 232 std::string firmware_revision_; | 241 std::string firmware_revision_; |
| 233 std::string hardware_revision_; | 242 std::string hardware_revision_; |
| 234 std::string last_update_; | 243 std::string last_update_; |
| 235 unsigned int prl_version_; | 244 unsigned int prl_version_; |
| 236 CellularDataPlanList data_plans_; | 245 CellularDataPlanList data_plans_; |
| 246 |
| 247 private: |
| 248 void set_activation_state(ActivationState state) { |
| 249 activation_state_ = state; |
| 250 } |
| 251 void set_payment_url(const std::string& url) { |
| 252 payment_url_ = url; |
| 253 } |
| 254 void set_network_technology(NetworkTechnology technology) { |
| 255 network_technology_ = technology; |
| 256 } |
| 257 void set_roaming_state(NetworkRoamingState state) { |
| 258 roaming_state_ = state; |
| 259 } |
| 260 void set_restricted_pool(bool restricted_pool) { |
| 261 restricted_pool_ = restricted_pool; |
| 262 } |
| 263 |
| 264 friend class NetworkLibraryImpl; |
| 237 }; | 265 }; |
| 238 | 266 |
| 239 class WifiNetwork : public WirelessNetwork { | 267 class WifiNetwork : public WirelessNetwork { |
| 240 public: | 268 public: |
| 241 WifiNetwork(); | 269 WifiNetwork(); |
| 242 explicit WifiNetwork(const WifiNetwork& network); | 270 explicit WifiNetwork(const WifiNetwork& network); |
| 243 explicit WifiNetwork(const ServiceInfo* service); | 271 explicit WifiNetwork(const ServiceInfo* service); |
| 244 | 272 |
| 245 bool encrypted() const { return encryption_ != SECURITY_NONE; } | 273 bool encrypted() const { return encryption_ != SECURITY_NONE; } |
| 246 ConnectionSecurity encryption() const { return encryption_; } | 274 ConnectionSecurity encryption() const { return encryption_; } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 std::string gateway; | 360 std::string gateway; |
| 333 std::string name_servers; | 361 std::string name_servers; |
| 334 }; | 362 }; |
| 335 typedef std::vector<NetworkIPConfig> NetworkIPConfigVector; | 363 typedef std::vector<NetworkIPConfig> NetworkIPConfigVector; |
| 336 | 364 |
| 337 // This class handles the interaction with the ChromeOS network library APIs. | 365 // This class handles the interaction with the ChromeOS network library APIs. |
| 338 // Classes can add themselves as observers. Users can get an instance of the | 366 // Classes can add themselves as observers. Users can get an instance of the |
| 339 // library like this: chromeos::CrosLibrary::Get()->GetNetworkLibrary() | 367 // library like this: chromeos::CrosLibrary::Get()->GetNetworkLibrary() |
| 340 class NetworkLibrary { | 368 class NetworkLibrary { |
| 341 public: | 369 public: |
| 342 class Observer { | 370 class NetworkManagerObserver { |
| 343 public: | 371 public: |
| 344 // Called when the network has changed. (wifi networks, and ethernet) | 372 // Called when the state of the network manager has changed, |
| 345 virtual void NetworkChanged(NetworkLibrary* obj) = 0; | 373 // for example, networks have appeared or disappeared. |
| 346 // Called when the cellular data plan has changed. | 374 virtual void OnNetworkManagerChanged(NetworkLibrary* obj) = 0; |
| 347 virtual void CellularDataPlanChanged(NetworkLibrary* obj) {} | |
| 348 }; | 375 }; |
| 349 | 376 |
| 350 class PropertyObserver { | 377 class NetworkObserver { |
| 351 public: | 378 public: |
| 352 virtual void PropertyChanged(const char* service_path, | 379 // Called when the state of a single network has changed, |
| 353 const char* key, | 380 // for example signal strength or connection state. |
| 354 const Value* value) = 0; | 381 virtual void OnNetworkChanged(NetworkLibrary* cros, |
| 382 const Network* network) = 0; |
| 383 }; |
| 384 |
| 385 class CellularDataPlanObserver { |
| 386 public: |
| 387 // Called when the cellular data plan has changed. |
| 388 virtual void OnCellularDataPlanChanged(NetworkLibrary* obj) = 0; |
| 355 }; | 389 }; |
| 356 | 390 |
| 357 virtual ~NetworkLibrary() {} | 391 virtual ~NetworkLibrary() {} |
| 358 virtual void AddObserver(Observer* observer) = 0; | 392 |
| 359 virtual void RemoveObserver(Observer* observer) = 0; | 393 virtual void AddNetworkManagerObserver(NetworkManagerObserver* observer) = 0; |
| 360 virtual void AddProperyObserver(const char* service_path, | 394 virtual void RemoveNetworkManagerObserver( |
| 361 PropertyObserver* observer) = 0; | 395 NetworkManagerObserver* observer) = 0; |
| 362 virtual void RemoveProperyObserver(PropertyObserver* observer) = 0; | 396 |
| 397 // An attempt to add an observer that has already been added for a |
| 398 // give service path will be ignored. |
| 399 virtual void AddNetworkObserver(const std::string& service_path, |
| 400 NetworkObserver* observer) = 0; |
| 401 // Remove an observer of a single network |
| 402 virtual void RemoveNetworkObserver(const std::string& service_path, |
| 403 NetworkObserver* observer) = 0; |
| 404 // Stop |observer| from observing any networks |
| 405 virtual void RemoveObserverForAllNetworks(NetworkObserver* observer) = 0; |
| 406 |
| 407 virtual void AddCellularDataPlanObserver( |
| 408 CellularDataPlanObserver* observer) = 0; |
| 409 virtual void RemoveCellularDataPlanObserver( |
| 410 CellularDataPlanObserver* observer) = 0; |
| 363 | 411 |
| 364 // Return the active Ethernet network (or a default structure if inactive). | 412 // Return the active Ethernet network (or a default structure if inactive). |
| 365 virtual EthernetNetwork* ethernet_network() = 0; | 413 virtual EthernetNetwork* ethernet_network() = 0; |
| 366 virtual bool ethernet_connecting() const = 0; | 414 virtual bool ethernet_connecting() const = 0; |
| 367 virtual bool ethernet_connected() const = 0; | 415 virtual bool ethernet_connected() const = 0; |
| 368 | 416 |
| 369 // Return the active Wifi network (or a default structure if none active). | 417 // Return the active Wifi network (or a default structure if none active). |
| 370 virtual WifiNetwork* wifi_network() = 0; | 418 virtual WifiNetwork* wifi_network() = 0; |
| 371 virtual bool wifi_connecting() const = 0; | 419 virtual bool wifi_connecting() const = 0; |
| 372 virtual bool wifi_connected() const = 0; | 420 virtual bool wifi_connected() const = 0; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 virtual void ForgetWifiNetwork(const std::string& service_path) = 0; | 498 virtual void ForgetWifiNetwork(const std::string& service_path) = 0; |
| 451 | 499 |
| 452 virtual bool ethernet_available() const = 0; | 500 virtual bool ethernet_available() const = 0; |
| 453 virtual bool wifi_available() const = 0; | 501 virtual bool wifi_available() const = 0; |
| 454 virtual bool cellular_available() const = 0; | 502 virtual bool cellular_available() const = 0; |
| 455 | 503 |
| 456 virtual bool ethernet_enabled() const = 0; | 504 virtual bool ethernet_enabled() const = 0; |
| 457 virtual bool wifi_enabled() const = 0; | 505 virtual bool wifi_enabled() const = 0; |
| 458 virtual bool cellular_enabled() const = 0; | 506 virtual bool cellular_enabled() const = 0; |
| 459 | 507 |
| 508 virtual const Network* active_network() const = 0; |
| 509 |
| 460 virtual bool offline_mode() const = 0; | 510 virtual bool offline_mode() const = 0; |
| 461 | 511 |
| 462 // Enables/disables the ethernet network device. | 512 // Enables/disables the ethernet network device. |
| 463 virtual void EnableEthernetNetworkDevice(bool enable) = 0; | 513 virtual void EnableEthernetNetworkDevice(bool enable) = 0; |
| 464 | 514 |
| 465 // Enables/disables the wifi network device. | 515 // Enables/disables the wifi network device. |
| 466 virtual void EnableWifiNetworkDevice(bool enable) = 0; | 516 virtual void EnableWifiNetworkDevice(bool enable) = 0; |
| 467 | 517 |
| 468 // Enables/disables the cellular network device. | 518 // Enables/disables the cellular network device. |
| 469 virtual void EnableCellularNetworkDevice(bool enable) = 0; | 519 virtual void EnableCellularNetworkDevice(bool enable) = 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 484 virtual std::string GetHtmlInfo(int refresh) = 0; | 534 virtual std::string GetHtmlInfo(int refresh) = 0; |
| 485 | 535 |
| 486 // Factory function, creates a new instance and returns ownership. | 536 // Factory function, creates a new instance and returns ownership. |
| 487 // For normal usage, access the singleton via CrosLibrary::Get(). | 537 // For normal usage, access the singleton via CrosLibrary::Get(). |
| 488 static NetworkLibrary* GetImpl(bool stub); | 538 static NetworkLibrary* GetImpl(bool stub); |
| 489 }; | 539 }; |
| 490 | 540 |
| 491 } // namespace chromeos | 541 } // namespace chromeos |
| 492 | 542 |
| 493 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ | 543 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
| OLD | NEW |