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 #include "chrome/browser/captive_portal/captive_portal_detector.h" | 5 #include "chrome/browser/captive_portal/captive_portal_detector.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "net/base/load_flags.h" | 10 #include "net/base/load_flags.h" |
11 #include "net/http/http_response_headers.h" | 11 #include "net/http/http_response_headers.h" |
12 #include "net/url_request/url_fetcher.h" | 12 #include "net/url_request/url_fetcher.h" |
13 #include "net/url_request/url_request_status.h" | 13 #include "net/url_request/url_request_status.h" |
14 | 14 |
15 namespace captive_portal { | 15 namespace captive_portal { |
16 | 16 |
| 17 namespace { |
| 18 |
| 19 const char* const kCaptivePortalResultNames[] = { |
| 20 "InternetConnected", |
| 21 "NoResponse", |
| 22 "BehindCaptivePortal", |
| 23 "NumCaptivePortalResults", |
| 24 }; |
| 25 COMPILE_ASSERT(arraysize(kCaptivePortalResultNames) == RESULT_COUNT + 1, |
| 26 captive_portal_result_name_count_mismatch); |
| 27 |
| 28 } // namespace |
| 29 |
17 const char CaptivePortalDetector::kDefaultURL[] = | 30 const char CaptivePortalDetector::kDefaultURL[] = |
18 "http://www.gstatic.com/generate_204"; | 31 "http://www.gstatic.com/generate_204"; |
19 | 32 |
20 CaptivePortalDetector::CaptivePortalDetector( | 33 CaptivePortalDetector::CaptivePortalDetector( |
21 const scoped_refptr<net::URLRequestContextGetter>& request_context) | 34 const scoped_refptr<net::URLRequestContextGetter>& request_context) |
22 : request_context_(request_context) { | 35 : request_context_(request_context) { |
23 } | 36 } |
24 | 37 |
25 CaptivePortalDetector::~CaptivePortalDetector() { | 38 CaptivePortalDetector::~CaptivePortalDetector() { |
26 } | 39 } |
27 | 40 |
| 41 // static |
| 42 std::string CaptivePortalDetector::CaptivePortalResultToString(Result result) { |
| 43 DCHECK_GE(result, 0); |
| 44 DCHECK_LT(static_cast<unsigned int>(result), |
| 45 arraysize(kCaptivePortalResultNames)); |
| 46 return kCaptivePortalResultNames[result]; |
| 47 } |
| 48 |
28 void CaptivePortalDetector::DetectCaptivePortal( | 49 void CaptivePortalDetector::DetectCaptivePortal( |
29 const GURL& url, | 50 const GURL& url, |
30 const DetectionCallback& detection_callback) { | 51 const DetectionCallback& detection_callback) { |
31 DCHECK(CalledOnValidThread()); | 52 DCHECK(CalledOnValidThread()); |
32 DCHECK(!FetchingURL()); | 53 DCHECK(!FetchingURL()); |
33 DCHECK(detection_callback_.is_null()); | 54 DCHECK(detection_callback_.is_null()); |
34 | 55 |
35 detection_callback_ = detection_callback; | 56 detection_callback_ = detection_callback; |
36 | 57 |
37 // The first 0 means this can use a TestURLFetcherFactory in unit tests. | 58 // The first 0 means this can use a TestURLFetcherFactory in unit tests. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 return base::Time::Now(); | 161 return base::Time::Now(); |
141 else | 162 else |
142 return time_for_testing_; | 163 return time_for_testing_; |
143 } | 164 } |
144 | 165 |
145 bool CaptivePortalDetector::FetchingURL() const { | 166 bool CaptivePortalDetector::FetchingURL() const { |
146 return url_fetcher_.get() != NULL; | 167 return url_fetcher_.get() != NULL; |
147 } | 168 } |
148 | 169 |
149 } // namespace captive_portal | 170 } // namespace captive_portal |
OLD | NEW |