Chromium Code Reviews| 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 3ff54e58d12ca4f500199e250ad1788a2dd498af..e5f7f20d5d6b47bea6a7a7803c555cdfaf8c9058 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,18 @@ 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 (static_cast<int>(kMaxAttemptTimeoutSec / |
| + delegate_->NoResponseResultCount()) > |
| + kBaseAttemptTimeoutSec) { |
| + timeout = |
| + kBaseAttemptTimeoutSec * (delegate_->NoResponseResultCount() + 1); |
|
antrim
2014/07/10 13:53:13
Hmm... this way result can get greater than kMaxAt
ygorshenin1
2014/07/11 11:46:12
It was a bug, thanks!
On 2014/07/10 13:53:13, ant
|
| + } |
| + return base::TimeDelta::FromSeconds(timeout); |
| + } |
| + return base::TimeDelta::FromSeconds(kBaseAttemptTimeoutSec); |
| } |
| private: |
| @@ -50,7 +50,6 @@ class LoginScreenStrategy : public PortalDetectorStrategy { |
| class ErrorScreenStrategy : public PortalDetectorStrategy { |
| public: |
| - static const int kDelayBetweenAttemptsSec = 3; |
| static const int kAttemptTimeoutSec = 15; |
| ErrorScreenStrategy() {} |
| @@ -59,11 +58,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,11 +68,8 @@ class ErrorScreenStrategy : public PortalDetectorStrategy { |
| class SessionStrategy : public PortalDetectorStrategy { |
| public: |
| - static const int kFastDelayBetweenAttemptsSec = 1; |
| static const int kMaxFastAttempts = 3; |
| static const int kFastAttemptTimeoutSec = 3; |
| - |
| - static const int kSlowDelayBetweenAttemptsSec = 10; |
| static const int kSlowAttemptTimeoutSec = 5; |
| SessionStrategy() {} |
| @@ -86,22 +77,14 @@ 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 (delegate_->AttemptCount() < kMaxFastAttempts) |
| - delay = kFastDelayBetweenAttemptsSec; |
| - else |
| - delay = kSlowDelayBetweenAttemptsSec; |
| - return AdjustDelay(base::TimeDelta::FromSeconds(delay)); |
| - } |
| virtual base::TimeDelta GetNextAttemptTimeoutImpl() OVERRIDE { |
| int timeout; |
| - if (delegate_->AttemptCount() < kMaxFastAttempts) |
| + if (delegate_->NoResponseResultCount() < |
| + static_cast<uint64>(kMaxFastAttempts)) { |
| timeout = kFastAttemptTimeoutSec; |
| - else |
| + } else { |
| timeout = kSlowAttemptTimeoutSec; |
| + } |
| return base::TimeDelta::FromSeconds(timeout); |
| } |
| @@ -127,7 +110,16 @@ 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) { |
| + 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() {} |
| @@ -148,18 +140,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() { |
| @@ -168,31 +152,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(); |
| } |