blob: 405d47621c6a6477b4891cb8004bb43ffe67a70a [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"
[email protected]4dc3ad4f2013-06-11 07:15:5010#include "base/strings/string_util.h"
[email protected]aa84a7e2012-03-15 21:29:0611#include "net/cookies/cookie_store.h"
[email protected]f2cb3cf2013-03-21 01:40:5312#include "net/dns/host_resolver.h"
[email protected]f6c21cb2011-02-16 19:45:4113#include "net/http/http_transaction_factory.h"
[email protected]ee4c30d2012-11-07 15:08:4314#include "net/url_request/http_user_agent_settings.h"
[email protected]7c52ed92012-04-06 15:42:4015#include "net/url_request/url_request.h"
[email protected]9349cfb2010-08-31 18:00:5316
[email protected]27a112c2011-01-06 04:19:3017namespace net {
18
[email protected]9349cfb2010-08-31 18:00:5319URLRequestContext::URLRequestContext()
[email protected]ef2bf422012-05-11 03:27:0920 : net_log_(NULL),
[email protected]c3a7bce2010-10-18 17:36:5421 host_resolver_(NULL),
[email protected]822581d2010-12-16 17:27:1522 cert_verifier_(NULL),
[email protected]9c4eff22012-03-20 22:42:2923 server_bound_cert_service_(NULL),
[email protected]b97d7702011-10-16 01:11:0724 fraudulent_certificate_reporter_(NULL),
[email protected]9349cfb2010-08-31 18:00:5325 http_auth_handler_factory_(NULL),
[email protected]160014da2011-05-13 19:37:4626 proxy_service_(NULL),
[email protected]9349cfb2010-08-31 18:00:5327 network_delegate_(NULL),
[email protected]db96a882011-10-09 02:01:5428 http_server_properties_(NULL),
[email protected]ee4c30d2012-11-07 15:08:4329 http_user_agent_settings_(NULL),
[email protected]70b92342010-10-12 05:54:0630 transport_security_state_(NULL),
[email protected]f6c21cb2011-02-16 19:45:4131 http_transaction_factory_(NULL),
[email protected]7c52ed92012-04-06 15:42:4032 job_factory_(NULL),
[email protected]a73a2802012-05-02 19:20:1533 throttler_manager_(NULL),
[email protected]7c52ed92012-04-06 15:42:4034 url_requests_(new std::set<const URLRequest*>) {
[email protected]9349cfb2010-08-31 18:00:5335}
[email protected]f1d81922010-07-31 17:47:0936
[email protected]ef2bf422012-05-11 03:27:0937URLRequestContext::~URLRequestContext() {
38 AssertNoURLRequests();
39}
40
[email protected]fa22a6f12012-05-11 17:19:5941void URLRequestContext::CopyFrom(const URLRequestContext* other) {
[email protected]d9696672011-03-15 22:45:0942 // Copy URLRequestContext parameters.
[email protected]fa22a6f12012-05-11 17:19:5943 set_net_log(other->net_log_);
44 set_host_resolver(other->host_resolver_);
45 set_cert_verifier(other->cert_verifier_);
46 set_server_bound_cert_service(other->server_bound_cert_service_);
47 set_fraudulent_certificate_reporter(other->fraudulent_certificate_reporter_);
48 set_http_auth_handler_factory(other->http_auth_handler_factory_);
49 set_proxy_service(other->proxy_service_);
[email protected]90499482013-06-01 00:39:5050 set_ssl_config_service(other->ssl_config_service_.get());
[email protected]fa22a6f12012-05-11 17:19:5951 set_network_delegate(other->network_delegate_);
52 set_http_server_properties(other->http_server_properties_);
[email protected]90499482013-06-01 00:39:5053 set_cookie_store(other->cookie_store_.get());
[email protected]fa22a6f12012-05-11 17:19:5954 set_transport_security_state(other->transport_security_state_);
[email protected]fa22a6f12012-05-11 17:19:5955 set_http_transaction_factory(other->http_transaction_factory_);
[email protected]fa22a6f12012-05-11 17:19:5956 set_job_factory(other->job_factory_);
57 set_throttler_manager(other->throttler_manager_);
[email protected]ee4c30d2012-11-07 15:08:4358 set_http_user_agent_settings(other->http_user_agent_settings_);
[email protected]d9696672011-03-15 22:45:0959}
60
[email protected]c2dad292012-09-07 21:27:3561const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams(
62 ) const {
63 HttpTransactionFactory* transaction_factory = http_transaction_factory();
64 if (!transaction_factory)
65 return NULL;
66 HttpNetworkSession* network_session = transaction_factory->GetSession();
67 if (!network_session)
68 return NULL;
69 return &network_session->params();
70}
71
[email protected]8a26ff62012-08-24 21:49:2072URLRequest* URLRequestContext::CreateRequest(
73 const GURL& url, URLRequest::Delegate* delegate) const {
74 return new URLRequest(url, delegate, this, network_delegate_);
75}
76
[email protected]d100e44f2011-01-26 22:47:1177void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
78 cookie_store_ = cookie_store;
79}
80
[email protected]ee4c30d2012-11-07 15:08:4381std::string URLRequestContext::GetAcceptLanguage() const {
82 return http_user_agent_settings_ ?
83 http_user_agent_settings_->GetAcceptLanguage() : EmptyString();
84}
85
86std::string URLRequestContext::GetUserAgent(const GURL& url) const {
87 return http_user_agent_settings_ ?
88 http_user_agent_settings_->GetUserAgent(url) : EmptyString();
[email protected]f1d81922010-07-31 17:47:0989}
[email protected]9349cfb2010-08-31 18:00:5390
[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 bool has_delegate = request->has_delegate();
100 int load_flags = request->load_flags();
[email protected]4eee0452012-05-12 01:29:27101 base::debug::StackTrace stack_trace(NULL, 0);
102 if (request->stack_trace())
103 stack_trace = *request->stack_trace();
[email protected]7c52ed92012-04-06 15:42:40104 base::debug::Alias(url_buf);
105 base::debug::Alias(&num_requests);
[email protected]eb4ecaca2012-05-04 01:05:03106 base::debug::Alias(&has_delegate);
107 base::debug::Alias(&load_flags);
[email protected]4eee0452012-05-12 01:29:27108 base::debug::Alias(&stack_trace);
[email protected]1f5f8e22012-09-06 23:40:54109 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: "
110 << request->url().spec().c_str() << ".";
[email protected]7c52ed92012-04-06 15:42:40111 }
[email protected]9349cfb2010-08-31 18:00:53112}
[email protected]2fb629202010-12-23 23:52:57113
[email protected]27a112c2011-01-06 04:19:30114} // namespace net