OLD | NEW |
---|---|
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_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ |
6 #define CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ | 6 #define CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_member.h" | 10 #include "base/prefs/pref_member.h" |
11 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
12 #include "base/time/tick_clock.h" | |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
14 #include "components/captive_portal/captive_portal_detector.h" | 15 #include "components/captive_portal/captive_portal_detector.h" |
15 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
16 #include "net/base/backoff_entry.h" | 17 #include "net/base/backoff_entry.h" |
17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
18 | 19 |
19 class Profile; | 20 class Profile; |
20 | 21 |
21 // Service that checks for captive portals when queried, and sends a | 22 // Service that checks for captive portals when queried, and sends a |
22 // NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT with the Profile as the source and | 23 // NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT with the Profile as the source and |
23 // a CaptivePortalService::Results as the details. | 24 // a CaptivePortalService::Results as the details. |
24 // | 25 // |
25 // Captive portal checks are rate-limited. The CaptivePortalService may only | 26 // Captive portal checks are rate-limited. The CaptivePortalService may only |
26 // be accessed on the UI thread. | 27 // be accessed on the UI thread. |
27 // Design doc: https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlU dlUdoW9WRaEmfM/edit | 28 // Design doc: https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlU dlUdoW9WRaEmfM/edit |
28 class CaptivePortalService : public KeyedService, public base::NonThreadSafe { | 29 class CaptivePortalService : public KeyedService, public base::NonThreadSafe, |
30 private base::TickClock { | |
pneubeck (no reviews)
2015/04/14 10:27:04
as you've hidden TickClock::NowTicks below, TickCl
johnme
2015/04/20 15:52:44
Note that I was using private inheritance, so AFAI
pneubeck (no reviews)
2015/04/20 16:35:50
Ha! I didn't even see that. Private inheritance is
| |
29 public: | 31 public: |
30 enum TestingState { | 32 enum TestingState { |
31 NOT_TESTING, | 33 NOT_TESTING, |
32 DISABLED_FOR_TESTING, // The service is always disabled. | 34 DISABLED_FOR_TESTING, // The service is always disabled. |
33 SKIP_OS_CHECK_FOR_TESTING, // The service can be enabled even if the OS | 35 SKIP_OS_CHECK_FOR_TESTING, // The service can be enabled even if the OS |
34 // has native captive portal detection. | 36 // has native captive portal detection. |
35 IGNORE_REQUESTS_FOR_TESTING // Disables actual portal checks. This also | 37 IGNORE_REQUESTS_FOR_TESTING // Disables actual portal checks. This also |
36 // implies SKIP_OS_CHECK_FOR_TESTING. | 38 // implies SKIP_OS_CHECK_FOR_TESTING. |
37 }; | 39 }; |
38 | 40 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 // tests. Should be called before the service is created. | 74 // tests. Should be called before the service is created. |
73 static void set_state_for_testing(TestingState testing_state) { | 75 static void set_state_for_testing(TestingState testing_state) { |
74 testing_state_ = testing_state; | 76 testing_state_ = testing_state; |
75 } | 77 } |
76 static TestingState get_state_for_testing() { return testing_state_; } | 78 static TestingState get_state_for_testing() { return testing_state_; } |
77 | 79 |
78 private: | 80 private: |
79 friend class CaptivePortalServiceTest; | 81 friend class CaptivePortalServiceTest; |
80 friend class CaptivePortalBrowserTest; | 82 friend class CaptivePortalBrowserTest; |
81 | 83 |
82 // Subclass of BackoffEntry that uses the CaptivePortalService's | 84 // Subclass of TickClock that uses the CaptivePortalService's |
83 // GetCurrentTime function, for unit testing. | 85 // GetCurrentTimeTicks function, for unit testing. |
pneubeck (no reviews)
2015/04/14 10:27:04
this function doesn't exist anymore.
johnme
2015/04/20 15:52:44
Done (removed comment).
| |
84 class RecheckBackoffEntry; | 86 class RecheckTickClock; |
pneubeck (no reviews)
2015/04/14 10:27:04
unused
johnme
2015/04/20 15:52:44
Done (removed).
| |
85 | 87 |
86 enum State { | 88 enum State { |
87 // No check is running or pending. | 89 // No check is running or pending. |
88 STATE_IDLE, | 90 STATE_IDLE, |
89 // The timer to check for a captive portal is running. | 91 // The timer to check for a captive portal is running. |
90 STATE_TIMER_RUNNING, | 92 STATE_TIMER_RUNNING, |
91 // There's an outstanding HTTP request to check for a captive portal. | 93 // There's an outstanding HTTP request to check for a captive portal. |
92 STATE_CHECKING_FOR_PORTAL, | 94 STATE_CHECKING_FOR_PORTAL, |
93 }; | 95 }; |
94 | 96 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 void ResetBackoffEntry(captive_portal::CaptivePortalResult result); | 133 void ResetBackoffEntry(captive_portal::CaptivePortalResult result); |
132 | 134 |
133 // Updates |enabled_| based on command line flags and Profile preferences, | 135 // Updates |enabled_| based on command line flags and Profile preferences, |
134 // and sets |state_| to STATE_NONE if it's false. | 136 // and sets |state_| to STATE_NONE if it's false. |
135 // TODO(mmenke): Figure out on which platforms, if any, should not use | 137 // TODO(mmenke): Figure out on which platforms, if any, should not use |
136 // automatic captive portal detection. Currently it's enabled | 138 // automatic captive portal detection. Currently it's enabled |
137 // on all platforms, though this code is not compiled on | 139 // on all platforms, though this code is not compiled on |
138 // Android, since it lacks the Browser class. | 140 // Android, since it lacks the Browser class. |
139 void UpdateEnabledState(); | 141 void UpdateEnabledState(); |
140 | 142 |
141 // Returns the current TimeTicks. | 143 // base::TickClock implementation. |
pneubeck (no reviews)
2015/04/14 10:27:04
visibility of inherited functions should usually n
johnme
2015/04/20 15:52:44
Done (it was private inheritance, as explained abo
| |
142 base::TimeTicks GetCurrentTimeTicks() const; | 144 base::TimeTicks NowTicks() override; |
143 | 145 |
144 bool DetectionInProgress() const; | 146 bool DetectionInProgress() const; |
145 | 147 |
146 // Returns true if the timer to try and detect a captive portal is running. | 148 // Returns true if the timer to try and detect a captive portal is running. |
147 bool TimerRunning() const; | 149 bool TimerRunning() const; |
148 | 150 |
149 State state() const { return state_; } | 151 State state() const { return state_; } |
150 | 152 |
151 RecheckPolicy& recheck_policy() { return recheck_policy_; } | 153 RecheckPolicy& recheck_policy() { return recheck_policy_; } |
152 | 154 |
153 void set_test_url(const GURL& test_url) { test_url_ = test_url; } | 155 void set_test_url(const GURL& test_url) { test_url_ = test_url; } |
154 | 156 |
155 // Sets current test time ticks. Used by unit tests. | 157 // Sets current test time ticks. Used by unit tests. |
156 void set_time_ticks_for_testing(const base::TimeTicks& time_ticks) { | 158 void set_time_ticks_for_testing(const base::TimeTicks& time_ticks) { |
pneubeck (no reviews)
2015/04/14 10:27:04
bad style. should be passed as TickClock dependenc
johnme
2015/04/20 15:52:44
Done.
| |
157 time_ticks_for_testing_ = time_ticks; | 159 time_ticks_for_testing_ = time_ticks; |
158 } | 160 } |
159 | 161 |
160 // Advances current test time ticks. Used by unit tests. | 162 // Advances current test time ticks. Used by unit tests. |
161 void advance_time_ticks_for_testing(const base::TimeDelta& delta) { | 163 void advance_time_ticks_for_testing(const base::TimeDelta& delta) { |
162 time_ticks_for_testing_ += delta; | 164 time_ticks_for_testing_ += delta; |
163 } | 165 } |
164 | 166 |
165 // The profile that owns this CaptivePortalService. | 167 // The profile that owns this CaptivePortalService. |
166 Profile* profile_; | 168 Profile* profile_; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 | 209 |
208 static TestingState testing_state_; | 210 static TestingState testing_state_; |
209 | 211 |
210 // Test time ticks used by unit tests. | 212 // Test time ticks used by unit tests. |
211 base::TimeTicks time_ticks_for_testing_; | 213 base::TimeTicks time_ticks_for_testing_; |
212 | 214 |
213 DISALLOW_COPY_AND_ASSIGN(CaptivePortalService); | 215 DISALLOW_COPY_AND_ASSIGN(CaptivePortalService); |
214 }; | 216 }; |
215 | 217 |
216 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ | 218 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ |
OLD | NEW |