OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ |
6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/hash_tables.h" | 13 #include "base/hash_tables.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
19 #include "base/time.h" | 19 #include "base/time.h" |
20 #include "chrome/browser/captive_portal/captive_portal_detector.h" | 20 #include "chrome/browser/captive_portal/captive_portal_detector.h" |
21 #include "chrome/browser/chromeos/cros/network_library.h" | |
22 #include "chrome/browser/chromeos/net/network_portal_detector.h" | 21 #include "chrome/browser/chromeos/net/network_portal_detector.h" |
22 #include "chromeos/network/network_state_handler_observer.h" | |
23 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
24 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
26 #include "net/url_request/url_fetcher.h" | 26 #include "net/url_request/url_fetcher.h" |
27 | 27 |
28 namespace net { | 28 namespace net { |
29 class URLRequestContextGetter; | 29 class URLRequestContextGetter; |
30 } | 30 } |
31 | 31 |
32 namespace chromeos { | 32 namespace chromeos { |
33 | 33 |
34 class NetworkState; | |
35 | |
34 // This class handles all notifications about network changes from | 36 // This class handles all notifications about network changes from |
35 // NetworkLibrary and delegates portal detection for the active | 37 // NetworkLibrary and delegates portal detection for the default |
36 // network to CaptivePortalService. | 38 // network to CaptivePortalService. |
37 class NetworkPortalDetectorImpl | 39 class NetworkPortalDetectorImpl |
38 : public NetworkPortalDetector, | 40 : public NetworkPortalDetector, |
39 public base::NonThreadSafe, | 41 public base::NonThreadSafe, |
40 public chromeos::NetworkLibrary::NetworkManagerObserver, | 42 public chromeos::NetworkStateHandlerObserver, |
41 public chromeos::NetworkLibrary::NetworkObserver, | |
42 public content::NotificationObserver { | 43 public content::NotificationObserver { |
43 public: | 44 public: |
44 explicit NetworkPortalDetectorImpl( | 45 explicit NetworkPortalDetectorImpl( |
45 const scoped_refptr<net::URLRequestContextGetter>& request_context); | 46 const scoped_refptr<net::URLRequestContextGetter>& request_context); |
46 virtual ~NetworkPortalDetectorImpl(); | 47 virtual ~NetworkPortalDetectorImpl(); |
47 | 48 |
48 // NetworkPortalDetector implementation: | 49 // NetworkPortalDetector implementation: |
49 virtual void Init() OVERRIDE; | 50 virtual void Init() OVERRIDE; |
50 virtual void Shutdown() OVERRIDE; | 51 virtual void Shutdown() OVERRIDE; |
51 virtual void AddObserver(Observer* observer) OVERRIDE; | 52 virtual void AddObserver(Observer* observer) OVERRIDE; |
52 virtual void AddAndFireObserver(Observer* observer) OVERRIDE; | 53 virtual void AddAndFireObserver(Observer* observer) OVERRIDE; |
53 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 54 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
54 virtual CaptivePortalState GetCaptivePortalState( | 55 virtual CaptivePortalState GetCaptivePortalState( |
55 const chromeos::Network* network) OVERRIDE; | 56 const chromeos::NetworkState* network) OVERRIDE; |
56 virtual bool IsEnabled() OVERRIDE; | 57 virtual bool IsEnabled() OVERRIDE; |
57 virtual void Enable(bool start_detection) OVERRIDE; | 58 virtual void Enable(bool start_detection) OVERRIDE; |
58 virtual void EnableLazyDetection() OVERRIDE; | 59 virtual void EnableLazyDetection() OVERRIDE; |
59 virtual void DisableLazyDetection() OVERRIDE; | 60 virtual void DisableLazyDetection() OVERRIDE; |
60 | 61 |
61 // NetworkLibrary::NetworkManagerObserver implementation: | 62 // NetworkStateHandlerObserver implementation: |
62 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* cros) OVERRIDE; | 63 virtual void NetworkManagerChanged() OVERRIDE; |
63 | 64 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE; |
64 // NetworkLibrary::NetworkObserver implementation: | |
65 virtual void OnNetworkChanged(chromeos::NetworkLibrary* cros, | |
66 const chromeos::Network* network) OVERRIDE; | |
67 | 65 |
68 private: | 66 private: |
69 friend class NetworkPortalDetectorImplTest; | 67 friend class NetworkPortalDetectorImplTest; |
70 | 68 |
71 typedef std::string NetworkId; | 69 typedef std::string NetworkId; |
72 typedef base::hash_map<NetworkId, CaptivePortalState> CaptivePortalStateMap; | 70 typedef base::hash_map<NetworkId, CaptivePortalState> CaptivePortalStateMap; |
73 enum State { | 71 enum State { |
74 // No portal check is running. | 72 // No portal check is running. |
75 STATE_IDLE = 0, | 73 STATE_IDLE = 0, |
76 // Waiting for portal check. | 74 // Waiting for portal check. |
(...skipping 27 matching lines...) Expand all Loading... | |
104 const content::NotificationSource& source, | 102 const content::NotificationSource& source, |
105 const content::NotificationDetails& details) OVERRIDE; | 103 const content::NotificationDetails& details) OVERRIDE; |
106 | 104 |
107 // Returns true if we're waiting for portal check. | 105 // Returns true if we're waiting for portal check. |
108 bool IsPortalCheckPending() const; | 106 bool IsPortalCheckPending() const; |
109 | 107 |
110 // Returns true if portal check is in progress. | 108 // Returns true if portal check is in progress. |
111 bool IsCheckingForPortal() const; | 109 bool IsCheckingForPortal() const; |
112 | 110 |
113 // Stores captive portal state for a |network|. | 111 // Stores captive portal state for a |network|. |
114 void SetCaptivePortalState(const Network* network, | 112 void SetCaptivePortalState(const NetworkState* network, |
115 const CaptivePortalState& results); | 113 const CaptivePortalState& results); |
116 | 114 |
117 // Notifies observers that portal detection is completed for a |network|. | 115 // Notifies observers that portal detection is completed for a |network|. |
118 void NotifyPortalDetectionCompleted(const Network* network, | 116 void NotifyPortalDetectionCompleted(const NetworkState* network, |
119 const CaptivePortalState& state); | 117 const CaptivePortalState& state); |
120 | 118 |
121 // Returns the current TimeTicks. | 119 // Returns the current TimeTicks. |
122 base::TimeTicks GetCurrentTimeTicks() const; | 120 base::TimeTicks GetCurrentTimeTicks() const; |
123 | 121 |
124 State state() { return state_; } | 122 State state() { return state_; } |
125 | 123 |
126 // Returns current number of portal detection attempts. | 124 // Returns current number of portal detection attempts. |
127 // Used by unit tests. | 125 // Used by unit tests. |
128 int attempt_count_for_testing() { return attempt_count_; } | 126 int attempt_count_for_testing() { return attempt_count_; } |
(...skipping 27 matching lines...) Expand all Loading... | |
156 | 154 |
157 // Advances current test time ticks. Used by unit tests. | 155 // Advances current test time ticks. Used by unit tests. |
158 void advance_time_ticks_for_testing(const base::TimeDelta& delta) { | 156 void advance_time_ticks_for_testing(const base::TimeDelta& delta) { |
159 time_ticks_for_testing_ += delta; | 157 time_ticks_for_testing_ += delta; |
160 } | 158 } |
161 | 159 |
162 // Returns true if detection timeout callback isn't fired or | 160 // Returns true if detection timeout callback isn't fired or |
163 // cancelled. | 161 // cancelled. |
164 bool DetectionTimeoutIsCancelledForTesting() const; | 162 bool DetectionTimeoutIsCancelledForTesting() const; |
165 | 163 |
166 // Unique identifier of the active network. | 164 // Unique identifier of the default network. |
167 std::string active_network_id_; | 165 std::string default_network_id_; |
168 | 166 |
169 // Service path of the active network. | 167 // Service path of the default network. |
170 std::string active_service_path_; | 168 std::string default_service_path_; |
171 | 169 |
172 // Connection state of the active network. | 170 std::string default_connection_state_; |
ygorshenin1
2013/05/06 09:14:39
Please, add comment to the |connection_state_|.
gauravsh
2013/05/07 23:38:10
Done.
| |
173 ConnectionState active_connection_state_; | |
174 | 171 |
175 State state_; | 172 State state_; |
176 CaptivePortalStateMap portal_state_map_; | 173 CaptivePortalStateMap portal_state_map_; |
177 ObserverList<Observer> observers_; | 174 ObserverList<Observer> observers_; |
178 | 175 |
179 base::CancelableClosure detection_task_; | 176 base::CancelableClosure detection_task_; |
180 base::CancelableClosure detection_timeout_; | 177 base::CancelableClosure detection_timeout_; |
181 | 178 |
182 // URL that returns a 204 response code when connected to the Internet. | 179 // URL that returns a 204 response code when connected to the Internet. |
183 GURL test_url_; | 180 GURL test_url_; |
184 | 181 |
185 // Detector for checking active network for a portal state. | 182 // Detector for checking default network for a portal state. |
186 scoped_ptr<captive_portal::CaptivePortalDetector> captive_portal_detector_; | 183 scoped_ptr<captive_portal::CaptivePortalDetector> captive_portal_detector_; |
187 | 184 |
188 // True if the NetworkPortalDetector is enabled. | 185 // True if the NetworkPortalDetector is enabled. |
189 bool enabled_; | 186 bool enabled_; |
190 | 187 |
191 base::WeakPtrFactory<NetworkPortalDetectorImpl> weak_ptr_factory_; | 188 base::WeakPtrFactory<NetworkPortalDetectorImpl> weak_ptr_factory_; |
192 | 189 |
193 // Number of portal detection attemps for an active network. | 190 // Number of portal detection attemps for an default network. |
ygorshenin1
2013/05/06 09:14:39
s/an/a
gauravsh
2013/05/07 23:38:10
Done.
| |
194 int attempt_count_; | 191 int attempt_count_; |
195 | 192 |
196 // True if lazy detection is enabled. | 193 // True if lazy detection is enabled. |
197 bool lazy_detection_enabled_; | 194 bool lazy_detection_enabled_; |
198 | 195 |
199 // Time between consecutive portal checks for a network in lazy | 196 // Time between consecutive portal checks for a network in lazy |
200 // mode. | 197 // mode. |
201 base::TimeDelta lazy_check_interval_; | 198 base::TimeDelta lazy_check_interval_; |
202 | 199 |
203 // Minimum time between consecutive portal checks for the same | 200 // Minimum time between consecutive portal checks for the same |
204 // active network. | 201 // default network. |
205 base::TimeDelta min_time_between_attempts_; | 202 base::TimeDelta min_time_between_attempts_; |
206 | 203 |
207 // Start time of portal detection. | 204 // Start time of portal detection. |
208 base::TimeTicks detection_start_time_; | 205 base::TimeTicks detection_start_time_; |
209 | 206 |
210 // Start time of portal detection attempt. | 207 // Start time of portal detection attempt. |
211 base::TimeTicks attempt_start_time_; | 208 base::TimeTicks attempt_start_time_; |
212 | 209 |
213 // Timeout for a portal detection. | 210 // Timeout for a portal detection. |
214 base::TimeDelta request_timeout_; | 211 base::TimeDelta request_timeout_; |
215 | 212 |
216 // Delay before next portal detection. | 213 // Delay before next portal detection. |
217 base::TimeDelta next_attempt_delay_; | 214 base::TimeDelta next_attempt_delay_; |
218 | 215 |
219 // Test time ticks used by unit tests. | 216 // Test time ticks used by unit tests. |
220 base::TimeTicks time_ticks_for_testing_; | 217 base::TimeTicks time_ticks_for_testing_; |
221 | 218 |
222 content::NotificationRegistrar registrar_; | 219 content::NotificationRegistrar registrar_; |
223 | 220 |
224 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetectorImpl); | 221 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetectorImpl); |
225 }; | 222 }; |
226 | 223 |
227 } // namespace chromeos | 224 } // namespace chromeos |
228 | 225 |
229 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ | 226 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ |
OLD | NEW |