| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ | 6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // Returns Captive Portal state for a given |network|. | 79 // Returns Captive Portal state for a given |network|. |
| 80 CaptivePortalState GetCaptivePortalState(const chromeos::Network* network); | 80 CaptivePortalState GetCaptivePortalState(const chromeos::Network* network); |
| 81 | 81 |
| 82 // NetworkLibrary::NetworkManagerObserver implementation: | 82 // NetworkLibrary::NetworkManagerObserver implementation: |
| 83 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* cros) OVERRIDE; | 83 virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* cros) OVERRIDE; |
| 84 | 84 |
| 85 // NetworkLibrary::NetworkObserver implementation: | 85 // NetworkLibrary::NetworkObserver implementation: |
| 86 virtual void OnNetworkChanged(chromeos::NetworkLibrary* cros, | 86 virtual void OnNetworkChanged(chromeos::NetworkLibrary* cros, |
| 87 const chromeos::Network* network) OVERRIDE; | 87 const chromeos::Network* network) OVERRIDE; |
| 88 | 88 |
| 89 // Enables lazy detection mode. In this mode portal detection after |
| 90 // first 3 consecutive attemps will be performed once in 30 seconds. |
| 91 void EnableLazyDetection(); |
| 92 |
| 93 // Dizables lazy detection mode. |
| 94 void DisableLazyDetection(); |
| 95 |
| 89 // Creates an instance of the NetworkPortalDetector. | 96 // Creates an instance of the NetworkPortalDetector. |
| 90 static NetworkPortalDetector* CreateInstance(); | 97 static NetworkPortalDetector* CreateInstance(); |
| 91 | 98 |
| 92 // Gets the instance of the NetworkPortalDetector. | 99 // Gets the instance of the NetworkPortalDetector. |
| 93 static NetworkPortalDetector* GetInstance(); | 100 static NetworkPortalDetector* GetInstance(); |
| 94 | 101 |
| 95 // Returns true is NetworkPortalDetector service is enabled. | 102 // Returns true is NetworkPortalDetector service is enabled. |
| 96 static bool IsEnabled(); | 103 static bool IsEnabled(); |
| 97 | 104 |
| 98 private: | 105 private: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 122 // calls OnPortalDetectionCompleted() with RESULT_NO_RESPONSE as | 129 // calls OnPortalDetectionCompleted() with RESULT_NO_RESPONSE as |
| 123 // a result. | 130 // a result. |
| 124 void PortalDetectionTimeout(); | 131 void PortalDetectionTimeout(); |
| 125 | 132 |
| 126 void CancelPortalDetection(); | 133 void CancelPortalDetection(); |
| 127 | 134 |
| 128 // Called by CaptivePortalDetector when detection completes. | 135 // Called by CaptivePortalDetector when detection completes. |
| 129 void OnPortalDetectionCompleted( | 136 void OnPortalDetectionCompleted( |
| 130 const captive_portal::CaptivePortalDetector::Results& results); | 137 const captive_portal::CaptivePortalDetector::Results& results); |
| 131 | 138 |
| 139 // Tries to perform portal detection in "lazy" mode. Does nothing in |
| 140 // the case of already pending/processing detection request. |
| 141 void TryLazyDetection(); |
| 142 |
| 132 // content::NotificationObserver implementation: | 143 // content::NotificationObserver implementation: |
| 133 virtual void Observe(int type, | 144 virtual void Observe(int type, |
| 134 const content::NotificationSource& source, | 145 const content::NotificationSource& source, |
| 135 const content::NotificationDetails& details) OVERRIDE; | 146 const content::NotificationDetails& details) OVERRIDE; |
| 136 | 147 |
| 137 // Returns true if we're waiting for portal check. | 148 // Returns true if we're waiting for portal check. |
| 138 bool IsPortalCheckPending() const; | 149 bool IsPortalCheckPending() const; |
| 139 | 150 |
| 140 // Returns true if portal check is in progress. | 151 // Returns true if portal check is in progress. |
| 141 bool IsCheckingForPortal() const; | 152 bool IsCheckingForPortal() const; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 156 // Returns current number of portal detection attempts. | 167 // Returns current number of portal detection attempts. |
| 157 // Used by unit tests. | 168 // Used by unit tests. |
| 158 int attempt_count_for_testing() { return attempt_count_; } | 169 int attempt_count_for_testing() { return attempt_count_; } |
| 159 | 170 |
| 160 // Sets minimum time between consecutive portal checks for the same | 171 // Sets minimum time between consecutive portal checks for the same |
| 161 // network. Used by unit tests. | 172 // network. Used by unit tests. |
| 162 void set_min_time_between_attempts_for_testing(const base::TimeDelta& delta) { | 173 void set_min_time_between_attempts_for_testing(const base::TimeDelta& delta) { |
| 163 min_time_between_attempts_ = delta; | 174 min_time_between_attempts_ = delta; |
| 164 } | 175 } |
| 165 | 176 |
| 177 // Sets default interval between consecutive portal checks for a |
| 178 // network in portal state. Used by unit tests. |
| 179 void set_lazy_check_interval_for_testing(const base::TimeDelta& delta) { |
| 180 lazy_check_interval_ = delta; |
| 181 } |
| 182 |
| 166 // Sets portal detection timeout. Used by unit tests. | 183 // Sets portal detection timeout. Used by unit tests. |
| 167 void set_request_timeout_for_testing(const base::TimeDelta& timeout) { | 184 void set_request_timeout_for_testing(const base::TimeDelta& timeout) { |
| 168 request_timeout_ = timeout; | 185 request_timeout_ = timeout; |
| 169 } | 186 } |
| 170 | 187 |
| 171 // Returns delay before next portal check. Used by unit tests. | 188 // Returns delay before next portal check. Used by unit tests. |
| 172 const base::TimeDelta& next_attempt_delay_for_testing() { | 189 const base::TimeDelta& next_attempt_delay_for_testing() { |
| 173 return next_attempt_delay_; | 190 return next_attempt_delay_; |
| 174 } | 191 } |
| 175 | 192 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 203 GURL test_url_; | 220 GURL test_url_; |
| 204 | 221 |
| 205 // Detector for checking active network for a portal state. | 222 // Detector for checking active network for a portal state. |
| 206 scoped_ptr<captive_portal::CaptivePortalDetector> captive_portal_detector_; | 223 scoped_ptr<captive_portal::CaptivePortalDetector> captive_portal_detector_; |
| 207 | 224 |
| 208 base::WeakPtrFactory<NetworkPortalDetector> weak_ptr_factory_; | 225 base::WeakPtrFactory<NetworkPortalDetector> weak_ptr_factory_; |
| 209 | 226 |
| 210 // Number of portal detection attemps for an active network. | 227 // Number of portal detection attemps for an active network. |
| 211 int attempt_count_; | 228 int attempt_count_; |
| 212 | 229 |
| 230 // True if lazy detection is enabled. |
| 231 bool lazy_detection_enabled_; |
| 232 |
| 233 // Time between consecutive portal checks for a network in lazy |
| 234 // mode. |
| 235 base::TimeDelta lazy_check_interval_; |
| 236 |
| 213 // Minimum time between consecutive portal checks for the same | 237 // Minimum time between consecutive portal checks for the same |
| 214 // active network. | 238 // active network. |
| 215 base::TimeDelta min_time_between_attempts_; | 239 base::TimeDelta min_time_between_attempts_; |
| 216 | 240 |
| 217 // Start time of portal detection. | 241 // Start time of portal detection. |
| 218 base::TimeTicks detection_start_time_; | 242 base::TimeTicks detection_start_time_; |
| 219 | 243 |
| 220 // Start time of portal detection attempt. | 244 // Start time of portal detection attempt. |
| 221 base::TimeTicks attempt_start_time_; | 245 base::TimeTicks attempt_start_time_; |
| 222 | 246 |
| 223 // Timeout for a portal detection. | 247 // Timeout for a portal detection. |
| 224 base::TimeDelta request_timeout_; | 248 base::TimeDelta request_timeout_; |
| 225 | 249 |
| 226 // Delay before next portal detection. | 250 // Delay before next portal detection. |
| 227 base::TimeDelta next_attempt_delay_; | 251 base::TimeDelta next_attempt_delay_; |
| 228 | 252 |
| 229 // Test time ticks used by unit tests. | 253 // Test time ticks used by unit tests. |
| 230 base::TimeTicks time_ticks_for_testing_; | 254 base::TimeTicks time_ticks_for_testing_; |
| 231 | 255 |
| 232 content::NotificationRegistrar registrar_; | 256 content::NotificationRegistrar registrar_; |
| 233 | 257 |
| 234 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetector); | 258 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetector); |
| 235 }; | 259 }; |
| 236 | 260 |
| 237 } // namespace chromeos | 261 } // namespace chromeos |
| 238 | 262 |
| 239 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ | 263 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ |
| OLD | NEW |