| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/url_request/url_request_context.h" | 5 #include "net/url_request/url_request_context.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/debug/alias.h" | 8 #include "base/debug/alias.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/trace_event/memory_allocator_dump.h" |
| 13 #include "base/trace_event/memory_dump_manager.h" |
| 14 #include "base/trace_event/process_memory_dump.h" |
| 15 #include "net/base/sdch_manager.h" |
| 11 #include "net/cookies/cookie_store.h" | 16 #include "net/cookies/cookie_store.h" |
| 12 #include "net/dns/host_resolver.h" | 17 #include "net/dns/host_resolver.h" |
| 13 #include "net/http/http_transaction_factory.h" | 18 #include "net/http/http_transaction_factory.h" |
| 19 #include "net/socket/ssl_client_socket_impl.h" |
| 14 #include "net/url_request/http_user_agent_settings.h" | 20 #include "net/url_request/http_user_agent_settings.h" |
| 15 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
| 16 | 22 |
| 17 namespace net { | 23 namespace net { |
| 18 | 24 |
| 19 URLRequestContext::URLRequestContext() | 25 URLRequestContext::URLRequestContext() |
| 20 : net_log_(nullptr), | 26 : net_log_(nullptr), |
| 21 host_resolver_(nullptr), | 27 host_resolver_(nullptr), |
| 22 cert_verifier_(nullptr), | 28 cert_verifier_(nullptr), |
| 23 channel_id_service_(nullptr), | 29 channel_id_service_(nullptr), |
| 24 http_auth_handler_factory_(nullptr), | 30 http_auth_handler_factory_(nullptr), |
| 25 proxy_service_(nullptr), | 31 proxy_service_(nullptr), |
| 26 network_delegate_(nullptr), | 32 network_delegate_(nullptr), |
| 27 http_server_properties_(nullptr), | 33 http_server_properties_(nullptr), |
| 28 http_user_agent_settings_(nullptr), | 34 http_user_agent_settings_(nullptr), |
| 29 cookie_store_(nullptr), | 35 cookie_store_(nullptr), |
| 30 transport_security_state_(nullptr), | 36 transport_security_state_(nullptr), |
| 31 cert_transparency_verifier_(nullptr), | 37 cert_transparency_verifier_(nullptr), |
| 32 ct_policy_enforcer_(nullptr), | 38 ct_policy_enforcer_(nullptr), |
| 33 http_transaction_factory_(nullptr), | 39 http_transaction_factory_(nullptr), |
| 34 job_factory_(nullptr), | 40 job_factory_(nullptr), |
| 35 throttler_manager_(nullptr), | 41 throttler_manager_(nullptr), |
| 36 backoff_manager_(nullptr), | 42 backoff_manager_(nullptr), |
| 37 sdch_manager_(nullptr), | 43 sdch_manager_(nullptr), |
| 38 network_quality_estimator_(nullptr), | 44 network_quality_estimator_(nullptr), |
| 39 url_requests_(new std::set<const URLRequest*>), | 45 url_requests_(new std::set<const URLRequest*>), |
| 40 enable_brotli_(false) {} | 46 enable_brotli_(false) { |
| 47 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 48 this, "URLRequestContext", base::ThreadTaskRunnerHandle::Get()); |
| 49 } |
| 41 | 50 |
| 42 URLRequestContext::~URLRequestContext() { | 51 URLRequestContext::~URLRequestContext() { |
| 43 AssertNoURLRequests(); | 52 AssertNoURLRequests(); |
| 53 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 54 this); |
| 44 } | 55 } |
| 45 | 56 |
| 46 void URLRequestContext::CopyFrom(const URLRequestContext* other) { | 57 void URLRequestContext::CopyFrom(const URLRequestContext* other) { |
| 47 // Copy URLRequestContext parameters. | 58 // Copy URLRequestContext parameters. |
| 48 set_net_log(other->net_log_); | 59 set_net_log(other->net_log_); |
| 49 set_host_resolver(other->host_resolver_); | 60 set_host_resolver(other->host_resolver_); |
| 50 set_cert_verifier(other->cert_verifier_); | 61 set_cert_verifier(other->cert_verifier_); |
| 51 set_channel_id_service(other->channel_id_service_); | 62 set_channel_id_service(other->channel_id_service_); |
| 52 set_http_auth_handler_factory(other->http_auth_handler_factory_); | 63 set_http_auth_handler_factory(other->http_auth_handler_factory_); |
| 53 set_proxy_service(other->proxy_service_); | 64 set_proxy_service(other->proxy_service_); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf)); | 112 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf)); |
| 102 int load_flags = request->load_flags(); | 113 int load_flags = request->load_flags(); |
| 103 base::debug::Alias(url_buf); | 114 base::debug::Alias(url_buf); |
| 104 base::debug::Alias(&num_requests); | 115 base::debug::Alias(&num_requests); |
| 105 base::debug::Alias(&load_flags); | 116 base::debug::Alias(&load_flags); |
| 106 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: " | 117 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: " |
| 107 << request->url().spec().c_str() << "."; | 118 << request->url().spec().c_str() << "."; |
| 108 } | 119 } |
| 109 } | 120 } |
| 110 | 121 |
| 122 bool URLRequestContext::OnMemoryDump( |
| 123 const base::trace_event::MemoryDumpArgs& args, |
| 124 base::trace_event::ProcessMemoryDump* pmd) { |
| 125 if (name_string_.empty()) |
| 126 name_string_ = "unknown"; |
| 127 base::trace_event::MemoryAllocatorDump* dump = |
| 128 pmd->CreateAllocatorDump(base::StringPrintf( |
| 129 "net/url_request_context/%s_%p", name_string_.c_str(), this)); |
| 130 for (const auto* url_request : *url_requests_.get()) { |
| 131 url_request->DumpMemoryStats(dump); |
| 132 } |
| 133 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectCount, |
| 134 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
| 135 url_requests_->size()); |
| 136 HttpTransactionFactory* transaction_factory = http_transaction_factory(); |
| 137 if (transaction_factory) { |
| 138 HttpNetworkSession* network_session = transaction_factory->GetSession(); |
| 139 if (network_session) |
| 140 network_session->DumpMemoryStats(dump); |
| 141 } |
| 142 SSLClientSocketImpl::DumpSSLClientSessionMemoryStats(pmd); |
| 143 if (sdch_manager_) |
| 144 sdch_manager_->DumpMemoryStats(dump); |
| 145 return true; |
| 146 } |
| 147 |
| 111 } // namespace net | 148 } // namespace net |
| OLD | NEW |