blob: cedd67874ceace41ea0d834bce8cadc2fd4ec3be [file] [log] [blame]
[email protected]26b9973962012-01-28 00:57:001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]9b9ae9552010-07-01 22:20:502// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]677c90572008-12-10 09:03:154
Lily Houghton582d4622018-01-22 22:43:405#include "net/proxy_resolution/pac_file_fetcher_impl.h"
[email protected]677c90572008-12-10 09:03:156
Sebastien Marchand6d0558fd2019-01-25 16:49:377#include "base/bind.h"
[email protected]677c90572008-12-10 09:03:158#include "base/compiler_specific.h"
skyostil4891b25b2015-06-11 11:43:459#include "base/location.h"
[email protected]13a279e2009-04-13 17:32:3710#include "base/logging.h"
Gabriel Charette9f60dd12020-03-06 20:48:0411#include "base/memory/ptr_util.h"
asvitkine30330812016-08-30 04:01:0812#include "base/metrics/histogram_macros.h"
skyostil4891b25b2015-06-11 11:43:4513#include "base/single_thread_task_runner.h"
Avi Drissman4365a4782018-12-28 19:26:2414#include "base/stl_util.h"
[email protected]fc9be5802013-06-11 10:56:5115#include "base/strings/string_util.h"
gabf767595f2016-05-11 18:50:3516#include "base/threading/thread_task_runner_handle.h"
[email protected]d9d71e082011-02-16 11:44:2817#include "net/base/data_url.h"
[email protected]9dea9e1f2009-01-29 00:30:4718#include "net/base/io_buffer.h"
[email protected]677c90572008-12-10 09:03:1519#include "net/base/load_flags.h"
[email protected]597cf6e2009-05-29 09:43:2620#include "net/base/net_errors.h"
[email protected]de362402014-05-10 18:32:4721#include "net/base/net_string_util.h"
[email protected]2ca01e52013-10-31 22:05:1922#include "net/base/request_priority.h"
[email protected]6e7845ae2013-03-29 21:48:1123#include "net/cert/cert_status_flags.h"
[email protected]e0ef2c22009-06-03 23:54:4424#include "net/http/http_response_headers.h"
Eric Romanab9fc652018-05-08 01:59:5325#include "net/url_request/redirect_info.h"
[email protected]86933612010-10-16 23:10:3326#include "net/url_request/url_request_context.h"
[email protected]677c90572008-12-10 09:03:1527
[email protected]f0a51fb52009-03-05 12:46:3828// TODO(eroman):
[email protected]33abb682011-03-29 03:58:4229// - Support auth-prompts (http://crbug.com/77366)
[email protected]677c90572008-12-10 09:03:1530
31namespace net {
32
33namespace {
34
35// The maximum size (in bytes) allowed for a PAC script. Responses exceeding
36// this will fail with ERR_FILE_TOO_BIG.
[email protected]86933612010-10-16 23:10:3337const int kDefaultMaxResponseBytes = 1048576; // 1 megabyte
[email protected]677c90572008-12-10 09:03:1538
39// The maximum duration (in milliseconds) allowed for fetching the PAC script.
40// Responses exceeding this will fail with ERR_TIMED_OUT.
Eric Romancdb1d1c2018-01-03 21:17:0841//
42// This timeout applies to both scripts fetched in the course of WPAD, as well
43// as explicitly configured ones.
44//
45// If the default timeout is too high, auto-detect can stall for a long time,
46// and if it is too low then slow loading scripts may be skipped.
47//
48// 30 seconds is a compromise between those competing goals. This value also
49// appears to match Microsoft Edge (based on testing).
50constexpr base::TimeDelta kDefaultMaxDuration =
51 base::TimeDelta::FromSeconds(30);
[email protected]677c90572008-12-10 09:03:1552
[email protected]13a279e2009-04-13 17:32:3753// Returns true if |mime_type| is one of the known PAC mime type.
54bool IsPacMimeType(const std::string& mime_type) {
Lily Houghton9844d322018-01-20 05:44:0155 static const char* const kSupportedPacMimeTypes[] = {
56 "application/x-ns-proxy-autoconfig", "application/x-javascript-config",
[email protected]13a279e2009-04-13 17:32:3757 };
Avi Drissman4365a4782018-12-28 19:26:2458 for (size_t i = 0; i < base::size(kSupportedPacMimeTypes); ++i) {
brettwbc17d2c82015-06-09 22:39:0859 if (base::LowerCaseEqualsASCII(mime_type, kSupportedPacMimeTypes[i]))
[email protected]13a279e2009-04-13 17:32:3760 return true;
61 }
62 return false;
63}
64
Eric Roman598760f2018-10-12 01:30:4165struct BomMapping {
66 base::StringPiece prefix;
67 const char* charset;
68};
69
70const BomMapping kBomMappings[] = {
71 {"\xFE\xFF", "utf-16be"},
72 {"\xFF\xFE", "utf-16le"},
73 {"\xEF\xBB\xBF", "utf-8"},
74};
75
[email protected]9b9ae9552010-07-01 22:20:5076// Converts |bytes| (which is encoded by |charset|) to UTF16, saving the resul
77// to |*utf16|.
[email protected]8f3c96342009-09-22 03:06:5478// If |charset| is empty, then we don't know what it was and guess.
[email protected]9b9ae9552010-07-01 22:20:5079void ConvertResponseToUTF16(const std::string& charset,
80 const std::string& bytes,
[email protected]42cba2fb2013-03-29 19:58:5781 base::string16* utf16) {
[email protected]8f3c96342009-09-22 03:06:5482 if (charset.empty()) {
Eric Roman598760f2018-10-12 01:30:4183 // Guess the charset by looking at the BOM.
84 base::StringPiece bytes_str(bytes);
85 for (const auto& bom : kBomMappings) {
86 if (bytes_str.starts_with(bom.prefix)) {
87 return ConvertResponseToUTF16(
88 bom.charset,
89 // Strip the BOM in the converted response.
90 bytes.substr(bom.prefix.size()), utf16);
91 }
92 }
93
94 // Otherwise assume ISO-8859-1 if no charset was specified.
95 return ConvertResponseToUTF16(kCharsetLatin1, bytes, utf16);
[email protected]8f3c96342009-09-22 03:06:5496 }
97
Eric Roman598760f2018-10-12 01:30:4198 DCHECK(!charset.empty());
99
[email protected]de362402014-05-10 18:32:47100 // Be generous in the conversion -- if any characters lie outside of |charset|
101 // (i.e. invalid), then substitute them with U+FFFD rather than failing.
Eric Roman598760f2018-10-12 01:30:41102 ConvertToUTF16WithSubstitutions(bytes, charset.c_str(), utf16);
[email protected]8f3c96342009-09-22 03:06:54103}
104
[email protected]677c90572008-12-10 09:03:15105} // namespace
106
Eric Romanab9fc652018-05-08 01:59:53107std::unique_ptr<PacFileFetcherImpl> PacFileFetcherImpl::Create(
108 URLRequestContext* url_request_context) {
Matt Menke27e91ae42019-09-10 16:10:48109 return base::WrapUnique(new PacFileFetcherImpl(url_request_context));
[email protected]677c90572008-12-10 09:03:15110}
111
Lily Houghton99597862018-03-07 16:40:42112PacFileFetcherImpl::~PacFileFetcherImpl() {
[email protected]da968bc2011-01-19 11:48:19113 // The URLRequest's destructor will cancel the outstanding request, and
[email protected]677c90572008-12-10 09:03:15114 // ensure that the delegate (this) is not called again.
115}
116
Lily Houghton99597862018-03-07 16:40:42117base::TimeDelta PacFileFetcherImpl::SetTimeoutConstraint(
[email protected]7aefb152011-01-21 23:46:49118 base::TimeDelta timeout) {
119 base::TimeDelta prev = max_duration_;
120 max_duration_ = timeout;
121 return prev;
122}
123
Lily Houghton99597862018-03-07 16:40:42124size_t PacFileFetcherImpl::SetSizeConstraint(size_t size_bytes) {
[email protected]7aefb152011-01-21 23:46:49125 size_t prev = max_response_bytes_;
126 max_response_bytes_ = size_bytes;
127 return prev;
128}
129
Lily Houghton99597862018-03-07 16:40:42130void PacFileFetcherImpl::OnResponseCompleted(URLRequest* request,
131 int net_error) {
[email protected]7aefb152011-01-21 23:46:49132 DCHECK_EQ(request, cur_request_.get());
133
134 // Use |result_code_| as the request's error if we have already set it to
135 // something specific.
maksim.sisovbf794e22016-09-13 09:20:34136 if (result_code_ == OK && net_error != OK)
137 result_code_ = net_error;
[email protected]7aefb152011-01-21 23:46:49138
139 FetchCompleted();
140}
141
Ramin Halavatibb8c4d82018-03-16 08:04:31142int PacFileFetcherImpl::Fetch(
143 const GURL& url,
144 base::string16* text,
Bence Békycc5b88a2018-05-25 20:24:17145 CompletionOnceCallback callback,
Ramin Halavatibb8c4d82018-03-16 08:04:31146 const NetworkTrafficAnnotationTag traffic_annotation) {
[email protected]677c90572008-12-10 09:03:15147 // It is invalid to call Fetch() while a request is already in progress.
148 DCHECK(!cur_request_.get());
[email protected]235786812011-12-20 02:15:31149 DCHECK(!callback.is_null());
[email protected]9b9ae9552010-07-01 22:20:50150 DCHECK(text);
[email protected]677c90572008-12-10 09:03:15151
mmenkeed8d7e432017-05-03 16:48:33152 if (!url_request_context_)
153 return ERR_CONTEXT_SHUT_DOWN;
154
Eric Romanab9fc652018-05-08 01:59:53155 if (!IsUrlSchemeAllowed(url))
156 return ERR_DISALLOWED_URL_SCHEME;
157
[email protected]d9d71e082011-02-16 11:44:28158 // Handle base-64 encoded data-urls that contain custom PAC scripts.
159 if (url.SchemeIs("data")) {
160 std::string mime_type;
161 std::string charset;
162 std::string data;
163 if (!DataURL::Parse(url, &mime_type, &charset, &data))
164 return ERR_FAILED;
165
166 ConvertResponseToUTF16(charset, data, text);
167 return OK;
168 }
169
cbentzel27d2e5e52015-07-10 17:39:56170 DCHECK(fetch_start_time_.is_null());
cbentzele45ccba2015-08-21 18:23:14171 fetch_start_time_ = base::TimeTicks::Now();
cbentzel27d2e5e52015-07-10 17:39:56172
mmenkeed8d7e432017-05-03 16:48:33173 // Use highest priority, so if socket pools are being used for other types of
174 // requests, PAC requests are aren't blocked on them.
rhalavatide8bf4e2017-05-16 06:09:11175 cur_request_ = url_request_context_->CreateRequest(url, MAXIMUM_PRIORITY,
176 this, traffic_annotation);
[email protected]677c90572008-12-10 09:03:15177
178 // Make sure that the PAC script is downloaded using a direct connection,
179 // to avoid circular dependencies (fetching is a part of proxy resolution).
[email protected]e0ef2c22009-06-03 23:54:44180 // Also disable the use of the disk cache. The cache is disabled so that if
181 // the user switches networks we don't potentially use the cached response
182 // from old network when we should in fact be re-fetching on the new network.
[email protected]6fbac162011-06-20 00:29:04183 // If the PAC script is hosted on an HTTPS server we bypass revocation
184 // checking in order to avoid a circular dependency when attempting to fetch
185 // the OCSP response or CRL. We could make the revocation check go direct but
mmenkeed8d7e432017-05-03 16:48:33186 // the proxy might be the only way to the outside world. IGNORE_LIMITS is
187 // used to avoid blocking proxy resolution on other network requests.
[email protected]bb1c4662013-11-14 00:00:07188 cur_request_->SetLoadFlags(LOAD_BYPASS_PROXY | LOAD_DISABLE_CACHE |
Ryan Sleevi24fe2682018-08-16 21:33:46189 LOAD_DISABLE_CERT_NETWORK_FETCHES |
mmenkeed8d7e432017-05-03 16:48:33190 LOAD_IGNORE_LIMITS);
[email protected]677c90572008-12-10 09:03:15191
192 // Save the caller's info for notification on completion.
Bence Békycc5b88a2018-05-25 20:24:17193 callback_ = std::move(callback);
[email protected]9b9ae9552010-07-01 22:20:50194 result_text_ = text;
195
196 bytes_read_so_far_.clear();
[email protected]677c90572008-12-10 09:03:15197
198 // Post a task to timeout this request if it takes too long.
199 cur_request_id_ = ++next_id_;
eromane1867242015-04-23 23:07:44200
skyostil4891b25b2015-06-11 11:43:45201 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
Lily Houghton9844d322018-01-20 05:44:01202 FROM_HERE,
kylecharf4fe5172019-02-15 18:53:49203 base::BindOnce(&PacFileFetcherImpl::OnTimeout, weak_factory_.GetWeakPtr(),
204 cur_request_id_),
[email protected]26b9973962012-01-28 00:57:00205 max_duration_);
[email protected]677c90572008-12-10 09:03:15206
207 // Start the request.
208 cur_request_->Start();
[email protected]620f5712009-08-04 22:43:12209 return ERR_IO_PENDING;
[email protected]677c90572008-12-10 09:03:15210}
211
Lily Houghton99597862018-03-07 16:40:42212void PacFileFetcherImpl::Cancel() {
[email protected]da968bc2011-01-19 11:48:19213 // ResetCurRequestState will free the URLRequest, which will cause
[email protected]677c90572008-12-10 09:03:15214 // cancellation.
215 ResetCurRequestState();
216}
217
Lily Houghton99597862018-03-07 16:40:42218URLRequestContext* PacFileFetcherImpl::GetRequestContext() const {
[email protected]20d296ddc2009-11-18 23:07:08219 return url_request_context_;
220}
221
Lily Houghton99597862018-03-07 16:40:42222void PacFileFetcherImpl::OnShutdown() {
mmenkeed8d7e432017-05-03 16:48:33223 url_request_context_ = nullptr;
224
225 if (cur_request_) {
226 result_code_ = ERR_CONTEXT_SHUT_DOWN;
227 FetchCompleted();
228 }
229}
230
Eric Romanab9fc652018-05-08 01:59:53231void PacFileFetcherImpl::OnReceivedRedirect(URLRequest* request,
232 const RedirectInfo& redirect_info,
233 bool* defer_redirect) {
234 int error = OK;
235
236 // Redirection to file:// is never OK. Ordinarily this is handled lower in the
237 // stack (|FileProtocolHandler::IsSafeRedirectTarget|), but this is reachable
238 // when built without file:// suppport. Return the same error for consistency.
239 if (redirect_info.new_url.SchemeIsFile()) {
240 error = ERR_UNSAFE_REDIRECT;
241 } else if (!IsUrlSchemeAllowed(redirect_info.new_url)) {
242 error = ERR_DISALLOWED_URL_SCHEME;
243 }
244
245 if (error != OK) {
246 // Fail the redirect.
247 request->CancelWithError(error);
248 OnResponseCompleted(request, error);
249 }
250}
251
Lily Houghton99597862018-03-07 16:40:42252void PacFileFetcherImpl::OnAuthRequired(URLRequest* request,
Emily Starkf2c9bbd2019-04-09 17:08:58253 const AuthChallengeInfo& auth_info) {
[email protected]0967249162010-11-20 00:13:32254 DCHECK_EQ(request, cur_request_.get());
[email protected]33abb682011-03-29 03:58:42255 // TODO(eroman): http://crbug.com/77366
[email protected]13a279e2009-04-13 17:32:37256 LOG(WARNING) << "Auth required to fetch PAC script, aborting.";
[email protected]677c90572008-12-10 09:03:15257 result_code_ = ERR_NOT_IMPLEMENTED;
258 request->CancelAuth();
259}
260
Lily Houghton99597862018-03-07 16:40:42261void PacFileFetcherImpl::OnSSLCertificateError(URLRequest* request,
Emily Stark79fba5842019-04-25 04:59:36262 int net_error,
Lily Houghton99597862018-03-07 16:40:42263 const SSLInfo& ssl_info,
264 bool fatal) {
[email protected]0967249162010-11-20 00:13:32265 DCHECK_EQ(request, cur_request_.get());
[email protected]13a279e2009-04-13 17:32:37266 LOG(WARNING) << "SSL certificate error when fetching PAC script, aborting.";
[email protected]677c90572008-12-10 09:03:15267 // Certificate errors are in same space as net errors.
Emily Stark79fba5842019-04-25 04:59:36268 result_code_ = net_error;
[email protected]677c90572008-12-10 09:03:15269 request->Cancel();
270}
271
Lily Houghton99597862018-03-07 16:40:42272void PacFileFetcherImpl::OnResponseStarted(URLRequest* request, int net_error) {
[email protected]0967249162010-11-20 00:13:32273 DCHECK_EQ(request, cur_request_.get());
maksim.sisovbf794e22016-09-13 09:20:34274 DCHECK_NE(ERR_IO_PENDING, net_error);
[email protected]677c90572008-12-10 09:03:15275
maksim.sisovbf794e22016-09-13 09:20:34276 if (net_error != OK) {
277 OnResponseCompleted(request, net_error);
[email protected]677c90572008-12-10 09:03:15278 return;
279 }
280
281 // Require HTTP responses to have a success status code.
[email protected]91f5689032013-08-22 01:43:33282 if (request->url().SchemeIsHTTPOrHTTPS()) {
[email protected]f0a51fb52009-03-05 12:46:38283 // NOTE about status codes: We are like Firefox 3 in this respect.
[email protected]677c90572008-12-10 09:03:15284 // {IE 7, Safari 3, Opera 9.5} do not care about the status code.
285 if (request->GetResponseCode() != 200) {
[email protected]b30a3f52010-10-16 01:05:46286 VLOG(1) << "Fetched PAC script had (bad) status line: "
287 << request->response_headers()->GetStatusLine();
Eric Romana22b1f72019-09-05 19:35:04288 result_code_ = ERR_HTTP_RESPONSE_CODE_FAILURE;
[email protected]677c90572008-12-10 09:03:15289 request->Cancel();
290 return;
291 }
[email protected]13a279e2009-04-13 17:32:37292
293 // NOTE about mime types: We do not enforce mime types on PAC files.
294 // This is for compatibility with {IE 7, Firefox 3, Opera 9.5}. We will
295 // however log mismatches to help with debugging.
[email protected]e0ef2c22009-06-03 23:54:44296 std::string mime_type;
297 cur_request_->GetMimeType(&mime_type);
298 if (!IsPacMimeType(mime_type)) {
[email protected]b30a3f52010-10-16 01:05:46299 VLOG(1) << "Fetched PAC script does not have a proper mime type: "
300 << mime_type;
[email protected]13a279e2009-04-13 17:32:37301 }
[email protected]677c90572008-12-10 09:03:15302 }
303
304 ReadBody(request);
305}
306
Lily Houghton99597862018-03-07 16:40:42307void PacFileFetcherImpl::OnReadCompleted(URLRequest* request, int num_bytes) {
maksim.sisovbf794e22016-09-13 09:20:34308 DCHECK_NE(ERR_IO_PENDING, num_bytes);
309
[email protected]0967249162010-11-20 00:13:32310 DCHECK_EQ(request, cur_request_.get());
311 if (ConsumeBytesRead(request, num_bytes)) {
312 // Keep reading.
[email protected]677c90572008-12-10 09:03:15313 ReadBody(request);
[email protected]677c90572008-12-10 09:03:15314 }
315}
316
Matt Menke27e91ae42019-09-10 16:10:48317PacFileFetcherImpl::PacFileFetcherImpl(URLRequestContext* url_request_context)
Eric Romanab9fc652018-05-08 01:59:53318 : url_request_context_(url_request_context),
Victor Costan9c7302b2018-08-27 16:39:44319 buf_(base::MakeRefCounted<IOBuffer>(kBufSize)),
Eric Romanab9fc652018-05-08 01:59:53320 next_id_(0),
321 cur_request_id_(0),
322 result_code_(OK),
Raul Tambre94493c652019-03-11 17:18:35323 result_text_(nullptr),
Eric Romanab9fc652018-05-08 01:59:53324 max_response_bytes_(kDefaultMaxResponseBytes),
Matt Menke27e91ae42019-09-10 16:10:48325 max_duration_(kDefaultMaxDuration) {
Eric Romanab9fc652018-05-08 01:59:53326 DCHECK(url_request_context);
327}
328
329bool PacFileFetcherImpl::IsUrlSchemeAllowed(const GURL& url) const {
330 // Always allow http://, https://, data:, and ftp://.
331 if (url.SchemeIsHTTPOrHTTPS() || url.SchemeIs("ftp") || url.SchemeIs("data"))
332 return true;
333
Eric Romanab9fc652018-05-08 01:59:53334 // Disallow any other URL scheme.
335 return false;
336}
337
Lily Houghton99597862018-03-07 16:40:42338void PacFileFetcherImpl::ReadBody(URLRequest* request) {
[email protected]0967249162010-11-20 00:13:32339 // Read as many bytes as are available synchronously.
340 while (true) {
maksim.sisovbf794e22016-09-13 09:20:34341 int num_bytes = request->Read(buf_.get(), kBufSize);
342 if (num_bytes == ERR_IO_PENDING)
343 return;
344
345 if (num_bytes < 0) {
346 OnResponseCompleted(request, num_bytes);
[email protected]0967249162010-11-20 00:13:32347 return;
348 }
maksim.sisovbf794e22016-09-13 09:20:34349
[email protected]0967249162010-11-20 00:13:32350 if (!ConsumeBytesRead(request, num_bytes))
351 return;
[email protected]677c90572008-12-10 09:03:15352 }
353}
354
Lily Houghton99597862018-03-07 16:40:42355bool PacFileFetcherImpl::ConsumeBytesRead(URLRequest* request, int num_bytes) {
Eric Romanf4174852018-02-16 22:47:13356 if (fetch_time_to_first_byte_.is_null())
357 fetch_time_to_first_byte_ = base::TimeTicks::Now();
358
[email protected]0967249162010-11-20 00:13:32359 if (num_bytes <= 0) {
360 // Error while reading, or EOF.
maksim.sisovbf794e22016-09-13 09:20:34361 OnResponseCompleted(request, num_bytes);
[email protected]0967249162010-11-20 00:13:32362 return false;
363 }
364
365 // Enforce maximum size bound.
366 if (num_bytes + bytes_read_so_far_.size() >
367 static_cast<size_t>(max_response_bytes_)) {
368 result_code_ = ERR_FILE_TOO_BIG;
369 request->Cancel();
370 return false;
371 }
372
373 bytes_read_so_far_.append(buf_->data(), num_bytes);
374 return true;
375}
376
Lily Houghton99597862018-03-07 16:40:42377void PacFileFetcherImpl::FetchCompleted() {
[email protected]8f3c96342009-09-22 03:06:54378 if (result_code_ == OK) {
Lily Houghton99597862018-03-07 16:40:42379 // Calculate duration of time for PAC file fetch to complete.
cbentzel27d2e5e52015-07-10 17:39:56380 DCHECK(!fetch_start_time_.is_null());
cbentzele45ccba2015-08-21 18:23:14381 DCHECK(!fetch_time_to_first_byte_.is_null());
382 UMA_HISTOGRAM_MEDIUM_TIMES("Net.ProxyScriptFetcher.SuccessDuration",
383 base::TimeTicks::Now() - fetch_start_time_);
384 UMA_HISTOGRAM_MEDIUM_TIMES("Net.ProxyScriptFetcher.FirstByteDuration",
385 fetch_time_to_first_byte_ - fetch_start_time_);
cbentzel27d2e5e52015-07-10 17:39:56386
[email protected]9b9ae9552010-07-01 22:20:50387 // The caller expects the response to be encoded as UTF16.
[email protected]8f3c96342009-09-22 03:06:54388 std::string charset;
389 cur_request_->GetCharset(&charset);
[email protected]9b9ae9552010-07-01 22:20:50390 ConvertResponseToUTF16(charset, bytes_read_so_far_, result_text_);
[email protected]8f3c96342009-09-22 03:06:54391 } else {
392 // On error, the caller expects empty string for bytes.
[email protected]9b9ae9552010-07-01 22:20:50393 result_text_->clear();
[email protected]8f3c96342009-09-22 03:06:54394 }
[email protected]677c90572008-12-10 09:03:15395
396 int result_code = result_code_;
Bence Békycc5b88a2018-05-25 20:24:17397 CompletionOnceCallback callback = std::move(callback_);
[email protected]677c90572008-12-10 09:03:15398
399 ResetCurRequestState();
400
Bence Békycc5b88a2018-05-25 20:24:17401 std::move(callback).Run(result_code);
[email protected]677c90572008-12-10 09:03:15402}
403
Lily Houghton99597862018-03-07 16:40:42404void PacFileFetcherImpl::ResetCurRequestState() {
[email protected]677c90572008-12-10 09:03:15405 cur_request_.reset();
406 cur_request_id_ = 0;
[email protected]235786812011-12-20 02:15:31407 callback_.Reset();
[email protected]677c90572008-12-10 09:03:15408 result_code_ = OK;
Raul Tambre94493c652019-03-11 17:18:35409 result_text_ = nullptr;
cbentzele45ccba2015-08-21 18:23:14410 fetch_start_time_ = base::TimeTicks();
411 fetch_time_to_first_byte_ = base::TimeTicks();
[email protected]677c90572008-12-10 09:03:15412}
413
Lily Houghton99597862018-03-07 16:40:42414void PacFileFetcherImpl::OnTimeout(int id) {
[email protected]da968bc2011-01-19 11:48:19415 // Timeout tasks may outlive the URLRequest they reference. Make sure it
[email protected]677c90572008-12-10 09:03:15416 // is still applicable.
417 if (cur_request_id_ != id)
418 return;
419
420 DCHECK(cur_request_.get());
421 result_code_ = ERR_TIMED_OUT;
mmenkeed8d7e432017-05-03 16:48:33422 FetchCompleted();
[email protected]677c90572008-12-10 09:03:15423}
424
[email protected]677c90572008-12-10 09:03:15425} // namespace net