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 #include "chrome/browser/captive_portal/captive_portal_service.h" | 5 #include "chrome/browser/captive_portal/captive_portal_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 backoff_policy.always_use_initial_delay = true; | 187 backoff_policy.always_use_initial_delay = true; |
188 } | 188 } |
189 | 189 |
190 CaptivePortalService::CaptivePortalService(Profile* profile) | 190 CaptivePortalService::CaptivePortalService(Profile* profile) |
191 : profile_(profile), | 191 : profile_(profile), |
192 state_(STATE_IDLE), | 192 state_(STATE_IDLE), |
193 captive_portal_detector_(profile->GetRequestContext()), | 193 captive_portal_detector_(profile->GetRequestContext()), |
194 enabled_(false), | 194 enabled_(false), |
195 last_detection_result_(captive_portal::RESULT_INTERNET_CONNECTED), | 195 last_detection_result_(captive_portal::RESULT_INTERNET_CONNECTED), |
196 num_checks_with_same_result_(0), | 196 num_checks_with_same_result_(0), |
197 test_url_(captive_portal::CaptivePortalDetector::kDefaultURL) { | 197 test_url_(captive_portal::CaptivePortalDetector::kDefaultURL), |
| 198 portal_detection_enabled_(true) { |
198 // The order matters here: | 199 // The order matters here: |
199 // |resolve_errors_with_web_service_| must be initialized and |backoff_entry_| | 200 // |resolve_errors_with_web_service_| must be initialized and |backoff_entry_| |
200 // created before the call to UpdateEnabledState. | 201 // created before the call to UpdateEnabledState. |
201 resolve_errors_with_web_service_.Init( | 202 resolve_errors_with_web_service_.Init( |
202 prefs::kAlternateErrorPagesEnabled, | 203 prefs::kAlternateErrorPagesEnabled, |
203 profile_->GetPrefs(), | 204 profile_->GetPrefs(), |
204 base::Bind(&CaptivePortalService::UpdateEnabledState, | 205 base::Bind(&CaptivePortalService::UpdateEnabledState, |
205 base::Unretained(this))); | 206 base::Unretained(this))); |
206 ResetBackoffEntry(last_detection_result_); | 207 ResetBackoffEntry(last_detection_result_); |
207 | 208 |
208 UpdateEnabledState(); | 209 UpdateEnabledState(); |
209 } | 210 } |
210 | 211 |
211 CaptivePortalService::~CaptivePortalService() { | 212 CaptivePortalService::~CaptivePortalService() { |
212 } | 213 } |
213 | 214 |
| 215 void CaptivePortalService::SetPortalDetectionEnabledForTest(bool enabled) { |
| 216 portal_detection_enabled_ = enabled; |
| 217 } |
| 218 |
214 void CaptivePortalService::DetectCaptivePortal() { | 219 void CaptivePortalService::DetectCaptivePortal() { |
215 DCHECK(CalledOnValidThread()); | 220 DCHECK(CalledOnValidThread()); |
216 | 221 |
| 222 // Detection should be disabled only in tests. |
| 223 if (!portal_detection_enabled_) |
| 224 return; |
| 225 |
217 // If a request is pending or running, do nothing. | 226 // If a request is pending or running, do nothing. |
218 if (state_ == STATE_CHECKING_FOR_PORTAL || state_ == STATE_TIMER_RUNNING) | 227 if (state_ == STATE_CHECKING_FOR_PORTAL || state_ == STATE_TIMER_RUNNING) |
219 return; | 228 return; |
220 | 229 |
221 base::TimeDelta time_until_next_check = backoff_entry_->GetTimeUntilRelease(); | 230 base::TimeDelta time_until_next_check = backoff_entry_->GetTimeUntilRelease(); |
222 | 231 |
223 // Start asynchronously. | 232 // Start asynchronously. |
224 state_ = STATE_TIMER_RUNNING; | 233 state_ = STATE_TIMER_RUNNING; |
225 check_captive_portal_timer_.Start( | 234 check_captive_portal_timer_.Start( |
226 FROM_HERE, | 235 FROM_HERE, |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 return time_ticks_for_testing_; | 399 return time_ticks_for_testing_; |
391 } | 400 } |
392 | 401 |
393 bool CaptivePortalService::DetectionInProgress() const { | 402 bool CaptivePortalService::DetectionInProgress() const { |
394 return state_ == STATE_CHECKING_FOR_PORTAL; | 403 return state_ == STATE_CHECKING_FOR_PORTAL; |
395 } | 404 } |
396 | 405 |
397 bool CaptivePortalService::TimerRunning() const { | 406 bool CaptivePortalService::TimerRunning() const { |
398 return check_captive_portal_timer_.IsRunning(); | 407 return check_captive_portal_timer_.IsRunning(); |
399 } | 408 } |
OLD | NEW |