summaryrefslogtreecommitdiffstats
path: root/chromeos/network
diff options
context:
space:
mode:
authorygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-24 18:11:16 +0000
committerygorshenin@chromium.org <ygorshenin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-24 18:11:16 +0000
commit43b72918dd64f7b54a5ea25544ce62017f7a4055 (patch)
treed534d6cdb46fccfd3da6e9bb8ade0c6d395e5f2b /chromeos/network
parent05b7ca055d13c42dcc1250ad692f139553dc3e66 (diff)
downloadchromium_src-43b72918dd64f7b54a5ea25544ce62017f7a4055.zip
chromium_src-43b72918dd64f7b54a5ea25544ce62017f7a4055.tar.gz
chromium_src-43b72918dd64f7b54a5ea25544ce62017f7a4055.tar.bz2
Increased delay before next portal detection attempt in the case of !ONLINE -> ONLINE transition.
BUG=377725 TEST=manual Review URL: https://codereview.chromium.org/419463004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285328 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/network')
-rw-r--r--chromeos/network/portal_detector/network_portal_detector_strategy.cc70
-rw-r--r--chromeos/network/portal_detector/network_portal_detector_strategy.h18
2 files changed, 60 insertions, 28 deletions
diff --git a/chromeos/network/portal_detector/network_portal_detector_strategy.cc b/chromeos/network/portal_detector/network_portal_detector_strategy.cc
index 0bcf070..dc9942b 100644
--- a/chromeos/network/portal_detector/network_portal_detector_strategy.cc
+++ b/chromeos/network/portal_detector/network_portal_detector_strategy.cc
@@ -17,14 +17,13 @@ const NetworkState* DefaultNetwork() {
return NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
}
-// TODO (ygorshenin@): reuse net::BackoffEntry for strategies.
-
class LoginScreenStrategy : public PortalDetectorStrategy {
public:
static const int kBaseAttemptTimeoutSec = 5;
static const int kMaxAttemptTimeoutSec = 30;
- LoginScreenStrategy() {}
+ explicit LoginScreenStrategy(PortalDetectorStrategy::Delegate* delegate)
+ : PortalDetectorStrategy(delegate) {}
virtual ~LoginScreenStrategy() {}
protected:
@@ -51,7 +50,8 @@ class ErrorScreenStrategy : public PortalDetectorStrategy {
public:
static const int kAttemptTimeoutSec = 15;
- ErrorScreenStrategy() {}
+ explicit ErrorScreenStrategy(PortalDetectorStrategy::Delegate* delegate)
+ : PortalDetectorStrategy(delegate) {}
virtual ~ErrorScreenStrategy() {}
protected:
@@ -71,7 +71,8 @@ class SessionStrategy : public PortalDetectorStrategy {
static const int kFastAttemptTimeoutSec = 3;
static const int kSlowAttemptTimeoutSec = 5;
- SessionStrategy() {}
+ explicit SessionStrategy(PortalDetectorStrategy::Delegate* delegate)
+ : PortalDetectorStrategy(delegate) {}
virtual ~SessionStrategy() {}
protected:
@@ -91,6 +92,26 @@ class SessionStrategy : public PortalDetectorStrategy {
} // namespace
+// PortalDetectorStrategy::BackoffEntryImpl ------------------------------------
+
+class PortalDetectorStrategy::BackoffEntryImpl : public net::BackoffEntry {
+ public:
+ BackoffEntryImpl(const net::BackoffEntry::Policy* const policy,
+ PortalDetectorStrategy::Delegate* delegate)
+ : net::BackoffEntry(policy), delegate_(delegate) {}
+ virtual ~BackoffEntryImpl() {}
+
+ // net::BackoffEntry overrides:
+ virtual base::TimeTicks ImplGetTimeNow() const OVERRIDE {
+ return delegate_->GetCurrentTimeTicks();
+ }
+
+ private:
+ PortalDetectorStrategy::Delegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(BackoffEntryImpl);
+};
+
// PortalDetectorStrategy -----------------------------------------------------
// static
@@ -107,12 +128,13 @@ base::TimeDelta PortalDetectorStrategy::next_attempt_timeout_for_testing_;
bool PortalDetectorStrategy::next_attempt_timeout_for_testing_initialized_ =
false;
-PortalDetectorStrategy::PortalDetectorStrategy()
- : net::BackoffEntry(&policy_), delegate_(NULL) {
- // First three attempts with the same result are performed with
- // 600ms delay between them. Delay before every consecutive attempt
- // is multplied by 2.0. Also, 30% fuzz factor is used for each
- // delay.
+PortalDetectorStrategy::PortalDetectorStrategy(Delegate* delegate)
+ : delegate_(delegate) {
+ // First |policy_.num_errors_to_ignore| attempts with the same
+ // result are performed with |policy_.initial_delay_ms| between
+ // them. Delay before every consecutive attempt is multplied by
+ // |policy_.multiply_factor_|. Also, |policy_.jitter_factor| is used
+ // for each delay.
policy_.num_errors_to_ignore = 3;
policy_.initial_delay_ms = 600;
policy_.multiply_factor = 2.0;
@@ -120,6 +142,7 @@ PortalDetectorStrategy::PortalDetectorStrategy()
policy_.maximum_backoff_ms = 2 * 60 * 1000;
policy_.entry_lifetime_ms = -1;
policy_.always_use_initial_delay = true;
+ backoff_entry_.reset(new BackoffEntryImpl(&policy_, delegate_));
}
PortalDetectorStrategy::~PortalDetectorStrategy() {
@@ -127,14 +150,17 @@ PortalDetectorStrategy::~PortalDetectorStrategy() {
// statc
scoped_ptr<PortalDetectorStrategy> PortalDetectorStrategy::CreateById(
- StrategyId id) {
+ StrategyId id,
+ Delegate* delegate) {
switch (id) {
case STRATEGY_ID_LOGIN_SCREEN:
- return scoped_ptr<PortalDetectorStrategy>(new LoginScreenStrategy());
+ return scoped_ptr<PortalDetectorStrategy>(
+ new LoginScreenStrategy(delegate));
case STRATEGY_ID_ERROR_SCREEN:
- return scoped_ptr<PortalDetectorStrategy>(new ErrorScreenStrategy());
+ return scoped_ptr<PortalDetectorStrategy>(
+ new ErrorScreenStrategy(delegate));
case STRATEGY_ID_SESSION:
- return scoped_ptr<PortalDetectorStrategy>(new SessionStrategy());
+ return scoped_ptr<PortalDetectorStrategy>(new SessionStrategy(delegate));
default:
NOTREACHED();
return scoped_ptr<PortalDetectorStrategy>(
@@ -145,7 +171,7 @@ scoped_ptr<PortalDetectorStrategy> PortalDetectorStrategy::CreateById(
base::TimeDelta PortalDetectorStrategy::GetDelayTillNextAttempt() {
if (delay_till_next_attempt_for_testing_initialized_)
return delay_till_next_attempt_for_testing_;
- return net::BackoffEntry::GetTimeUntilRelease();
+ return backoff_entry_->GetTimeUntilRelease();
}
base::TimeDelta PortalDetectorStrategy::GetNextAttemptTimeout() {
@@ -155,15 +181,17 @@ base::TimeDelta PortalDetectorStrategy::GetNextAttemptTimeout() {
}
void PortalDetectorStrategy::Reset() {
- net::BackoffEntry::Reset();
+ backoff_entry_->Reset();
}
-void PortalDetectorStrategy::OnDetectionCompleted() {
- net::BackoffEntry::InformOfRequest(false);
+void PortalDetectorStrategy::SetPolicyAndReset(
+ const net::BackoffEntry::Policy& policy) {
+ policy_ = policy;
+ backoff_entry_.reset(new BackoffEntryImpl(&policy_, delegate_));
}
-base::TimeTicks PortalDetectorStrategy::ImplGetTimeNow() const {
- return delegate_->GetCurrentTimeTicks();
+void PortalDetectorStrategy::OnDetectionCompleted() {
+ backoff_entry_->InformOfRequest(false);
}
base::TimeDelta PortalDetectorStrategy::GetNextAttemptTimeoutImpl() {
diff --git a/chromeos/network/portal_detector/network_portal_detector_strategy.h b/chromeos/network/portal_detector/network_portal_detector_strategy.h
index be0a6a7..ff6e890 100644
--- a/chromeos/network/portal_detector/network_portal_detector_strategy.h
+++ b/chromeos/network/portal_detector/network_portal_detector_strategy.h
@@ -15,7 +15,7 @@
namespace chromeos {
-class CHROMEOS_EXPORT PortalDetectorStrategy : protected net::BackoffEntry {
+class CHROMEOS_EXPORT PortalDetectorStrategy {
public:
enum StrategyId {
STRATEGY_ID_LOGIN_SCREEN,
@@ -40,9 +40,8 @@ class CHROMEOS_EXPORT PortalDetectorStrategy : protected net::BackoffEntry {
virtual ~PortalDetectorStrategy();
- static scoped_ptr<PortalDetectorStrategy> CreateById(StrategyId id);
-
- void set_delegate(Delegate* delegate) { delegate_ = delegate; }
+ static scoped_ptr<PortalDetectorStrategy> CreateById(StrategyId id,
+ Delegate* delegate);
// Returns delay before next detection attempt. This delay is needed
// to separate detection attempts in time.
@@ -56,21 +55,26 @@ class CHROMEOS_EXPORT PortalDetectorStrategy : protected net::BackoffEntry {
// Resets strategy to the initial state.
void Reset();
+ const net::BackoffEntry::Policy& policy() const { return policy_; }
+
+ // Resets strategy to the initial stater and sets custom policy.
+ void SetPolicyAndReset(const net::BackoffEntry::Policy& policy);
+
// Should be called when portal detection is completed and timeout before next
// attempt should be adjusted.
void OnDetectionCompleted();
protected:
- PortalDetectorStrategy();
+ class BackoffEntryImpl;
- // net::BackoffEntry overrides:
- virtual base::TimeTicks ImplGetTimeNow() const OVERRIDE;
+ explicit PortalDetectorStrategy(Delegate* delegate);
// Interface for subclasses:
virtual base::TimeDelta GetNextAttemptTimeoutImpl();
Delegate* delegate_;
net::BackoffEntry::Policy policy_;
+ scoped_ptr<BackoffEntryImpl> backoff_entry_;
private:
friend class NetworkPortalDetectorImplTest;