| 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 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 51 net::LOAD_DO_NOT_SEND_COOKIES | | 64 net::LOAD_DO_NOT_SEND_COOKIES | |
| 52 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 65 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
| 53 url_fetcher_->Start(); | 66 url_fetcher_->Start(); |
| 54 } | 67 } |
| 55 | 68 |
| 56 void CaptivePortalDetector::Cancel() { | 69 void CaptivePortalDetector::Cancel() { |
| 57 url_fetcher_.reset(); | 70 url_fetcher_.reset(); |
| 58 detection_callback_.Reset(); | 71 detection_callback_.Reset(); |
| 59 } | 72 } |
| 60 | 73 |
| 74 // static |
| 75 std::string CaptivePortalDetector::CaptivePortalResultToString(Result result) { |
| 76 DCHECK_GE(result, 0); |
| 77 DCHECK_LT(static_cast<unsigned int>(result), |
| 78 arraysize(kCaptivePortalResultNames)); |
| 79 return kCaptivePortalResultNames[result]; |
| 80 } |
| 81 |
| 61 void CaptivePortalDetector::OnURLFetchComplete(const net::URLFetcher* source) { | 82 void CaptivePortalDetector::OnURLFetchComplete(const net::URLFetcher* source) { |
| 62 DCHECK(CalledOnValidThread()); | 83 DCHECK(CalledOnValidThread()); |
| 63 DCHECK(FetchingURL()); | 84 DCHECK(FetchingURL()); |
| 64 DCHECK_EQ(url_fetcher_.get(), source); | 85 DCHECK_EQ(url_fetcher_.get(), source); |
| 65 DCHECK(!detection_callback_.is_null()); | 86 DCHECK(!detection_callback_.is_null()); |
| 66 | 87 |
| 67 Results results; | 88 Results results; |
| 68 GetCaptivePortalResultFromResponse(url_fetcher_.get(), &results); | 89 GetCaptivePortalResultFromResponse(url_fetcher_.get(), &results); |
| 69 DetectionCallback callback = detection_callback_; | 90 DetectionCallback callback = detection_callback_; |
| 70 url_fetcher_.reset(); | 91 url_fetcher_.reset(); |
| (...skipping 69 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 |