| Index: chrome/browser/chromeos/net/network_portal_detector_strategy.cc
|
| diff --git a/chrome/browser/chromeos/net/network_portal_detector_strategy.cc b/chrome/browser/chromeos/net/network_portal_detector_strategy.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..210dc9b432cab90044e819553a31d19349c75e31
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/net/network_portal_detector_strategy.cc
|
| @@ -0,0 +1,168 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/chromeos/net/network_portal_detector_strategy.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "chromeos/network/network_handler.h"
|
| +#include "chromeos/network/network_state.h"
|
| +#include "chromeos/network/network_state_handler.h"
|
| +
|
| +namespace chromeos {
|
| +
|
| +namespace {
|
| +
|
| +const NetworkState* DefaultNetwork() {
|
| + return NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
|
| +}
|
| +
|
| +std::string DefaultNetworkName() {
|
| + const NetworkState* network = DefaultNetwork();
|
| + return network ? network->name() : std::string();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// PortalDetectorStrategy -----------------------------------------------------
|
| +
|
| +// static
|
| +base::TimeDelta PortalDetectorStrategy::request_timeout_for_testing_;
|
| +
|
| +// static
|
| +bool PortalDetectorStrategy::request_timeout_for_testing_initialized_ = false;
|
| +
|
| +// static
|
| +base::TimeDelta PortalDetectorStrategy::min_time_between_attempts_for_testing_;
|
| +
|
| +// static
|
| +bool
|
| + PortalDetectorStrategy::min_time_between_attempts_for_testing_initialized_ =
|
| + false;
|
| +
|
| +PortalDetectorStrategy::PortalDetectorStrategy(Delegate* delegate)
|
| + : delegate_(delegate) {}
|
| +PortalDetectorStrategy::~PortalDetectorStrategy() {}
|
| +
|
| +void PortalDetectorStrategy::Reset() { ResetImpl(); }
|
| +
|
| +bool PortalDetectorStrategy::CanPerformAttempt() {
|
| + return CanPerformAttemptImpl();
|
| +}
|
| +
|
| +base::TimeDelta PortalDetectorStrategy::GetDelayBeforeCurrentAttempt() {
|
| + if (min_time_between_attempts_for_testing_initialized_)
|
| + return min_time_between_attempts_for_testing_;
|
| + return GetDelayBeforeCurrentAttemptImpl();
|
| +}
|
| +
|
| +base::TimeDelta PortalDetectorStrategy::GetCurrentAttemptTimeout() {
|
| + if (request_timeout_for_testing_initialized_)
|
| + return request_timeout_for_testing_;
|
| + return GetCurrentAttemptTimeoutImpl();
|
| +}
|
| +
|
| +void PortalDetectorStrategy::OnAttemptStarted() {
|
| + attempt_start_time_ = GetCurrentTimeTicks();
|
| + OnAttemptStartedImpl();
|
| +}
|
| +
|
| +void PortalDetectorStrategy::OnDetectionCompleted() {
|
| + return OnDetectionCompletedImpl();
|
| +}
|
| +
|
| +void PortalDetectorStrategy::ResetImpl() {}
|
| +
|
| +bool PortalDetectorStrategy::CanPerformAttemptImpl() { return false; }
|
| +
|
| +base::TimeDelta PortalDetectorStrategy::GetDelayBeforeCurrentAttemptImpl() {
|
| + return base::TimeDelta();
|
| +}
|
| +
|
| +base::TimeDelta PortalDetectorStrategy::GetCurrentAttemptTimeoutImpl() {
|
| + return base::TimeDelta();
|
| +}
|
| +
|
| +void PortalDetectorStrategy::OnAttemptStartedImpl() {}
|
| +
|
| +void PortalDetectorStrategy::OnDetectionCompletedImpl() {}
|
| +
|
| +// LoginScreenStrategy ---------------------------------------------------------
|
| +
|
| +LoginScreenStrategy::LoginScreenStrategy(
|
| + PortalDetectorStrategy::Delegate* delegate)
|
| + : PortalDetectorStrategy(delegate),
|
| + attempt_count_(0),
|
| + detection_completed_(false) {}
|
| +
|
| +LoginScreenStrategy::~LoginScreenStrategy() {}
|
| +
|
| +void LoginScreenStrategy::ResetImpl() {
|
| + attempt_count_ = 0;
|
| + detection_completed_ = false;
|
| +}
|
| +
|
| +bool LoginScreenStrategy::CanPerformAttemptImpl() {
|
| + return !detection_completed_ && attempt_count_ < kMaxRequestAttempts;
|
| +}
|
| +
|
| +base::TimeDelta LoginScreenStrategy::GetDelayBeforeCurrentAttemptImpl() {
|
| + DCHECK(CanPerformAttempt());
|
| + if (!attempt_count_)
|
| + return base::TimeDelta();
|
| +
|
| + base::TimeTicks now = GetCurrentTimeTicks();
|
| + base::TimeDelta delay =
|
| + base::TimeDelta::FromSeconds(kMinTimeBetweenAttemptsSec);
|
| + base::TimeDelta elapsed;
|
| + if (now > attempt_start_time_)
|
| + elapsed = now - attempt_start_time_;
|
| + if (delay > elapsed)
|
| + return delay - elapsed;
|
| + return base::TimeDelta();
|
| +}
|
| +
|
| +base::TimeDelta LoginScreenStrategy::GetCurrentAttemptTimeoutImpl() {
|
| + int timeout = DefaultNetwork() ? attempt_count_ * kBaseRequestTimeoutSec
|
| + : kBaseRequestTimeoutSec;
|
| + return base::TimeDelta::FromSeconds(timeout);
|
| +}
|
| +
|
| +void LoginScreenStrategy::OnAttemptStartedImpl() {
|
| + ++attempt_count_;
|
| + VLOG(1) << "Detection attempt on login screen started: "
|
| + << "name=" << DefaultNetworkName() << ", "
|
| + << "attempt=" << attempt_count_ << " of " << kMaxRequestAttempts
|
| + << ".";
|
| +}
|
| +
|
| +void LoginScreenStrategy::OnDetectionCompletedImpl() {
|
| + detection_completed_ = true;
|
| +}
|
| +
|
| +// ErrorScreenStrategy --------------------------------------------------------
|
| +
|
| +ErrorScreenStrategy::ErrorScreenStrategy(
|
| + PortalDetectorStrategy::Delegate* delegate)
|
| + : PortalDetectorStrategy(delegate),
|
| + delay_between_attempts_(
|
| + base::TimeDelta::FromSeconds(kMinTimeBetweenAttemptsSec)) {}
|
| +
|
| +ErrorScreenStrategy::~ErrorScreenStrategy() {}
|
| +
|
| +bool ErrorScreenStrategy::CanPerformAttemptImpl() { return true; }
|
| +
|
| +base::TimeDelta ErrorScreenStrategy::GetDelayBeforeCurrentAttemptImpl() {
|
| + return base::TimeDelta::FromSeconds(kMinTimeBetweenAttemptsSec);
|
| +}
|
| +
|
| +base::TimeDelta ErrorScreenStrategy::GetCurrentAttemptTimeoutImpl() {
|
| + return base::TimeDelta::FromSeconds(kRequestTimeoutSec);
|
| +}
|
| +
|
| +void ErrorScreenStrategy::OnAttemptStartedImpl() {
|
| + VLOG(1) << "Detection attempt on error screen started: "
|
| + << "name=" << DefaultNetworkName();
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|