| 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 "net/proxy/proxy_script_fetcher_impl.h" | 5 #include "net/proxy/proxy_script_fetcher_impl.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 FetchCompleted(); | 116 FetchCompleted(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 int ProxyScriptFetcherImpl::Fetch( | 119 int ProxyScriptFetcherImpl::Fetch( |
| 120 const GURL& url, base::string16* text, const CompletionCallback& callback) { | 120 const GURL& url, base::string16* text, const CompletionCallback& callback) { |
| 121 // It is invalid to call Fetch() while a request is already in progress. | 121 // It is invalid to call Fetch() while a request is already in progress. |
| 122 DCHECK(!cur_request_.get()); | 122 DCHECK(!cur_request_.get()); |
| 123 DCHECK(!callback.is_null()); | 123 DCHECK(!callback.is_null()); |
| 124 DCHECK(text); | 124 DCHECK(text); |
| 125 | 125 |
| 126 if (!url_request_context_) |
| 127 return ERR_CONTEXT_SHUT_DOWN; |
| 128 |
| 126 // Handle base-64 encoded data-urls that contain custom PAC scripts. | 129 // Handle base-64 encoded data-urls that contain custom PAC scripts. |
| 127 if (url.SchemeIs("data")) { | 130 if (url.SchemeIs("data")) { |
| 128 std::string mime_type; | 131 std::string mime_type; |
| 129 std::string charset; | 132 std::string charset; |
| 130 std::string data; | 133 std::string data; |
| 131 if (!DataURL::Parse(url, &mime_type, &charset, &data)) | 134 if (!DataURL::Parse(url, &mime_type, &charset, &data)) |
| 132 return ERR_FAILED; | 135 return ERR_FAILED; |
| 133 | 136 |
| 134 ConvertResponseToUTF16(charset, data, text); | 137 ConvertResponseToUTF16(charset, data, text); |
| 135 return OK; | 138 return OK; |
| 136 } | 139 } |
| 137 | 140 |
| 138 DCHECK(fetch_start_time_.is_null()); | 141 DCHECK(fetch_start_time_.is_null()); |
| 139 fetch_start_time_ = base::TimeTicks::Now(); | 142 fetch_start_time_ = base::TimeTicks::Now(); |
| 140 | 143 |
| 144 // Use highest priority, so if socket pools are being used for other types of |
| 145 // requests, PAC requests are aren't blocked on them. |
| 141 cur_request_ = | 146 cur_request_ = |
| 142 url_request_context_->CreateRequest(url, DEFAULT_PRIORITY, this); | 147 url_request_context_->CreateRequest(url, MAXIMUM_PRIORITY, this); |
| 143 cur_request_->set_method("GET"); | 148 cur_request_->set_method("GET"); |
| 144 | 149 |
| 145 // Make sure that the PAC script is downloaded using a direct connection, | 150 // Make sure that the PAC script is downloaded using a direct connection, |
| 146 // to avoid circular dependencies (fetching is a part of proxy resolution). | 151 // to avoid circular dependencies (fetching is a part of proxy resolution). |
| 147 // Also disable the use of the disk cache. The cache is disabled so that if | 152 // Also disable the use of the disk cache. The cache is disabled so that if |
| 148 // the user switches networks we don't potentially use the cached response | 153 // the user switches networks we don't potentially use the cached response |
| 149 // from old network when we should in fact be re-fetching on the new network. | 154 // from old network when we should in fact be re-fetching on the new network. |
| 150 // If the PAC script is hosted on an HTTPS server we bypass revocation | 155 // If the PAC script is hosted on an HTTPS server we bypass revocation |
| 151 // checking in order to avoid a circular dependency when attempting to fetch | 156 // checking in order to avoid a circular dependency when attempting to fetch |
| 152 // the OCSP response or CRL. We could make the revocation check go direct but | 157 // the OCSP response or CRL. We could make the revocation check go direct but |
| 153 // the proxy might be the only way to the outside world. | 158 // the proxy might be the only way to the outside world. IGNORE_LIMITS is |
| 159 // used to avoid blocking proxy resolution on other network requests. |
| 154 cur_request_->SetLoadFlags(LOAD_BYPASS_PROXY | LOAD_DISABLE_CACHE | | 160 cur_request_->SetLoadFlags(LOAD_BYPASS_PROXY | LOAD_DISABLE_CACHE | |
| 155 LOAD_DISABLE_CERT_REVOCATION_CHECKING); | 161 LOAD_DISABLE_CERT_REVOCATION_CHECKING | |
| 162 LOAD_IGNORE_LIMITS); |
| 156 | 163 |
| 157 // Save the caller's info for notification on completion. | 164 // Save the caller's info for notification on completion. |
| 158 callback_ = callback; | 165 callback_ = callback; |
| 159 result_text_ = text; | 166 result_text_ = text; |
| 160 | 167 |
| 161 bytes_read_so_far_.clear(); | 168 bytes_read_so_far_.clear(); |
| 162 | 169 |
| 163 // Post a task to timeout this request if it takes too long. | 170 // Post a task to timeout this request if it takes too long. |
| 164 cur_request_id_ = ++next_id_; | 171 cur_request_id_ = ++next_id_; |
| 165 | 172 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 176 void ProxyScriptFetcherImpl::Cancel() { | 183 void ProxyScriptFetcherImpl::Cancel() { |
| 177 // ResetCurRequestState will free the URLRequest, which will cause | 184 // ResetCurRequestState will free the URLRequest, which will cause |
| 178 // cancellation. | 185 // cancellation. |
| 179 ResetCurRequestState(); | 186 ResetCurRequestState(); |
| 180 } | 187 } |
| 181 | 188 |
| 182 URLRequestContext* ProxyScriptFetcherImpl::GetRequestContext() const { | 189 URLRequestContext* ProxyScriptFetcherImpl::GetRequestContext() const { |
| 183 return url_request_context_; | 190 return url_request_context_; |
| 184 } | 191 } |
| 185 | 192 |
| 193 void ProxyScriptFetcherImpl::OnShutdown() { |
| 194 url_request_context_ = nullptr; |
| 195 result_code_ = ERR_CONTEXT_SHUT_DOWN; |
| 196 FetchCompleted(); |
| 197 } |
| 198 |
| 186 void ProxyScriptFetcherImpl::OnAuthRequired(URLRequest* request, | 199 void ProxyScriptFetcherImpl::OnAuthRequired(URLRequest* request, |
| 187 AuthChallengeInfo* auth_info) { | 200 AuthChallengeInfo* auth_info) { |
| 188 DCHECK_EQ(request, cur_request_.get()); | 201 DCHECK_EQ(request, cur_request_.get()); |
| 189 // TODO(eroman): http://crbug.com/77366 | 202 // TODO(eroman): http://crbug.com/77366 |
| 190 LOG(WARNING) << "Auth required to fetch PAC script, aborting."; | 203 LOG(WARNING) << "Auth required to fetch PAC script, aborting."; |
| 191 result_code_ = ERR_NOT_IMPLEMENTED; | 204 result_code_ = ERR_NOT_IMPLEMENTED; |
| 192 request->CancelAuth(); | 205 request->CancelAuth(); |
| 193 } | 206 } |
| 194 | 207 |
| 195 void ProxyScriptFetcherImpl::OnSSLCertificateError(URLRequest* request, | 208 void ProxyScriptFetcherImpl::OnSSLCertificateError(URLRequest* request, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 } | 347 } |
| 335 | 348 |
| 336 void ProxyScriptFetcherImpl::OnTimeout(int id) { | 349 void ProxyScriptFetcherImpl::OnTimeout(int id) { |
| 337 // Timeout tasks may outlive the URLRequest they reference. Make sure it | 350 // Timeout tasks may outlive the URLRequest they reference. Make sure it |
| 338 // is still applicable. | 351 // is still applicable. |
| 339 if (cur_request_id_ != id) | 352 if (cur_request_id_ != id) |
| 340 return; | 353 return; |
| 341 | 354 |
| 342 DCHECK(cur_request_.get()); | 355 DCHECK(cur_request_.get()); |
| 343 result_code_ = ERR_TIMED_OUT; | 356 result_code_ = ERR_TIMED_OUT; |
| 344 cur_request_->Cancel(); | 357 FetchCompleted(); |
| 345 } | 358 } |
| 346 | 359 |
| 347 } // namespace net | 360 } // namespace net |
| OLD | NEW |