Remove linux_chromium_gn_dbg from the chromium CQ.
[chromium-blink-merge.git] / net / url_request / url_request_context.cc
blobb83cf023be39cc57c7d9aaa47cc81cf6aafc32dc
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_(nullptr),
21 host_resolver_(nullptr),
22 cert_verifier_(nullptr),
23 channel_id_service_(nullptr),
24 http_auth_handler_factory_(nullptr),
25 proxy_service_(nullptr),
26 network_delegate_(nullptr),
27 http_user_agent_settings_(nullptr),
28 transport_security_state_(nullptr),
29 cert_transparency_verifier_(nullptr),
30 http_transaction_factory_(nullptr),
31 job_factory_(nullptr),
32 throttler_manager_(nullptr),
33 backoff_manager_(nullptr),
34 sdch_manager_(nullptr),
35 network_quality_estimator_(nullptr),
36 url_requests_(new std::set<const URLRequest*>) {
39 URLRequestContext::~URLRequestContext() {
40 AssertNoURLRequests();
43 void URLRequestContext::CopyFrom(const URLRequestContext* other) {
44 // Copy URLRequestContext parameters.
45 set_net_log(other->net_log_);
46 set_host_resolver(other->host_resolver_);
47 set_cert_verifier(other->cert_verifier_);
48 set_channel_id_service(other->channel_id_service_);
49 set_http_auth_handler_factory(other->http_auth_handler_factory_);
50 set_proxy_service(other->proxy_service_);
51 set_ssl_config_service(other->ssl_config_service_.get());
52 set_network_delegate(other->network_delegate_);
53 set_http_server_properties(other->http_server_properties_);
54 set_cookie_store(other->cookie_store_.get());
55 set_transport_security_state(other->transport_security_state_);
56 set_cert_transparency_verifier(other->cert_transparency_verifier_);
57 set_http_transaction_factory(other->http_transaction_factory_);
58 set_job_factory(other->job_factory_);
59 set_throttler_manager(other->throttler_manager_);
60 set_backoff_manager(other->backoff_manager_);
61 set_sdch_manager(other->sdch_manager_);
62 set_http_user_agent_settings(other->http_user_agent_settings_);
63 set_network_quality_estimator(other->network_quality_estimator_);
66 const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams(
67 ) const {
68 HttpTransactionFactory* transaction_factory = http_transaction_factory();
69 if (!transaction_factory)
70 return nullptr;
71 HttpNetworkSession* network_session = transaction_factory->GetSession();
72 if (!network_session)
73 return nullptr;
74 return &network_session->params();
77 scoped_ptr<URLRequest> URLRequestContext::CreateRequest(
78 const GURL& url,
79 RequestPriority priority,
80 URLRequest::Delegate* delegate) const {
81 return make_scoped_ptr(
82 new URLRequest(url, priority, delegate, this, network_delegate_));
85 void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
86 cookie_store_ = cookie_store;
89 void URLRequestContext::AssertNoURLRequests() const {
90 int num_requests = url_requests_->size();
91 if (num_requests != 0) {
92 // We're leaking URLRequests :( Dump the URL of the first one and record how
93 // many we leaked so we have an idea of how bad it is.
94 char url_buf[128];
95 const URLRequest* request = *url_requests_->begin();
96 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf));
97 bool has_delegate = request->has_delegate();
98 int load_flags = request->load_flags();
99 base::debug::StackTrace stack_trace(NULL, 0);
100 if (request->stack_trace())
101 stack_trace = *request->stack_trace();
102 base::debug::Alias(url_buf);
103 base::debug::Alias(&num_requests);
104 base::debug::Alias(&has_delegate);
105 base::debug::Alias(&load_flags);
106 base::debug::Alias(&stack_trace);
107 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: "
108 << request->url().spec().c_str() << ".";
112 } // namespace net