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

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

Issue 2010001: Refactor WifiNetwork, CellularNetwork, and EthernetNetwork into classes to ma... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 7 months 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) 2009 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 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "base/platform_thread.h" 12 #include "base/platform_thread.h"
13 #include "base/singleton.h" 13 #include "base/singleton.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "base/timer.h" 15 #include "base/timer.h"
16 #include "net/url_request/url_request_job_tracker.h" 16 #include "net/url_request/url_request_job_tracker.h"
17 #include "third_party/cros/chromeos_network.h" 17 #include "third_party/cros/chromeos_network.h"
18 18
19 namespace chromeos { 19 namespace chromeos {
20 20
21 struct EthernetNetwork { 21 class Network {
22 EthernetNetwork() 22 public:
23 : connecting(false), 23 const std::string& service_path() const { return service_path_; }
24 connected(false) {} 24 const std::string& device_path() const { return device_path_; }
25 const std::string& ip_address() const { return ip_address_; }
26 bool connecting() const { return connecting_; }
27 bool connected() const { return connected_; }
28 bool connecting_or_connected() const { return connecting_ || connected_; }
25 29
26 std::string device_path; 30 void set_connecting(bool connecting) { connecting_ = connecting; }
27 std::string ip_address; 31 void set_connected(bool connected) { connected_ = connected; }
28 bool connecting; 32
29 bool connected; 33 // Clear the fields.
34 virtual void Clear();
35
36 // Configure the Network from a ServiceInfo object.
37 virtual void ConfigureFromService(const ServiceInfo& service);
38
39 protected:
40 Network()
41 : connecting_(false),
42 connected_(false) {}
43 virtual ~Network() {}
44
45 private:
46 std::string service_path_;
47 std::string device_path_;
48 std::string ip_address_;
49 bool connecting_;
50 bool connected_;
30 }; 51 };
31 52
32 struct WifiNetwork { 53 class EthernetNetwork : public Network {
33 WifiNetwork() 54 public:
34 : encrypted(false), 55 EthernetNetwork() : Network() {}
35 encryption(SECURITY_UNKNOWN), 56 };
36 strength(0),
37 connecting(false),
38 connected(false),
39 auto_connect(false) {}
40 WifiNetwork(ServiceInfo service, bool connecting, bool connected,
41 const std::string& ip_address)
42 : service_path(service.service_path),
43 device_path(service.device_path),
44 ssid(service.name),
45 encrypted(service.security != SECURITY_NONE),
46 encryption(service.security),
47 passphrase(service.passphrase),
48 strength(service.strength),
49 connecting(connecting),
50 connected(connected),
51 auto_connect(service.auto_connect),
52 ip_address(ip_address) {}
53 57
54 // WifiNetworks are sorted by ssids. 58 class WirelessNetwork : public Network {
55 bool operator< (const WifiNetwork& other) const { 59 public:
56 return ssid < other.ssid; 60 // WirelessNetwork are sorted by name.
61 bool operator< (const WirelessNetwork& other) const {
62 return name_ < other.name();
57 } 63 }
58 64
59 std::string service_path; 65 const std::string& name() const { return name_; }
60 std::string device_path; 66 int strength() const { return strength_; }
61 std::string ssid; 67 bool auto_connect() const { return auto_connect_; }
62 bool encrypted; 68
63 ConnectionSecurity encryption; 69 void set_name(const std::string& name) { name_ = name; }
64 std::string passphrase; 70 void set_auto_connect(bool auto_connect) { auto_connect_ = auto_connect; }
65 int strength; 71
66 bool connecting; 72 // Network overrides.
67 bool connected; 73 virtual void Clear();
68 bool auto_connect; 74 virtual void ConfigureFromService(const ServiceInfo& service);
69 std::string ip_address; 75
76 protected:
77 WirelessNetwork()
78 : Network(),
79 strength_(0),
80 auto_connect_(false) {}
81
82 private:
83 std::string name_;
84 int strength_;
85 bool auto_connect_;
70 }; 86 };
71 typedef std::vector<WifiNetwork> WifiNetworkVector;
72 87
73 struct CellularNetwork { 88 class CellularNetwork : public WirelessNetwork {
74 CellularNetwork() 89 public:
75 : strength(strength), 90 CellularNetwork() : WirelessNetwork() {}
76 connecting(false), 91 explicit CellularNetwork(const ServiceInfo& service)
77 connected(false), 92 : WirelessNetwork() {
78 auto_connect(false) {} 93 ConfigureFromService(service);
79 CellularNetwork(ServiceInfo service, bool connecting, bool connected, 94 }
80 const std::string& ip_address) 95 };
81 : service_path(service.service_path),
82 device_path(service.device_path),
83 name(service.name),
84 strength(service.strength),
85 connecting(connecting),
86 connected(connected),
87 auto_connect(service.auto_connect),
88 ip_address(ip_address) {}
89 96
90 // CellularNetworks are sorted by name. 97 class WifiNetwork : public WirelessNetwork {
91 bool operator< (const CellularNetwork& other) const { 98 public:
92 return name < other.name; 99 WifiNetwork()
100 : WirelessNetwork(),
101 encryption_(SECURITY_NONE) {}
102 explicit WifiNetwork(const ServiceInfo& service)
103 : WirelessNetwork() {
104 ConfigureFromService(service);
93 } 105 }
94 106
95 std::string service_path; 107 bool encrypted() const { return encryption_ != SECURITY_NONE; }
96 std::string device_path; 108 ConnectionSecurity encryption() const { return encryption_; }
97 std::string name; 109 const std::string& passphrase() const { return passphrase_; }
98 int strength; 110
99 bool connecting; 111 void set_encryption(ConnectionSecurity encryption) {
100 bool connected; 112 encryption_ = encryption;
101 bool auto_connect; 113 }
102 std::string ip_address; 114 void set_passphrase(const std::string& passphrase) {
115 passphrase_ = passphrase;
116 }
117
118 // WirelessNetwork overrides.
119 virtual void Clear();
120 virtual void ConfigureFromService(const ServiceInfo& service);
121
122 private:
123 ConnectionSecurity encryption_;
124 std::string passphrase_;
103 }; 125 };
126
127 typedef std::vector<WifiNetwork> WifiNetworkVector;
104 typedef std::vector<CellularNetwork> CellularNetworkVector; 128 typedef std::vector<CellularNetwork> CellularNetworkVector;
105 129
106 struct NetworkIPConfig { 130 struct NetworkIPConfig {
107 NetworkIPConfig(const std::string& device_path, IPConfigType type, 131 NetworkIPConfig(const std::string& device_path, IPConfigType type,
108 const std::string& address, const std::string& netmask, 132 const std::string& address, const std::string& netmask,
109 const std::string& gateway, const std::string& name_servers) 133 const std::string& gateway, const std::string& name_servers)
110 : device_path(device_path), 134 : device_path(device_path),
111 type(type), 135 type(type),
112 address(address), 136 address(address),
113 netmask(netmask), 137 netmask(netmask),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 }; 171 };
148 172
149 virtual ~NetworkLibrary() {} 173 virtual ~NetworkLibrary() {}
150 virtual void AddObserver(Observer* observer) = 0; 174 virtual void AddObserver(Observer* observer) = 0;
151 virtual void RemoveObserver(Observer* observer) = 0; 175 virtual void RemoveObserver(Observer* observer) = 0;
152 176
153 virtual const EthernetNetwork& ethernet_network() const = 0; 177 virtual const EthernetNetwork& ethernet_network() const = 0;
154 virtual bool ethernet_connecting() const = 0; 178 virtual bool ethernet_connecting() const = 0;
155 virtual bool ethernet_connected() const = 0; 179 virtual bool ethernet_connected() const = 0;
156 180
157 virtual const std::string& wifi_ssid() const = 0; 181 virtual const std::string& wifi_name() const = 0;
158 virtual bool wifi_connecting() const = 0; 182 virtual bool wifi_connecting() const = 0;
159 virtual bool wifi_connected() const = 0; 183 virtual bool wifi_connected() const = 0;
160 virtual int wifi_strength() const = 0; 184 virtual int wifi_strength() const = 0;
161 185
162 virtual const std::string& cellular_name() const = 0; 186 virtual const std::string& cellular_name() const = 0;
163 virtual bool cellular_connecting() const = 0; 187 virtual bool cellular_connecting() const = 0;
164 virtual bool cellular_connected() const = 0; 188 virtual bool cellular_connected() const = 0;
165 virtual int cellular_strength() const = 0; 189 virtual int cellular_strength() const = 0;
166 190
167 // Return true if any network is currently connected. 191 // Return true if any network is currently connected.
(...skipping 29 matching lines...) Expand all
197 // Connect to the specified wifi ssid with password. 221 // Connect to the specified wifi ssid with password.
198 virtual void ConnectToWifiNetwork(const string16& ssid, 222 virtual void ConnectToWifiNetwork(const string16& ssid,
199 const string16& password, 223 const string16& password,
200 const string16& identity, 224 const string16& identity,
201 const string16& certpath, 225 const string16& certpath,
202 bool auto_connect) = 0; 226 bool auto_connect) = 0;
203 227
204 // Connect to the specified cellular network. 228 // Connect to the specified cellular network.
205 virtual void ConnectToCellularNetwork(CellularNetwork network) = 0; 229 virtual void ConnectToCellularNetwork(CellularNetwork network) = 0;
206 230
207 // Disconnect from the specified wifi network. 231 // Disconnect from the specified wireless (either cellular or wifi) network.
208 virtual void DisconnectFromWifiNetwork(const WifiNetwork& network) = 0; 232 virtual void DisconnectFromWirelessNetwork(
209 233 const WirelessNetwork& network) = 0;
210 // Disconnect from the specified cellular network.
211 virtual void DisconnectFromCellularNetwork(
212 const CellularNetwork& network) = 0;
213 234
214 // Set whether or not to auto-connect to this network. 235 // Set whether or not to auto-connect to this network.
215 virtual void SaveWifiNetwork(const WifiNetwork& network) = 0; 236 virtual void SaveWifiNetwork(const WifiNetwork& network) = 0;
216 237
217 // Forget the passed in wifi network. 238 // Forget the passed in wireless (either cellular or wifi) network.
218 virtual void ForgetWifiNetwork(const WifiNetwork& network) = 0; 239 virtual void ForgetWirelessNetwork(const WirelessNetwork& network) = 0;
219
220 // Forget the passed in cellular network.
221 virtual void ForgetCellularNetwork(const CellularNetwork& network) = 0;
222 240
223 virtual bool ethernet_available() const = 0; 241 virtual bool ethernet_available() const = 0;
224 virtual bool wifi_available() const = 0; 242 virtual bool wifi_available() const = 0;
225 virtual bool cellular_available() const = 0; 243 virtual bool cellular_available() const = 0;
226 244
227 virtual bool ethernet_enabled() const = 0; 245 virtual bool ethernet_enabled() const = 0;
228 virtual bool wifi_enabled() const = 0; 246 virtual bool wifi_enabled() const = 0;
229 virtual bool cellular_enabled() const = 0; 247 virtual bool cellular_enabled() const = 0;
230 248
231 virtual bool offline_mode() const = 0; 249 virtual bool offline_mode() const = 0;
(...skipping 30 matching lines...) Expand all
262 virtual void OnJobDone(URLRequestJob* job, const URLRequestStatus& status); 280 virtual void OnJobDone(URLRequestJob* job, const URLRequestStatus& status);
263 virtual void OnJobRedirect(URLRequestJob* job, const GURL& location, 281 virtual void OnJobRedirect(URLRequestJob* job, const GURL& location,
264 int status_code); 282 int status_code);
265 virtual void OnBytesRead(URLRequestJob* job, int byte_count); 283 virtual void OnBytesRead(URLRequestJob* job, int byte_count);
266 284
267 // NetworkLibrary overrides. 285 // NetworkLibrary overrides.
268 virtual void AddObserver(Observer* observer); 286 virtual void AddObserver(Observer* observer);
269 virtual void RemoveObserver(Observer* observer); 287 virtual void RemoveObserver(Observer* observer);
270 288
271 virtual const EthernetNetwork& ethernet_network() const { return ethernet_; } 289 virtual const EthernetNetwork& ethernet_network() const { return ethernet_; }
272 virtual bool ethernet_connecting() const { return ethernet_.connecting; } 290 virtual bool ethernet_connecting() const { return ethernet_.connecting(); }
273 virtual bool ethernet_connected() const { return ethernet_.connected; } 291 virtual bool ethernet_connected() const { return ethernet_.connected(); }
274 292
275 virtual const std::string& wifi_ssid() const { return wifi_.ssid; } 293 virtual const std::string& wifi_name() const { return wifi_.name(); }
276 virtual bool wifi_connecting() const { return wifi_.connecting; } 294 virtual bool wifi_connecting() const { return wifi_.connecting(); }
277 virtual bool wifi_connected() const { return wifi_.connected; } 295 virtual bool wifi_connected() const { return wifi_.connected(); }
278 virtual int wifi_strength() const { return wifi_.strength; } 296 virtual int wifi_strength() const { return wifi_.strength(); }
279 297
280 virtual const std::string& cellular_name() const { return cellular_.name; } 298 virtual const std::string& cellular_name() const { return cellular_.name(); }
281 virtual bool cellular_connecting() const { return cellular_.connecting; } 299 virtual bool cellular_connecting() const { return cellular_.connecting(); }
282 virtual bool cellular_connected() const { return cellular_.connected; } 300 virtual bool cellular_connected() const { return cellular_.connected(); }
283 virtual int cellular_strength() const { return cellular_.strength; } 301 virtual int cellular_strength() const { return cellular_.strength(); }
284 302
285 // Return true if any network is currently connected. 303 // Return true if any network is currently connected.
286 virtual bool Connected() const; 304 virtual bool Connected() const;
287 305
288 // Return true if any network is currently connecting. 306 // Return true if any network is currently connecting.
289 virtual bool Connecting() const; 307 virtual bool Connecting() const;
290 308
291 // Returns the current IP address if connected. If not, returns empty string. 309 // Returns the current IP address if connected. If not, returns empty string.
292 virtual const std::string& IPAddress() const; 310 virtual const std::string& IPAddress() const;
293 311
(...skipping 29 matching lines...) Expand all
323 // Connect to the specified wifi ssid with password. 341 // Connect to the specified wifi ssid with password.
324 virtual void ConnectToWifiNetwork(const string16& ssid, 342 virtual void ConnectToWifiNetwork(const string16& ssid,
325 const string16& password, 343 const string16& password,
326 const string16& identity, 344 const string16& identity,
327 const string16& certpath, 345 const string16& certpath,
328 bool auto_connect); 346 bool auto_connect);
329 347
330 // Connect to the specified cellular network. 348 // Connect to the specified cellular network.
331 virtual void ConnectToCellularNetwork(CellularNetwork network); 349 virtual void ConnectToCellularNetwork(CellularNetwork network);
332 350
333 // Disconnect from the specified wifi network. 351 // Disconnect from the specified wireless (either cellular or wifi) network.
334 virtual void DisconnectFromWifiNetwork(const WifiNetwork& network); 352 virtual void DisconnectFromWirelessNetwork(const WirelessNetwork& network);
335
336 // Disconnect from the specified cellular network.
337 virtual void DisconnectFromCellularNetwork(const CellularNetwork& network);
338 353
339 // Set whether or not to auto-connect to this network. 354 // Set whether or not to auto-connect to this network.
340 virtual void SaveWifiNetwork(const WifiNetwork& network); 355 virtual void SaveWifiNetwork(const WifiNetwork& network);
341 356
342 // Forget the passed in wifi network. 357 // Forget the passed in wireless (either cellular or wifi) network.
343 virtual void ForgetWifiNetwork(const WifiNetwork& network); 358 virtual void ForgetWirelessNetwork(const WirelessNetwork& network);
344
345 // Forget the passed in cellular network.
346 virtual void ForgetCellularNetwork(const CellularNetwork& network);
347 359
348 virtual bool ethernet_available() const { 360 virtual bool ethernet_available() const {
349 return available_devices_ & (1 << TYPE_ETHERNET); } 361 return available_devices_ & (1 << TYPE_ETHERNET);
362 }
350 virtual bool wifi_available() const { 363 virtual bool wifi_available() const {
351 return available_devices_ & (1 << TYPE_WIFI); } 364 return available_devices_ & (1 << TYPE_WIFI);
365 }
352 virtual bool cellular_available() const { 366 virtual bool cellular_available() const {
353 return available_devices_ & (1 << TYPE_CELLULAR); } 367 return available_devices_ & (1 << TYPE_CELLULAR);
368 }
354 369
355 virtual bool ethernet_enabled() const { 370 virtual bool ethernet_enabled() const {
356 return enabled_devices_ & (1 << TYPE_ETHERNET); } 371 return enabled_devices_ & (1 << TYPE_ETHERNET);
372 }
357 virtual bool wifi_enabled() const { 373 virtual bool wifi_enabled() const {
358 return enabled_devices_ & (1 << TYPE_WIFI); } 374 return enabled_devices_ & (1 << TYPE_WIFI);
375 }
359 virtual bool cellular_enabled() const { 376 virtual bool cellular_enabled() const {
360 return enabled_devices_ & (1 << TYPE_CELLULAR); } 377 return enabled_devices_ & (1 << TYPE_CELLULAR);
378 }
361 379
362 virtual bool offline_mode() const { return offline_mode_; } 380 virtual bool offline_mode() const { return offline_mode_; }
363 381
364 // Enables/disables the ethernet network device. 382 // Enables/disables the ethernet network device.
365 virtual void EnableEthernetNetworkDevice(bool enable); 383 virtual void EnableEthernetNetworkDevice(bool enable);
366 384
367 // Enables/disables the wifi network device. 385 // Enables/disables the wifi network device.
368 virtual void EnableWifiNetworkDevice(bool enable); 386 virtual void EnableWifiNetworkDevice(bool enable);
369 387
370 // Enables/disables the cellular network device. 388 // Enables/disables the cellular network device.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 int connected_devices_; 487 int connected_devices_;
470 488
471 bool offline_mode_; 489 bool offline_mode_;
472 490
473 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImpl); 491 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImpl);
474 }; 492 };
475 493
476 } // namespace chromeos 494 } // namespace chromeos
477 495
478 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ 496 #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