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

Side by Side Diff: chrome/browser/chromeos/net/network_portal_detector_impl.h

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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/net/network_portal_detector_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ 6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 const std::string& guid) OVERRIDE; 75 const std::string& guid) OVERRIDE;
76 virtual bool IsEnabled() OVERRIDE; 76 virtual bool IsEnabled() OVERRIDE;
77 virtual void Enable(bool start_detection) OVERRIDE; 77 virtual void Enable(bool start_detection) OVERRIDE;
78 virtual bool StartDetectionIfIdle() OVERRIDE; 78 virtual bool StartDetectionIfIdle() OVERRIDE;
79 virtual void SetStrategy(PortalDetectorStrategy::StrategyId id) OVERRIDE; 79 virtual void SetStrategy(PortalDetectorStrategy::StrategyId id) OVERRIDE;
80 80
81 // NetworkStateHandlerObserver implementation: 81 // NetworkStateHandlerObserver implementation:
82 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE; 82 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE;
83 83
84 // PortalDetectorStrategy::Delegate implementation: 84 // PortalDetectorStrategy::Delegate implementation:
85 virtual int AttemptCount() OVERRIDE; 85 virtual int NoResponseResultCount() OVERRIDE;
86 virtual base::TimeTicks AttemptStartTime() OVERRIDE; 86 virtual base::TimeTicks AttemptStartTime() OVERRIDE;
87 virtual base::TimeTicks GetCurrentTimeTicks() OVERRIDE; 87 virtual base::TimeTicks GetCurrentTimeTicks() OVERRIDE;
88 88
89 private: 89 private:
90 friend class NetworkPortalDetectorImplTest; 90 friend class NetworkPortalDetectorImplTest;
91 friend class NetworkPortalDetectorImplBrowserTest; 91 friend class NetworkPortalDetectorImplBrowserTest;
92 92
93 struct DetectionAttemptCompletedReport { 93 struct DetectionAttemptCompletedReport {
94 DetectionAttemptCompletedReport(); 94 DetectionAttemptCompletedReport();
95 95
(...skipping 23 matching lines...) Expand all
119 // Portal check is in progress. 119 // Portal check is in progress.
120 STATE_CHECKING_FOR_PORTAL, 120 STATE_CHECKING_FOR_PORTAL,
121 }; 121 };
122 122
123 // Starts detection process. 123 // Starts detection process.
124 void StartDetection(); 124 void StartDetection();
125 125
126 // Stops whole detection process. 126 // Stops whole detection process.
127 void StopDetection(); 127 void StopDetection();
128 128
129 // Internal predicate which describes set of states from which
130 // DetectCaptivePortal() can be called.
131 bool CanPerformAttempt() const;
132
133 // Initiates Captive Portal detection attempt after |delay|. 129 // Initiates Captive Portal detection attempt after |delay|.
134 // You should check CanPerformAttempt() before calling this method.
135 void ScheduleAttempt(const base::TimeDelta& delay); 130 void ScheduleAttempt(const base::TimeDelta& delay);
136 131
137 // Starts detection attempt. 132 // Starts detection attempt.
138 void StartAttempt(); 133 void StartAttempt();
139 134
140 // Called when portal check is timed out. Cancels portal check and calls 135 // Called when portal check is timed out. Cancels portal check and calls
141 // OnPortalDetectionCompleted() with RESULT_NO_RESPONSE as a result. 136 // OnPortalDetectionCompleted() with RESULT_NO_RESPONSE as a result.
142 void OnAttemptTimeout(); 137 void OnAttemptTimeout();
143 138
144 // Called by CaptivePortalDetector when detection attempt completes. 139 // Called by CaptivePortalDetector when detection attempt completes.
(...skipping 18 matching lines...) Expand all
163 bool is_idle() const { 158 bool is_idle() const {
164 return state_ == STATE_IDLE; 159 return state_ == STATE_IDLE;
165 } 160 }
166 bool is_portal_check_pending() const { 161 bool is_portal_check_pending() const {
167 return state_ == STATE_PORTAL_CHECK_PENDING; 162 return state_ == STATE_PORTAL_CHECK_PENDING;
168 } 163 }
169 bool is_checking_for_portal() const { 164 bool is_checking_for_portal() const {
170 return state_ == STATE_CHECKING_FOR_PORTAL; 165 return state_ == STATE_CHECKING_FOR_PORTAL;
171 } 166 }
172 167
173 int attempt_count_for_testing() { 168 int same_detection_result_count_for_testing() const {
174 return attempt_count_; 169 return same_detection_result_count_;
175 } 170 }
176 171
177 void set_attempt_count_for_testing(int attempt_count) { 172 int no_response_result_count_for_testing() const {
178 attempt_count_ = attempt_count; 173 return no_response_result_count_;
174 }
175
176 void set_no_response_result_count_for_testing(int count) {
177 no_response_result_count_ = count;
179 } 178 }
180 179
181 // Returns delay before next portal check. Used by unit tests. 180 // Returns delay before next portal check. Used by unit tests.
182 const base::TimeDelta& next_attempt_delay_for_testing() const { 181 const base::TimeDelta& next_attempt_delay_for_testing() const {
183 return next_attempt_delay_; 182 return next_attempt_delay_;
184 } 183 }
185 184
186 // Returns true if attempt timeout callback isn't fired or 185 // Returns true if attempt timeout callback isn't fired or
187 // cancelled. 186 // cancelled.
188 bool AttemptTimeoutIsCancelledForTesting() const; 187 bool AttemptTimeoutIsCancelledForTesting() const;
189 188
190 // Record detection stats such as detection duration and detection 189 // Record detection stats such as detection duration and detection
191 // result in UMA. 190 // result in UMA.
192 void RecordDetectionStats(const NetworkState* network, 191 void RecordDetectionStats(const NetworkState* network,
193 CaptivePortalStatus status); 192 CaptivePortalStatus status);
194 193
194 // Resets strategy and all counters used in computations of
195 // timeouts.
196 void ResetStrategyAndCounters();
197
195 // Sets current test time ticks. Used by unit tests. 198 // Sets current test time ticks. Used by unit tests.
196 void set_time_ticks_for_testing(const base::TimeTicks& time_ticks) { 199 void set_time_ticks_for_testing(const base::TimeTicks& time_ticks) {
197 time_ticks_for_testing_ = time_ticks; 200 time_ticks_for_testing_ = time_ticks;
198 } 201 }
199 202
200 // Advances current test time ticks. Used by unit tests. 203 // Advances current test time ticks. Used by unit tests.
201 void advance_time_ticks_for_testing(const base::TimeDelta& delta) { 204 void advance_time_ticks_for_testing(const base::TimeDelta& delta) {
202 time_ticks_for_testing_ += delta; 205 time_ticks_for_testing_ += delta;
203 } 206 }
204 207
(...skipping 21 matching lines...) Expand all
226 229
227 // True if the NetworkPortalDetector is enabled. 230 // True if the NetworkPortalDetector is enabled.
228 bool enabled_; 231 bool enabled_;
229 232
230 // Start time of portal detection. 233 // Start time of portal detection.
231 base::TimeTicks detection_start_time_; 234 base::TimeTicks detection_start_time_;
232 235
233 // Start time of detection attempt. 236 // Start time of detection attempt.
234 base::TimeTicks attempt_start_time_; 237 base::TimeTicks attempt_start_time_;
235 238
236 // Number of already performed detection attempts.
237 int attempt_count_;
238
239 // Delay before next portal detection. 239 // Delay before next portal detection.
240 base::TimeDelta next_attempt_delay_; 240 base::TimeDelta next_attempt_delay_;
241 241
242 // Current detection strategy. 242 // Current detection strategy.
243 scoped_ptr<PortalDetectorStrategy> strategy_; 243 scoped_ptr<PortalDetectorStrategy> strategy_;
244 244
245 // Last received result from captive portal detector.
246 CaptivePortalStatus last_detection_result_;
247
248 // Number of detection attempts with same result in a row.
249 int same_detection_result_count_;
250
251 // Number of detection attempts in a row with NO RESPONSE result.
252 int no_response_result_count_;
253
245 // UI notification controller about captive portal state. 254 // UI notification controller about captive portal state.
246 NetworkPortalNotificationController notification_controller_; 255 NetworkPortalNotificationController notification_controller_;
247 256
248 content::NotificationRegistrar registrar_; 257 content::NotificationRegistrar registrar_;
249 258
250 // Test time ticks used by unit tests. 259 // Test time ticks used by unit tests.
251 base::TimeTicks time_ticks_for_testing_; 260 base::TimeTicks time_ticks_for_testing_;
252 261
253 // Contents of a last log message about completed detection attempt. 262 // Contents of a last log message about completed detection attempt.
254 DetectionAttemptCompletedReport attempt_completed_report_; 263 DetectionAttemptCompletedReport attempt_completed_report_;
255 264
256 base::WeakPtrFactory<NetworkPortalDetectorImpl> weak_factory_; 265 base::WeakPtrFactory<NetworkPortalDetectorImpl> weak_factory_;
257 266
258 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetectorImpl); 267 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetectorImpl);
259 }; 268 };
260 269
261 } // namespace chromeos 270 } // namespace chromeos
262 271
263 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ 272 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/net/network_portal_detector_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698