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

Side by Side Diff: components/captive_portal/captive_portal_detector.h

Issue 242483003: Move CaptivePortalDetector to src/components/captive_portal (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 | « components/captive_portal/OWNERS ('k') | components/captive_portal/captive_portal_detector.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) 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_DETECTOR_H_ 5 #ifndef COMPONENTS_CAPTIVE_PORTAL_CAPTIVE_PORTAL_DETECTOR_H_
6 #define CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_DETECTOR_H_ 6 #define COMPONENTS_CAPTIVE_PORTAL_CAPTIVE_PORTAL_DETECTOR_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/threading/non_thread_safe.h" 13 #include "base/threading/non_thread_safe.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "components/captive_portal/captive_portal_export.h"
16 #include "components/captive_portal/captive_portal_types.h"
15 #include "net/url_request/url_fetcher.h" 17 #include "net/url_request/url_fetcher.h"
16 #include "net/url_request/url_fetcher_delegate.h" 18 #include "net/url_request/url_fetcher_delegate.h"
17 #include "net/url_request/url_request_context_getter.h" 19 #include "net/url_request/url_request_context_getter.h"
18 20
19 class GURL; 21 class GURL;
20 22
21 namespace captive_portal { 23 namespace captive_portal {
22 24
23 // Possible results of an attempt to detect a captive portal. 25 class CAPTIVE_PORTAL_EXPORT CaptivePortalDetector
24 enum Result { 26 : public net::URLFetcherDelegate,
25 // There's a confirmed connection to the Internet. 27 public base::NonThreadSafe {
26 RESULT_INTERNET_CONNECTED,
27 // The URL request received a network or HTTP error, or a non-HTTP response.
28 RESULT_NO_RESPONSE,
29 // The URL request apparently encountered a captive portal. It received a
30 // a valid HTTP response with a 2xx other than 204, 3xx, or 511 status code.
31 RESULT_BEHIND_CAPTIVE_PORTAL,
32 RESULT_COUNT
33 };
34
35 class CaptivePortalDetector : public net::URLFetcherDelegate,
36 public base::NonThreadSafe {
37 public: 28 public:
38 struct Results { 29 struct Results {
39 Results() 30 Results()
40 : result(RESULT_NO_RESPONSE), 31 : result(captive_portal::RESULT_NO_RESPONSE),
41 response_code(net::URLFetcher::RESPONSE_CODE_INVALID) { 32 response_code(net::URLFetcher::RESPONSE_CODE_INVALID) {
42 } 33 }
43 34
44 Result result; 35 captive_portal::CaptivePortalResult result;
45 int response_code; 36 int response_code;
46 base::TimeDelta retry_after_delta; 37 base::TimeDelta retry_after_delta;
47 GURL landing_url; 38 GURL landing_url;
48 }; 39 };
49 40
50 typedef base::Callback<void(const Results& results)> DetectionCallback; 41 typedef base::Callback<void(const Results& results)> DetectionCallback;
51 42
52 // The test URL. When connected to the Internet, it should return a 43 // The test URL. When connected to the Internet, it should return a
53 // blank page with a 204 status code. When behind a captive portal, 44 // blank page with a 204 status code. When behind a captive portal,
54 // requests for this URL should get an HTTP redirect or a login 45 // requests for this URL should get an HTTP redirect or a login
55 // page. When neither is true, no server should respond to requests 46 // page. When neither is true, no server should respond to requests
56 // for this URL. 47 // for this URL.
57 static const char kDefaultURL[]; 48 static const char kDefaultURL[];
58 49
59 explicit CaptivePortalDetector( 50 explicit CaptivePortalDetector(
60 const scoped_refptr<net::URLRequestContextGetter>& request_context); 51 const scoped_refptr<net::URLRequestContextGetter>& request_context);
61 virtual ~CaptivePortalDetector(); 52 virtual ~CaptivePortalDetector();
62 53
63 static std::string CaptivePortalResultToString(Result result);
64
65 // Triggers a check for a captive portal. After completion, runs the 54 // Triggers a check for a captive portal. After completion, runs the
66 // |callback|. 55 // |callback|.
67 void DetectCaptivePortal(const GURL& url, const DetectionCallback& callback); 56 void DetectCaptivePortal(const GURL& url, const DetectionCallback& callback);
68 57
69 // Cancels captive portal check. 58 // Cancels captive portal check.
70 void Cancel(); 59 void Cancel();
71 60
72 private: 61 private:
73 friend class CaptivePortalDetectorTestBase; 62 friend class CaptivePortalDetectorTestBase;
74 63
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 scoped_ptr<net::URLFetcher> url_fetcher_; 97 scoped_ptr<net::URLFetcher> url_fetcher_;
109 98
110 // Test time used by unit tests. 99 // Test time used by unit tests.
111 base::Time time_for_testing_; 100 base::Time time_for_testing_;
112 101
113 DISALLOW_COPY_AND_ASSIGN(CaptivePortalDetector); 102 DISALLOW_COPY_AND_ASSIGN(CaptivePortalDetector);
114 }; 103 };
115 104
116 } // namespace captive_portal 105 } // namespace captive_portal
117 106
118 #endif // CHROME_BROWSER_CAPTIVE_PORTAL_CAPTIVE_PORTAL_DETECTOR_H_ 107 #endif // COMPONENTS_CAPTIVE_PORTAL_CAPTIVE_PORTAL_DETECTOR_H_
OLDNEW
« no previous file with comments | « components/captive_portal/OWNERS ('k') | components/captive_portal/captive_portal_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698