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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 203 |
204 UpdateEnabledState(); | 204 UpdateEnabledState(); |
205 } | 205 } |
206 | 206 |
207 CaptivePortalService::~CaptivePortalService() { | 207 CaptivePortalService::~CaptivePortalService() { |
208 } | 208 } |
209 | 209 |
210 void CaptivePortalService::DetectCaptivePortal() { | 210 void CaptivePortalService::DetectCaptivePortal() { |
211 DCHECK(CalledOnValidThread()); | 211 DCHECK(CalledOnValidThread()); |
212 | 212 |
| 213 // Detection should be disabled only in tests. |
| 214 if (testing_state_ == IGNORE_REQUESTS_FOR_TESTING) |
| 215 return; |
| 216 |
213 // If a request is pending or running, do nothing. | 217 // If a request is pending or running, do nothing. |
214 if (state_ == STATE_CHECKING_FOR_PORTAL || state_ == STATE_TIMER_RUNNING) | 218 if (state_ == STATE_CHECKING_FOR_PORTAL || state_ == STATE_TIMER_RUNNING) |
215 return; | 219 return; |
216 | 220 |
217 base::TimeDelta time_until_next_check = backoff_entry_->GetTimeUntilRelease(); | 221 base::TimeDelta time_until_next_check = backoff_entry_->GetTimeUntilRelease(); |
218 | 222 |
219 // Start asynchronously. | 223 // Start asynchronously. |
220 state_ = STATE_TIMER_RUNNING; | 224 state_ = STATE_TIMER_RUNNING; |
221 check_captive_portal_timer_.Start( | 225 check_captive_portal_timer_.Start( |
222 FROM_HERE, | 226 FROM_HERE, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 backoff_entry_.reset(new RecheckBackoffEntry(this)); | 349 backoff_entry_.reset(new RecheckBackoffEntry(this)); |
346 } | 350 } |
347 | 351 |
348 void CaptivePortalService::UpdateEnabledState() { | 352 void CaptivePortalService::UpdateEnabledState() { |
349 DCHECK(CalledOnValidThread()); | 353 DCHECK(CalledOnValidThread()); |
350 bool enabled_before = enabled_; | 354 bool enabled_before = enabled_; |
351 enabled_ = testing_state_ != DISABLED_FOR_TESTING && | 355 enabled_ = testing_state_ != DISABLED_FOR_TESTING && |
352 resolve_errors_with_web_service_.GetValue(); | 356 resolve_errors_with_web_service_.GetValue(); |
353 | 357 |
354 if (testing_state_ != SKIP_OS_CHECK_FOR_TESTING && | 358 if (testing_state_ != SKIP_OS_CHECK_FOR_TESTING && |
| 359 testing_state_ != IGNORE_REQUESTS_FOR_TESTING && |
355 ShouldDeferToNativeCaptivePortalDetection()) { | 360 ShouldDeferToNativeCaptivePortalDetection()) { |
356 enabled_ = false; | 361 enabled_ = false; |
357 } | 362 } |
358 | 363 |
359 if (enabled_before == enabled_) | 364 if (enabled_before == enabled_) |
360 return; | 365 return; |
361 | 366 |
362 // Clear data used for histograms. | 367 // Clear data used for histograms. |
363 num_checks_with_same_result_ = 0; | 368 num_checks_with_same_result_ = 0; |
364 first_check_time_with_same_result_ = base::TimeTicks(); | 369 first_check_time_with_same_result_ = base::TimeTicks(); |
(...skipping 21 matching lines...) Expand all Loading... |
386 return time_ticks_for_testing_; | 391 return time_ticks_for_testing_; |
387 } | 392 } |
388 | 393 |
389 bool CaptivePortalService::DetectionInProgress() const { | 394 bool CaptivePortalService::DetectionInProgress() const { |
390 return state_ == STATE_CHECKING_FOR_PORTAL; | 395 return state_ == STATE_CHECKING_FOR_PORTAL; |
391 } | 396 } |
392 | 397 |
393 bool CaptivePortalService::TimerRunning() const { | 398 bool CaptivePortalService::TimerRunning() const { |
394 return check_captive_portal_timer_.IsRunning(); | 399 return check_captive_portal_timer_.IsRunning(); |
395 } | 400 } |
OLD | NEW |