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

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

Issue 1142005: Mocks for all libcros elements (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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) 2009 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
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 std::string device_path; 120 std::string device_path;
121 IPConfigType type; 121 IPConfigType type;
122 std::string address; 122 std::string address;
123 std::string netmask; 123 std::string netmask;
124 std::string gateway; 124 std::string gateway;
125 std::string name_servers; 125 std::string name_servers;
126 }; 126 };
127 typedef std::vector<NetworkIPConfig> NetworkIPConfigVector; 127 typedef std::vector<NetworkIPConfig> NetworkIPConfigVector;
128 128
129 // This class handles the interaction with the ChromeOS network library APIs. 129 class NetworkLibrary {
130 // Classes can add themselves as observers. Users can get an instance of this
131 // library class like this: NetworkLibrary::Get()
132 class NetworkLibrary : public URLRequestJobTracker::JobObserver {
133 public: 130 public:
134 class Observer { 131 class Observer {
135 public: 132 public:
136 // A bitfield mask for traffic types. 133 // A bitfield mask for traffic types.
137 enum TrafficTypes { 134 enum TrafficTypes {
138 TRAFFIC_DOWNLOAD = 0x1, 135 TRAFFIC_DOWNLOAD = 0x1,
139 TRAFFIC_UPLOAD = 0x2, 136 TRAFFIC_UPLOAD = 0x2,
140 } TrafficTypeMasks; 137 } TrafficTypeMasks;
141 138
142 // Called when the network has changed. (wifi networks, and ethernet) 139 // Called when the network has changed. (wifi networks, and ethernet)
143 virtual void NetworkChanged(NetworkLibrary* obj) = 0; 140 virtual void NetworkChanged(NetworkLibrary* obj) = 0;
144 141
145 // Called when network traffic has been detected. 142 // Called when network traffic has been detected.
146 // Takes a bitfield of TrafficTypeMasks. 143 // Takes a bitfield of TrafficTypeMasks.
147 virtual void NetworkTraffic(NetworkLibrary* obj, int traffic_type) = 0; 144 virtual void NetworkTraffic(NetworkLibrary* obj, int traffic_type) = 0;
148 }; 145 };
149 146
150 // This gets the singleton NetworkLibrary 147 virtual ~NetworkLibrary() {}
151 static NetworkLibrary* Get(); 148 virtual void AddObserver(Observer* observer) = 0;
149 virtual void RemoveObserver(Observer* observer) = 0;
150
151 virtual const EthernetNetwork& ethernet_network() const = 0;
152 virtual bool ethernet_connecting() const = 0;
153 virtual bool ethernet_connected() const = 0;
154
155 virtual const std::string& wifi_ssid() const = 0;
156 virtual bool wifi_connecting() const = 0;
157 virtual bool wifi_connected() const = 0;
158 virtual int wifi_strength() const = 0;
159
160 virtual const std::string& cellular_name() const = 0;
161 virtual bool cellular_connecting() const = 0;
162 virtual bool cellular_connected() const = 0;
163 virtual int cellular_strength() const = 0;
164
165 // Return true if any network is currently connected.
166 virtual bool Connected() const = 0;
167
168 // Return true if any network is currently connecting.
169 virtual bool Connecting() const = 0;
170
171 // Returns the current IP address if connected. If not, returns empty string.
172 virtual const std::string& IPAddress() const = 0;
173
174 // Returns the current list of wifi networks.
175 virtual const WifiNetworkVector& wifi_networks() const = 0;
176
177 // Returns the current list of cellular networks.
178 virtual const CellularNetworkVector& cellular_networks() const = 0;
179
180 // Request a scan for new wifi networks.
181 virtual void RequestWifiScan() = 0;
182
183 // Connect to the specified wireless network with password.
184 virtual void ConnectToWifiNetwork(WifiNetwork network,
185 const string16& password) = 0;
186
187 // Connect to the specified wifi ssid with password.
188 virtual void ConnectToWifiNetwork(const string16& ssid,
189 const string16& password) = 0;
190
191 // Connect to the specified cellular network.
192 virtual void ConnectToCellularNetwork(CellularNetwork network) = 0;
193
194 virtual bool ethernet_available() const = 0;
195 virtual bool wifi_available() const = 0;
196 virtual bool cellular_available() const = 0;
197
198 virtual bool ethernet_enabled() const = 0;
199 virtual bool wifi_enabled() const = 0;
200 virtual bool cellular_enabled() const = 0;
201
202 virtual bool offline_mode() const = 0;
203
204 // Enables/disables the ethernet network device.
205 virtual void EnableEthernetNetworkDevice(bool enable) = 0;
206
207 // Enables/disables the wifi network device.
208 virtual void EnableWifiNetworkDevice(bool enable) = 0;
209
210 // Enables/disables the cellular network device.
211 virtual void EnableCellularNetworkDevice(bool enable) = 0;
212
213 // Enables/disables offline mode.
214 virtual void EnableOfflineMode(bool enable) = 0;
215
216 // Fetches IP configs for a given device_path
217 virtual NetworkIPConfigVector GetIPConfigs(
218 const std::string& device_path) = 0;
219 };
220
221 // This class handles the interaction with the ChromeOS network library APIs.
222 // Classes can add themselves as observers. Users can get an instance of this
223 // library class like this: NetworkLibrary::Get()
224 class NetworkLibraryImpl : public NetworkLibrary,
225 public URLRequestJobTracker::JobObserver {
226 public:
227 NetworkLibraryImpl();
228 virtual ~NetworkLibraryImpl();
152 229
153 // URLRequestJobTracker::JobObserver methods (called on the IO thread): 230 // URLRequestJobTracker::JobObserver methods (called on the IO thread):
154 virtual void OnJobAdded(URLRequestJob* job); 231 virtual void OnJobAdded(URLRequestJob* job);
155 virtual void OnJobRemoved(URLRequestJob* job); 232 virtual void OnJobRemoved(URLRequestJob* job);
156 virtual void OnJobDone(URLRequestJob* job, const URLRequestStatus& status); 233 virtual void OnJobDone(URLRequestJob* job, const URLRequestStatus& status);
157 virtual void OnJobRedirect(URLRequestJob* job, const GURL& location, 234 virtual void OnJobRedirect(URLRequestJob* job, const GURL& location,
158 int status_code); 235 int status_code);
159 virtual void OnBytesRead(URLRequestJob* job, int byte_count); 236 virtual void OnBytesRead(URLRequestJob* job, int byte_count);
160 237
161 void AddObserver(Observer* observer); 238 // NetworkLibrary overrides.
162 void RemoveObserver(Observer* observer); 239 virtual void AddObserver(Observer* observer);
240 virtual void RemoveObserver(Observer* observer);
163 241
164 const EthernetNetwork& ethernet_network() const { return ethernet_; } 242 virtual const EthernetNetwork& ethernet_network() const { return ethernet_; }
165 bool ethernet_connecting() const { return ethernet_.connecting; } 243 virtual bool ethernet_connecting() const { return ethernet_.connecting; }
166 bool ethernet_connected() const { return ethernet_.connected; } 244 virtual bool ethernet_connected() const { return ethernet_.connected; }
167 245
168 const std::string& wifi_ssid() const { return wifi_.ssid; } 246 virtual const std::string& wifi_ssid() const { return wifi_.ssid; }
169 bool wifi_connecting() const { return wifi_.connecting; } 247 virtual bool wifi_connecting() const { return wifi_.connecting; }
170 bool wifi_connected() const { return wifi_.connected; } 248 virtual bool wifi_connected() const { return wifi_.connected; }
171 int wifi_strength() const { return wifi_.strength; } 249 virtual int wifi_strength() const { return wifi_.strength; }
172 250
173 const std::string& cellular_name() const { return cellular_.name; } 251 virtual const std::string& cellular_name() const { return cellular_.name; }
174 bool cellular_connecting() const { return cellular_.connecting; } 252 virtual bool cellular_connecting() const { return cellular_.connecting; }
175 bool cellular_connected() const { return cellular_.connected; } 253 virtual bool cellular_connected() const { return cellular_.connected; }
176 int cellular_strength() const { return cellular_.strength; } 254 virtual int cellular_strength() const { return cellular_.strength; }
177 255
178 // Return true if any network is currently connected. 256 // Return true if any network is currently connected.
179 bool Connected() const; 257 virtual bool Connected() const;
180 258
181 // Return true if any network is currently connecting. 259 // Return true if any network is currently connecting.
182 bool Connecting() const; 260 virtual bool Connecting() const;
183 261
184 // Returns the current IP address if connected. If not, returns empty string. 262 // Returns the current IP address if connected. If not, returns empty string.
185 const std::string& IPAddress() const; 263 virtual const std::string& IPAddress() const;
186 264
187 // Returns the current list of wifi networks. 265 // Returns the current list of wifi networks.
188 const WifiNetworkVector& wifi_networks() const { return wifi_networks_; } 266 virtual const WifiNetworkVector& wifi_networks() const {
267 return wifi_networks_;
268 }
189 269
190 // Returns the current list of cellular networks. 270 // Returns the current list of cellular networks.
191 const CellularNetworkVector& cellular_networks() const { 271 virtual const CellularNetworkVector& cellular_networks() const {
192 return cellular_networks_; 272 return cellular_networks_;
193 } 273 }
194 274
195 // Request a scan for new wifi networks. 275 // Request a scan for new wifi networks.
196 void RequestWifiScan(); 276 virtual void RequestWifiScan();
197 277
198 // Connect to the specified wireless network with password. 278 // Connect to the specified wireless network with password.
199 void ConnectToWifiNetwork(WifiNetwork network, const string16& password); 279 virtual void ConnectToWifiNetwork(WifiNetwork network,
280 const string16& password);
200 281
201 // Connect to the specified wifi ssid with password. 282 // Connect to the specified wifi ssid with password.
202 void ConnectToWifiNetwork(const string16& ssid, const string16& password); 283 virtual void ConnectToWifiNetwork(const string16& ssid,
284 const string16& password);
203 285
204 // Connect to the specified cellular network. 286 // Connect to the specified cellular network.
205 void ConnectToCellularNetwork(CellularNetwork network); 287 virtual void ConnectToCellularNetwork(CellularNetwork network);
206 288
207 bool ethernet_available() const { 289 virtual bool ethernet_available() const {
208 return available_devices_ & (1 << TYPE_ETHERNET); } 290 return available_devices_ & (1 << TYPE_ETHERNET); }
209 bool wifi_available() const { 291 virtual bool wifi_available() const {
210 return available_devices_ & (1 << TYPE_WIFI); } 292 return available_devices_ & (1 << TYPE_WIFI); }
211 bool cellular_available() const { 293 virtual bool cellular_available() const {
212 return available_devices_ & (1 << TYPE_CELLULAR); } 294 return available_devices_ & (1 << TYPE_CELLULAR); }
213 295
214 bool ethernet_enabled() const { 296 virtual bool ethernet_enabled() const {
215 return enabled_devices_ & (1 << TYPE_ETHERNET); } 297 return enabled_devices_ & (1 << TYPE_ETHERNET); }
216 bool wifi_enabled() const { 298 virtual bool wifi_enabled() const {
217 return enabled_devices_ & (1 << TYPE_WIFI); } 299 return enabled_devices_ & (1 << TYPE_WIFI); }
218 bool cellular_enabled() const { 300 virtual bool cellular_enabled() const {
219 return enabled_devices_ & (1 << TYPE_CELLULAR); } 301 return enabled_devices_ & (1 << TYPE_CELLULAR); }
220 302
221 bool offline_mode() const { return offline_mode_; } 303 virtual bool offline_mode() const { return offline_mode_; }
222 304
223 // Enables/disables the ethernet network device. 305 // Enables/disables the ethernet network device.
224 void EnableEthernetNetworkDevice(bool enable); 306 virtual void EnableEthernetNetworkDevice(bool enable);
225 307
226 // Enables/disables the wifi network device. 308 // Enables/disables the wifi network device.
227 void EnableWifiNetworkDevice(bool enable); 309 virtual void EnableWifiNetworkDevice(bool enable);
228 310
229 // Enables/disables the cellular network device. 311 // Enables/disables the cellular network device.
230 void EnableCellularNetworkDevice(bool enable); 312 virtual void EnableCellularNetworkDevice(bool enable);
231 313
232 // Enables/disables offline mode. 314 // Enables/disables offline mode.
233 void EnableOfflineMode(bool enable); 315 virtual void EnableOfflineMode(bool enable);
234 316
235 // Fetches IP configs for a given device_path 317 // Fetches IP configs for a given device_path
236 NetworkIPConfigVector GetIPConfigs(const std::string& device_path); 318 virtual NetworkIPConfigVector GetIPConfigs(const std::string& device_path);
237 319
238 private: 320 private:
239 friend struct DefaultSingletonTraits<NetworkLibrary>;
240
241 NetworkLibrary();
242 ~NetworkLibrary();
243 321
244 // This method is called when there's a change in network status. 322 // This method is called when there's a change in network status.
245 // This method is called on a background thread. 323 // This method is called on a background thread.
246 static void NetworkStatusChangedHandler(void* object); 324 static void NetworkStatusChangedHandler(void* object);
247 325
248 // This parses SystemInfo and creates a WifiNetworkVector of wifi networks 326 // This parses SystemInfo and creates a WifiNetworkVector of wifi networks
249 // and a CellularNetworkVector of cellular networks. 327 // and a CellularNetworkVector of cellular networks.
250 // It also sets the ethernet connecting/connected status. 328 // It also sets the ethernet connecting/connected status.
251 static void ParseSystem(SystemInfo* system, 329 static void ParseSystem(SystemInfo* system,
252 EthernetNetwork* ethernet, 330 EthernetNetwork* ethernet,
(...skipping 27 matching lines...) Expand all
280 // This will notify all obeservers on the UI thread. 358 // This will notify all obeservers on the UI thread.
281 void NotifyObservers(); 359 void NotifyObservers();
282 360
283 ObserverList<Observer> observers_; 361 ObserverList<Observer> observers_;
284 362
285 // The amount of time to wait between each NetworkTraffic notifications. 363 // The amount of time to wait between each NetworkTraffic notifications.
286 static const int kNetworkTrafficeTimerSecs; 364 static const int kNetworkTrafficeTimerSecs;
287 365
288 // Timer for sending NetworkTraffic notification every 366 // Timer for sending NetworkTraffic notification every
289 // kNetworkTrafficeTimerSecs seconds. 367 // kNetworkTrafficeTimerSecs seconds.
290 base::OneShotTimer<NetworkLibrary> timer_; 368 base::OneShotTimer<NetworkLibraryImpl> timer_;
291 369
292 // The current traffic type that will be sent out for the next NetworkTraffic 370 // The current traffic type that will be sent out for the next NetworkTraffic
293 // notification. This is a bitfield of TrafficTypeMasks. 371 // notification. This is a bitfield of TrafficTypeMasks.
294 int traffic_type_; 372 int traffic_type_;
295 373
296 // The network status connection for monitoring network status changes. 374 // The network status connection for monitoring network status changes.
297 MonitorNetworkConnection network_status_connection_; 375 MonitorNetworkConnection network_status_connection_;
298 376
299 // The ethernet network. 377 // The ethernet network.
300 EthernetNetwork ethernet_; 378 EthernetNetwork ethernet_;
(...skipping 14 matching lines...) Expand all
315 int available_devices_; 393 int available_devices_;
316 394
317 // The current enabled network devices. Bitwise flag of ConnectionTypes. 395 // The current enabled network devices. Bitwise flag of ConnectionTypes.
318 int enabled_devices_; 396 int enabled_devices_;
319 397
320 // The current connected network devices. Bitwise flag of ConnectionTypes. 398 // The current connected network devices. Bitwise flag of ConnectionTypes.
321 int connected_devices_; 399 int connected_devices_;
322 400
323 bool offline_mode_; 401 bool offline_mode_;
324 402
325 DISALLOW_COPY_AND_ASSIGN(NetworkLibrary); 403 DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImpl);
326 }; 404 };
327 405
328 } // namespace chromeos 406 } // namespace chromeos
329 407
330 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ 408 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/mount_library.cc ('k') | chrome/browser/chromeos/cros/network_library.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698