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