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

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: 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
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..974f878182620da8140a9cb0c6be2e9f9849a3fe 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,8 +128,8 @@ base::TimeDelta PortalDetectorStrategy::next_attempt_timeout_for_testing_;
bool PortalDetectorStrategy::next_attempt_timeout_for_testing_initialized_ =
false;
-PortalDetectorStrategy::PortalDetectorStrategy()
- : net::BackoffEntry(&policy_), delegate_(NULL) {
+PortalDetectorStrategy::PortalDetectorStrategy(Delegate* delegate)
+ : delegate_(delegate) {
// 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
@@ -120,6 +141,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 +149,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 +170,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 +180,16 @@ base::TimeDelta PortalDetectorStrategy::GetNextAttemptTimeout() {
}
void PortalDetectorStrategy::Reset() {
- net::BackoffEntry::Reset();
+ backoff_entry_->Reset();
}
-void PortalDetectorStrategy::OnDetectionCompleted() {
- net::BackoffEntry::InformOfRequest(false);
+void PortalDetectorStrategy::SetInitialDelayAndReset(int initial_delay_ms) {
+ policy_.initial_delay_ms = initial_delay_ms;
+ 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() {

Powered by Google App Engine
This is Rietveld 408576698