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

Side by Side Diff: chrome/browser/chromeos/cros_network_library.h

Issue 315008: New wifi icons animation. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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) 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
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"
16 #include "net/url_request/url_request_job_tracker.h"
15 #include "third_party/cros/chromeos_network.h" 17 #include "third_party/cros/chromeos_network.h"
16 18
17 struct WifiNetwork { 19 struct WifiNetwork {
18 WifiNetwork() 20 WifiNetwork()
19 : encrypted(false), 21 : encrypted(false),
20 encryption(chromeos::NONE), 22 encryption(chromeos::NONE),
21 strength(0), 23 strength(0),
22 connecting(false), 24 connecting(false),
23 connected(false), 25 connected(false),
24 destroyed(false) {} 26 destroyed(false) {}
(...skipping 19 matching lines...) Expand all
44 int strength; 46 int strength;
45 bool connecting; 47 bool connecting;
46 bool connected; 48 bool connected;
47 bool destroyed; 49 bool destroyed;
48 }; 50 };
49 typedef std::vector<WifiNetwork> WifiNetworkVector; 51 typedef std::vector<WifiNetwork> WifiNetworkVector;
50 52
51 // This class handles the interaction with the ChromeOS network library APIs. 53 // This class handles the interaction with the ChromeOS network library APIs.
52 // Classes can add themselves as observers. Users can get an instance of this 54 // Classes can add themselves as observers. Users can get an instance of this
53 // library class like this: CrosNetworkLibrary::Get() 55 // library class like this: CrosNetworkLibrary::Get()
54 class CrosNetworkLibrary { 56 class CrosNetworkLibrary : public URLRequestJobTracker::JobObserver {
55 public: 57 public:
56 class Observer { 58 class Observer {
57 public: 59 public:
60 // A bitfield mask for traffic types.
61 enum TrafficTypes {
62 TRAFFIC_DOWNLOAD = 0x1,
63 TRAFFIC_UPLOAD = 0x2,
64 } TrafficTypeMasks;
65
66 // Called when the network has changed. (wifi networks, and ethernet)
58 virtual void NetworkChanged(CrosNetworkLibrary* obj) = 0; 67 virtual void NetworkChanged(CrosNetworkLibrary* obj) = 0;
68
69 // Called when network traffic has been detected.
70 // Takes a bitfield of TrafficTypeMasks.
71 virtual void NetworkTraffic(CrosNetworkLibrary* obj, int traffic_type) = 0;
59 }; 72 };
60 73
61 // This gets the singleton CrosNetworkLibrary 74 // This gets the singleton CrosNetworkLibrary
62 static CrosNetworkLibrary* Get(); 75 static CrosNetworkLibrary* Get();
63 76
64 // Returns true if the ChromeOS library was loaded. 77 // Returns true if the ChromeOS library was loaded.
65 static bool loaded(); 78 static bool loaded();
66 79
80 // URLRequestJobTracker::JobObserver methods (called on the IO thread):
81 virtual void OnJobAdded(URLRequestJob* job);
82 virtual void OnJobRemoved(URLRequestJob* job);
83 virtual void OnJobDone(URLRequestJob* job, const URLRequestStatus& status);
84 virtual void OnJobRedirect(URLRequestJob* job, const GURL& location,
85 int status_code);
86 virtual void OnBytesRead(URLRequestJob* job, int byte_count);
87
67 void AddObserver(Observer* observer); 88 void AddObserver(Observer* observer);
68 void RemoveObserver(Observer* observer); 89 void RemoveObserver(Observer* observer);
69 90
70 bool ethernet_connected() const { return ethernet_connected_; } 91 bool ethernet_connected() const { return ethernet_connected_; }
71 const std::string& wifi_ssid() const { return wifi_.ssid; } 92 const std::string& wifi_ssid() const { return wifi_.ssid; }
72 bool wifi_connecting() const { return wifi_.connecting; } 93 bool wifi_connecting() const { return wifi_.connecting; }
73 int wifi_strength() const { return wifi_.strength; } 94 int wifi_strength() const { return wifi_.strength; }
74 95
75 // Returns the current list of wifi networks. 96 // Returns the current list of wifi networks.
76 const WifiNetworkVector& wifi_networks() const { return wifi_networks_; } 97 const WifiNetworkVector& wifi_networks() const { return wifi_networks_; }
(...skipping 20 matching lines...) Expand all
97 118
98 // This methods loads the initial list of networks on startup and starts the 119 // This methods loads the initial list of networks on startup and starts the
99 // monitoring of network changes. 120 // monitoring of network changes.
100 void Init(); 121 void Init();
101 122
102 // Update the network with the a list of wifi networks and ethernet status. 123 // Update the network with the a list of wifi networks and ethernet status.
103 // This will notify all the Observers. 124 // This will notify all the Observers.
104 void UpdateNetworkStatus(const WifiNetworkVector& networks, 125 void UpdateNetworkStatus(const WifiNetworkVector& networks,
105 bool ethernet_connected); 126 bool ethernet_connected);
106 127
128 // Checks network traffic to see if there is any uploading.
129 // If there is download traffic, then true is passed in for download.
130 // If there is network traffic then start timer that invokes
131 // NetworkTrafficTimerFired.
132 void CheckNetworkTraffic(bool download);
133
134 // Called when the timer fires and we need to send out NetworkTraffic
135 // notifications.
136 void NetworkTrafficTimerFired();
137
138 // This is a helper method to notify the observers on the UI thread.
139 void NotifyNetworkTraffic(int traffic_type);
140
141 // This will notify all obeservers on the UI thread.
142 void NotifyObservers();
143
107 ObserverList<Observer> observers_; 144 ObserverList<Observer> observers_;
108 145
146 // The amount of time to wait between each NetworkTraffic notifications.
147 static const int kNetworkTrafficeTimerSecs;
148
149 // Timer for sending NetworkTraffic notification every
150 // kNetworkTrafficeTimerSecs seconds.
151 base::OneShotTimer<CrosNetworkLibrary> timer_;
152
153 // The current traffic type that will be sent out for the next NetworkTraffic
154 // notification. This is a bitfield of TrafficTypeMasks.
155 int traffic_type_;
156
109 // The network status connection for monitoring network status changes. 157 // The network status connection for monitoring network status changes.
110 chromeos::NetworkStatusConnection network_status_connection_; 158 chromeos::NetworkStatusConnection network_status_connection_;
111 159
112 // Whether or not we are connected to the ethernet line. 160 // Whether or not we are connected to the ethernet line.
113 bool ethernet_connected_; 161 bool ethernet_connected_;
114 162
115 // The list of available wifi networks. 163 // The list of available wifi networks.
116 WifiNetworkVector wifi_networks_; 164 WifiNetworkVector wifi_networks_;
117 165
118 // The current connected (or connecting) wifi network. 166 // The current connected (or connecting) wifi network.
119 WifiNetwork wifi_; 167 WifiNetwork wifi_;
120 168
121 DISALLOW_COPY_AND_ASSIGN(CrosNetworkLibrary); 169 DISALLOW_COPY_AND_ASSIGN(CrosNetworkLibrary);
122 }; 170 };
123 171
124 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ 172 #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698