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

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

Issue 4552002: Merge 65106 - Landing change for ers@chromium.org: http://codereview.chromium... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/552/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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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
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 virtual ~WirelessNetwork() {} 147 virtual ~WirelessNetwork() {}
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 CellularDataPlan { 160 class CellularDataPlan {
146 public: 161 public:
147 CellularDataPlan() : 162 CellularDataPlan() :
148 plan_name("Unknown"), 163 plan_name("Unknown"),
149 plan_type(CELLULAR_DATA_PLAN_UNLIMITED), 164 plan_type(CELLULAR_DATA_PLAN_UNLIMITED),
150 plan_data_bytes(0), 165 plan_data_bytes(0),
151 data_bytes_used(0) { } 166 data_bytes_used(0) { }
152 explicit CellularDataPlan(const CellularDataPlanInfo &plan) : 167 explicit CellularDataPlan(const CellularDataPlanInfo &plan) :
(...skipping 25 matching lines...) Expand all
178 DATA_NONE 193 DATA_NONE
179 }; 194 };
180 195
181 CellularNetwork(); 196 CellularNetwork();
182 explicit CellularNetwork(const CellularNetwork& network); 197 explicit CellularNetwork(const CellularNetwork& network);
183 explicit CellularNetwork(const ServiceInfo* service); 198 explicit CellularNetwork(const ServiceInfo* service);
184 virtual ~CellularNetwork(); 199 virtual ~CellularNetwork();
185 // Starts device activation process. Returns false if the device state does 200 // Starts device activation process. Returns false if the device state does
186 // not permit activation. 201 // not permit activation.
187 bool StartActivation() const; 202 bool StartActivation() const;
188 void set_activation_state(ActivationState state) {
189 activation_state_ = state;
190 }
191 const ActivationState activation_state() const { return activation_state_; } 203 const ActivationState activation_state() const { return activation_state_; }
192 const NetworkTechnology network_technology() const { 204 const NetworkTechnology network_technology() const {
193 return network_technology_; 205 return network_technology_;
194 } 206 }
195 const NetworkRoamingState roaming_state() const { return roaming_state_; } 207 const NetworkRoamingState roaming_state() const { return roaming_state_; }
196 bool restricted_pool() const { return restricted_pool_; } 208 bool restricted_pool() const { return restricted_pool_; }
197 const std::string& service_name() const { return service_name_; } 209 const std::string& service_name() const { return service_name_; }
198 const std::string& operator_name() const { return operator_name_; } 210 const std::string& operator_name() const { return operator_name_; }
199 const std::string& operator_code() const { return operator_code_; } 211 const std::string& operator_code() const { return operator_code_; }
200 const std::string& payment_url() const { return payment_url_; } 212 const std::string& payment_url() const { return payment_url_; }
201 void set_payment_url(const std::string& url) {
202 payment_url_ = url;
203 }
204 const std::string& meid() const { return meid_; } 213 const std::string& meid() const { return meid_; }
205 const std::string& imei() const { return imei_; } 214 const std::string& imei() const { return imei_; }
206 const std::string& imsi() const { return imsi_; } 215 const std::string& imsi() const { return imsi_; }
207 const std::string& esn() const { return esn_; } 216 const std::string& esn() const { return esn_; }
208 const std::string& mdn() const { return mdn_; } 217 const std::string& mdn() const { return mdn_; }
209 const std::string& min() const { return min_; } 218 const std::string& min() const { return min_; }
210 const std::string& model_id() const { return model_id_; } 219 const std::string& model_id() const { return model_id_; }
211 const std::string& manufacturer() const { return manufacturer_; } 220 const std::string& manufacturer() const { return manufacturer_; }
212 const std::string& firmware_revision() const { return firmware_revision_; } 221 const std::string& firmware_revision() const { return firmware_revision_; }
213 const std::string& hardware_revision() const { return hardware_revision_; } 222 const std::string& hardware_revision() const { return hardware_revision_; }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 std::string esn_; 267 std::string esn_;
259 std::string mdn_; 268 std::string mdn_;
260 std::string min_; 269 std::string min_;
261 std::string model_id_; 270 std::string model_id_;
262 std::string manufacturer_; 271 std::string manufacturer_;
263 std::string firmware_revision_; 272 std::string firmware_revision_;
264 std::string hardware_revision_; 273 std::string hardware_revision_;
265 std::string last_update_; 274 std::string last_update_;
266 unsigned int prl_version_; 275 unsigned int prl_version_;
267 CellularDataPlanVector data_plans_; 276 CellularDataPlanVector data_plans_;
277
278 private:
279 void set_activation_state(ActivationState state) {
280 activation_state_ = state;
281 }
282 void set_payment_url(const std::string& url) {
283 payment_url_ = url;
284 }
285 void set_network_technology(NetworkTechnology technology) {
286 network_technology_ = technology;
287 }
288 void set_roaming_state(NetworkRoamingState state) {
289 roaming_state_ = state;
290 }
291 void set_restricted_pool(bool restricted_pool) {
292 restricted_pool_ = restricted_pool;
293 }
294
295 friend class NetworkLibraryImpl;
268 }; 296 };
269 297
270 class WifiNetwork : public WirelessNetwork { 298 class WifiNetwork : public WirelessNetwork {
271 public: 299 public:
272 WifiNetwork(); 300 WifiNetwork();
273 explicit WifiNetwork(const WifiNetwork& network); 301 explicit WifiNetwork(const WifiNetwork& network);
274 explicit WifiNetwork(const ServiceInfo* service); 302 explicit WifiNetwork(const ServiceInfo* service);
275 303
276 bool encrypted() const { return encryption_ != SECURITY_NONE; } 304 bool encrypted() const { return encryption_ != SECURITY_NONE; }
277 ConnectionSecurity encryption() const { return encryption_; } 305 ConnectionSecurity encryption() const { return encryption_; }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 std::string gateway; 391 std::string gateway;
364 std::string name_servers; 392 std::string name_servers;
365 }; 393 };
366 typedef std::vector<NetworkIPConfig> NetworkIPConfigVector; 394 typedef std::vector<NetworkIPConfig> NetworkIPConfigVector;
367 395
368 // This class handles the interaction with the ChromeOS network library APIs. 396 // This class handles the interaction with the ChromeOS network library APIs.
369 // Classes can add themselves as observers. Users can get an instance of the 397 // Classes can add themselves as observers. Users can get an instance of the
370 // library like this: chromeos::CrosLibrary::Get()->GetNetworkLibrary() 398 // library like this: chromeos::CrosLibrary::Get()->GetNetworkLibrary()
371 class NetworkLibrary { 399 class NetworkLibrary {
372 public: 400 public:
373 class Observer { 401 class NetworkManagerObserver {
374 public: 402 public:
375 // Called when the network has changed. (wifi networks, and ethernet) 403 // Called when the state of the network manager has changed,
376 virtual void NetworkChanged(NetworkLibrary* obj) = 0; 404 // for example, networks have appeared or disappeared.
377 // Called when the cellular data plan has changed. 405 virtual void OnNetworkManagerChanged(NetworkLibrary* obj) = 0;
378 virtual void CellularDataPlanChanged(NetworkLibrary* obj) {}
379 }; 406 };
380 407
381 class PropertyObserver { 408 class NetworkObserver {
382 public: 409 public:
383 virtual void PropertyChanged(const char* service_path, 410 // Called when the state of a single network has changed,
384 const char* key, 411 // for example signal strength or connection state.
385 const Value* value) = 0; 412 virtual void OnNetworkChanged(NetworkLibrary* cros,
413 const Network* network) = 0;
414 };
415
416 class CellularDataPlanObserver {
417 public:
418 // Called when the cellular data plan has changed.
419 virtual void OnCellularDataPlanChanged(NetworkLibrary* obj) = 0;
386 }; 420 };
387 421
388 virtual ~NetworkLibrary() {} 422 virtual ~NetworkLibrary() {}
389 virtual void AddObserver(Observer* observer) = 0; 423
390 virtual void RemoveObserver(Observer* observer) = 0; 424 virtual void AddNetworkManagerObserver(NetworkManagerObserver* observer) = 0;
391 virtual void AddProperyObserver(const char* service_path, 425 virtual void RemoveNetworkManagerObserver(
392 PropertyObserver* observer) = 0; 426 NetworkManagerObserver* observer) = 0;
393 virtual void RemoveProperyObserver(PropertyObserver* observer) = 0; 427
428 // An attempt to add an observer that has already been added for a
429 // give service path will be ignored.
430 virtual void AddNetworkObserver(const std::string& service_path,
431 NetworkObserver* observer) = 0;
432 // Remove an observer of a single network
433 virtual void RemoveNetworkObserver(const std::string& service_path,
434 NetworkObserver* observer) = 0;
435 // Stop |observer| from observing any networks
436 virtual void RemoveObserverForAllNetworks(NetworkObserver* observer) = 0;
437
438 virtual void AddCellularDataPlanObserver(
439 CellularDataPlanObserver* observer) = 0;
440 virtual void RemoveCellularDataPlanObserver(
441 CellularDataPlanObserver* observer) = 0;
394 442
395 // Return the active Ethernet network (or a default structure if inactive). 443 // Return the active Ethernet network (or a default structure if inactive).
396 virtual EthernetNetwork* ethernet_network() = 0; 444 virtual EthernetNetwork* ethernet_network() = 0;
397 virtual bool ethernet_connecting() const = 0; 445 virtual bool ethernet_connecting() const = 0;
398 virtual bool ethernet_connected() const = 0; 446 virtual bool ethernet_connected() const = 0;
399 447
400 // Return the active Wifi network (or a default structure if none active). 448 // Return the active Wifi network (or a default structure if none active).
401 virtual WifiNetwork* wifi_network() = 0; 449 virtual WifiNetwork* wifi_network() = 0;
402 virtual bool wifi_connecting() const = 0; 450 virtual bool wifi_connecting() const = 0;
403 virtual bool wifi_connected() const = 0; 451 virtual bool wifi_connected() const = 0;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 virtual void ForgetWifiNetwork(const std::string& service_path) = 0; 529 virtual void ForgetWifiNetwork(const std::string& service_path) = 0;
482 530
483 virtual bool ethernet_available() const = 0; 531 virtual bool ethernet_available() const = 0;
484 virtual bool wifi_available() const = 0; 532 virtual bool wifi_available() const = 0;
485 virtual bool cellular_available() const = 0; 533 virtual bool cellular_available() const = 0;
486 534
487 virtual bool ethernet_enabled() const = 0; 535 virtual bool ethernet_enabled() const = 0;
488 virtual bool wifi_enabled() const = 0; 536 virtual bool wifi_enabled() const = 0;
489 virtual bool cellular_enabled() const = 0; 537 virtual bool cellular_enabled() const = 0;
490 538
539 virtual const Network* active_network() const = 0;
540
491 virtual bool offline_mode() const = 0; 541 virtual bool offline_mode() const = 0;
492 542
493 // Enables/disables the ethernet network device. 543 // Enables/disables the ethernet network device.
494 virtual void EnableEthernetNetworkDevice(bool enable) = 0; 544 virtual void EnableEthernetNetworkDevice(bool enable) = 0;
495 545
496 // Enables/disables the wifi network device. 546 // Enables/disables the wifi network device.
497 virtual void EnableWifiNetworkDevice(bool enable) = 0; 547 virtual void EnableWifiNetworkDevice(bool enable) = 0;
498 548
499 // Enables/disables the cellular network device. 549 // Enables/disables the cellular network device.
500 virtual void EnableCellularNetworkDevice(bool enable) = 0; 550 virtual void EnableCellularNetworkDevice(bool enable) = 0;
(...skipping 14 matching lines...) Expand all
515 virtual std::string GetHtmlInfo(int refresh) = 0; 565 virtual std::string GetHtmlInfo(int refresh) = 0;
516 566
517 // Factory function, creates a new instance and returns ownership. 567 // Factory function, creates a new instance and returns ownership.
518 // For normal usage, access the singleton via CrosLibrary::Get(). 568 // For normal usage, access the singleton via CrosLibrary::Get().
519 static NetworkLibrary* GetImpl(bool stub); 569 static NetworkLibrary* GetImpl(bool stub);
520 }; 570 };
521 571
522 } // namespace chromeos 572 } // namespace chromeos
523 573
524 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ 574 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698