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

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

Issue 419463004: Increased delay before next portal detection attempt in the case of !ONLINE -> ONLINE transition. (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 0bcf070bab10e77bad8b1697eb50cd1d8af9c4d1..dc9942b141102b9eda50518e222c8a1aede20f5d 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() {
« 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