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

Side by Side Diff: chromeos/network/portal_detector/network_portal_detector_strategy.cc

Issue 1076853003: Refactor net::BackoffEntry to not require subclassing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address pneubeck's review comments Created 5 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/network/portal_detector/network_portal_detector_strategy.h" 5 #include "chromeos/network/portal_detector/network_portal_detector_strategy.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chromeos/network/network_handler.h" 8 #include "chromeos/network/network_handler.h"
9 #include "chromeos/network/network_state.h" 9 #include "chromeos/network/network_state.h"
10 #include "chromeos/network/network_state_handler.h" 10 #include "chromeos/network/network_state_handler.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 timeout = kSlowAttemptTimeoutSec; 85 timeout = kSlowAttemptTimeoutSec;
86 return base::TimeDelta::FromSeconds(timeout); 86 return base::TimeDelta::FromSeconds(timeout);
87 } 87 }
88 88
89 private: 89 private:
90 DISALLOW_COPY_AND_ASSIGN(SessionStrategy); 90 DISALLOW_COPY_AND_ASSIGN(SessionStrategy);
91 }; 91 };
92 92
93 } // namespace 93 } // namespace
94 94
95 // PortalDetectorStrategy::BackoffEntryImpl ------------------------------------ 95 // PortalDetectorStrategy::Delegate --------------------------------------------
96 96
97 class PortalDetectorStrategy::BackoffEntryImpl : public net::BackoffEntry { 97 PortalDetectorStrategy::Delegate::~Delegate() {}
98 public:
99 BackoffEntryImpl(const net::BackoffEntry::Policy* const policy,
100 PortalDetectorStrategy::Delegate* delegate)
101 : net::BackoffEntry(policy), delegate_(delegate) {}
102 ~BackoffEntryImpl() override {}
103
104 // net::BackoffEntry overrides:
105 base::TimeTicks ImplGetTimeNow() const override {
106 return delegate_->GetCurrentTimeTicks();
107 }
108
109 private:
110 PortalDetectorStrategy::Delegate* delegate_;
111
112 DISALLOW_COPY_AND_ASSIGN(BackoffEntryImpl);
113 };
114 98
115 // PortalDetectorStrategy ----------------------------------------------------- 99 // PortalDetectorStrategy -----------------------------------------------------
116 100
117 // static 101 // static
118 base::TimeDelta PortalDetectorStrategy::delay_till_next_attempt_for_testing_; 102 base::TimeDelta PortalDetectorStrategy::delay_till_next_attempt_for_testing_;
119 103
120 // static 104 // static
121 bool PortalDetectorStrategy::delay_till_next_attempt_for_testing_initialized_ = 105 bool PortalDetectorStrategy::delay_till_next_attempt_for_testing_initialized_ =
122 false; 106 false;
123 107
(...skipping 11 matching lines...) Expand all
135 // them. Delay before every consecutive attempt is multplied by 119 // them. Delay before every consecutive attempt is multplied by
136 // |policy_.multiply_factor_|. Also, |policy_.jitter_factor| is used 120 // |policy_.multiply_factor_|. Also, |policy_.jitter_factor| is used
137 // for each delay. 121 // for each delay.
138 policy_.num_errors_to_ignore = 3; 122 policy_.num_errors_to_ignore = 3;
139 policy_.initial_delay_ms = 600; 123 policy_.initial_delay_ms = 600;
140 policy_.multiply_factor = 2.0; 124 policy_.multiply_factor = 2.0;
141 policy_.jitter_factor = 0.3; 125 policy_.jitter_factor = 0.3;
142 policy_.maximum_backoff_ms = 2 * 60 * 1000; 126 policy_.maximum_backoff_ms = 2 * 60 * 1000;
143 policy_.entry_lifetime_ms = -1; 127 policy_.entry_lifetime_ms = -1;
144 policy_.always_use_initial_delay = true; 128 policy_.always_use_initial_delay = true;
145 backoff_entry_.reset(new BackoffEntryImpl(&policy_, delegate_)); 129 backoff_entry_.reset(new net::BackoffEntry(&policy_, delegate_));
146 } 130 }
147 131
148 PortalDetectorStrategy::~PortalDetectorStrategy() { 132 PortalDetectorStrategy::~PortalDetectorStrategy() {
149 } 133 }
150 134
151 // statc 135 // statc
152 scoped_ptr<PortalDetectorStrategy> PortalDetectorStrategy::CreateById( 136 scoped_ptr<PortalDetectorStrategy> PortalDetectorStrategy::CreateById(
153 StrategyId id, 137 StrategyId id,
154 Delegate* delegate) { 138 Delegate* delegate) {
155 switch (id) { 139 switch (id) {
(...skipping 24 matching lines...) Expand all
180 return GetNextAttemptTimeoutImpl(); 164 return GetNextAttemptTimeoutImpl();
181 } 165 }
182 166
183 void PortalDetectorStrategy::Reset() { 167 void PortalDetectorStrategy::Reset() {
184 backoff_entry_->Reset(); 168 backoff_entry_->Reset();
185 } 169 }
186 170
187 void PortalDetectorStrategy::SetPolicyAndReset( 171 void PortalDetectorStrategy::SetPolicyAndReset(
188 const net::BackoffEntry::Policy& policy) { 172 const net::BackoffEntry::Policy& policy) {
189 policy_ = policy; 173 policy_ = policy;
190 backoff_entry_.reset(new BackoffEntryImpl(&policy_, delegate_)); 174 backoff_entry_.reset(new net::BackoffEntry(&policy_, delegate_));
191 } 175 }
192 176
193 void PortalDetectorStrategy::OnDetectionCompleted() { 177 void PortalDetectorStrategy::OnDetectionCompleted() {
194 backoff_entry_->InformOfRequest(false); 178 backoff_entry_->InformOfRequest(false);
195 } 179 }
196 180
197 base::TimeDelta PortalDetectorStrategy::GetNextAttemptTimeoutImpl() { 181 base::TimeDelta PortalDetectorStrategy::GetNextAttemptTimeoutImpl() {
198 return base::TimeDelta(); 182 return base::TimeDelta();
199 } 183 }
200 184
201 } // namespace chromeos 185 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698