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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/timer.h" | 13 #include "base/timer.h" |
14 #include "chrome/browser/prefs/pref_member.h" | 14 #include "chrome/browser/prefs/pref_member.h" |
15 #include "chrome/browser/profiles/profile_keyed_service.h" | 15 #include "chrome/browser/profiles/profile_keyed_service.h" |
16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/common/url_fetcher_delegate.h" | |
18 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
19 #include "net/base/backoff_entry.h" | 18 #include "net/base/backoff_entry.h" |
| 19 #include "net/url_request/url_fetcher_delegate.h" |
20 | 20 |
21 class Profile; | 21 class Profile; |
22 | 22 |
23 namespace net { | 23 namespace net { |
24 class URLFetcher; | 24 class URLFetcher; |
25 } | 25 } |
26 | 26 |
27 namespace captive_portal { | 27 namespace captive_portal { |
28 | 28 |
29 // Possible results of an attempt to detect a captive portal. | 29 // Possible results of an attempt to detect a captive portal. |
30 enum Result { | 30 enum Result { |
31 // There's a confirmed connection to the Internet. | 31 // There's a confirmed connection to the Internet. |
32 RESULT_INTERNET_CONNECTED, | 32 RESULT_INTERNET_CONNECTED, |
33 // The URL request received a network or HTTP error, or a non-HTTP response. | 33 // The URL request received a network or HTTP error, or a non-HTTP response. |
34 RESULT_NO_RESPONSE, | 34 RESULT_NO_RESPONSE, |
35 // The URL request apparently encountered a captive portal. It received a | 35 // The URL request apparently encountered a captive portal. It received a |
36 // a valid HTTP response with a 2xx or 3xx status code, other than a 204. | 36 // a valid HTTP response with a 2xx or 3xx status code, other than a 204. |
37 RESULT_BEHIND_CAPTIVE_PORTAL, | 37 RESULT_BEHIND_CAPTIVE_PORTAL, |
38 RESULT_COUNT | 38 RESULT_COUNT |
39 }; | 39 }; |
40 | 40 |
41 // Service that checks for captive portals when queried, and sends a | 41 // Service that checks for captive portals when queried, and sends a |
42 // NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT with the Profile as the source and | 42 // NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT with the Profile as the source and |
43 // a CaptivePortalService::Results as the details. | 43 // a CaptivePortalService::Results as the details. |
44 // | 44 // |
45 // Captive portal checks are rate-limited. The CaptivePortalService may only | 45 // Captive portal checks are rate-limited. The CaptivePortalService may only |
46 // be accessed on the UI thread. | 46 // be accessed on the UI thread. |
47 // Design doc: https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlU
dlUdoW9WRaEmfM/edit | 47 // Design doc: https://docs.google.com/document/d/1k-gP2sswzYNvryu9NcgN7q5XrsMlU
dlUdoW9WRaEmfM/edit |
48 class CaptivePortalService : public ProfileKeyedService, | 48 class CaptivePortalService : public ProfileKeyedService, |
49 public content::URLFetcherDelegate, | 49 public net::URLFetcherDelegate, |
50 public content::NotificationObserver, | 50 public content::NotificationObserver, |
51 public base::NonThreadSafe { | 51 public base::NonThreadSafe { |
52 public: | 52 public: |
53 // The details sent via a NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT. | 53 // The details sent via a NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT. |
54 struct Results { | 54 struct Results { |
55 // The result of the second most recent captive portal check. | 55 // The result of the second most recent captive portal check. |
56 Result previous_result; | 56 Result previous_result; |
57 // The result of the most recent captive portal check. | 57 // The result of the most recent captive portal check. |
58 Result result; | 58 Result result; |
59 }; | 59 }; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // |initial_backoff_no_portal_ms|. Also used when the service is disabled. | 108 // |initial_backoff_no_portal_ms|. Also used when the service is disabled. |
109 int initial_backoff_portal_ms; | 109 int initial_backoff_portal_ms; |
110 | 110 |
111 net::BackoffEntry::Policy backoff_policy; | 111 net::BackoffEntry::Policy backoff_policy; |
112 }; | 112 }; |
113 | 113 |
114 // Initiates a captive portal check, without any throttling. If the service | 114 // Initiates a captive portal check, without any throttling. If the service |
115 // is disabled, just acts like there's an Internet connection. | 115 // is disabled, just acts like there's an Internet connection. |
116 void DetectCaptivePortalInternal(); | 116 void DetectCaptivePortalInternal(); |
117 | 117 |
118 // content::URLFetcherDelegate: | 118 // net::URLFetcherDelegate: |
119 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 119 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
120 | 120 |
121 // content::NotificationObserver: | 121 // content::NotificationObserver: |
122 virtual void Observe( | 122 virtual void Observe( |
123 int type, | 123 int type, |
124 const content::NotificationSource& source, | 124 const content::NotificationSource& source, |
125 const content::NotificationDetails& details) OVERRIDE; | 125 const content::NotificationDetails& details) OVERRIDE; |
126 | 126 |
127 // ProfileKeyedService: | 127 // ProfileKeyedService: |
128 virtual void Shutdown() OVERRIDE; | 128 virtual void Shutdown() OVERRIDE; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 BooleanPrefMember resolve_errors_with_web_service_; | 208 BooleanPrefMember resolve_errors_with_web_service_; |
209 | 209 |
210 base::OneShotTimer<CaptivePortalService> check_captive_portal_timer_; | 210 base::OneShotTimer<CaptivePortalService> check_captive_portal_timer_; |
211 | 211 |
212 DISALLOW_COPY_AND_ASSIGN(CaptivePortalService); | 212 DISALLOW_COPY_AND_ASSIGN(CaptivePortalService); |
213 }; | 213 }; |
214 | 214 |
215 } // namespace captive_portal | 215 } // namespace captive_portal |
216 | 216 |
217 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ | 217 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_SERVICE_H_ |
OLD | NEW |