Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/chromeos/cros/network_library.h

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

Powered by Google App Engine
This is Rietveld 408576698