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

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

Issue 11419070: Added detection timeouts and usage of Retry-After HTTP header. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 8 years, 1 month 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_
6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ 6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/cancelable_callback.h"
10 #include "base/hash_tables.h" 11 #include "base/hash_tables.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h" 15 #include "base/observer_list.h"
14 #include "base/threading/non_thread_safe.h" 16 #include "base/threading/non_thread_safe.h"
17 #include "base/time.h"
15 #include "chrome/browser/captive_portal/captive_portal_detector.h" 18 #include "chrome/browser/captive_portal/captive_portal_detector.h"
16 #include "chrome/browser/chromeos/cros/network_library.h" 19 #include "chrome/browser/chromeos/cros/network_library.h"
17 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
18 21
19 namespace net { 22 namespace net {
20 class URLRequestContextGetter; 23 class URLRequestContextGetter;
21 } 24 }
22 25
23 namespace chromeos { 26 namespace chromeos {
24 27
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 73
71 private: 74 private:
72 friend class NetworkPortalDetectorTest; 75 friend class NetworkPortalDetectorTest;
73 76
74 typedef std::string NetworkId; 77 typedef std::string NetworkId;
75 typedef base::hash_map<NetworkId, CaptivePortalState> CaptivePortalStateMap; 78 typedef base::hash_map<NetworkId, CaptivePortalState> CaptivePortalStateMap;
76 79
77 enum State { 80 enum State {
78 // No portal check is running. 81 // No portal check is running.
79 STATE_IDLE, 82 STATE_IDLE,
83 // Waiting for portal check.
84 STATE_PORTAL_CHECK_PENDING,
80 // Portal check is in progress. 85 // Portal check is in progress.
81 STATE_CHECKING_FOR_PORTAL, 86 STATE_CHECKING_FOR_PORTAL,
82 // Portal check is in progress, but other portal detection request
83 // is pending.
84 STATE_CHECKING_FOR_PORTAL_NETWORK_CHANGED,
85 }; 87 };
86 88
87 explicit NetworkPortalDetector( 89 explicit NetworkPortalDetector(
88 const scoped_refptr<net::URLRequestContextGetter>& request_context); 90 const scoped_refptr<net::URLRequestContextGetter>& request_context);
89 91
90 // Initiates Captive Portal detection. If currently portal detection 92 // Initiates Captive Portal detection after |delay|.
91 // in in progress, then delays portal detection. 93 void DetectCaptivePortal(const base::TimeDelta& delay);
92 void DetectCaptivePortal(); 94
95 void DetectCaptivePortalTask();
96
97 // Called when portal check is timed out. Cancels portal check and
98 // calls OnPortalDetectionCompleted() with RESULT_NO_RESPONSE as
99 // a result.
100 void PortalDetectionTimeout();
101
102 void CancelPortalDetection();
93 103
94 // Called by CaptivePortalDetector when detection completes. 104 // Called by CaptivePortalDetector when detection completes.
95 void OnPortalDetectionCompleted( 105 void OnPortalDetectionCompleted(
96 const captive_portal::CaptivePortalDetector::Results& results); 106 const captive_portal::CaptivePortalDetector::Results& results);
97 107
108 // Returns true if we're waiting for portal check.
109 bool IsPortalCheckPending() const;
110
98 // Returns true if portal check is in progress. 111 // Returns true if portal check is in progress.
99 bool IsCheckingForPortal() const; 112 bool IsCheckingForPortal() const;
100 113
101 // Stores captive portal state for a |network|. 114 // Stores captive portal state for a |network|.
102 void SetCaptivePortalState(const Network* network, 115 void SetCaptivePortalState(const Network* network,
103 CaptivePortalState state); 116 CaptivePortalState state);
104 117
105 // Notifies observers that portal state is changed for a |network|. 118 // Notifies observers that portal state is changed for a |network|.
106 void NotifyPortalStateChanged(const Network* network, 119 void NotifyPortalStateChanged(const Network* network,
107 CaptivePortalState state); 120 CaptivePortalState state);
108 121
122 // Returns the current TimeTicks.
123 base::TimeTicks GetCurrentTimeTicks() const;
124
109 State state() { return state_; } 125 State state() { return state_; }
110 126
127 // Returns current number of portal detection attempts.
128 // Used by unit tests.
129 int attempt_count_for_testing() { return attempt_count_; }
130
131 // Sets minimum time between consecutive portal checks for the same
132 // network. Used by unit tests.
133 void set_min_time_between_attempts_for_testing(const base::TimeDelta& delta) {
134 min_time_between_attempts_ = delta;
135 }
136
137 // Sets portal detection timeout. Used by unit tests.
138 void set_request_timeout_for_testing(const base::TimeDelta& timeout) {
139 request_timeout_ = timeout;
140 }
141
142 // Returns delay before next portal check. Used by unit tests.
143 const base::TimeDelta& next_attempt_delay_for_testing() {
144 return next_attempt_delay_;
145 }
146
147 // Sets current test time ticks. Used by unit tests.
148 void set_time_ticks_for_testing(const base::TimeTicks& time_ticks) {
149 time_ticks_for_testing_ = time_ticks;
150 }
151
152 // Advances current test time ticks. Used by unit tests.
153 void advance_time_ticks_for_testing(const base::TimeDelta& delta) {
154 time_ticks_for_testing_ += delta;
155 }
156
111 std::string active_network_id_; 157 std::string active_network_id_;
112 State state_; 158 State state_;
113 CaptivePortalStateMap captive_portal_state_map_; 159 CaptivePortalStateMap captive_portal_state_map_;
114 ObserverList<Observer> observers_; 160 ObserverList<Observer> observers_;
115 161
162 base::CancelableClosure detection_task_;
163 base::CancelableClosure detection_timeout_;
164
116 // URL that returns a 204 response code when connected to the Internet. 165 // URL that returns a 204 response code when connected to the Internet.
117 GURL test_url_; 166 GURL test_url_;
118 167
119 // Detector for checking active network for a portal state. 168 // Detector for checking active network for a portal state.
120 scoped_ptr<captive_portal::CaptivePortalDetector> captive_portal_detector_; 169 scoped_ptr<captive_portal::CaptivePortalDetector> captive_portal_detector_;
170
171 base::WeakPtrFactory<NetworkPortalDetector> weak_ptr_factory_;
172
173 // Number of portal detection attemps for an active network.
174 int attempt_count_;
175
176 // Minimum time between consecutive portal checks for the same
177 // active network.
178 base::TimeDelta min_time_between_attempts_;
179
180 // Start time of portal detection attempt.
181 base::TimeTicks attempt_start_time_;
182
183 // Timeout for a portal detection.
184 base::TimeDelta request_timeout_;
185
186 // Delay before next portal detection.
187 base::TimeDelta next_attempt_delay_;
188
189 // Test time ticks used by unit tests.
190 base::TimeTicks time_ticks_for_testing_;
191
192 DISALLOW_COPY_AND_ASSIGN(NetworkPortalDetector);
121 }; 193 };
122 194
123 } // namespace chromeos 195 } // namespace chromeos
124 196
125 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_ 197 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_DETECTOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/captive_portal/testing_utils.cc ('k') | chrome/browser/chromeos/net/network_portal_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698