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 #include "chrome/browser/chromeos/net/network_portal_detector_impl.h" | 5 #include "chrome/browser/chromeos/net/network_portal_detector_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 if (elapsed_time < delay_between_attempts && | 279 if (elapsed_time < delay_between_attempts && |
280 delay_between_attempts - elapsed_time > next_attempt_delay_) { | 280 delay_between_attempts - elapsed_time > next_attempt_delay_) { |
281 next_attempt_delay_ = delay_between_attempts - elapsed_time; | 281 next_attempt_delay_ = delay_between_attempts - elapsed_time; |
282 } | 282 } |
283 } else { | 283 } else { |
284 detection_start_time_ = GetCurrentTimeTicks(); | 284 detection_start_time_ = GetCurrentTimeTicks(); |
285 } | 285 } |
286 detection_task_.Reset( | 286 detection_task_.Reset( |
287 base::Bind(&NetworkPortalDetectorImpl::DetectCaptivePortalTask, | 287 base::Bind(&NetworkPortalDetectorImpl::DetectCaptivePortalTask, |
288 weak_ptr_factory_.GetWeakPtr())); | 288 weak_ptr_factory_.GetWeakPtr())); |
289 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 289 base::MessageLoop::current()->PostDelayedTask( |
290 detection_task_.callback(), | 290 FROM_HERE, detection_task_.callback(), next_attempt_delay_); |
291 next_attempt_delay_); | |
292 } | 291 } |
293 | 292 |
294 void NetworkPortalDetectorImpl::DetectCaptivePortalTask() { | 293 void NetworkPortalDetectorImpl::DetectCaptivePortalTask() { |
295 DCHECK(IsPortalCheckPending()); | 294 DCHECK(IsPortalCheckPending()); |
296 | 295 |
297 state_ = STATE_CHECKING_FOR_PORTAL; | 296 state_ = STATE_CHECKING_FOR_PORTAL; |
298 attempt_start_time_ = GetCurrentTimeTicks(); | 297 attempt_start_time_ = GetCurrentTimeTicks(); |
299 | 298 |
300 if (attempt_count_ < kMaxRequestAttempts) { | 299 if (attempt_count_ < kMaxRequestAttempts) { |
301 ++attempt_count_; | 300 ++attempt_count_; |
(...skipping 13 matching lines...) Expand all Loading... |
315 base::Bind(&NetworkPortalDetectorImpl::PortalDetectionTimeout, | 314 base::Bind(&NetworkPortalDetectorImpl::PortalDetectionTimeout, |
316 weak_ptr_factory_.GetWeakPtr())); | 315 weak_ptr_factory_.GetWeakPtr())); |
317 base::TimeDelta request_timeout; | 316 base::TimeDelta request_timeout; |
318 | 317 |
319 // For easier unit testing check for testing state is performed here | 318 // For easier unit testing check for testing state is performed here |
320 // and not in the GetRequestTimeoutSec(). | 319 // and not in the GetRequestTimeoutSec(). |
321 if (request_timeout_for_testing_initialized_) | 320 if (request_timeout_for_testing_initialized_) |
322 request_timeout = request_timeout_for_testing_; | 321 request_timeout = request_timeout_for_testing_; |
323 else | 322 else |
324 request_timeout = base::TimeDelta::FromSeconds(GetRequestTimeoutSec()); | 323 request_timeout = base::TimeDelta::FromSeconds(GetRequestTimeoutSec()); |
325 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 324 base::MessageLoop::current()->PostDelayedTask( |
326 detection_timeout_.callback(), | 325 FROM_HERE, detection_timeout_.callback(), request_timeout); |
327 request_timeout); | |
328 } | 326 } |
329 | 327 |
330 void NetworkPortalDetectorImpl::PortalDetectionTimeout() { | 328 void NetworkPortalDetectorImpl::PortalDetectionTimeout() { |
331 DCHECK(CalledOnValidThread()); | 329 DCHECK(CalledOnValidThread()); |
332 DCHECK(IsCheckingForPortal()); | 330 DCHECK(IsCheckingForPortal()); |
333 | 331 |
334 VLOG(1) << "Portal detection timeout: network=" << default_network_id_; | 332 VLOG(1) << "Portal detection timeout: network=" << default_network_id_; |
335 | 333 |
336 captive_portal_detector_->Cancel(); | 334 captive_portal_detector_->Cancel(); |
337 CaptivePortalDetector::Results results; | 335 CaptivePortalDetector::Results results; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 const NetworkState* network = | 482 const NetworkState* network = |
485 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); | 483 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
486 if (!network) | 484 if (!network) |
487 return kBaseRequestTimeoutSec; | 485 return kBaseRequestTimeoutSec; |
488 if (lazy_detection_enabled_) | 486 if (lazy_detection_enabled_) |
489 return kLazyRequestTimeoutSec; | 487 return kLazyRequestTimeoutSec; |
490 return attempt_count_ * kBaseRequestTimeoutSec; | 488 return attempt_count_ * kBaseRequestTimeoutSec; |
491 } | 489 } |
492 | 490 |
493 } // namespace chromeos | 491 } // namespace chromeos |
OLD | NEW |