[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | f1d8192 | 2010-07-31 17:47:09 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/url_request/url_request_context.h" |
| 6 | |
xunjieli | d5debfc | 2017-02-24 15:55:49 | [diff] [blame] | 7 | #include <inttypes.h> |
ainozaki | b220727 | 2021-09-17 01:30:35 | [diff] [blame^] | 8 | #include <stdint.h> |
xunjieli | d5debfc | 2017-02-24 15:55:49 | [diff] [blame] | 9 | |
[email protected] | 18590f2 | 2011-07-29 16:41:28 | [diff] [blame] | 10 | #include "base/compiler_specific.h" |
[email protected] | 7c52ed9 | 2012-04-06 15:42:40 | [diff] [blame] | 11 | #include "base/debug/alias.h" |
danakj | 8522a25b | 2016-04-16 00:17:36 | [diff] [blame] | 12 | #include "base/memory/ptr_util.h" |
Ilya Sherman | 0eb3980 | 2017-12-08 20:58:18 | [diff] [blame] | 13 | #include "base/metrics/histogram_functions.h" |
xunjieli | 3fcbcc1 | 2017-04-26 15:51:19 | [diff] [blame] | 14 | #include "base/metrics/histogram_macros.h" |
[email protected] | 4dc3ad4f | 2013-06-11 07:15:50 | [diff] [blame] | 15 | #include "base/strings/string_util.h" |
xunjieli | 96ab36a7 | 2016-12-05 21:36:05 | [diff] [blame] | 16 | #include "base/strings/stringprintf.h" |
fdoray | a19b770 | 2016-12-23 14:19:31 | [diff] [blame] | 17 | #include "base/threading/thread_task_runner_handle.h" |
Yuta Hijikata | 101ed2a | 2020-11-18 07:50:39 | [diff] [blame] | 18 | #include "build/chromeos_buildflags.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 19 | #include "net/base/http_user_agent_settings.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 20 | #include "net/cookies/cookie_store.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 21 | #include "net/dns/host_resolver.h" |
xunjieli | a0166f4 | 2017-02-23 17:44:57 | [diff] [blame] | 22 | #include "net/http/http_cache.h" |
Matt Menke | 30a878c | 2021-07-20 22:25:09 | [diff] [blame] | 23 | #include "net/http/http_network_session.h" |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 24 | #include "net/http/http_transaction_factory.h" |
xunjieli | 9f8c5fb5 | 2016-12-07 22:59:33 | [diff] [blame] | 25 | #include "net/socket/ssl_client_socket_impl.h" |
[email protected] | 7c52ed9 | 2012-04-06 15:42:40 | [diff] [blame] | 26 | #include "net/url_request/url_request.h" |
[email protected] | 9349cfb | 2010-08-31 18:00:53 | [diff] [blame] | 27 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 28 | namespace net { |
| 29 | |
Maks Orlovich | 9fdb727 | 2019-12-13 01:28:23 | [diff] [blame] | 30 | URLRequestContext::URLRequestContext() |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 31 | : net_log_(nullptr), |
| 32 | host_resolver_(nullptr), |
| 33 | cert_verifier_(nullptr), |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 34 | http_auth_handler_factory_(nullptr), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 35 | proxy_resolution_service_(nullptr), |
Wojciech Dzierżanowski | 1f82356 | 2019-01-18 11:26:00 | [diff] [blame] | 36 | proxy_delegate_(nullptr), |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 37 | ssl_config_service_(nullptr), |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 38 | network_delegate_(nullptr), |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 39 | http_server_properties_(nullptr), |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 40 | http_user_agent_settings_(nullptr), |
mmenke | 606c59c | 2016-03-07 18:20:55 | [diff] [blame] | 41 | cookie_store_(nullptr), |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 42 | transport_security_state_(nullptr), |
rsleevi | d6de830 | 2016-06-21 01:33:20 | [diff] [blame] | 43 | ct_policy_enforcer_(nullptr), |
Chris Thompson | f31b249 | 2020-07-21 05:47:42 | [diff] [blame] | 44 | sct_auditing_delegate_(nullptr), |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 45 | http_transaction_factory_(nullptr), |
| 46 | job_factory_(nullptr), |
| 47 | throttler_manager_(nullptr), |
Victor Vasiliev | 7752898d | 2019-11-14 21:30:22 | [diff] [blame] | 48 | quic_context_(nullptr), |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 49 | network_quality_estimator_(nullptr), |
Julia Tuttle | 3f9acac | 2017-11-20 22:06:30 | [diff] [blame] | 50 | #if BUILDFLAG(ENABLE_REPORTING) |
juliatuttle | 2b8dd2d1 | 2017-04-12 21:27:41 | [diff] [blame] | 51 | reporting_service_(nullptr), |
Julia Tuttle | cba7d22 | 2018-02-23 19:37:27 | [diff] [blame] | 52 | network_error_logging_service_(nullptr), |
Julia Tuttle | 3f9acac | 2017-11-20 22:06:30 | [diff] [blame] | 53 | #endif // BUILDFLAG(ENABLE_REPORTING) |
Helen Li | f5e4a75 | 2018-01-02 16:03:02 | [diff] [blame] | 54 | url_requests_(std::make_unique<std::set<const URLRequest*>>()), |
mgersh | d21d6d14 | 2016-12-14 23:06:36 | [diff] [blame] | 55 | enable_brotli_(false), |
xunjieli | c4da1de | 2017-03-28 16:19:50 | [diff] [blame] | 56 | check_cleartext_permitted_(false), |
Kenichi Ishibashi | a92b965 | 2021-09-10 23:43:44 | [diff] [blame] | 57 | require_network_isolation_key_(false) { |
xunjieli | 96ab36a7 | 2016-12-05 21:36:05 | [diff] [blame] | 58 | } |
[email protected] | f1d8192 | 2010-07-31 17:47:09 | [diff] [blame] | 59 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 60 | URLRequestContext::~URLRequestContext() { |
gab | 47aa7da | 2017-06-02 16:09:43 | [diff] [blame] | 61 | DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 62 | AssertNoURLRequests(); |
| 63 | } |
| 64 | |
Matt Menke | 30a878c | 2021-07-20 22:25:09 | [diff] [blame] | 65 | const HttpNetworkSessionParams* URLRequestContext::GetNetworkSessionParams() |
| 66 | const { |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 67 | HttpTransactionFactory* transaction_factory = http_transaction_factory(); |
| 68 | if (!transaction_factory) |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 69 | return nullptr; |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 70 | HttpNetworkSession* network_session = transaction_factory->GetSession(); |
| 71 | if (!network_session) |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 72 | return nullptr; |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 73 | return &network_session->params(); |
| 74 | } |
| 75 | |
Matt Menke | 30a878c | 2021-07-20 22:25:09 | [diff] [blame] | 76 | const HttpNetworkSessionContext* URLRequestContext::GetNetworkSessionContext() |
mmenke | 6ddfbea | 2017-05-31 21:48:41 | [diff] [blame] | 77 | const { |
| 78 | HttpTransactionFactory* transaction_factory = http_transaction_factory(); |
| 79 | if (!transaction_factory) |
| 80 | return nullptr; |
| 81 | HttpNetworkSession* network_session = transaction_factory->GetSession(); |
| 82 | if (!network_session) |
| 83 | return nullptr; |
| 84 | return &network_session->context(); |
| 85 | } |
| 86 | |
Yuta Hijikata | 101ed2a | 2020-11-18 07:50:39 | [diff] [blame] | 87 | // TODO(crbug.com/1052397): Revisit once build flag switch of lacros-chrome is |
| 88 | // complete. |
| 89 | #if !defined(OS_WIN) && !(defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)) |
danakj | 8522a25b | 2016-04-16 00:17:36 | [diff] [blame] | 90 | std::unique_ptr<URLRequest> URLRequestContext::CreateRequest( |
[email protected] | 2ca01e5 | 2013-10-31 22:05:19 | [diff] [blame] | 91 | const GURL& url, |
| 92 | RequestPriority priority, |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 93 | URLRequest::Delegate* delegate) const { |
Matt Menke | fe9a9df | 2021-09-08 17:55:24 | [diff] [blame] | 94 | return CreateRequest(url, priority, delegate, MISSING_TRAFFIC_ANNOTATION, |
| 95 | /*is_for_websockets=*/false); |
[email protected] | 8a26ff6 | 2012-08-24 21:49:20 | [diff] [blame] | 96 | } |
Nicolas Ouellet-Payeur | 6e833b5 | 2019-07-02 17:18:08 | [diff] [blame] | 97 | #endif |
[email protected] | 8a26ff6 | 2012-08-24 21:49:20 | [diff] [blame] | 98 | |
rhalavati | a9b551d | 2017-02-09 12:03:00 | [diff] [blame] | 99 | std::unique_ptr<URLRequest> URLRequestContext::CreateRequest( |
| 100 | const GURL& url, |
| 101 | RequestPriority priority, |
| 102 | URLRequest::Delegate* delegate, |
Matt Menke | fe9a9df | 2021-09-08 17:55:24 | [diff] [blame] | 103 | NetworkTrafficAnnotationTag traffic_annotation, |
ainozaki | b220727 | 2021-09-17 01:30:35 | [diff] [blame^] | 104 | bool is_for_websockets, |
| 105 | const absl::optional<uint32_t> net_log_source_id) const { |
| 106 | return base::WrapUnique(new URLRequest(url, priority, delegate, this, |
| 107 | traffic_annotation, is_for_websockets, |
| 108 | net_log_source_id)); |
rhalavati | a9b551d | 2017-02-09 12:03:00 | [diff] [blame] | 109 | } |
| 110 | |
[email protected] | d100e44f | 2011-01-26 22:47:11 | [diff] [blame] | 111 | void URLRequestContext::set_cookie_store(CookieStore* cookie_store) { |
| 112 | cookie_store_ = cookie_store; |
| 113 | } |
| 114 | |
[email protected] | 1e714bba | 2012-04-10 17:01:05 | [diff] [blame] | 115 | void URLRequestContext::AssertNoURLRequests() const { |
Helen Li | f5e4a75 | 2018-01-02 16:03:02 | [diff] [blame] | 116 | int num_requests = url_requests_->size(); |
[email protected] | 7c52ed9 | 2012-04-06 15:42:40 | [diff] [blame] | 117 | if (num_requests != 0) { |
| 118 | // We're leaking URLRequests :( Dump the URL of the first one and record how |
| 119 | // many we leaked so we have an idea of how bad it is. |
Helen Li | f5e4a75 | 2018-01-02 16:03:02 | [diff] [blame] | 120 | const URLRequest* request = *url_requests_->begin(); |
[email protected] | eb4ecaca | 2012-05-04 01:05:03 | [diff] [blame] | 121 | int load_flags = request->load_flags(); |
Lukasz Anforowicz | 68c2177 | 2018-01-13 03:42:44 | [diff] [blame] | 122 | DEBUG_ALIAS_FOR_GURL(url_buf, request->url()); |
[email protected] | 7c52ed9 | 2012-04-06 15:42:40 | [diff] [blame] | 123 | base::debug::Alias(&num_requests); |
[email protected] | eb4ecaca | 2012-05-04 01:05:03 | [diff] [blame] | 124 | base::debug::Alias(&load_flags); |
[email protected] | 1f5f8e2 | 2012-09-06 23:40:54 | [diff] [blame] | 125 | CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: " |
| 126 | << request->url().spec().c_str() << "."; |
[email protected] | 7c52ed9 | 2012-04-06 15:42:40 | [diff] [blame] | 127 | } |
[email protected] | 9349cfb | 2010-08-31 18:00:53 | [diff] [blame] | 128 | } |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 129 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 130 | } // namespace net |