blob: ed0aba3fe23a56ab796779d57709d414251d0d4f [file] [log] [blame]
[email protected]aa84a7e2012-03-15 21:29:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]f1d81922010-07-31 17:47:092// 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
[email protected]18590f22011-07-29 16:41:287#include "base/compiler_specific.h"
[email protected]7c52ed92012-04-06 15:42:408#include "base/debug/alias.h"
[email protected]4eee0452012-05-12 01:29:279#include "base/debug/stack_trace.h"
danakj8522a25b2016-04-16 00:17:3610#include "base/memory/ptr_util.h"
[email protected]4dc3ad4f2013-06-11 07:15:5011#include "base/strings/string_util.h"
[email protected]aa84a7e2012-03-15 21:29:0612#include "net/cookies/cookie_store.h"
[email protected]f2cb3cf2013-03-21 01:40:5313#include "net/dns/host_resolver.h"
[email protected]f6c21cb2011-02-16 19:45:4114#include "net/http/http_transaction_factory.h"
[email protected]ee4c30d2012-11-07 15:08:4315#include "net/url_request/http_user_agent_settings.h"
[email protected]7c52ed92012-04-06 15:42:4016#include "net/url_request/url_request.h"
[email protected]9349cfb2010-08-31 18:00:5317
[email protected]27a112c2011-01-06 04:19:3018namespace net {
19
[email protected]9349cfb2010-08-31 18:00:5320URLRequestContext::URLRequestContext()
tbansalea2fb8c2015-05-22 22:23:0021 : net_log_(nullptr),
22 host_resolver_(nullptr),
23 cert_verifier_(nullptr),
24 channel_id_service_(nullptr),
tbansalea2fb8c2015-05-22 22:23:0025 http_auth_handler_factory_(nullptr),
26 proxy_service_(nullptr),
27 network_delegate_(nullptr),
28 http_user_agent_settings_(nullptr),
mmenke606c59c2016-03-07 18:20:5529 cookie_store_(nullptr),
tbansalea2fb8c2015-05-22 22:23:0030 transport_security_state_(nullptr),
31 cert_transparency_verifier_(nullptr),
32 http_transaction_factory_(nullptr),
33 job_factory_(nullptr),
34 throttler_manager_(nullptr),
xunjieli3bb781a2015-07-22 22:40:3435 backoff_manager_(nullptr),
rdsmithd6ee1642015-05-29 15:01:3036 sdch_manager_(nullptr),
tbansalea2fb8c2015-05-22 22:23:0037 network_quality_estimator_(nullptr),
nharper5babb5e62016-03-09 18:58:0738 url_requests_(new std::set<const URLRequest*>),
39 has_known_mismatched_cookie_store_(false) {}
[email protected]f1d81922010-07-31 17:47:0940
[email protected]ef2bf422012-05-11 03:27:0941URLRequestContext::~URLRequestContext() {
42 AssertNoURLRequests();
43}
44
[email protected]fa22a6f12012-05-11 17:19:5945void URLRequestContext::CopyFrom(const URLRequestContext* other) {
[email protected]d9696672011-03-15 22:45:0946 // Copy URLRequestContext parameters.
[email protected]fa22a6f12012-05-11 17:19:5947 set_net_log(other->net_log_);
48 set_host_resolver(other->host_resolver_);
49 set_cert_verifier(other->cert_verifier_);
[email protected]6b8a3c742014-07-25 00:25:3550 set_channel_id_service(other->channel_id_service_);
[email protected]fa22a6f12012-05-11 17:19:5951 set_http_auth_handler_factory(other->http_auth_handler_factory_);
52 set_proxy_service(other->proxy_service_);
[email protected]90499482013-06-01 00:39:5053 set_ssl_config_service(other->ssl_config_service_.get());
[email protected]fa22a6f12012-05-11 17:19:5954 set_network_delegate(other->network_delegate_);
55 set_http_server_properties(other->http_server_properties_);
mmenke606c59c2016-03-07 18:20:5556 set_cookie_store(other->cookie_store_);
[email protected]fa22a6f12012-05-11 17:19:5957 set_transport_security_state(other->transport_security_state_);
[email protected]284303b62013-11-28 15:11:5458 set_cert_transparency_verifier(other->cert_transparency_verifier_);
[email protected]fa22a6f12012-05-11 17:19:5959 set_http_transaction_factory(other->http_transaction_factory_);
[email protected]fa22a6f12012-05-11 17:19:5960 set_job_factory(other->job_factory_);
61 set_throttler_manager(other->throttler_manager_);
xunjieli3bb781a2015-07-22 22:40:3462 set_backoff_manager(other->backoff_manager_);
rdsmithd6ee1642015-05-29 15:01:3063 set_sdch_manager(other->sdch_manager_);
[email protected]ee4c30d2012-11-07 15:08:4364 set_http_user_agent_settings(other->http_user_agent_settings_);
tbansalea2fb8c2015-05-22 22:23:0065 set_network_quality_estimator(other->network_quality_estimator_);
[email protected]d9696672011-03-15 22:45:0966}
67
[email protected]c2dad292012-09-07 21:27:3568const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams(
69 ) const {
70 HttpTransactionFactory* transaction_factory = http_transaction_factory();
71 if (!transaction_factory)
tbansalea2fb8c2015-05-22 22:23:0072 return nullptr;
[email protected]c2dad292012-09-07 21:27:3573 HttpNetworkSession* network_session = transaction_factory->GetSession();
74 if (!network_session)
tbansalea2fb8c2015-05-22 22:23:0075 return nullptr;
[email protected]c2dad292012-09-07 21:27:3576 return &network_session->params();
77}
78
danakj8522a25b2016-04-16 00:17:3679std::unique_ptr<URLRequest> URLRequestContext::CreateRequest(
[email protected]2ca01e52013-10-31 22:05:1980 const GURL& url,
81 RequestPriority priority,
davidben151423e2015-03-23 18:48:3682 URLRequest::Delegate* delegate) const {
danakj8522a25b2016-04-16 00:17:3683 return base::WrapUnique(
davidben151423e2015-03-23 18:48:3684 new URLRequest(url, priority, delegate, this, network_delegate_));
[email protected]8a26ff62012-08-24 21:49:2085}
86
[email protected]d100e44f2011-01-26 22:47:1187void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
88 cookie_store_ = cookie_store;
89}
90
[email protected]1e714bba2012-04-10 17:01:0591void URLRequestContext::AssertNoURLRequests() const {
[email protected]7c52ed92012-04-06 15:42:4092 int num_requests = url_requests_->size();
93 if (num_requests != 0) {
94 // We're leaking URLRequests :( Dump the URL of the first one and record how
95 // many we leaked so we have an idea of how bad it is.
96 char url_buf[128];
97 const URLRequest* request = *url_requests_->begin();
98 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf));
[email protected]eb4ecaca2012-05-04 01:05:0399 int load_flags = request->load_flags();
[email protected]4eee0452012-05-12 01:29:27100 base::debug::StackTrace stack_trace(NULL, 0);
101 if (request->stack_trace())
102 stack_trace = *request->stack_trace();
[email protected]7c52ed92012-04-06 15:42:40103 base::debug::Alias(url_buf);
104 base::debug::Alias(&num_requests);
[email protected]eb4ecaca2012-05-04 01:05:03105 base::debug::Alias(&load_flags);
[email protected]4eee0452012-05-12 01:29:27106 base::debug::Alias(&stack_trace);
[email protected]1f5f8e22012-09-06 23:40:54107 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: "
108 << request->url().spec().c_str() << ".";
[email protected]7c52ed92012-04-06 15:42:40109 }
[email protected]9349cfb2010-08-31 18:00:53110}
[email protected]2fb629202010-12-23 23:52:57111
[email protected]27a112c2011-01-06 04:19:30112} // namespace net