Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Unified Diff: chromeos/network/portal_detector/network_portal_detector_strategy.cc

Issue 385553002: BackoffEntry is used to compute timeouts between consecutive captive portal checks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/network/portal_detector/network_portal_detector_strategy.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/network/portal_detector/network_portal_detector_strategy.cc
diff --git a/chromeos/network/portal_detector/network_portal_detector_strategy.cc b/chromeos/network/portal_detector/network_portal_detector_strategy.cc
index 6a860c958bf6689cac82f7e9932bf792f234f020..0bcf070bab10e77bad8b1697eb50cd1d8af9c4d1 100644
--- a/chromeos/network/portal_detector/network_portal_detector_strategy.cc
+++ b/chromeos/network/portal_detector/network_portal_detector_strategy.cc
@@ -21,9 +21,8 @@ const NetworkState* DefaultNetwork() {
class LoginScreenStrategy : public PortalDetectorStrategy {
public:
- static const int kMaxAttempts = 3;
- static const int kDelayBetweenAttemptsSec = 3;
static const int kBaseAttemptTimeoutSec = 5;
+ static const int kMaxAttemptTimeoutSec = 30;
LoginScreenStrategy() {}
virtual ~LoginScreenStrategy() {}
@@ -31,17 +30,17 @@ class LoginScreenStrategy : public PortalDetectorStrategy {
protected:
// PortalDetectorStrategy overrides:
virtual StrategyId Id() const OVERRIDE { return STRATEGY_ID_LOGIN_SCREEN; }
- virtual bool CanPerformAttemptImpl() OVERRIDE {
- return delegate_->AttemptCount() < kMaxAttempts;
- }
- virtual base::TimeDelta GetDelayTillNextAttemptImpl() OVERRIDE {
- return AdjustDelay(base::TimeDelta::FromSeconds(kDelayBetweenAttemptsSec));
- }
virtual base::TimeDelta GetNextAttemptTimeoutImpl() OVERRIDE {
- int timeout = DefaultNetwork()
- ? (delegate_->AttemptCount() + 1) * kBaseAttemptTimeoutSec
- : kBaseAttemptTimeoutSec;
- return base::TimeDelta::FromSeconds(timeout);
+ if (DefaultNetwork() && delegate_->NoResponseResultCount() != 0) {
+ int timeout = kMaxAttemptTimeoutSec;
+ if (kMaxAttemptTimeoutSec / (delegate_->NoResponseResultCount() + 1) >
+ kBaseAttemptTimeoutSec) {
+ timeout =
+ kBaseAttemptTimeoutSec * (delegate_->NoResponseResultCount() + 1);
+ }
+ return base::TimeDelta::FromSeconds(timeout);
+ }
+ return base::TimeDelta::FromSeconds(kBaseAttemptTimeoutSec);
}
private:
@@ -50,7 +49,6 @@ class LoginScreenStrategy : public PortalDetectorStrategy {
class ErrorScreenStrategy : public PortalDetectorStrategy {
public:
- static const int kDelayBetweenAttemptsSec = 3;
static const int kAttemptTimeoutSec = 15;
ErrorScreenStrategy() {}
@@ -59,11 +57,6 @@ class ErrorScreenStrategy : public PortalDetectorStrategy {
protected:
// PortalDetectorStrategy overrides:
virtual StrategyId Id() const OVERRIDE { return STRATEGY_ID_ERROR_SCREEN; }
- virtual bool CanPerformAttemptImpl() OVERRIDE { return true; }
- virtual bool CanPerformAttemptAfterDetectionImpl() OVERRIDE { return true; }
- virtual base::TimeDelta GetDelayTillNextAttemptImpl() OVERRIDE {
- return AdjustDelay(base::TimeDelta::FromSeconds(kDelayBetweenAttemptsSec));
- }
virtual base::TimeDelta GetNextAttemptTimeoutImpl() OVERRIDE {
return base::TimeDelta::FromSeconds(kAttemptTimeoutSec);
}
@@ -74,15 +67,8 @@ class ErrorScreenStrategy : public PortalDetectorStrategy {
class SessionStrategy : public PortalDetectorStrategy {
public:
- static const int kFastDelayBetweenAttemptsSec = 1;
- static const int kFastAttemptTimeoutSec = 3;
static const int kMaxFastAttempts = 3;
-
- static const int kNormalDelayBetweenAttemptsSec = 10;
- static const int kNormalAttemptTimeoutSec = 5;
- static const int kMaxNormalAttempts = 3;
-
- static const int kSlowDelayBetweenAttemptsSec = 2 * 60;
+ static const int kFastAttemptTimeoutSec = 3;
static const int kSlowAttemptTimeoutSec = 5;
SessionStrategy() {}
@@ -90,38 +76,16 @@ class SessionStrategy : public PortalDetectorStrategy {
protected:
virtual StrategyId Id() const OVERRIDE { return STRATEGY_ID_SESSION; }
- virtual bool CanPerformAttemptImpl() OVERRIDE { return true; }
- virtual bool CanPerformAttemptAfterDetectionImpl() OVERRIDE { return true; }
- virtual base::TimeDelta GetDelayTillNextAttemptImpl() OVERRIDE {
- int delay;
- if (IsFastAttempt())
- delay = kFastDelayBetweenAttemptsSec;
- else if (IsNormalAttempt())
- delay = kNormalDelayBetweenAttemptsSec;
- else
- delay = kSlowDelayBetweenAttemptsSec;
- return AdjustDelay(base::TimeDelta::FromSeconds(delay));
- }
virtual base::TimeDelta GetNextAttemptTimeoutImpl() OVERRIDE {
int timeout;
- if (IsFastAttempt())
+ if (delegate_->NoResponseResultCount() < kMaxFastAttempts)
timeout = kFastAttemptTimeoutSec;
- else if (IsNormalAttempt())
- timeout = kNormalAttemptTimeoutSec;
else
timeout = kSlowAttemptTimeoutSec;
return base::TimeDelta::FromSeconds(timeout);
}
private:
- bool IsFastAttempt() {
- return delegate_->AttemptCount() < kMaxFastAttempts;
- }
-
- bool IsNormalAttempt() {
- return delegate_->AttemptCount() < kMaxFastAttempts + kMaxNormalAttempts;
- }
-
DISALLOW_COPY_AND_ASSIGN(SessionStrategy);
};
@@ -143,9 +107,23 @@ base::TimeDelta PortalDetectorStrategy::next_attempt_timeout_for_testing_;
bool PortalDetectorStrategy::next_attempt_timeout_for_testing_initialized_ =
false;
-PortalDetectorStrategy::PortalDetectorStrategy() : delegate_(NULL) {}
+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.
+ policy_.num_errors_to_ignore = 3;
+ policy_.initial_delay_ms = 600;
+ policy_.multiply_factor = 2.0;
+ policy_.jitter_factor = 0.3;
+ policy_.maximum_backoff_ms = 2 * 60 * 1000;
+ policy_.entry_lifetime_ms = -1;
+ policy_.always_use_initial_delay = true;
+}
-PortalDetectorStrategy::~PortalDetectorStrategy() {}
+PortalDetectorStrategy::~PortalDetectorStrategy() {
+}
// statc
scoped_ptr<PortalDetectorStrategy> PortalDetectorStrategy::CreateById(
@@ -164,18 +142,10 @@ scoped_ptr<PortalDetectorStrategy> PortalDetectorStrategy::CreateById(
}
}
-bool PortalDetectorStrategy::CanPerformAttempt() {
- return CanPerformAttemptImpl();
-}
-
-bool PortalDetectorStrategy::CanPerformAttemptAfterDetection() {
- return CanPerformAttemptAfterDetectionImpl();
-}
-
base::TimeDelta PortalDetectorStrategy::GetDelayTillNextAttempt() {
if (delay_till_next_attempt_for_testing_initialized_)
return delay_till_next_attempt_for_testing_;
- return GetDelayTillNextAttemptImpl();
+ return net::BackoffEntry::GetTimeUntilRelease();
}
base::TimeDelta PortalDetectorStrategy::GetNextAttemptTimeout() {
@@ -184,31 +154,19 @@ base::TimeDelta PortalDetectorStrategy::GetNextAttemptTimeout() {
return GetNextAttemptTimeoutImpl();
}
-bool PortalDetectorStrategy::CanPerformAttemptImpl() { return false; }
-
-bool PortalDetectorStrategy::CanPerformAttemptAfterDetectionImpl() {
- return false;
+void PortalDetectorStrategy::Reset() {
+ net::BackoffEntry::Reset();
}
-base::TimeDelta PortalDetectorStrategy::GetDelayTillNextAttemptImpl() {
- return base::TimeDelta();
+void PortalDetectorStrategy::OnDetectionCompleted() {
+ net::BackoffEntry::InformOfRequest(false);
}
-base::TimeDelta PortalDetectorStrategy::GetNextAttemptTimeoutImpl() {
- return base::TimeDelta();
+base::TimeTicks PortalDetectorStrategy::ImplGetTimeNow() const {
+ return delegate_->GetCurrentTimeTicks();
}
-base::TimeDelta PortalDetectorStrategy::AdjustDelay(
- const base::TimeDelta& delay) {
- if (!delegate_->AttemptCount())
- return base::TimeDelta();
-
- base::TimeTicks now = delegate_->GetCurrentTimeTicks();
- base::TimeDelta elapsed;
- if (now > delegate_->AttemptStartTime())
- elapsed = now - delegate_->AttemptStartTime();
- if (delay > elapsed)
- return delay - elapsed;
+base::TimeDelta PortalDetectorStrategy::GetNextAttemptTimeoutImpl() {
return base::TimeDelta();
}
« no previous file with comments | « chromeos/network/portal_detector/network_portal_detector_strategy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698