[email protected] | 26b997396 | 2012-01-28 00:57:00 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 9b9ae955 | 2010-07-01 22:20:50 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 4 | |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 5 | #include "net/proxy/proxy_script_fetcher_impl.h" |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 6 | |
| 7 | #include "base/compiler_specific.h" |
[email protected] | d6e58c6e | 2009-10-10 20:40:50 | [diff] [blame] | 8 | #include "base/i18n/icu_string_conversions.h" |
[email protected] | 13a279e | 2009-04-13 17:32:37 | [diff] [blame] | 9 | #include "base/logging.h" |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 10 | #include "base/message_loop.h" |
| 11 | #include "base/string_util.h" |
[email protected] | e5624f0 | 2011-09-27 19:43:53 | [diff] [blame] | 12 | #include "net/base/cert_status_flags.h" |
[email protected] | d9d71e08 | 2011-02-16 11:44:28 | [diff] [blame] | 13 | #include "net/base/data_url.h" |
[email protected] | 9dea9e1f | 2009-01-29 00:30:47 | [diff] [blame] | 14 | #include "net/base/io_buffer.h" |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 15 | #include "net/base/load_flags.h" |
[email protected] | 597cf6e | 2009-05-29 09:43:26 | [diff] [blame] | 16 | #include "net/base/net_errors.h" |
[email protected] | e0ef2c2 | 2009-06-03 23:54:44 | [diff] [blame] | 17 | #include "net/http/http_response_headers.h" |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 18 | #include "net/url_request/url_request_context.h" |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 19 | |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 20 | // TODO(eroman): |
[email protected] | 33abb68 | 2011-03-29 03:58:42 | [diff] [blame] | 21 | // - Support auth-prompts (http://crbug.com/77366) |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 22 | |
| 23 | namespace net { |
| 24 | |
| 25 | namespace { |
| 26 | |
| 27 | // The maximum size (in bytes) allowed for a PAC script. Responses exceeding |
| 28 | // this will fail with ERR_FILE_TOO_BIG. |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 29 | const int kDefaultMaxResponseBytes = 1048576; // 1 megabyte |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 30 | |
| 31 | // The maximum duration (in milliseconds) allowed for fetching the PAC script. |
| 32 | // Responses exceeding this will fail with ERR_TIMED_OUT. |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 33 | const int kDefaultMaxDurationMs = 300000; // 5 minutes |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 34 | |
[email protected] | 13a279e | 2009-04-13 17:32:37 | [diff] [blame] | 35 | // Returns true if |mime_type| is one of the known PAC mime type. |
| 36 | bool IsPacMimeType(const std::string& mime_type) { |
| 37 | static const char * const kSupportedPacMimeTypes[] = { |
| 38 | "application/x-ns-proxy-autoconfig", |
| 39 | "application/x-javascript-config", |
| 40 | }; |
| 41 | for (size_t i = 0; i < arraysize(kSupportedPacMimeTypes); ++i) { |
| 42 | if (LowerCaseEqualsASCII(mime_type, kSupportedPacMimeTypes[i])) |
| 43 | return true; |
| 44 | } |
| 45 | return false; |
| 46 | } |
| 47 | |
[email protected] | 9b9ae955 | 2010-07-01 22:20:50 | [diff] [blame] | 48 | // Converts |bytes| (which is encoded by |charset|) to UTF16, saving the resul |
| 49 | // to |*utf16|. |
[email protected] | 8f3c9634 | 2009-09-22 03:06:54 | [diff] [blame] | 50 | // If |charset| is empty, then we don't know what it was and guess. |
[email protected] | 9b9ae955 | 2010-07-01 22:20:50 | [diff] [blame] | 51 | void ConvertResponseToUTF16(const std::string& charset, |
| 52 | const std::string& bytes, |
| 53 | string16* utf16) { |
[email protected] | 8f3c9634 | 2009-09-22 03:06:54 | [diff] [blame] | 54 | const char* codepage; |
| 55 | |
| 56 | if (charset.empty()) { |
| 57 | // Assume ISO-8859-1 if no charset was specified. |
[email protected] | d6e58c6e | 2009-10-10 20:40:50 | [diff] [blame] | 58 | codepage = base::kCodepageLatin1; |
[email protected] | 8f3c9634 | 2009-09-22 03:06:54 | [diff] [blame] | 59 | } else { |
| 60 | // Otherwise trust the charset that was provided. |
| 61 | codepage = charset.c_str(); |
| 62 | } |
| 63 | |
| 64 | // We will be generous in the conversion -- if any characters lie |
| 65 | // outside of |charset| (i.e. invalid), then substitute them with |
| 66 | // U+FFFD rather than failing. |
[email protected] | 9b9ae955 | 2010-07-01 22:20:50 | [diff] [blame] | 67 | base::CodepageToUTF16(bytes, codepage, |
| 68 | base::OnStringConversionError::SUBSTITUTE, |
| 69 | utf16); |
[email protected] | 8f3c9634 | 2009-09-22 03:06:54 | [diff] [blame] | 70 | } |
| 71 | |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 72 | } // namespace |
| 73 | |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 74 | ProxyScriptFetcherImpl::ProxyScriptFetcherImpl( |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 75 | URLRequestContext* url_request_context) |
[email protected] | 23578681 | 2011-12-20 02:15:31 | [diff] [blame] | 76 | : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 77 | url_request_context_(url_request_context), |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 78 | buf_(new IOBuffer(kBufSize)), |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 79 | next_id_(0), |
| 80 | cur_request_(NULL), |
| 81 | cur_request_id_(0), |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 82 | result_code_(OK), |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 83 | result_text_(NULL), |
| 84 | max_response_bytes_(kDefaultMaxResponseBytes), |
| 85 | max_duration_(base::TimeDelta::FromMilliseconds(kDefaultMaxDurationMs)) { |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 86 | DCHECK(url_request_context); |
| 87 | } |
| 88 | |
| 89 | ProxyScriptFetcherImpl::~ProxyScriptFetcherImpl() { |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 90 | // The URLRequest's destructor will cancel the outstanding request, and |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 91 | // ensure that the delegate (this) is not called again. |
| 92 | } |
| 93 | |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 94 | base::TimeDelta ProxyScriptFetcherImpl::SetTimeoutConstraint( |
| 95 | base::TimeDelta timeout) { |
| 96 | base::TimeDelta prev = max_duration_; |
| 97 | max_duration_ = timeout; |
| 98 | return prev; |
| 99 | } |
| 100 | |
| 101 | size_t ProxyScriptFetcherImpl::SetSizeConstraint(size_t size_bytes) { |
| 102 | size_t prev = max_response_bytes_; |
| 103 | max_response_bytes_ = size_bytes; |
| 104 | return prev; |
| 105 | } |
| 106 | |
| 107 | void ProxyScriptFetcherImpl::OnResponseCompleted(URLRequest* request) { |
| 108 | DCHECK_EQ(request, cur_request_.get()); |
| 109 | |
| 110 | // Use |result_code_| as the request's error if we have already set it to |
| 111 | // something specific. |
| 112 | if (result_code_ == OK && !request->status().is_success()) |
[email protected] | d0cc35b | 2011-09-08 12:02:05 | [diff] [blame] | 113 | result_code_ = request->status().error(); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 114 | |
| 115 | FetchCompleted(); |
| 116 | } |
| 117 | |
[email protected] | 23578681 | 2011-12-20 02:15:31 | [diff] [blame] | 118 | int ProxyScriptFetcherImpl::Fetch( |
| 119 | const GURL& url, string16* text, const CompletionCallback& callback) { |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 120 | // It is invalid to call Fetch() while a request is already in progress. |
| 121 | DCHECK(!cur_request_.get()); |
[email protected] | 23578681 | 2011-12-20 02:15:31 | [diff] [blame] | 122 | DCHECK(!callback.is_null()); |
[email protected] | 9b9ae955 | 2010-07-01 22:20:50 | [diff] [blame] | 123 | DCHECK(text); |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 124 | |
[email protected] | d9d71e08 | 2011-02-16 11:44:28 | [diff] [blame] | 125 | // Handle base-64 encoded data-urls that contain custom PAC scripts. |
| 126 | if (url.SchemeIs("data")) { |
| 127 | std::string mime_type; |
| 128 | std::string charset; |
| 129 | std::string data; |
| 130 | if (!DataURL::Parse(url, &mime_type, &charset, &data)) |
| 131 | return ERR_FAILED; |
| 132 | |
| 133 | ConvertResponseToUTF16(charset, data, text); |
| 134 | return OK; |
| 135 | } |
| 136 | |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 137 | cur_request_.reset(new URLRequest(url, this)); |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 138 | cur_request_->set_context(url_request_context_); |
| 139 | cur_request_->set_method("GET"); |
| 140 | |
| 141 | // Make sure that the PAC script is downloaded using a direct connection, |
| 142 | // to avoid circular dependencies (fetching is a part of proxy resolution). |
[email protected] | e0ef2c2 | 2009-06-03 23:54:44 | [diff] [blame] | 143 | // Also disable the use of the disk cache. The cache is disabled so that if |
| 144 | // the user switches networks we don't potentially use the cached response |
| 145 | // from old network when we should in fact be re-fetching on the new network. |
[email protected] | 6fbac16 | 2011-06-20 00:29:04 | [diff] [blame] | 146 | // If the PAC script is hosted on an HTTPS server we bypass revocation |
| 147 | // checking in order to avoid a circular dependency when attempting to fetch |
| 148 | // the OCSP response or CRL. We could make the revocation check go direct but |
| 149 | // the proxy might be the only way to the outside world. |
| 150 | cur_request_->set_load_flags(LOAD_BYPASS_PROXY | LOAD_DISABLE_CACHE | |
| 151 | LOAD_DISABLE_CERT_REVOCATION_CHECKING); |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 152 | |
| 153 | // Save the caller's info for notification on completion. |
| 154 | callback_ = callback; |
[email protected] | 9b9ae955 | 2010-07-01 22:20:50 | [diff] [blame] | 155 | result_text_ = text; |
| 156 | |
| 157 | bytes_read_so_far_.clear(); |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 158 | |
| 159 | // Post a task to timeout this request if it takes too long. |
| 160 | cur_request_id_ = ++next_id_; |
[email protected] | 23578681 | 2011-12-20 02:15:31 | [diff] [blame] | 161 | MessageLoop::current()->PostDelayedTask( |
| 162 | FROM_HERE, |
| 163 | base::Bind(&ProxyScriptFetcherImpl::OnTimeout, weak_factory_.GetWeakPtr(), |
| 164 | cur_request_id_), |
[email protected] | 26b997396 | 2012-01-28 00:57:00 | [diff] [blame^] | 165 | max_duration_); |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 166 | |
| 167 | // Start the request. |
| 168 | cur_request_->Start(); |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 169 | return ERR_IO_PENDING; |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | void ProxyScriptFetcherImpl::Cancel() { |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 173 | // ResetCurRequestState will free the URLRequest, which will cause |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 174 | // cancellation. |
| 175 | ResetCurRequestState(); |
| 176 | } |
| 177 | |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 178 | URLRequestContext* ProxyScriptFetcherImpl::GetRequestContext() const { |
[email protected] | 20d296ddc | 2009-11-18 23:07:08 | [diff] [blame] | 179 | return url_request_context_; |
| 180 | } |
| 181 | |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 182 | void ProxyScriptFetcherImpl::OnAuthRequired(URLRequest* request, |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 183 | AuthChallengeInfo* auth_info) { |
[email protected] | 096724916 | 2010-11-20 00:13:32 | [diff] [blame] | 184 | DCHECK_EQ(request, cur_request_.get()); |
[email protected] | 33abb68 | 2011-03-29 03:58:42 | [diff] [blame] | 185 | // TODO(eroman): http://crbug.com/77366 |
[email protected] | 13a279e | 2009-04-13 17:32:37 | [diff] [blame] | 186 | LOG(WARNING) << "Auth required to fetch PAC script, aborting."; |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 187 | result_code_ = ERR_NOT_IMPLEMENTED; |
| 188 | request->CancelAuth(); |
| 189 | } |
| 190 | |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 191 | void ProxyScriptFetcherImpl::OnSSLCertificateError(URLRequest* request, |
[email protected] | e5624f0 | 2011-09-27 19:43:53 | [diff] [blame] | 192 | const SSLInfo& ssl_info, |
[email protected] | 46d117e | 2012-01-18 01:53:14 | [diff] [blame] | 193 | bool fatal) { |
[email protected] | 096724916 | 2010-11-20 00:13:32 | [diff] [blame] | 194 | DCHECK_EQ(request, cur_request_.get()); |
[email protected] | 5db5a73d | 2011-10-12 16:19:36 | [diff] [blame] | 195 | // Revocation check failures are not fatal. |
| 196 | if (IsCertStatusMinorError(ssl_info.cert_status)) { |
| 197 | request->ContinueDespiteLastError(); |
| 198 | return; |
| 199 | } |
[email protected] | 13a279e | 2009-04-13 17:32:37 | [diff] [blame] | 200 | LOG(WARNING) << "SSL certificate error when fetching PAC script, aborting."; |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 201 | // Certificate errors are in same space as net errors. |
[email protected] | e5624f0 | 2011-09-27 19:43:53 | [diff] [blame] | 202 | result_code_ = MapCertStatusToNetError(ssl_info.cert_status); |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 203 | request->Cancel(); |
| 204 | } |
| 205 | |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 206 | void ProxyScriptFetcherImpl::OnResponseStarted(URLRequest* request) { |
[email protected] | 096724916 | 2010-11-20 00:13:32 | [diff] [blame] | 207 | DCHECK_EQ(request, cur_request_.get()); |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 208 | |
| 209 | if (!request->status().is_success()) { |
| 210 | OnResponseCompleted(request); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | // Require HTTP responses to have a success status code. |
| 215 | if (request->url().SchemeIs("http") || request->url().SchemeIs("https")) { |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 216 | // NOTE about status codes: We are like Firefox 3 in this respect. |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 217 | // {IE 7, Safari 3, Opera 9.5} do not care about the status code. |
| 218 | if (request->GetResponseCode() != 200) { |
[email protected] | b30a3f5 | 2010-10-16 01:05:46 | [diff] [blame] | 219 | VLOG(1) << "Fetched PAC script had (bad) status line: " |
| 220 | << request->response_headers()->GetStatusLine(); |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 221 | result_code_ = ERR_PAC_STATUS_NOT_OK; |
| 222 | request->Cancel(); |
| 223 | return; |
| 224 | } |
[email protected] | 13a279e | 2009-04-13 17:32:37 | [diff] [blame] | 225 | |
| 226 | // NOTE about mime types: We do not enforce mime types on PAC files. |
| 227 | // This is for compatibility with {IE 7, Firefox 3, Opera 9.5}. We will |
| 228 | // however log mismatches to help with debugging. |
[email protected] | e0ef2c2 | 2009-06-03 23:54:44 | [diff] [blame] | 229 | std::string mime_type; |
| 230 | cur_request_->GetMimeType(&mime_type); |
| 231 | if (!IsPacMimeType(mime_type)) { |
[email protected] | b30a3f5 | 2010-10-16 01:05:46 | [diff] [blame] | 232 | VLOG(1) << "Fetched PAC script does not have a proper mime type: " |
| 233 | << mime_type; |
[email protected] | 13a279e | 2009-04-13 17:32:37 | [diff] [blame] | 234 | } |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | ReadBody(request); |
| 238 | } |
| 239 | |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 240 | void ProxyScriptFetcherImpl::OnReadCompleted(URLRequest* request, |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 241 | int num_bytes) { |
[email protected] | 096724916 | 2010-11-20 00:13:32 | [diff] [blame] | 242 | DCHECK_EQ(request, cur_request_.get()); |
| 243 | if (ConsumeBytesRead(request, num_bytes)) { |
| 244 | // Keep reading. |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 245 | ReadBody(request); |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 249 | void ProxyScriptFetcherImpl::ReadBody(URLRequest* request) { |
[email protected] | 096724916 | 2010-11-20 00:13:32 | [diff] [blame] | 250 | // Read as many bytes as are available synchronously. |
| 251 | while (true) { |
| 252 | int num_bytes; |
| 253 | if (!request->Read(buf_, kBufSize, &num_bytes)) { |
| 254 | // Check whether the read failed synchronously. |
| 255 | if (!request->status().is_io_pending()) |
| 256 | OnResponseCompleted(request); |
| 257 | return; |
| 258 | } |
| 259 | if (!ConsumeBytesRead(request, num_bytes)) |
| 260 | return; |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 264 | bool ProxyScriptFetcherImpl::ConsumeBytesRead(URLRequest* request, |
[email protected] | 096724916 | 2010-11-20 00:13:32 | [diff] [blame] | 265 | int num_bytes) { |
| 266 | if (num_bytes <= 0) { |
| 267 | // Error while reading, or EOF. |
| 268 | OnResponseCompleted(request); |
| 269 | return false; |
| 270 | } |
| 271 | |
| 272 | // Enforce maximum size bound. |
| 273 | if (num_bytes + bytes_read_so_far_.size() > |
| 274 | static_cast<size_t>(max_response_bytes_)) { |
| 275 | result_code_ = ERR_FILE_TOO_BIG; |
| 276 | request->Cancel(); |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | bytes_read_so_far_.append(buf_->data(), num_bytes); |
| 281 | return true; |
| 282 | } |
| 283 | |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 284 | void ProxyScriptFetcherImpl::FetchCompleted() { |
[email protected] | 8f3c9634 | 2009-09-22 03:06:54 | [diff] [blame] | 285 | if (result_code_ == OK) { |
[email protected] | 9b9ae955 | 2010-07-01 22:20:50 | [diff] [blame] | 286 | // The caller expects the response to be encoded as UTF16. |
[email protected] | 8f3c9634 | 2009-09-22 03:06:54 | [diff] [blame] | 287 | std::string charset; |
| 288 | cur_request_->GetCharset(&charset); |
[email protected] | 9b9ae955 | 2010-07-01 22:20:50 | [diff] [blame] | 289 | ConvertResponseToUTF16(charset, bytes_read_so_far_, result_text_); |
[email protected] | 8f3c9634 | 2009-09-22 03:06:54 | [diff] [blame] | 290 | } else { |
| 291 | // On error, the caller expects empty string for bytes. |
[email protected] | 9b9ae955 | 2010-07-01 22:20:50 | [diff] [blame] | 292 | result_text_->clear(); |
[email protected] | 8f3c9634 | 2009-09-22 03:06:54 | [diff] [blame] | 293 | } |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 294 | |
| 295 | int result_code = result_code_; |
[email protected] | 23578681 | 2011-12-20 02:15:31 | [diff] [blame] | 296 | CompletionCallback callback = callback_; |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 297 | |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 298 | // Hold a reference to the URLRequestContext to prevent re-entrancy from |
| 299 | // ~URLRequestContext. |
[email protected] | ede9666 | 2011-07-14 12:34:18 | [diff] [blame] | 300 | scoped_refptr<const URLRequestContext> context(cur_request_->context()); |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 301 | ResetCurRequestState(); |
| 302 | |
[email protected] | 23578681 | 2011-12-20 02:15:31 | [diff] [blame] | 303 | callback.Run(result_code); |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | void ProxyScriptFetcherImpl::ResetCurRequestState() { |
| 307 | cur_request_.reset(); |
| 308 | cur_request_id_ = 0; |
[email protected] | 23578681 | 2011-12-20 02:15:31 | [diff] [blame] | 309 | callback_.Reset(); |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 310 | result_code_ = OK; |
[email protected] | 9b9ae955 | 2010-07-01 22:20:50 | [diff] [blame] | 311 | result_text_ = NULL; |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | void ProxyScriptFetcherImpl::OnTimeout(int id) { |
[email protected] | da968bc | 2011-01-19 11:48:19 | [diff] [blame] | 315 | // Timeout tasks may outlive the URLRequest they reference. Make sure it |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 316 | // is still applicable. |
| 317 | if (cur_request_id_ != id) |
| 318 | return; |
| 319 | |
| 320 | DCHECK(cur_request_.get()); |
| 321 | result_code_ = ERR_TIMED_OUT; |
| 322 | cur_request_->Cancel(); |
| 323 | } |
| 324 | |
[email protected] | 677c9057 | 2008-12-10 09:03:15 | [diff] [blame] | 325 | } // namespace net |