blob: b566b8c6dbdcf47b1037508ebde2367d1235af96 [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"
asvitkine30330812016-08-30 04:01:0811#include "base/metrics/histogram_macros.h"
skyostil4891b25b2015-06-11 11:43:4512#include "base/single_thread_task_runner.h"
Avi Drissman4365a4782018-12-28 19:26:2413#include "base/stl_util.h"
[email protected]fc9be5802013-06-11 10:56:5114#include "base/strings/string_util.h"
gabf767595f2016-05-11 18:50:3515#include "base/threading/thread_task_runner_handle.h"
[email protected]d9d71e082011-02-16 11:44:2816#include "net/base/data_url.h"
[email protected]9dea9e1f2009-01-29 00:30:4717#include "net/base/io_buffer.h"
[email protected]677c90572008-12-10 09:03:1518#include "net/base/load_flags.h"
[email protected]597cf6e2009-05-29 09:43:2619#include "net/base/net_errors.h"
[email protected]de362402014-05-10 18:32:4720#include "net/base/net_string_util.h"
[email protected]2ca01e52013-10-31 22:05:1921#include "net/base/request_priority.h"
[email protected]6e7845ae2013-03-29 21:48:1122#include "net/cert/cert_status_flags.h"
[email protected]e0ef2c22009-06-03 23:54:4423#include "net/http/http_response_headers.h"
Eric Romanab9fc652018-05-08 01:59:5324#include "net/url_request/redirect_info.h"
[email protected]86933612010-10-16 23:10:3325#include "net/url_request/url_request_context.h"
[email protected]677c90572008-12-10 09:03:1526
[email protected]f0a51fb52009-03-05 12:46:3827// TODO(eroman):
[email protected]33abb682011-03-29 03:58:4228// - Support auth-prompts (http://crbug.com/77366)
[email protected]677c90572008-12-10 09:03:1529
30namespace net {
31
32namespace {
33
34// The maximum size (in bytes) allowed for a PAC script. Responses exceeding
35// this will fail with ERR_FILE_TOO_BIG.
[email protected]86933612010-10-16 23:10:3336const int kDefaultMaxResponseBytes = 1048576; // 1 megabyte
[email protected]677c90572008-12-10 09:03:1537
38// The maximum duration (in milliseconds) allowed for fetching the PAC script.
39// Responses exceeding this will fail with ERR_TIMED_OUT.
Eric Romancdb1d1c2018-01-03 21:17:0840//
41// This timeout applies to both scripts fetched in the course of WPAD, as well
42// as explicitly configured ones.
43//
44// If the default timeout is too high, auto-detect can stall for a long time,
45// and if it is too low then slow loading scripts may be skipped.
46//
47// 30 seconds is a compromise between those competing goals. This value also
48// appears to match Microsoft Edge (based on testing).
49constexpr base::TimeDelta kDefaultMaxDuration =
50 base::TimeDelta::FromSeconds(30);
[email protected]677c90572008-12-10 09:03:1551
[email protected]13a279e2009-04-13 17:32:3752// Returns true if |mime_type| is one of the known PAC mime type.
53bool IsPacMimeType(const std::string& mime_type) {
Lily Houghton9844d322018-01-20 05:44:0154 static const char* const kSupportedPacMimeTypes[] = {
55 "application/x-ns-proxy-autoconfig", "application/x-javascript-config",
[email protected]13a279e2009-04-13 17:32:3756 };
Avi Drissman4365a4782018-12-28 19:26:2457 for (size_t i = 0; i < base::size(kSupportedPacMimeTypes); ++i) {
brettwbc17d2c82015-06-09 22:39:0858 if (base::LowerCaseEqualsASCII(mime_type, kSupportedPacMimeTypes[i]))
[email protected]13a279e2009-04-13 17:32:3759 return true;
60 }
61 return false;
62}
63
Eric Roman598760f2018-10-12 01:30:4164struct BomMapping {
65 base::StringPiece prefix;
66 const char* charset;
67};
68
69const BomMapping kBomMappings[] = {
70 {"\xFE\xFF", "utf-16be"},
71 {"\xFF\xFE", "utf-16le"},
72 {"\xEF\xBB\xBF", "utf-8"},
73};
74
[email protected]9b9ae9552010-07-01 22:20:5075// Converts |bytes| (which is encoded by |charset|) to UTF16, saving the resul
76// to |*utf16|.
[email protected]8f3c96342009-09-22 03:06:5477// If |charset| is empty, then we don't know what it was and guess.
[email protected]9b9ae9552010-07-01 22:20:5078void ConvertResponseToUTF16(const std::string& charset,
79 const std::string& bytes,
[email protected]42cba2fb2013-03-29 19:58:5780 base::string16* utf16) {
[email protected]8f3c96342009-09-22 03:06:5481 if (charset.empty()) {
Eric Roman598760f2018-10-12 01:30:4182 // Guess the charset by looking at the BOM.
83 base::StringPiece bytes_str(bytes);
84 for (const auto& bom : kBomMappings) {
85 if (bytes_str.starts_with(bom.prefix)) {
86 return ConvertResponseToUTF16(
87 bom.charset,
88 // Strip the BOM in the converted response.
89 bytes.substr(bom.prefix.size()), utf16);
90 }
91 }
92
93 // Otherwise assume ISO-8859-1 if no charset was specified.
94 return ConvertResponseToUTF16(kCharsetLatin1, bytes, utf16);
[email protected]8f3c96342009-09-22 03:06:5495 }
96
Eric Roman598760f2018-10-12 01:30:4197 DCHECK(!charset.empty());
98
[email protected]de362402014-05-10 18:32:4799 // Be generous in the conversion -- if any characters lie outside of |charset|
100 // (i.e. invalid), then substitute them with U+FFFD rather than failing.
Eric Roman598760f2018-10-12 01:30:41101 ConvertToUTF16WithSubstitutions(bytes, charset.c_str(), utf16);
[email protected]8f3c96342009-09-22 03:06:54102}
103
[email protected]677c90572008-12-10 09:03:15104} // namespace
105
Eric Romanab9fc652018-05-08 01:59:53106std::unique_ptr<PacFileFetcherImpl> PacFileFetcherImpl::Create(
107 URLRequestContext* url_request_context) {
Matt Menke27e91ae42019-09-10 16:10:48108 return base::WrapUnique(new PacFileFetcherImpl(url_request_context));
[email protected]677c90572008-12-10 09:03:15109}
110
Lily Houghton99597862018-03-07 16:40:42111PacFileFetcherImpl::~PacFileFetcherImpl() {
[email protected]da968bc2011-01-19 11:48:19112 // The URLRequest's destructor will cancel the outstanding request, and
[email protected]677c90572008-12-10 09:03:15113 // ensure that the delegate (this) is not called again.
114}
115
Lily Houghton99597862018-03-07 16:40:42116base::TimeDelta PacFileFetcherImpl::SetTimeoutConstraint(
[email protected]7aefb152011-01-21 23:46:49117 base::TimeDelta timeout) {
118 base::TimeDelta prev = max_duration_;
119 max_duration_ = timeout;
120 return prev;
121}
122
Lily Houghton99597862018-03-07 16:40:42123size_t PacFileFetcherImpl::SetSizeConstraint(size_t size_bytes) {
[email protected]7aefb152011-01-21 23:46:49124 size_t prev = max_response_bytes_;
125 max_response_bytes_ = size_bytes;
126 return prev;
127}
128
Lily Houghton99597862018-03-07 16:40:42129void PacFileFetcherImpl::OnResponseCompleted(URLRequest* request,
130 int net_error) {
[email protected]7aefb152011-01-21 23:46:49131 DCHECK_EQ(request, cur_request_.get());
132
133 // Use |result_code_| as the request's error if we have already set it to
134 // something specific.
maksim.sisovbf794e22016-09-13 09:20:34135 if (result_code_ == OK && net_error != OK)
136 result_code_ = net_error;
[email protected]7aefb152011-01-21 23:46:49137
138 FetchCompleted();
139}
140
Ramin Halavatibb8c4d82018-03-16 08:04:31141int PacFileFetcherImpl::Fetch(
142 const GURL& url,
143 base::string16* text,
Bence Békycc5b88a2018-05-25 20:24:17144 CompletionOnceCallback callback,
Ramin Halavatibb8c4d82018-03-16 08:04:31145 const NetworkTrafficAnnotationTag traffic_annotation) {
[email protected]677c90572008-12-10 09:03:15146 // It is invalid to call Fetch() while a request is already in progress.
147 DCHECK(!cur_request_.get());
[email protected]235786812011-12-20 02:15:31148 DCHECK(!callback.is_null());
[email protected]9b9ae9552010-07-01 22:20:50149 DCHECK(text);
[email protected]677c90572008-12-10 09:03:15150
mmenkeed8d7e432017-05-03 16:48:33151 if (!url_request_context_)
152 return ERR_CONTEXT_SHUT_DOWN;
153
Eric Romanab9fc652018-05-08 01:59:53154 if (!IsUrlSchemeAllowed(url))
155 return ERR_DISALLOWED_URL_SCHEME;
156
[email protected]d9d71e082011-02-16 11:44:28157 // Handle base-64 encoded data-urls that contain custom PAC scripts.
158 if (url.SchemeIs("data")) {
159 std::string mime_type;
160 std::string charset;
161 std::string data;
162 if (!DataURL::Parse(url, &mime_type, &charset, &data))
163 return ERR_FAILED;
164
165 ConvertResponseToUTF16(charset, data, text);
166 return OK;
167 }
168
cbentzel27d2e5e52015-07-10 17:39:56169 DCHECK(fetch_start_time_.is_null());
cbentzele45ccba2015-08-21 18:23:14170 fetch_start_time_ = base::TimeTicks::Now();
cbentzel27d2e5e52015-07-10 17:39:56171
mmenkeed8d7e432017-05-03 16:48:33172 // Use highest priority, so if socket pools are being used for other types of
173 // requests, PAC requests are aren't blocked on them.
rhalavatide8bf4e2017-05-16 06:09:11174 cur_request_ = url_request_context_->CreateRequest(url, MAXIMUM_PRIORITY,
175 this, traffic_annotation);
[email protected]677c90572008-12-10 09:03:15176
177 // Make sure that the PAC script is downloaded using a direct connection,
178 // to avoid circular dependencies (fetching is a part of proxy resolution).
[email protected]e0ef2c22009-06-03 23:54:44179 // Also disable the use of the disk cache. The cache is disabled so that if
180 // the user switches networks we don't potentially use the cached response
181 // from old network when we should in fact be re-fetching on the new network.
[email protected]6fbac162011-06-20 00:29:04182 // If the PAC script is hosted on an HTTPS server we bypass revocation
183 // checking in order to avoid a circular dependency when attempting to fetch
184 // the OCSP response or CRL. We could make the revocation check go direct but
mmenkeed8d7e432017-05-03 16:48:33185 // the proxy might be the only way to the outside world. IGNORE_LIMITS is
186 // used to avoid blocking proxy resolution on other network requests.
[email protected]bb1c4662013-11-14 00:00:07187 cur_request_->SetLoadFlags(LOAD_BYPASS_PROXY | LOAD_DISABLE_CACHE |
Ryan Sleevi24fe2682018-08-16 21:33:46188 LOAD_DISABLE_CERT_NETWORK_FETCHES |
mmenkeed8d7e432017-05-03 16:48:33189 LOAD_IGNORE_LIMITS);
[email protected]677c90572008-12-10 09:03:15190
191 // Save the caller's info for notification on completion.
Bence Békycc5b88a2018-05-25 20:24:17192 callback_ = std::move(callback);
[email protected]9b9ae9552010-07-01 22:20:50193 result_text_ = text;
194
195 bytes_read_so_far_.clear();
[email protected]677c90572008-12-10 09:03:15196
197 // Post a task to timeout this request if it takes too long.
198 cur_request_id_ = ++next_id_;
eromane1867242015-04-23 23:07:44199
skyostil4891b25b2015-06-11 11:43:45200 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
Lily Houghton9844d322018-01-20 05:44:01201 FROM_HERE,
kylecharf4fe5172019-02-15 18:53:49202 base::BindOnce(&PacFileFetcherImpl::OnTimeout, weak_factory_.GetWeakPtr(),
203 cur_request_id_),
[email protected]26b9973962012-01-28 00:57:00204 max_duration_);
[email protected]677c90572008-12-10 09:03:15205
206 // Start the request.
207 cur_request_->Start();
[email protected]620f5712009-08-04 22:43:12208 return ERR_IO_PENDING;
[email protected]677c90572008-12-10 09:03:15209}
210
Lily Houghton99597862018-03-07 16:40:42211void PacFileFetcherImpl::Cancel() {
[email protected]da968bc2011-01-19 11:48:19212 // ResetCurRequestState will free the URLRequest, which will cause
[email protected]677c90572008-12-10 09:03:15213 // cancellation.
214 ResetCurRequestState();
215}
216
Lily Houghton99597862018-03-07 16:40:42217URLRequestContext* PacFileFetcherImpl::GetRequestContext() const {
[email protected]20d296ddc2009-11-18 23:07:08218 return url_request_context_;
219}
220
Lily Houghton99597862018-03-07 16:40:42221void PacFileFetcherImpl::OnShutdown() {
mmenkeed8d7e432017-05-03 16:48:33222 url_request_context_ = nullptr;
223
224 if (cur_request_) {
225 result_code_ = ERR_CONTEXT_SHUT_DOWN;
226 FetchCompleted();
227 }
228}
229
Eric Romanab9fc652018-05-08 01:59:53230void PacFileFetcherImpl::OnReceivedRedirect(URLRequest* request,
231 const RedirectInfo& redirect_info,
232 bool* defer_redirect) {
233 int error = OK;
234
235 // Redirection to file:// is never OK. Ordinarily this is handled lower in the
236 // stack (|FileProtocolHandler::IsSafeRedirectTarget|), but this is reachable
237 // when built without file:// suppport. Return the same error for consistency.
238 if (redirect_info.new_url.SchemeIsFile()) {
239 error = ERR_UNSAFE_REDIRECT;
240 } else if (!IsUrlSchemeAllowed(redirect_info.new_url)) {
241 error = ERR_DISALLOWED_URL_SCHEME;
242 }
243
244 if (error != OK) {
245 // Fail the redirect.
246 request->CancelWithError(error);
247 OnResponseCompleted(request, error);
248 }
249}
250
Lily Houghton99597862018-03-07 16:40:42251void PacFileFetcherImpl::OnAuthRequired(URLRequest* request,
Emily Starkf2c9bbd2019-04-09 17:08:58252 const AuthChallengeInfo& auth_info) {
[email protected]0967249162010-11-20 00:13:32253 DCHECK_EQ(request, cur_request_.get());
[email protected]33abb682011-03-29 03:58:42254 // TODO(eroman): http://crbug.com/77366
[email protected]13a279e2009-04-13 17:32:37255 LOG(WARNING) << "Auth required to fetch PAC script, aborting.";
[email protected]677c90572008-12-10 09:03:15256 result_code_ = ERR_NOT_IMPLEMENTED;
257 request->CancelAuth();
258}
259
Lily Houghton99597862018-03-07 16:40:42260void PacFileFetcherImpl::OnSSLCertificateError(URLRequest* request,
Emily Stark79fba5842019-04-25 04:59:36261 int net_error,
Lily Houghton99597862018-03-07 16:40:42262 const SSLInfo& ssl_info,
263 bool fatal) {
[email protected]0967249162010-11-20 00:13:32264 DCHECK_EQ(request, cur_request_.get());
[email protected]13a279e2009-04-13 17:32:37265 LOG(WARNING) << "SSL certificate error when fetching PAC script, aborting.";
[email protected]677c90572008-12-10 09:03:15266 // Certificate errors are in same space as net errors.
Emily Stark79fba5842019-04-25 04:59:36267 result_code_ = net_error;
[email protected]677c90572008-12-10 09:03:15268 request->Cancel();
269}
270
Lily Houghton99597862018-03-07 16:40:42271void PacFileFetcherImpl::OnResponseStarted(URLRequest* request, int net_error) {
[email protected]0967249162010-11-20 00:13:32272 DCHECK_EQ(request, cur_request_.get());
maksim.sisovbf794e22016-09-13 09:20:34273 DCHECK_NE(ERR_IO_PENDING, net_error);
[email protected]677c90572008-12-10 09:03:15274
maksim.sisovbf794e22016-09-13 09:20:34275 if (net_error != OK) {
276 OnResponseCompleted(request, net_error);
[email protected]677c90572008-12-10 09:03:15277 return;
278 }
279
280 // Require HTTP responses to have a success status code.
[email protected]91f5689032013-08-22 01:43:33281 if (request->url().SchemeIsHTTPOrHTTPS()) {
[email protected]f0a51fb52009-03-05 12:46:38282 // NOTE about status codes: We are like Firefox 3 in this respect.
[email protected]677c90572008-12-10 09:03:15283 // {IE 7, Safari 3, Opera 9.5} do not care about the status code.
284 if (request->GetResponseCode() != 200) {
[email protected]b30a3f52010-10-16 01:05:46285 VLOG(1) << "Fetched PAC script had (bad) status line: "
286 << request->response_headers()->GetStatusLine();
Eric Romana22b1f72019-09-05 19:35:04287 result_code_ = ERR_HTTP_RESPONSE_CODE_FAILURE;
[email protected]677c90572008-12-10 09:03:15288 request->Cancel();
289 return;
290 }
[email protected]13a279e2009-04-13 17:32:37291
292 // NOTE about mime types: We do not enforce mime types on PAC files.
293 // This is for compatibility with {IE 7, Firefox 3, Opera 9.5}. We will
294 // however log mismatches to help with debugging.
[email protected]e0ef2c22009-06-03 23:54:44295 std::string mime_type;
296 cur_request_->GetMimeType(&mime_type);
297 if (!IsPacMimeType(mime_type)) {
[email protected]b30a3f52010-10-16 01:05:46298 VLOG(1) << "Fetched PAC script does not have a proper mime type: "
299 << mime_type;
[email protected]13a279e2009-04-13 17:32:37300 }
[email protected]677c90572008-12-10 09:03:15301 }
302
303 ReadBody(request);
304}
305
Lily Houghton99597862018-03-07 16:40:42306void PacFileFetcherImpl::OnReadCompleted(URLRequest* request, int num_bytes) {
maksim.sisovbf794e22016-09-13 09:20:34307 DCHECK_NE(ERR_IO_PENDING, num_bytes);
308
[email protected]0967249162010-11-20 00:13:32309 DCHECK_EQ(request, cur_request_.get());
310 if (ConsumeBytesRead(request, num_bytes)) {
311 // Keep reading.
[email protected]677c90572008-12-10 09:03:15312 ReadBody(request);
[email protected]677c90572008-12-10 09:03:15313 }
314}
315
Matt Menke27e91ae42019-09-10 16:10:48316PacFileFetcherImpl::PacFileFetcherImpl(URLRequestContext* url_request_context)
Eric Romanab9fc652018-05-08 01:59:53317 : url_request_context_(url_request_context),
Victor Costan9c7302b2018-08-27 16:39:44318 buf_(base::MakeRefCounted<IOBuffer>(kBufSize)),
Eric Romanab9fc652018-05-08 01:59:53319 next_id_(0),
320 cur_request_id_(0),
321 result_code_(OK),
Raul Tambre94493c652019-03-11 17:18:35322 result_text_(nullptr),
Eric Romanab9fc652018-05-08 01:59:53323 max_response_bytes_(kDefaultMaxResponseBytes),
Matt Menke27e91ae42019-09-10 16:10:48324 max_duration_(kDefaultMaxDuration) {
Eric Romanab9fc652018-05-08 01:59:53325 DCHECK(url_request_context);
326}
327
328bool PacFileFetcherImpl::IsUrlSchemeAllowed(const GURL& url) const {
329 // Always allow http://, https://, data:, and ftp://.
330 if (url.SchemeIsHTTPOrHTTPS() || url.SchemeIs("ftp") || url.SchemeIs("data"))
331 return true;
332
Eric Romanab9fc652018-05-08 01:59:53333 // Disallow any other URL scheme.
334 return false;
335}
336
Lily Houghton99597862018-03-07 16:40:42337void PacFileFetcherImpl::ReadBody(URLRequest* request) {
[email protected]0967249162010-11-20 00:13:32338 // Read as many bytes as are available synchronously.
339 while (true) {
maksim.sisovbf794e22016-09-13 09:20:34340 int num_bytes = request->Read(buf_.get(), kBufSize);
341 if (num_bytes == ERR_IO_PENDING)
342 return;
343
344 if (num_bytes < 0) {
345 OnResponseCompleted(request, num_bytes);
[email protected]0967249162010-11-20 00:13:32346 return;
347 }
maksim.sisovbf794e22016-09-13 09:20:34348
[email protected]0967249162010-11-20 00:13:32349 if (!ConsumeBytesRead(request, num_bytes))
350 return;
[email protected]677c90572008-12-10 09:03:15351 }
352}
353
Lily Houghton99597862018-03-07 16:40:42354bool PacFileFetcherImpl::ConsumeBytesRead(URLRequest* request, int num_bytes) {
Eric Romanf4174852018-02-16 22:47:13355 if (fetch_time_to_first_byte_.is_null())
356 fetch_time_to_first_byte_ = base::TimeTicks::Now();
357
[email protected]0967249162010-11-20 00:13:32358 if (num_bytes <= 0) {
359 // Error while reading, or EOF.
maksim.sisovbf794e22016-09-13 09:20:34360 OnResponseCompleted(request, num_bytes);
[email protected]0967249162010-11-20 00:13:32361 return false;
362 }
363
364 // Enforce maximum size bound.
365 if (num_bytes + bytes_read_so_far_.size() >
366 static_cast<size_t>(max_response_bytes_)) {
367 result_code_ = ERR_FILE_TOO_BIG;
368 request->Cancel();
369 return false;
370 }
371
372 bytes_read_so_far_.append(buf_->data(), num_bytes);
373 return true;
374}
375
Lily Houghton99597862018-03-07 16:40:42376void PacFileFetcherImpl::FetchCompleted() {
[email protected]8f3c96342009-09-22 03:06:54377 if (result_code_ == OK) {
Lily Houghton99597862018-03-07 16:40:42378 // Calculate duration of time for PAC file fetch to complete.
cbentzel27d2e5e52015-07-10 17:39:56379 DCHECK(!fetch_start_time_.is_null());
cbentzele45ccba2015-08-21 18:23:14380 DCHECK(!fetch_time_to_first_byte_.is_null());
381 UMA_HISTOGRAM_MEDIUM_TIMES("Net.ProxyScriptFetcher.SuccessDuration",
382 base::TimeTicks::Now() - fetch_start_time_);
383 UMA_HISTOGRAM_MEDIUM_TIMES("Net.ProxyScriptFetcher.FirstByteDuration",
384 fetch_time_to_first_byte_ - fetch_start_time_);
cbentzel27d2e5e52015-07-10 17:39:56385
[email protected]9b9ae9552010-07-01 22:20:50386 // The caller expects the response to be encoded as UTF16.
[email protected]8f3c96342009-09-22 03:06:54387 std::string charset;
388 cur_request_->GetCharset(&charset);
[email protected]9b9ae9552010-07-01 22:20:50389 ConvertResponseToUTF16(charset, bytes_read_so_far_, result_text_);
[email protected]8f3c96342009-09-22 03:06:54390 } else {
391 // On error, the caller expects empty string for bytes.
[email protected]9b9ae9552010-07-01 22:20:50392 result_text_->clear();
[email protected]8f3c96342009-09-22 03:06:54393 }
[email protected]677c90572008-12-10 09:03:15394
395 int result_code = result_code_;
Bence Békycc5b88a2018-05-25 20:24:17396 CompletionOnceCallback callback = std::move(callback_);
[email protected]677c90572008-12-10 09:03:15397
398 ResetCurRequestState();
399
Bence Békycc5b88a2018-05-25 20:24:17400 std::move(callback).Run(result_code);
[email protected]677c90572008-12-10 09:03:15401}
402
Lily Houghton99597862018-03-07 16:40:42403void PacFileFetcherImpl::ResetCurRequestState() {
[email protected]677c90572008-12-10 09:03:15404 cur_request_.reset();
405 cur_request_id_ = 0;
[email protected]235786812011-12-20 02:15:31406 callback_.Reset();
[email protected]677c90572008-12-10 09:03:15407 result_code_ = OK;
Raul Tambre94493c652019-03-11 17:18:35408 result_text_ = nullptr;
cbentzele45ccba2015-08-21 18:23:14409 fetch_start_time_ = base::TimeTicks();
410 fetch_time_to_first_byte_ = base::TimeTicks();
[email protected]677c90572008-12-10 09:03:15411}
412
Lily Houghton99597862018-03-07 16:40:42413void PacFileFetcherImpl::OnTimeout(int id) {
[email protected]da968bc2011-01-19 11:48:19414 // Timeout tasks may outlive the URLRequest they reference. Make sure it
[email protected]677c90572008-12-10 09:03:15415 // is still applicable.
416 if (cur_request_id_ != id)
417 return;
418
419 DCHECK(cur_request_.get());
420 result_code_ = ERR_TIMED_OUT;
mmenkeed8d7e432017-05-03 16:48:33421 FetchCompleted();
[email protected]677c90572008-12-10 09:03:15422}
423
[email protected]677c90572008-12-10 09:03:15424} // namespace net