forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl_request_context.cc
256 lines (237 loc) · 9.71 KB
/
url_request_context.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/url_request/url_request_context.h"
#include <inttypes.h>
#include <stdint.h>
#include "base/compiler_specific.h"
#include "base/debug/alias.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_util.h"
#include "base/types/pass_key.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "net/base/http_user_agent_settings.h"
#include "net/base/network_delegate.h"
#include "net/base/proxy_delegate.h"
#include "net/cert/cert_verifier.h"
#include "net/cert/ct_policy_enforcer.h"
#include "net/cert/sct_auditing_delegate.h"
#include "net/cookies/cookie_store.h"
#include "net/dns/host_resolver.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_cache.h"
#include "net/http/http_network_session.h"
#include "net/http/http_server_properties.h"
#include "net/http/http_transaction_factory.h"
#include "net/http/transport_security_persister.h"
#include "net/http/transport_security_state.h"
#include "net/log/net_log.h"
#include "net/log/net_log_source.h"
#include "net/nqe/network_quality_estimator.h"
#include "net/proxy_resolution/proxy_resolution_service.h"
#include "net/quic/quic_context.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/ssl_client_socket_impl.h"
#include "net/ssl/ssl_config_service.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job_factory.h"
#include "net/url_request/url_request_throttler_manager.h"
#if BUILDFLAG(ENABLE_REPORTING)
#include "net/network_error_logging/network_error_logging_service.h"
#include "net/network_error_logging/persistent_reporting_and_nel_store.h"
#include "net/reporting/reporting_service.h"
#endif // BUILDFLAG(ENABLE_REPORTING)
namespace net {
URLRequestContext::URLRequestContext(
base::PassKey<URLRequestContextBuilder> pass_key)
: url_requests_(std::make_unique<std::set<const URLRequest*>>()),
bound_network_(handles::kInvalidNetworkHandle) {}
URLRequestContext::~URLRequestContext() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
#if BUILDFLAG(ENABLE_REPORTING)
// Shut down the NetworkErrorLoggingService so that destroying the
// ReportingService (which might abort in-flight URLRequests, generating
// network errors) won't recursively try to queue more network error
// reports.
if (network_error_logging_service())
network_error_logging_service()->OnShutdown();
// Shut down the ReportingService before the rest of the URLRequestContext,
// so it cancels any pending requests it may have.
if (reporting_service())
reporting_service()->OnShutdown();
#endif // BUILDFLAG(ENABLE_REPORTING)
// Shut down the ProxyResolutionService, as it may have pending URLRequests
// using this context. Since this cancels requests, it's not safe to
// subclass this, as some parts of the URLRequestContext may then be torn
// down before this cancels the ProxyResolutionService's URLRequests.
proxy_resolution_service()->OnShutdown();
DCHECK(host_resolver());
host_resolver()->OnShutdown();
AssertNoURLRequests();
}
const HttpNetworkSessionParams* URLRequestContext::GetNetworkSessionParams()
const {
HttpTransactionFactory* transaction_factory = http_transaction_factory();
if (!transaction_factory)
return nullptr;
HttpNetworkSession* network_session = transaction_factory->GetSession();
if (!network_session)
return nullptr;
return &network_session->params();
}
const HttpNetworkSessionContext* URLRequestContext::GetNetworkSessionContext()
const {
HttpTransactionFactory* transaction_factory = http_transaction_factory();
if (!transaction_factory)
return nullptr;
HttpNetworkSession* network_session = transaction_factory->GetSession();
if (!network_session)
return nullptr;
return &network_session->context();
}
// TODO(crbug.com/1052397): Revisit once build flag switch of lacros-chrome is
// complete.
#if !BUILDFLAG(IS_WIN) && \
!(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
std::unique_ptr<URLRequest> URLRequestContext::CreateRequest(
const GURL& url,
RequestPriority priority,
URLRequest::Delegate* delegate) const {
return CreateRequest(url, priority, delegate, MISSING_TRAFFIC_ANNOTATION,
/*is_for_websockets=*/false);
}
#endif
std::unique_ptr<URLRequest> URLRequestContext::CreateRequest(
const GURL& url,
RequestPriority priority,
URLRequest::Delegate* delegate,
NetworkTrafficAnnotationTag traffic_annotation,
bool is_for_websockets,
const absl::optional<net::NetLogSource> net_log_source) const {
return std::make_unique<URLRequest>(
base::PassKey<URLRequestContext>(), url, priority, delegate, this,
traffic_annotation, is_for_websockets, net_log_source);
}
void URLRequestContext::AssertNoURLRequests() const {
int num_requests = url_requests_->size();
if (num_requests != 0) {
// We're leaking URLRequests :( Dump the URL of the first one and record how
// many we leaked so we have an idea of how bad it is.
const URLRequest* request = *url_requests_->begin();
int load_flags = request->load_flags();
DEBUG_ALIAS_FOR_GURL(url_buf, request->url());
base::debug::Alias(&num_requests);
base::debug::Alias(&load_flags);
CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: "
<< request->url().spec().c_str() << ".";
}
}
void URLRequestContext::set_net_log(NetLog* net_log) {
net_log_ = net_log;
}
void URLRequestContext::set_host_resolver(
std::unique_ptr<HostResolver> host_resolver) {
DCHECK(host_resolver.get());
host_resolver_ = std::move(host_resolver);
}
void URLRequestContext::set_cert_verifier(
std::unique_ptr<CertVerifier> cert_verifier) {
cert_verifier_ = std::move(cert_verifier);
}
void URLRequestContext::set_proxy_resolution_service(
std::unique_ptr<ProxyResolutionService> proxy_resolution_service) {
proxy_resolution_service_ = std::move(proxy_resolution_service);
}
void URLRequestContext::set_proxy_delegate(
std::unique_ptr<ProxyDelegate> proxy_delegate) {
proxy_delegate_ = std::move(proxy_delegate);
}
void URLRequestContext::set_ssl_config_service(
std::unique_ptr<SSLConfigService> service) {
ssl_config_service_ = std::move(service);
}
void URLRequestContext::set_http_auth_handler_factory(
std::unique_ptr<HttpAuthHandlerFactory> factory) {
http_auth_handler_factory_ = std::move(factory);
}
void URLRequestContext::set_http_network_session(
std::unique_ptr<HttpNetworkSession> http_network_session) {
http_network_session_ = std::move(http_network_session);
}
void URLRequestContext::set_http_transaction_factory(
std::unique_ptr<HttpTransactionFactory> factory) {
http_transaction_factory_ = std::move(factory);
}
void URLRequestContext::set_network_delegate(
std::unique_ptr<NetworkDelegate> network_delegate) {
network_delegate_ = std::move(network_delegate);
}
void URLRequestContext::set_http_server_properties(
std::unique_ptr<HttpServerProperties> http_server_properties) {
http_server_properties_ = std::move(http_server_properties);
}
void URLRequestContext::set_cookie_store(
std::unique_ptr<CookieStore> cookie_store) {
cookie_store_ = std::move(cookie_store);
}
void URLRequestContext::set_transport_security_state(
std::unique_ptr<TransportSecurityState> state) {
transport_security_state_ = std::move(state);
}
void URLRequestContext::set_ct_policy_enforcer(
std::unique_ptr<CTPolicyEnforcer> enforcer) {
ct_policy_enforcer_ = std::move(enforcer);
}
void URLRequestContext::set_sct_auditing_delegate(
std::unique_ptr<SCTAuditingDelegate> delegate) {
sct_auditing_delegate_ = std::move(delegate);
}
void URLRequestContext::set_job_factory(
std::unique_ptr<const URLRequestJobFactory> job_factory) {
job_factory_storage_ = std::move(job_factory);
job_factory_ = job_factory_storage_.get();
}
void URLRequestContext::set_throttler_manager(
std::unique_ptr<URLRequestThrottlerManager> throttler_manager) {
throttler_manager_ = std::move(throttler_manager);
}
void URLRequestContext::set_quic_context(
std::unique_ptr<QuicContext> quic_context) {
quic_context_ = std::move(quic_context);
}
void URLRequestContext::set_http_user_agent_settings(
std::unique_ptr<const HttpUserAgentSettings> http_user_agent_settings) {
http_user_agent_settings_ = std::move(http_user_agent_settings);
}
void URLRequestContext::set_network_quality_estimator(
NetworkQualityEstimator* network_quality_estimator) {
network_quality_estimator_ = network_quality_estimator;
}
void URLRequestContext::set_client_socket_factory(
std::unique_ptr<ClientSocketFactory> client_socket_factory) {
client_socket_factory_ = std::move(client_socket_factory);
}
#if BUILDFLAG(ENABLE_REPORTING)
void URLRequestContext::set_persistent_reporting_and_nel_store(
std::unique_ptr<PersistentReportingAndNelStore>
persistent_reporting_and_nel_store) {
persistent_reporting_and_nel_store_ =
std::move(persistent_reporting_and_nel_store);
}
void URLRequestContext::set_reporting_service(
std::unique_ptr<ReportingService> reporting_service) {
reporting_service_ = std::move(reporting_service);
}
void URLRequestContext::set_network_error_logging_service(
std::unique_ptr<NetworkErrorLoggingService> network_error_logging_service) {
network_error_logging_service_ = std::move(network_error_logging_service);
}
#endif // BUILDFLAG(ENABLE_REPORTING)
void URLRequestContext::set_transport_security_persister(
std::unique_ptr<TransportSecurityPersister> transport_security_persister) {
transport_security_persister_ = std::move(transport_security_persister);
}
} // namespace net