1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/url_request/url_request_context.h"
7 #include "base/compiler_specific.h"
8 #include "base/debug/alias.h"
9 #include "base/string_util.h"
10 #include "net/base/host_resolver.h"
11 #include "net/cookies/cookie_store.h"
12 #include "net/ftp/ftp_transaction_factory.h"
13 #include "net/http/http_transaction_factory.h"
14 #include "net/url_request/url_request.h"
18 URLRequestContext::URLRequestContext()
22 server_bound_cert_service_(NULL
),
23 fraudulent_certificate_reporter_(NULL
),
24 http_auth_handler_factory_(NULL
),
26 network_delegate_(NULL
),
27 http_server_properties_(NULL
),
28 transport_security_state_(NULL
),
29 ftp_auth_cache_(new FtpAuthCache
),
30 http_transaction_factory_(NULL
),
31 ftp_transaction_factory_(NULL
),
33 throttler_manager_(NULL
),
34 url_requests_(new std::set
<const URLRequest
*>) {
37 URLRequestContext::~URLRequestContext() {
38 AssertNoURLRequests();
41 void URLRequestContext::CopyFrom(const URLRequestContext
* other
) {
42 // Copy URLRequestContext parameters.
43 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_
);
50 set_ssl_config_service(other
->ssl_config_service_
);
51 set_network_delegate(other
->network_delegate_
);
52 set_http_server_properties(other
->http_server_properties_
);
53 set_cookie_store(other
->cookie_store_
);
54 set_transport_security_state(other
->transport_security_state_
);
55 // FTPAuthCache is unique per context.
56 set_accept_language(other
->accept_language_
);
57 set_accept_charset(other
->accept_charset_
);
58 set_referrer_charset(other
->referrer_charset_
);
59 set_http_transaction_factory(other
->http_transaction_factory_
);
60 set_ftp_transaction_factory(other
->ftp_transaction_factory_
);
61 set_job_factory(other
->job_factory_
);
62 set_throttler_manager(other
->throttler_manager_
);
65 void URLRequestContext::set_cookie_store(CookieStore
* cookie_store
) {
66 cookie_store_
= cookie_store
;
69 const std::string
& URLRequestContext::GetUserAgent(const GURL
& url
) const {
73 void URLRequestContext::AssertNoURLRequests() const {
74 int num_requests
= url_requests_
->size();
75 if (num_requests
!= 0) {
76 // We're leaking URLRequests :( Dump the URL of the first one and record how
77 // many we leaked so we have an idea of how bad it is.
79 const URLRequest
* request
= *url_requests_
->begin();
80 base::strlcpy(url_buf
, request
->url().spec().c_str(), arraysize(url_buf
));
81 bool has_delegate
= request
->has_delegate();
82 int load_flags
= request
->load_flags();
83 base::debug::Alias(url_buf
);
84 base::debug::Alias(&num_requests
);
85 base::debug::Alias(&has_delegate
);
86 base::debug::Alias(&load_flags
);