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

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: . 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
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& service_path) OVERRIDE; 75 const std::string& service_path) 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 uint64 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 uint64 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 uint64 no_response_result_count_for_testing() const {
antrim 2014/07/10 13:53:13 What is the reason for using uint64 instead of int
ygorshenin1 2014/07/11 11:46:12 Due to errors or something else int can overflow w
178 attempt_count_ = attempt_count; 173 return no_response_result_count_;
174 }
175
176 void set_no_response_result_count_for_testing(uint64 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 24 matching lines...) Expand all
229 232
230 // True if the NetworkPortalDetector is enabled. 233 // True if the NetworkPortalDetector is enabled.
231 bool enabled_; 234 bool enabled_;
232 235
233 // Start time of portal detection. 236 // Start time of portal detection.
234 base::TimeTicks detection_start_time_; 237 base::TimeTicks detection_start_time_;
235 238
236 // Start time of detection attempt. 239 // Start time of detection attempt.
237 base::TimeTicks attempt_start_time_; 240 base::TimeTicks attempt_start_time_;
238 241
239 // Number of already performed detection attempts.
240 int attempt_count_;
241
242 // Delay before next portal detection. 242 // Delay before next portal detection.
243 base::TimeDelta next_attempt_delay_; 243 base::TimeDelta next_attempt_delay_;
244 244
245 // Current detection strategy. 245 // Current detection strategy.
246 scoped_ptr<PortalDetectorStrategy> strategy_; 246 scoped_ptr<PortalDetectorStrategy> strategy_;
247 247
248 // Last received result from captive portal detector.
249 CaptivePortalStatus last_detection_result_;
250
251 // Number of detection attempts with same result in a row.
252 uint64 same_detection_result_count_;
253
254 // Number of detection attempts in a row with NO RESPONSE result.
255 uint64 no_response_result_count_;
256
248 // UI notification controller about captive portal state. 257 // UI notification controller about captive portal state.
249 NetworkPortalNotificationController notification_controller_; 258 NetworkPortalNotificationController notification_controller_;
250 259
251 content::NotificationRegistrar registrar_; 260 content::NotificationRegistrar registrar_;
252 261
253 // Test time ticks used by unit tests. 262 // Test time ticks used by unit tests.
254 base::TimeTicks time_ticks_for_testing_; 263 base::TimeTicks time_ticks_for_testing_;
255 264
256 // Contents of a last log message about completed detection attempt. 265 // Contents of a last log message about completed detection attempt.
257 DetectionAttemptCompletedReport attempt_completed_report_; 266 DetectionAttemptCompletedReport attempt_completed_report_;
258 267
259 base::WeakPtrFactory<NetworkPortalDetectorImpl> weak_factory_; 268 base::WeakPtrFactory<NetworkPortalDetectorImpl> weak_factory_;
260 269
261 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetectorImpl); 270 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetectorImpl);
262 }; 271 };
263 272
264 } // namespace chromeos 273 } // namespace chromeos
265 274
266 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_ 275 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698