We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / net / url_request / url_request_context.cc
blobeb6a35c6d790e3e3ce5e001ed825c52834fd640b
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/debug/stack_trace.h"
10 #include "base/strings/string_util.h"
11 #include "net/cookies/cookie_store.h"
12 #include "net/dns/host_resolver.h"
13 #include "net/http/http_transaction_factory.h"
14 #include "net/url_request/http_user_agent_settings.h"
15 #include "net/url_request/url_request.h"
17 namespace net {
19 URLRequestContext::URLRequestContext()
20 : net_log_(NULL),
21 host_resolver_(NULL),
22 cert_verifier_(NULL),
23 channel_id_service_(NULL),
24 fraudulent_certificate_reporter_(NULL),
25 http_auth_handler_factory_(NULL),
26 proxy_service_(NULL),
27 network_delegate_(NULL),
28 http_user_agent_settings_(NULL),
29 transport_security_state_(NULL),
30 cert_transparency_verifier_(NULL),
31 http_transaction_factory_(NULL),
32 job_factory_(NULL),
33 throttler_manager_(NULL),
34 // For investigation of http://crbug.com/454198; restore when resolved.
35 // sdch_manager_(NULL),
36 have_sdch_manager_(false),
37 url_requests_(new std::set<const URLRequest*>) {
40 URLRequestContext::~URLRequestContext() {
41 AssertNoURLRequests();
44 void URLRequestContext::CopyFrom(const URLRequestContext* other) {
45 // Copy URLRequestContext parameters.
46 set_net_log(other->net_log_);
47 set_host_resolver(other->host_resolver_);
48 set_cert_verifier(other->cert_verifier_);
49 set_channel_id_service(other->channel_id_service_);
50 set_fraudulent_certificate_reporter(other->fraudulent_certificate_reporter_);
51 set_http_auth_handler_factory(other->http_auth_handler_factory_);
52 set_proxy_service(other->proxy_service_);
53 set_ssl_config_service(other->ssl_config_service_.get());
54 set_network_delegate(other->network_delegate_);
55 set_http_server_properties(other->http_server_properties_);
56 set_cookie_store(other->cookie_store_.get());
57 set_transport_security_state(other->transport_security_state_);
58 set_cert_transparency_verifier(other->cert_transparency_verifier_);
59 set_http_transaction_factory(other->http_transaction_factory_);
60 set_job_factory(other->job_factory_);
61 set_throttler_manager(other->throttler_manager_);
62 // For investigation of http://crbug.com/454198; remove when resolved.
63 CHECK(!other->have_sdch_manager_ || other->sdch_manager_.get());
64 set_sdch_manager(other->sdch_manager_.get());
65 set_http_user_agent_settings(other->http_user_agent_settings_);
68 const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams(
69 ) const {
70 HttpTransactionFactory* transaction_factory = http_transaction_factory();
71 if (!transaction_factory)
72 return NULL;
73 HttpNetworkSession* network_session = transaction_factory->GetSession();
74 if (!network_session)
75 return NULL;
76 return &network_session->params();
79 scoped_ptr<URLRequest> URLRequestContext::CreateRequest(
80 const GURL& url,
81 RequestPriority priority,
82 URLRequest::Delegate* delegate) const {
83 return make_scoped_ptr(
84 new URLRequest(url, priority, delegate, this, network_delegate_));
87 void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
88 cookie_store_ = cookie_store;
91 void URLRequestContext::AssertNoURLRequests() const {
92 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));
99 bool has_delegate = request->has_delegate();
100 int load_flags = request->load_flags();
101 base::debug::StackTrace stack_trace(NULL, 0);
102 if (request->stack_trace())
103 stack_trace = *request->stack_trace();
104 base::debug::Alias(url_buf);
105 base::debug::Alias(&num_requests);
106 base::debug::Alias(&has_delegate);
107 base::debug::Alias(&load_flags);
108 base::debug::Alias(&stack_trace);
109 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: "
110 << request->url().spec().c_str() << ".";
114 } // namespace net