[email protected] | 353e0dd8 | 2010-11-22 08:39:31 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 268b02f | 2010-02-04 21:07:15 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
| 6 | #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 8 | |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
[email protected] | 0aadb27 | 2010-11-17 09:33:08 | [diff] [blame] | 12 | #include "base/gtest_prod_util.h" |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 13 | #include "base/observer_list.h" |
[email protected] | 633e5c0 | 2010-11-19 22:11:35 | [diff] [blame] | 14 | #include "base/scoped_vector.h" |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 15 | #include "base/singleton.h" |
[email protected] | f005394 | 2010-11-13 02:33:54 | [diff] [blame] | 16 | #include "base/string16.h" |
[email protected] | 1f41000 | 2009-10-28 04:11:00 | [diff] [blame] | 17 | #include "base/timer.h" |
[email protected] | 583dca28 | 2010-12-17 01:12:05 | [diff] [blame] | 18 | #include "third_party/cros/chromeos_network.h" |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 19 | |
[email protected] | 3c1139f | 2010-10-22 06:17:42 | [diff] [blame] | 20 | class Value; |
| 21 | |
[email protected] | b22c21c | 2009-10-30 00:35:00 | [diff] [blame] | 22 | namespace chromeos { |
| 23 | |
[email protected] | 543a79a | 2010-10-20 01:14:58 | [diff] [blame] | 24 | // Cellular network is considered low data when less than 60 minues. |
| 25 | static const int kCellularDataLowSecs = 60 * 60; |
| 26 | |
| 27 | // Cellular network is considered low data when less than 30 minues. |
| 28 | static const int kCellularDataVeryLowSecs = 30 * 60; |
| 29 | |
| 30 | // Cellular network is considered low data when less than 100MB. |
| 31 | static const int kCellularDataLowBytes = 100 * 1024 * 1024; |
| 32 | |
| 33 | // Cellular network is considered very low data when less than 50MB. |
| 34 | static const int kCellularDataVeryLowBytes = 50 * 1024 * 1024; |
| 35 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 36 | class Network { |
| 37 | public: |
| 38 | const std::string& service_path() const { return service_path_; } |
| 39 | const std::string& device_path() const { return device_path_; } |
| 40 | const std::string& ip_address() const { return ip_address_; } |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 41 | ConnectionType type() const { return type_; } |
[email protected] | 9a24152e | 2010-10-08 23:15:31 | [diff] [blame] | 42 | ConnectionState connection_state() const { return state_; } |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 43 | bool connecting() const { return state_ == STATE_ASSOCIATION || |
| 44 | state_ == STATE_CONFIGURATION || state_ == STATE_CARRIER; } |
[email protected] | 8df038b | 2010-10-28 22:56:46 | [diff] [blame] | 45 | bool configuring() const { return state_ == STATE_CONFIGURATION; } |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 46 | bool connected() const { return state_ == STATE_READY; } |
| 47 | bool connecting_or_connected() const { return connecting() || connected(); } |
| 48 | bool failed() const { return state_ == STATE_FAILURE; } |
[email protected] | 3c1139f | 2010-10-22 06:17:42 | [diff] [blame] | 49 | bool failed_or_disconnected() const { return failed() || |
| 50 | state_ == STATE_IDLE; } |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 51 | ConnectionError error() const { return error_; } |
[email protected] | 89ccd24 | 2010-10-12 08:58:27 | [diff] [blame] | 52 | ConnectionState state() const { return state_; } |
[email protected] | ca9f670 | 2010-11-17 01:28:14 | [diff] [blame] | 53 | // Is this network connectable. Some networks are not yet ready to be |
| 54 | // connected. For example, an 8021X network without certificates. |
| 55 | bool connectable() const { return connectable_; } |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 56 | // Is this the active network, i.e, the one through which |
| 57 | // network traffic is being routed? A network can be connected, |
| 58 | // but not be carrying traffic. |
| 59 | bool is_active() const { return is_active_; } |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 60 | |
| 61 | // Clear the fields. |
| 62 | virtual void Clear(); |
| 63 | |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 64 | // Return a string representation of the state code. |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 65 | std::string GetStateString() const; |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 66 | |
| 67 | // Return a string representation of the error code. |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 68 | std::string GetErrorString() const; |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 69 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 70 | protected: |
| 71 | Network() |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 72 | : type_(TYPE_UNKNOWN), |
| 73 | state_(STATE_UNKNOWN), |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 74 | error_(ERROR_UNKNOWN), |
[email protected] | ca9f670 | 2010-11-17 01:28:14 | [diff] [blame] | 75 | connectable_(true), |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 76 | is_active_(false) {} |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 77 | explicit Network(const Network& network); |
| 78 | explicit Network(const ServiceInfo* service); |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 79 | virtual ~Network() {} |
| 80 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 81 | std::string service_path_; |
| 82 | std::string device_path_; |
| 83 | std::string ip_address_; |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 84 | ConnectionType type_; |
[email protected] | 9a24152e | 2010-10-08 23:15:31 | [diff] [blame] | 85 | ConnectionState state_; |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 86 | ConnectionError error_; |
[email protected] | ca9f670 | 2010-11-17 01:28:14 | [diff] [blame] | 87 | bool connectable_; |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 88 | bool is_active_; |
| 89 | |
| 90 | private: |
| 91 | void set_service_path(const std::string& service_path) { |
| 92 | service_path_ = service_path; } |
| 93 | void set_connecting(bool connecting) { state_ = (connecting ? |
| 94 | STATE_ASSOCIATION : STATE_IDLE); } |
| 95 | void set_connected(bool connected) { state_ = (connected ? |
| 96 | STATE_READY : STATE_IDLE); } |
| 97 | void set_state(ConnectionState state) { state_ = state; } |
[email protected] | ca9f670 | 2010-11-17 01:28:14 | [diff] [blame] | 98 | void set_connectable(bool connectable) { connectable_ = connectable; } |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 99 | void set_active(bool is_active) { is_active_ = is_active; } |
[email protected] | fe3a0509 | 2010-11-24 23:53:16 | [diff] [blame] | 100 | void set_error(ConnectionError error) { error_ = error; } |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 101 | |
[email protected] | 9e32029 | 2010-11-18 00:52:29 | [diff] [blame] | 102 | // Initialize the IP address field |
| 103 | void InitIPAddress(); |
| 104 | |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 105 | friend class NetworkLibraryImpl; |
[email protected] | 0fb499a | 2009-11-10 21:03:33 | [diff] [blame] | 106 | }; |
| 107 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 108 | class EthernetNetwork : public Network { |
| 109 | public: |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 110 | EthernetNetwork() : Network() { |
| 111 | type_ = TYPE_ETHERNET; |
| 112 | } |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 113 | |
| 114 | explicit EthernetNetwork(const EthernetNetwork& network) |
| 115 | : Network(network) { |
| 116 | type_ = TYPE_ETHERNET; |
| 117 | } |
| 118 | |
| 119 | explicit EthernetNetwork(const ServiceInfo* service) : Network(service) { |
| 120 | type_ = TYPE_ETHERNET; |
| 121 | } |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | class WirelessNetwork : public Network { |
| 125 | public: |
| 126 | // WirelessNetwork are sorted by name. |
| 127 | bool operator< (const WirelessNetwork& other) const { |
| 128 | return name_ < other.name(); |
| 129 | } |
| 130 | |
[email protected] | f9384b55 | 2010-06-28 23:02:26 | [diff] [blame] | 131 | // We frequently want to compare networks by service path. |
| 132 | struct ServicePathEq { |
| 133 | explicit ServicePathEq(const std::string& path_in) : path(path_in) {} |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 134 | bool operator()(const WirelessNetwork* a) { |
| 135 | return a->service_path().compare(path) == 0; |
[email protected] | f9384b55 | 2010-06-28 23:02:26 | [diff] [blame] | 136 | } |
| 137 | const std::string& path; |
| 138 | }; |
| 139 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 140 | const std::string& name() const { return name_; } |
| 141 | int strength() const { return strength_; } |
| 142 | bool auto_connect() const { return auto_connect_; } |
[email protected] | be3c882c | 2010-09-07 16:40:02 | [diff] [blame] | 143 | bool favorite() const { return favorite_; } |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 144 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 145 | void set_auto_connect(bool auto_connect) { auto_connect_ = auto_connect; } |
[email protected] | 0aadb27 | 2010-11-17 09:33:08 | [diff] [blame] | 146 | // We don't have a setter for |favorite_| because to unfavorite a network is |
| 147 | // equivalent to forget a network, so we call forget network on cros for |
| 148 | // that. See ForgetWifiNetwork(). |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 149 | |
| 150 | // Network overrides. |
| 151 | virtual void Clear(); |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 152 | |
| 153 | protected: |
| 154 | WirelessNetwork() |
| 155 | : Network(), |
| 156 | strength_(0), |
[email protected] | be3c882c | 2010-09-07 16:40:02 | [diff] [blame] | 157 | auto_connect_(false), |
| 158 | favorite_(false) {} |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 159 | explicit WirelessNetwork(const WirelessNetwork& network); |
| 160 | explicit WirelessNetwork(const ServiceInfo* service); |
[email protected] | 05f06df | 2010-11-04 17:31:16 | [diff] [blame] | 161 | virtual ~WirelessNetwork() {} |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 162 | std::string name_; |
| 163 | int strength_; |
| 164 | bool auto_connect_; |
[email protected] | be3c882c | 2010-09-07 16:40:02 | [diff] [blame] | 165 | bool favorite_; |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 166 | |
| 167 | private: |
[email protected] | 0aadb27 | 2010-11-17 09:33:08 | [diff] [blame] | 168 | // ChangeAutoConnectSaveTest accesses |favorite_|. |
| 169 | FRIEND_TEST_ALL_PREFIXES(WifiConfigViewTest, ChangeAutoConnectSaveTest); |
| 170 | |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 171 | void set_name(const std::string& name) { name_ = name; } |
| 172 | void set_strength(int strength) { strength_ = strength; } |
| 173 | |
| 174 | friend class NetworkLibraryImpl; |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 175 | }; |
| 176 | |
[email protected] | 05f06df | 2010-11-04 17:31:16 | [diff] [blame] | 177 | class CellularDataPlan { |
| 178 | public: |
| 179 | CellularDataPlan() : |
| 180 | plan_name("Unknown"), |
| 181 | plan_type(CELLULAR_DATA_PLAN_UNLIMITED), |
| 182 | plan_data_bytes(0), |
| 183 | data_bytes_used(0) { } |
| 184 | explicit CellularDataPlan(const CellularDataPlanInfo &plan) : |
| 185 | plan_name(plan.plan_name?plan.plan_name:""), |
| 186 | plan_type(plan.plan_type), |
| 187 | update_time(base::Time::FromInternalValue(plan.update_time)), |
| 188 | plan_start_time(base::Time::FromInternalValue(plan.plan_start_time)), |
| 189 | plan_end_time(base::Time::FromInternalValue(plan.plan_end_time)), |
| 190 | plan_data_bytes(plan.plan_data_bytes), |
| 191 | data_bytes_used(plan.data_bytes_used) { } |
[email protected] | f005394 | 2010-11-13 02:33:54 | [diff] [blame] | 192 | // Formats cellular plan description. |
| 193 | string16 GetPlanDesciption() const; |
| 194 | // Evaluates cellular plans status and returns warning string if it is near |
| 195 | // expiration. |
| 196 | string16 GetRemainingWarning() const; |
| 197 | // Formats remaining plan data description. |
| 198 | string16 GetDataRemainingDesciption() const; |
| 199 | // Formats plan expiration description. |
| 200 | string16 GetPlanExpiration() const; |
| 201 | // Formats plan usage info. |
| 202 | string16 GetUsageInfo() const; |
[email protected] | 633e5c0 | 2010-11-19 22:11:35 | [diff] [blame] | 203 | base::TimeDelta remaining_time() const; |
[email protected] | f005394 | 2010-11-13 02:33:54 | [diff] [blame] | 204 | int64 remaining_minutes() const; |
[email protected] | 633e5c0 | 2010-11-19 22:11:35 | [diff] [blame] | 205 | int64 remaining_data() const; |
[email protected] | f005394 | 2010-11-13 02:33:54 | [diff] [blame] | 206 | int64 remaining_mbytes() const; |
[email protected] | 05f06df | 2010-11-04 17:31:16 | [diff] [blame] | 207 | std::string plan_name; |
| 208 | CellularDataPlanType plan_type; |
| 209 | base::Time update_time; |
| 210 | base::Time plan_start_time; |
| 211 | base::Time plan_end_time; |
| 212 | int64 plan_data_bytes; |
| 213 | int64 data_bytes_used; |
| 214 | }; |
| 215 | |
[email protected] | 633e5c0 | 2010-11-19 22:11:35 | [diff] [blame] | 216 | typedef ScopedVector<CellularDataPlan> CellularDataPlanVector; |
[email protected] | 05f06df | 2010-11-04 17:31:16 | [diff] [blame] | 217 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 218 | class CellularNetwork : public WirelessNetwork { |
| 219 | public: |
[email protected] | 543a79a | 2010-10-20 01:14:58 | [diff] [blame] | 220 | enum DataLeft { |
[email protected] | eda4d0c | 2011-01-24 19:52:02 | [diff] [blame^] | 221 | DATA_UNKNOWN, |
[email protected] | 543a79a | 2010-10-20 01:14:58 | [diff] [blame] | 222 | DATA_NORMAL, |
| 223 | DATA_LOW, |
| 224 | DATA_VERY_LOW, |
| 225 | DATA_NONE |
| 226 | }; |
| 227 | |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 228 | CellularNetwork(); |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 229 | explicit CellularNetwork(const CellularNetwork& network); |
| 230 | explicit CellularNetwork(const ServiceInfo* service); |
[email protected] | 05f06df | 2010-11-04 17:31:16 | [diff] [blame] | 231 | virtual ~CellularNetwork(); |
[email protected] | 9d3f7d5e | 2010-09-25 06:17:04 | [diff] [blame] | 232 | // Starts device activation process. Returns false if the device state does |
| 233 | // not permit activation. |
| 234 | bool StartActivation() const; |
[email protected] | ad75cda | 2010-09-28 23:18:46 | [diff] [blame] | 235 | const ActivationState activation_state() const { return activation_state_; } |
[email protected] | 17cc052 | 2010-10-01 20:19:12 | [diff] [blame] | 236 | const NetworkTechnology network_technology() const { |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 237 | return network_technology_; |
| 238 | } |
[email protected] | 17cc052 | 2010-10-01 20:19:12 | [diff] [blame] | 239 | const NetworkRoamingState roaming_state() const { return roaming_state_; } |
[email protected] | 353e0dd8 | 2010-11-22 08:39:31 | [diff] [blame] | 240 | const ConnectivityState connectivity_state() const { |
| 241 | return connectivity_state_; |
| 242 | } |
| 243 | bool restricted_pool() const { |
| 244 | return connectivity_state() == CONN_STATE_RESTRICTED; |
| 245 | } |
[email protected] | f005394 | 2010-11-13 02:33:54 | [diff] [blame] | 246 | bool needs_new_plan() const { |
| 247 | return restricted_pool() && connected() && |
| 248 | activation_state() == ACTIVATION_STATE_ACTIVATED; |
| 249 | } |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 250 | const std::string& service_name() const { return service_name_; } |
[email protected] | 9a24152e | 2010-10-08 23:15:31 | [diff] [blame] | 251 | const std::string& operator_name() const { return operator_name_; } |
| 252 | const std::string& operator_code() const { return operator_code_; } |
[email protected] | 9d3f7d5e | 2010-09-25 06:17:04 | [diff] [blame] | 253 | const std::string& payment_url() const { return payment_url_; } |
| 254 | const std::string& meid() const { return meid_; } |
| 255 | const std::string& imei() const { return imei_; } |
| 256 | const std::string& imsi() const { return imsi_; } |
| 257 | const std::string& esn() const { return esn_; } |
| 258 | const std::string& mdn() const { return mdn_; } |
[email protected] | 7b947813da | 2010-10-07 23:47:42 | [diff] [blame] | 259 | const std::string& min() const { return min_; } |
| 260 | const std::string& model_id() const { return model_id_; } |
| 261 | const std::string& manufacturer() const { return manufacturer_; } |
| 262 | const std::string& firmware_revision() const { return firmware_revision_; } |
| 263 | const std::string& hardware_revision() const { return hardware_revision_; } |
| 264 | const std::string& last_update() const { return last_update_; } |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 265 | const unsigned int prl_version() const { return prl_version_; } |
[email protected] | 633e5c0 | 2010-11-19 22:11:35 | [diff] [blame] | 266 | bool is_gsm() const { |
| 267 | return network_technology_ != NETWORK_TECHNOLOGY_EVDO && |
| 268 | network_technology_ != NETWORK_TECHNOLOGY_1XRTT && |
| 269 | network_technology_ != NETWORK_TECHNOLOGY_UNKNOWN; |
| 270 | } |
[email protected] | 3cc2e59 | 2010-06-21 13:45:43 | [diff] [blame] | 271 | |
| 272 | // WirelessNetwork overrides. |
| 273 | virtual void Clear(); |
[email protected] | 9d3f7d5e | 2010-09-25 06:17:04 | [diff] [blame] | 274 | |
[email protected] | 05f06df | 2010-11-04 17:31:16 | [diff] [blame] | 275 | const CellularDataPlanVector& GetDataPlans() const { |
[email protected] | 3801761 | 2010-10-13 18:46:00 | [diff] [blame] | 276 | return data_plans_; |
| 277 | } |
| 278 | |
[email protected] | 05f06df | 2010-11-04 17:31:16 | [diff] [blame] | 279 | void SetDataPlans(const CellularDataPlanList* data_plan_list) { |
[email protected] | 633e5c0 | 2010-11-19 22:11:35 | [diff] [blame] | 280 | data_plans_.reset(); |
[email protected] | 05f06df | 2010-11-04 17:31:16 | [diff] [blame] | 281 | for (size_t i = 0; i < data_plan_list->plans_size; i++) { |
| 282 | const CellularDataPlanInfo* info(data_plan_list->GetCellularDataPlan(i)); |
[email protected] | 633e5c0 | 2010-11-19 22:11:35 | [diff] [blame] | 283 | data_plans_.push_back(new CellularDataPlan(*info)); |
[email protected] | 05f06df | 2010-11-04 17:31:16 | [diff] [blame] | 284 | } |
[email protected] | 3801761 | 2010-10-13 18:46:00 | [diff] [blame] | 285 | } |
[email protected] | 633e5c0 | 2010-11-19 22:11:35 | [diff] [blame] | 286 | |
| 287 | // This returns the significant data plan. If the user only has the |
| 288 | // base data plan, then return that. If there is a base and a paid data plan, |
| 289 | // then the significant one is the paid one. So return the paid plan. |
| 290 | // If there are no data plans, then this method returns NULL. |
| 291 | // This returns a pointer to a member of data_plans_, so if SetDataPlans() |
| 292 | // gets called, the result becomes invalid. |
| 293 | const CellularDataPlan* GetSignificantDataPlan() const; |
| 294 | |
| 295 | DataLeft GetDataLeft() const; |
| 296 | |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 297 | // Return a string representation of network technology. |
| 298 | std::string GetNetworkTechnologyString() const; |
[email protected] | 353e0dd8 | 2010-11-22 08:39:31 | [diff] [blame] | 299 | // Return a string representation of connectivity state. |
| 300 | std::string GetConnectivityStateString() const; |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 301 | // Return a string representation of activation state. |
| 302 | std::string GetActivationStateString() const; |
| 303 | // Return a string representation of roaming state. |
| 304 | std::string GetRoamingStateString() const; |
| 305 | |
[email protected] | 3c1139f | 2010-10-22 06:17:42 | [diff] [blame] | 306 | // Return a string representation of |activation_state|. |
| 307 | static std::string ActivationStateToString(ActivationState activation_state); |
| 308 | |
[email protected] | 9d3f7d5e | 2010-09-25 06:17:04 | [diff] [blame] | 309 | protected: |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 310 | |
[email protected] | ad75cda | 2010-09-28 23:18:46 | [diff] [blame] | 311 | ActivationState activation_state_; |
[email protected] | 17cc052 | 2010-10-01 20:19:12 | [diff] [blame] | 312 | NetworkTechnology network_technology_; |
| 313 | NetworkRoamingState roaming_state_; |
[email protected] | 353e0dd8 | 2010-11-22 08:39:31 | [diff] [blame] | 314 | ConnectivityState connectivity_state_; |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 315 | std::string service_name_; |
[email protected] | 7b947813da | 2010-10-07 23:47:42 | [diff] [blame] | 316 | // Carrier Info |
| 317 | std::string operator_name_; |
| 318 | std::string operator_code_; |
[email protected] | 9d3f7d5e | 2010-09-25 06:17:04 | [diff] [blame] | 319 | std::string payment_url_; |
[email protected] | 7b947813da | 2010-10-07 23:47:42 | [diff] [blame] | 320 | // Device Info |
[email protected] | 9d3f7d5e | 2010-09-25 06:17:04 | [diff] [blame] | 321 | std::string meid_; |
| 322 | std::string imei_; |
| 323 | std::string imsi_; |
| 324 | std::string esn_; |
| 325 | std::string mdn_; |
[email protected] | 7b947813da | 2010-10-07 23:47:42 | [diff] [blame] | 326 | std::string min_; |
| 327 | std::string model_id_; |
| 328 | std::string manufacturer_; |
| 329 | std::string firmware_revision_; |
| 330 | std::string hardware_revision_; |
| 331 | std::string last_update_; |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 332 | unsigned int prl_version_; |
[email protected] | 05f06df | 2010-11-04 17:31:16 | [diff] [blame] | 333 | CellularDataPlanVector data_plans_; |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 334 | |
| 335 | private: |
| 336 | void set_activation_state(ActivationState state) { |
| 337 | activation_state_ = state; |
| 338 | } |
| 339 | void set_payment_url(const std::string& url) { |
| 340 | payment_url_ = url; |
| 341 | } |
| 342 | void set_network_technology(NetworkTechnology technology) { |
| 343 | network_technology_ = technology; |
| 344 | } |
| 345 | void set_roaming_state(NetworkRoamingState state) { |
| 346 | roaming_state_ = state; |
| 347 | } |
[email protected] | 353e0dd8 | 2010-11-22 08:39:31 | [diff] [blame] | 348 | void set_connectivity_state(ConnectivityState connectivity_state) { |
| 349 | connectivity_state_ = connectivity_state; |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | friend class NetworkLibraryImpl; |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 353 | }; |
| 354 | |
| 355 | class WifiNetwork : public WirelessNetwork { |
| 356 | public: |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 357 | WifiNetwork(); |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 358 | explicit WifiNetwork(const WifiNetwork& network); |
| 359 | explicit WifiNetwork(const ServiceInfo* service); |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 360 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 361 | bool encrypted() const { return encryption_ != SECURITY_NONE; } |
| 362 | ConnectionSecurity encryption() const { return encryption_; } |
| 363 | const std::string& passphrase() const { return passphrase_; } |
[email protected] | d4731385 | 2010-05-11 23:01:04 | [diff] [blame] | 364 | const std::string& identity() const { return identity_; } |
| 365 | const std::string& cert_path() const { return cert_path_; } |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 366 | |
| 367 | void set_encryption(ConnectionSecurity encryption) { |
| 368 | encryption_ = encryption; |
| 369 | } |
| 370 | void set_passphrase(const std::string& passphrase) { |
| 371 | passphrase_ = passphrase; |
| 372 | } |
[email protected] | d4731385 | 2010-05-11 23:01:04 | [diff] [blame] | 373 | void set_identity(const std::string& identity) { |
| 374 | identity_ = identity; |
| 375 | } |
| 376 | void set_cert_path(const std::string& cert_path) { |
| 377 | cert_path_ = cert_path; |
| 378 | } |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 379 | |
| 380 | // WirelessNetwork overrides. |
| 381 | virtual void Clear(); |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 382 | |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 383 | // Return a string representation of the encryption code. |
| 384 | // This not translated and should be only used for debugging purposes. |
| 385 | std::string GetEncryptionString(); |
| 386 | |
[email protected] | 8416136 | 2010-12-15 16:50:33 | [diff] [blame] | 387 | // Return true if a passphrase or other input is required to connect. |
| 388 | bool IsPassphraseRequired() const; |
| 389 | |
[email protected] | c1ee006 | 2010-10-14 18:37:22 | [diff] [blame] | 390 | // Return true if cert_path_ indicates that we have loaded the certificate. |
| 391 | bool IsCertificateLoaded() const; |
| 392 | |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 393 | protected: |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 394 | ConnectionSecurity encryption_; |
| 395 | std::string passphrase_; |
[email protected] | e027da19 | 2010-11-08 21:35:08 | [diff] [blame] | 396 | bool passphrase_required_; |
[email protected] | d4731385 | 2010-05-11 23:01:04 | [diff] [blame] | 397 | std::string identity_; |
| 398 | std::string cert_path_; |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 399 | }; |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 400 | |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 401 | typedef std::vector<chromeos::WifiNetwork*> WifiNetworkVector; |
| 402 | typedef std::vector<chromeos::CellularNetwork*> CellularNetworkVector; |
[email protected] | 38d387cd | 2010-01-14 01:00:39 | [diff] [blame] | 403 | |
[email protected] | 63259a5 | 2010-07-15 10:55:38 | [diff] [blame] | 404 | struct CellTower { |
| 405 | enum RadioType { |
| 406 | RADIOTYPE_GSM, |
| 407 | RADIOTYPE_CDMA, |
| 408 | RADIOTYPE_WCDMA, |
| 409 | } radio_type; // GSM/WCDMA CDMA |
| 410 | int mobile_country_code; // MCC MCC |
| 411 | int mobile_network_code; // MNC SID |
| 412 | int location_area_code; // LAC NID |
| 413 | int cell_id; // CID BID |
[email protected] | 17f12b5 | 2010-10-02 02:08:16 | [diff] [blame] | 414 | base::Time timestamp; // Timestamp when this cell was primary |
| 415 | int signal_strength; // Radio signal strength measured in dBm. |
| 416 | int timing_advance; // Represents the distance from the cell tower. |
| 417 | // Each unit is roughly 550 meters. |
[email protected] | 63259a5 | 2010-07-15 10:55:38 | [diff] [blame] | 418 | }; |
| 419 | |
| 420 | struct WifiAccessPoint { |
| 421 | std::string mac_address; // The mac address of the WiFi node. |
| 422 | std::string name; // The SSID of the WiFi node. |
| 423 | base::Time timestamp; // Timestamp when this AP was detected. |
| 424 | int signal_strength; // Radio signal strength measured in dBm. |
| 425 | int signal_to_noise; // Current signal to noise ratio measured in dB. |
| 426 | int channel; // Wifi channel number. |
| 427 | }; |
| 428 | |
| 429 | typedef std::vector<CellTower> CellTowerVector; |
| 430 | typedef std::vector<WifiAccessPoint> WifiAccessPointVector; |
| 431 | |
[email protected] | 3fb19f5c | 2010-02-17 00:49:50 | [diff] [blame] | 432 | struct NetworkIPConfig { |
| 433 | NetworkIPConfig(const std::string& device_path, IPConfigType type, |
| 434 | const std::string& address, const std::string& netmask, |
| 435 | const std::string& gateway, const std::string& name_servers) |
| 436 | : device_path(device_path), |
| 437 | type(type), |
| 438 | address(address), |
| 439 | netmask(netmask), |
| 440 | gateway(gateway), |
| 441 | name_servers(name_servers) {} |
| 442 | |
| 443 | // NetworkIPConfigs are sorted by tyoe. |
| 444 | bool operator< (const NetworkIPConfig& other) const { |
| 445 | return type < other.type; |
| 446 | } |
| 447 | |
| 448 | std::string device_path; |
| 449 | IPConfigType type; |
[email protected] | ea21f9c | 2010-10-21 08:26:54 | [diff] [blame] | 450 | std::string address; // This looks like "/device/0011aa22bb33" |
[email protected] | 3fb19f5c | 2010-02-17 00:49:50 | [diff] [blame] | 451 | std::string netmask; |
| 452 | std::string gateway; |
| 453 | std::string name_servers; |
| 454 | }; |
| 455 | typedef std::vector<NetworkIPConfig> NetworkIPConfigVector; |
| 456 | |
[email protected] | 819a4386 | 2010-08-12 10:09:21 | [diff] [blame] | 457 | // This class handles the interaction with the ChromeOS network library APIs. |
| 458 | // Classes can add themselves as observers. Users can get an instance of the |
| 459 | // library like this: chromeos::CrosLibrary::Get()->GetNetworkLibrary() |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 460 | class NetworkLibrary { |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 461 | public: |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 462 | class NetworkManagerObserver { |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 463 | public: |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 464 | // Called when the state of the network manager has changed, |
| 465 | // for example, networks have appeared or disappeared. |
| 466 | virtual void OnNetworkManagerChanged(NetworkLibrary* obj) = 0; |
[email protected] | 7c3cc8a3 | 2010-11-03 06:58:14 | [diff] [blame] | 467 | }; |
| 468 | |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 469 | class NetworkObserver { |
[email protected] | 7c3cc8a3 | 2010-11-03 06:58:14 | [diff] [blame] | 470 | public: |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 471 | // Called when the state of a single network has changed, |
| 472 | // for example signal strength or connection state. |
| 473 | virtual void OnNetworkChanged(NetworkLibrary* cros, |
| 474 | const Network* network) = 0; |
| 475 | }; |
| 476 | |
| 477 | class CellularDataPlanObserver { |
| 478 | public: |
| 479 | // Called when the cellular data plan has changed. |
| 480 | virtual void OnCellularDataPlanChanged(NetworkLibrary* obj) = 0; |
[email protected] | 3c1139f | 2010-10-22 06:17:42 | [diff] [blame] | 481 | }; |
| 482 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 483 | virtual ~NetworkLibrary() {} |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 484 | |
| 485 | virtual void AddNetworkManagerObserver(NetworkManagerObserver* observer) = 0; |
| 486 | virtual void RemoveNetworkManagerObserver( |
| 487 | NetworkManagerObserver* observer) = 0; |
| 488 | |
| 489 | // An attempt to add an observer that has already been added for a |
| 490 | // give service path will be ignored. |
| 491 | virtual void AddNetworkObserver(const std::string& service_path, |
| 492 | NetworkObserver* observer) = 0; |
| 493 | // Remove an observer of a single network |
| 494 | virtual void RemoveNetworkObserver(const std::string& service_path, |
| 495 | NetworkObserver* observer) = 0; |
| 496 | // Stop |observer| from observing any networks |
| 497 | virtual void RemoveObserverForAllNetworks(NetworkObserver* observer) = 0; |
| 498 | |
[email protected] | 1b57b4c | 2011-01-21 21:43:11 | [diff] [blame] | 499 | // Temporarily locks down certain functionality in network library to prevent |
| 500 | // unplanned side effects. During the lock down, Enable*Device() calls cannot |
| 501 | // be made. |
| 502 | virtual void Lock() = 0; |
| 503 | // Removes temporarily lock of network library. |
| 504 | virtual void Unlock() = 0; |
| 505 | // Checks if access to network library is locked. |
| 506 | virtual bool IsLocked() = 0; |
| 507 | |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 508 | virtual void AddCellularDataPlanObserver( |
| 509 | CellularDataPlanObserver* observer) = 0; |
| 510 | virtual void RemoveCellularDataPlanObserver( |
| 511 | CellularDataPlanObserver* observer) = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 512 | |
[email protected] | 21e74460 | 2010-10-16 03:16:53 | [diff] [blame] | 513 | // Return the active Ethernet network (or a default structure if inactive). |
[email protected] | 37eec14 | 2010-12-02 18:47:09 | [diff] [blame] | 514 | virtual const EthernetNetwork* ethernet_network() const = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 515 | virtual bool ethernet_connecting() const = 0; |
| 516 | virtual bool ethernet_connected() const = 0; |
| 517 | |
[email protected] | 21e74460 | 2010-10-16 03:16:53 | [diff] [blame] | 518 | // Return the active Wifi network (or a default structure if none active). |
[email protected] | 37eec14 | 2010-12-02 18:47:09 | [diff] [blame] | 519 | virtual const WifiNetwork* wifi_network() const = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 520 | virtual bool wifi_connecting() const = 0; |
| 521 | virtual bool wifi_connected() const = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 522 | |
[email protected] | 21e74460 | 2010-10-16 03:16:53 | [diff] [blame] | 523 | // Return the active Cellular network (or a default structure if none active). |
[email protected] | 37eec14 | 2010-12-02 18:47:09 | [diff] [blame] | 524 | virtual const CellularNetwork* cellular_network() const = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 525 | virtual bool cellular_connecting() const = 0; |
| 526 | virtual bool cellular_connected() const = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 527 | |
| 528 | // Return true if any network is currently connected. |
| 529 | virtual bool Connected() const = 0; |
| 530 | |
| 531 | // Return true if any network is currently connecting. |
| 532 | virtual bool Connecting() const = 0; |
| 533 | |
| 534 | // Returns the current IP address if connected. If not, returns empty string. |
[email protected] | 460c3f1 | 2010-11-08 18:20:58 | [diff] [blame] | 535 | virtual const std::string& IPAddress() const = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 536 | |
| 537 | // Returns the current list of wifi networks. |
| 538 | virtual const WifiNetworkVector& wifi_networks() const = 0; |
| 539 | |
[email protected] | 665d7d6 | 2010-04-20 23:32:49 | [diff] [blame] | 540 | // Returns the list of remembered wifi networks. |
| 541 | virtual const WifiNetworkVector& remembered_wifi_networks() const = 0; |
| 542 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 543 | // Returns the current list of cellular networks. |
| 544 | virtual const CellularNetworkVector& cellular_networks() const = 0; |
| 545 | |
[email protected] | d1dae8a5 | 2010-12-02 21:27:42 | [diff] [blame] | 546 | // Search the current list of networks by path and if the network |
| 547 | // is available, copy the result and return true. |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 548 | virtual WifiNetwork* FindWifiNetworkByPath(const std::string& path) = 0; |
| 549 | virtual CellularNetwork* FindCellularNetworkByPath( |
| 550 | const std::string& path) = 0; |
| 551 | |
[email protected] | f9384b55 | 2010-06-28 23:02:26 | [diff] [blame] | 552 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 553 | // Request a scan for new wifi networks. |
| 554 | virtual void RequestWifiScan() = 0; |
| 555 | |
[email protected] | 63259a5 | 2010-07-15 10:55:38 | [diff] [blame] | 556 | // Reads out the results of the last wifi scan. These results are not |
| 557 | // pre-cached in the library, so the call may block whilst the results are |
| 558 | // read over IPC. |
| 559 | // Returns false if an error occurred in reading the results. Note that |
| 560 | // a true return code only indicates the result set was successfully read, |
| 561 | // it does not imply a scan has successfully completed yet. |
| 562 | virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) = 0; |
| 563 | |
| 564 | // TODO(joth): Add GetCellTowers to retrieve a CellTowerVector. |
| 565 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 566 | // Connect to the specified wireless network with password. |
[email protected] | fe3a0509 | 2010-11-24 23:53:16 | [diff] [blame] | 567 | // Returns false if the attempt fails immediately (e.g. passphrase too short) |
| 568 | // and sets network->error(). |
| 569 | virtual bool ConnectToWifiNetwork(WifiNetwork* network, |
[email protected] | 4a5c59c8 | 2010-06-30 21:03:34 | [diff] [blame] | 570 | const std::string& password, |
| 571 | const std::string& identity, |
| 572 | const std::string& certpath) = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 573 | |
[email protected] | 0673a28 | 2010-11-02 20:41:44 | [diff] [blame] | 574 | // Connect to the specified network with security, ssid, and password. |
[email protected] | e027da19 | 2010-11-08 21:35:08 | [diff] [blame] | 575 | // Returns false if the attempt fails immediately (e.g. passphrase too short). |
| 576 | virtual bool ConnectToWifiNetwork(ConnectionSecurity security, |
[email protected] | 0673a28 | 2010-11-02 20:41:44 | [diff] [blame] | 577 | const std::string& ssid, |
[email protected] | 4a5c59c8 | 2010-06-30 21:03:34 | [diff] [blame] | 578 | const std::string& password, |
| 579 | const std::string& identity, |
| 580 | const std::string& certpath, |
[email protected] | 88908d6 | 2010-04-30 21:50:45 | [diff] [blame] | 581 | bool auto_connect) = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 582 | |
| 583 | // Connect to the specified cellular network. |
[email protected] | e027da19 | 2010-11-08 21:35:08 | [diff] [blame] | 584 | // Returns false if the attempt fails immediately. |
| 585 | virtual bool ConnectToCellularNetwork(const CellularNetwork* network) = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 586 | |
[email protected] | 3801761 | 2010-10-13 18:46:00 | [diff] [blame] | 587 | // Initiates cellular data plan refresh. Plan data will be passed through |
| 588 | // Network::Observer::CellularDataPlanChanged callback. |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 589 | virtual void RefreshCellularDataPlans(const CellularNetwork* network) = 0; |
[email protected] | 3801761 | 2010-10-13 18:46:00 | [diff] [blame] | 590 | |
[email protected] | c3a54e4b | 2011-01-18 04:37:05 | [diff] [blame] | 591 | // Records information that cellular play payment had happened. |
| 592 | virtual void SignalCellularPlanPayment() = 0; |
| 593 | |
| 594 | // Returns true if cellular plan payment had been recorded recently. |
| 595 | virtual bool HasRecentCellularPlanPayment() = 0; |
| 596 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 597 | // Disconnect from the specified wireless (either cellular or wifi) network. |
| 598 | virtual void DisconnectFromWirelessNetwork( |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 599 | const WirelessNetwork* network) = 0; |
[email protected] | d1958fe | 2010-04-30 22:29:42 | [diff] [blame] | 600 | |
[email protected] | f49a0c88 | 2010-07-15 23:35:00 | [diff] [blame] | 601 | // Save network information including passwords (wifi) and auto-connect. |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 602 | virtual void SaveCellularNetwork(const CellularNetwork* network) = 0; |
| 603 | virtual void SaveWifiNetwork(const WifiNetwork* network) = 0; |
[email protected] | 88908d6 | 2010-04-30 21:50:45 | [diff] [blame] | 604 | |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 605 | // Forget the wifi network corresponding to service_path. |
| 606 | virtual void ForgetWifiNetwork(const std::string& service_path) = 0; |
[email protected] | 665d7d6 | 2010-04-20 23:32:49 | [diff] [blame] | 607 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 608 | virtual bool ethernet_available() const = 0; |
| 609 | virtual bool wifi_available() const = 0; |
| 610 | virtual bool cellular_available() const = 0; |
| 611 | |
| 612 | virtual bool ethernet_enabled() const = 0; |
| 613 | virtual bool wifi_enabled() const = 0; |
| 614 | virtual bool cellular_enabled() const = 0; |
| 615 | |
[email protected] | d3f9b88 | 2010-11-18 22:30:40 | [diff] [blame] | 616 | virtual bool wifi_scanning() const = 0; |
| 617 | |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 618 | virtual const Network* active_network() const = 0; |
| 619 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 620 | virtual bool offline_mode() const = 0; |
| 621 | |
| 622 | // Enables/disables the ethernet network device. |
| 623 | virtual void EnableEthernetNetworkDevice(bool enable) = 0; |
| 624 | |
| 625 | // Enables/disables the wifi network device. |
| 626 | virtual void EnableWifiNetworkDevice(bool enable) = 0; |
| 627 | |
| 628 | // Enables/disables the cellular network device. |
| 629 | virtual void EnableCellularNetworkDevice(bool enable) = 0; |
| 630 | |
| 631 | // Enables/disables offline mode. |
| 632 | virtual void EnableOfflineMode(bool enable) = 0; |
| 633 | |
[email protected] | ea21f9c | 2010-10-21 08:26:54 | [diff] [blame] | 634 | // Fetches IP configs and hardware address for a given device_path. |
| 635 | // The hardware address is usually a MAC address like "0011AA22BB33". |
| 636 | // |hardware_address| will be an empty string, if no hardware address is |
| 637 | // found. |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 638 | virtual NetworkIPConfigVector GetIPConfigs( |
[email protected] | ea21f9c | 2010-10-21 08:26:54 | [diff] [blame] | 639 | const std::string& device_path, |
| 640 | std::string* hardware_address) = 0; |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 641 | |
| 642 | // Fetches debug network info for display in about:network. |
| 643 | // The page will have a meta refresh of |refresh| seconds if |refresh| > 0. |
| 644 | virtual std::string GetHtmlInfo(int refresh) = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 645 | |
[email protected] | 819a4386 | 2010-08-12 10:09:21 | [diff] [blame] | 646 | // Factory function, creates a new instance and returns ownership. |
| 647 | // For normal usage, access the singleton via CrosLibrary::Get(). |
[email protected] | 617fd0d | 2010-08-04 20:05:17 | [diff] [blame] | 648 | static NetworkLibrary* GetImpl(bool stub); |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 649 | }; |
| 650 | |
[email protected] | b22c21c | 2009-10-30 00:35:00 | [diff] [blame] | 651 | } // namespace chromeos |
| 652 | |
[email protected] | 268b02f | 2010-02-04 21:07:15 | [diff] [blame] | 653 | #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |