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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 } | 391 } |
392 | 392 |
393 int NetworkPortalDetectorImpl::NoResponseResultCount() { | 393 int NetworkPortalDetectorImpl::NoResponseResultCount() { |
394 return no_response_result_count_; | 394 return no_response_result_count_; |
395 } | 395 } |
396 | 396 |
397 base::TimeTicks NetworkPortalDetectorImpl::AttemptStartTime() { | 397 base::TimeTicks NetworkPortalDetectorImpl::AttemptStartTime() { |
398 return attempt_start_time_; | 398 return attempt_start_time_; |
399 } | 399 } |
400 | 400 |
401 base::TimeTicks NetworkPortalDetectorImpl::GetCurrentTimeTicks() { | 401 base::TimeTicks NetworkPortalDetectorImpl::NowTicks() { |
402 if (time_ticks_for_testing_.is_null()) | 402 if (time_ticks_for_testing_.is_null()) |
403 return base::TimeTicks::Now(); | 403 return base::TimeTicks::Now(); |
404 return time_ticks_for_testing_; | 404 return time_ticks_for_testing_; |
405 } | 405 } |
406 | 406 |
407 | 407 |
408 //////////////////////////////////////////////////////////////////////////////// | 408 //////////////////////////////////////////////////////////////////////////////// |
409 // NetworkPortalDetectorImpl, private: | 409 // NetworkPortalDetectorImpl, private: |
410 | 410 |
411 void NetworkPortalDetectorImpl::StartDetection() { | 411 void NetworkPortalDetectorImpl::StartDetection() { |
412 DCHECK(is_idle()); | 412 DCHECK(is_idle()); |
413 | 413 |
414 ResetStrategyAndCounters(); | 414 ResetStrategyAndCounters(); |
415 detection_start_time_ = GetCurrentTimeTicks(); | 415 detection_start_time_ = NowTicks(); |
416 ScheduleAttempt(base::TimeDelta()); | 416 ScheduleAttempt(base::TimeDelta()); |
417 } | 417 } |
418 | 418 |
419 void NetworkPortalDetectorImpl::StopDetection() { | 419 void NetworkPortalDetectorImpl::StopDetection() { |
420 attempt_task_.Cancel(); | 420 attempt_task_.Cancel(); |
421 attempt_timeout_.Cancel(); | 421 attempt_timeout_.Cancel(); |
422 captive_portal_detector_->Cancel(); | 422 captive_portal_detector_->Cancel(); |
423 state_ = STATE_IDLE; | 423 state_ = STATE_IDLE; |
424 ResetStrategyAndCounters(); | 424 ResetStrategyAndCounters(); |
425 } | 425 } |
(...skipping 17 matching lines...) Expand all Loading... |
443 attempt_task_.Reset(base::Bind(&NetworkPortalDetectorImpl::StartAttempt, | 443 attempt_task_.Reset(base::Bind(&NetworkPortalDetectorImpl::StartAttempt, |
444 weak_factory_.GetWeakPtr())); | 444 weak_factory_.GetWeakPtr())); |
445 base::MessageLoop::current()->PostDelayedTask( | 445 base::MessageLoop::current()->PostDelayedTask( |
446 FROM_HERE, attempt_task_.callback(), next_attempt_delay_); | 446 FROM_HERE, attempt_task_.callback(), next_attempt_delay_); |
447 } | 447 } |
448 | 448 |
449 void NetworkPortalDetectorImpl::StartAttempt() { | 449 void NetworkPortalDetectorImpl::StartAttempt() { |
450 DCHECK(is_portal_check_pending()); | 450 DCHECK(is_portal_check_pending()); |
451 | 451 |
452 state_ = STATE_CHECKING_FOR_PORTAL; | 452 state_ = STATE_CHECKING_FOR_PORTAL; |
453 attempt_start_time_ = GetCurrentTimeTicks(); | 453 attempt_start_time_ = NowTicks(); |
454 | 454 |
455 captive_portal_detector_->DetectCaptivePortal( | 455 captive_portal_detector_->DetectCaptivePortal( |
456 test_url_, | 456 test_url_, |
457 base::Bind(&NetworkPortalDetectorImpl::OnAttemptCompleted, | 457 base::Bind(&NetworkPortalDetectorImpl::OnAttemptCompleted, |
458 weak_factory_.GetWeakPtr())); | 458 weak_factory_.GetWeakPtr())); |
459 attempt_timeout_.Reset( | 459 attempt_timeout_.Reset( |
460 base::Bind(&NetworkPortalDetectorImpl::OnAttemptTimeout, | 460 base::Bind(&NetworkPortalDetectorImpl::OnAttemptTimeout, |
461 weak_factory_.GetWeakPtr())); | 461 weak_factory_.GetWeakPtr())); |
462 | 462 |
463 base::MessageLoop::current()->PostDelayedTask( | 463 base::MessageLoop::current()->PostDelayedTask( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 if (!attempt_completed_report_.Equals(attempt_completed_report)) { | 504 if (!attempt_completed_report_.Equals(attempt_completed_report)) { |
505 attempt_completed_report_ = attempt_completed_report; | 505 attempt_completed_report_ = attempt_completed_report; |
506 attempt_completed_report_.Report(); | 506 attempt_completed_report_.Report(); |
507 } | 507 } |
508 | 508 |
509 state_ = STATE_IDLE; | 509 state_ = STATE_IDLE; |
510 attempt_timeout_.Cancel(); | 510 attempt_timeout_.Cancel(); |
511 | 511 |
512 CaptivePortalState state; | 512 CaptivePortalState state; |
513 state.response_code = response_code; | 513 state.response_code = response_code; |
514 state.time = GetCurrentTimeTicks(); | 514 state.time = NowTicks(); |
515 switch (result) { | 515 switch (result) { |
516 case captive_portal::RESULT_NO_RESPONSE: | 516 case captive_portal::RESULT_NO_RESPONSE: |
517 if (state.response_code == net::HTTP_PROXY_AUTHENTICATION_REQUIRED) { | 517 if (state.response_code == net::HTTP_PROXY_AUTHENTICATION_REQUIRED) { |
518 state.status = CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; | 518 state.status = CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; |
519 } else if (network && network->is_captive_portal()) { | 519 } else if (network && network->is_captive_portal()) { |
520 // Take into account shill's detection results. | 520 // Take into account shill's detection results. |
521 state.status = CAPTIVE_PORTAL_STATUS_PORTAL; | 521 state.status = CAPTIVE_PORTAL_STATUS_PORTAL; |
522 } else { | 522 } else { |
523 state.status = CAPTIVE_PORTAL_STATUS_OFFLINE; | 523 state.status = CAPTIVE_PORTAL_STATUS_OFFLINE; |
524 } | 524 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 } | 616 } |
617 | 617 |
618 void NetworkPortalDetectorImpl::RecordDetectionStats( | 618 void NetworkPortalDetectorImpl::RecordDetectionStats( |
619 const NetworkState* network, | 619 const NetworkState* network, |
620 CaptivePortalStatus status) { | 620 CaptivePortalStatus status) { |
621 // Don't record stats for offline state. | 621 // Don't record stats for offline state. |
622 if (!network) | 622 if (!network) |
623 return; | 623 return; |
624 | 624 |
625 if (!detection_start_time_.is_null()) | 625 if (!detection_start_time_.is_null()) |
626 RecordDetectionDuration(GetCurrentTimeTicks() - detection_start_time_); | 626 RecordDetectionDuration(NowTicks() - detection_start_time_); |
627 RecordDetectionResult(status); | 627 RecordDetectionResult(status); |
628 | 628 |
629 switch (status) { | 629 switch (status) { |
630 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN: | 630 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN: |
631 NOTREACHED(); | 631 NOTREACHED(); |
632 break; | 632 break; |
633 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE: | 633 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE: |
634 if (network->IsConnectedState()) | 634 if (network->IsConnectedState()) |
635 RecordDiscrepancyWithShill(network, status); | 635 RecordDiscrepancyWithShill(network, status); |
636 break; | 636 break; |
(...skipping 16 matching lines...) Expand all Loading... |
653 } | 653 } |
654 | 654 |
655 void NetworkPortalDetectorImpl::ResetStrategyAndCounters() { | 655 void NetworkPortalDetectorImpl::ResetStrategyAndCounters() { |
656 last_detection_result_ = CAPTIVE_PORTAL_STATUS_UNKNOWN; | 656 last_detection_result_ = CAPTIVE_PORTAL_STATUS_UNKNOWN; |
657 same_detection_result_count_ = 0; | 657 same_detection_result_count_ = 0; |
658 no_response_result_count_ = 0; | 658 no_response_result_count_ = 0; |
659 strategy_->Reset(); | 659 strategy_->Reset(); |
660 } | 660 } |
661 | 661 |
662 } // namespace chromeos | 662 } // namespace chromeos |
OLD | NEW |