Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(720)

Side by Side Diff: net/http/http_stream_factory_impl.cc

Issue 2910463004: Revert "Revert CLs landed in HttpStreamFactoryImpl to track down a crasher" (Closed)
Patch Set: rebased Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_stream_factory_impl.h ('k') | net/http/http_stream_factory_impl_job.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/http/http_stream_factory_impl.h" 5 #include "net/http/http_stream_factory_impl.h"
6 6
7 #include <string>
8 #include <tuple> 7 #include <tuple>
8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/trace_event/memory_allocator_dump.h" 16 #include "base/trace_event/memory_allocator_dump.h"
17 #include "base/trace_event/memory_usage_estimator.h" 17 #include "base/trace_event/memory_usage_estimator.h"
18 #include "base/trace_event/process_memory_dump.h" 18 #include "base/trace_event/process_memory_dump.h"
19 #include "net/http/http_network_session.h" 19 #include "net/http/http_network_session.h"
20 #include "net/http/http_server_properties.h" 20 #include "net/http/http_server_properties.h"
21 #include "net/http/http_stream_factory_impl_job.h" 21 #include "net/http/http_stream_factory_impl_job.h"
22 #include "net/http/http_stream_factory_impl_job_controller.h" 22 #include "net/http/http_stream_factory_impl_job_controller.h"
23 #include "net/http/http_stream_factory_impl_request.h" 23 #include "net/http/http_stream_factory_impl_request.h"
24 #include "net/http/transport_security_state.h" 24 #include "net/http/transport_security_state.h"
25 #include "net/proxy/proxy_info.h" 25 #include "net/proxy/proxy_info.h"
26 #include "net/quic/core/quic_server_id.h" 26 #include "net/quic/core/quic_server_id.h"
27 #include "net/spdy/chromium/bidirectional_stream_spdy_impl.h" 27 #include "net/spdy/chromium/bidirectional_stream_spdy_impl.h"
28 #include "net/spdy/chromium/spdy_http_stream.h" 28 #include "net/spdy/chromium/spdy_http_stream.h"
29 #include "url/gurl.h" 29 #include "url/gurl.h"
30 #include "url/scheme_host_port.h" 30 #include "url/scheme_host_port.h"
31 #include "url/url_constants.h" 31 #include "url/url_constants.h"
32 32
33 namespace net { 33 namespace net {
34 34
35 namespace {
36 // Default JobFactory for creating HttpStreamFactoryImpl::Jobs.
37 class DefaultJobFactory : public HttpStreamFactoryImpl::JobFactory {
38 public:
39 DefaultJobFactory() {}
40
41 ~DefaultJobFactory() override {}
42
43 HttpStreamFactoryImpl::Job* CreateJob(
44 HttpStreamFactoryImpl::Job::Delegate* delegate,
45 HttpStreamFactoryImpl::JobType job_type,
46 HttpNetworkSession* session,
47 const HttpRequestInfo& request_info,
48 RequestPriority priority,
49 const SSLConfig& server_ssl_config,
50 const SSLConfig& proxy_ssl_config,
51 HostPortPair destination,
52 GURL origin_url,
53 bool enable_ip_based_pooling,
54 NetLog* net_log) override {
55 return new HttpStreamFactoryImpl::Job(
56 delegate, job_type, session, request_info, priority, server_ssl_config,
57 proxy_ssl_config, destination, origin_url, enable_ip_based_pooling,
58 net_log);
59 }
60
61 HttpStreamFactoryImpl::Job* CreateJob(
62 HttpStreamFactoryImpl::Job::Delegate* delegate,
63 HttpStreamFactoryImpl::JobType job_type,
64 HttpNetworkSession* session,
65 const HttpRequestInfo& request_info,
66 RequestPriority priority,
67 const SSLConfig& server_ssl_config,
68 const SSLConfig& proxy_ssl_config,
69 HostPortPair destination,
70 GURL origin_url,
71 AlternativeService alternative_service,
72 bool enable_ip_based_pooling,
73 NetLog* net_log) override {
74 return new HttpStreamFactoryImpl::Job(
75 delegate, job_type, session, request_info, priority, server_ssl_config,
76 proxy_ssl_config, destination, origin_url, alternative_service,
77 ProxyServer(), enable_ip_based_pooling, net_log);
78 }
79
80 HttpStreamFactoryImpl::Job* CreateJob(
81 HttpStreamFactoryImpl::Job::Delegate* delegate,
82 HttpStreamFactoryImpl::JobType job_type,
83 HttpNetworkSession* session,
84 const HttpRequestInfo& request_info,
85 RequestPriority priority,
86 const SSLConfig& server_ssl_config,
87 const SSLConfig& proxy_ssl_config,
88 HostPortPair destination,
89 GURL origin_url,
90 const ProxyServer& alternative_proxy_server,
91 bool enable_ip_based_pooling,
92 NetLog* net_log) override {
93 return new HttpStreamFactoryImpl::Job(
94 delegate, job_type, session, request_info, priority, server_ssl_config,
95 proxy_ssl_config, destination, origin_url, AlternativeService(),
96 alternative_proxy_server, enable_ip_based_pooling, net_log);
97 }
98 };
99
100 } // anonymous namespace
101
102 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, 35 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session,
103 bool for_websockets) 36 bool for_websockets)
104 : session_(session), 37 : session_(session),
105 job_factory_(new DefaultJobFactory()), 38 job_factory_(new JobFactory()),
106 for_websockets_(for_websockets), 39 for_websockets_(for_websockets),
107 last_logged_job_controller_count_(0) {} 40 last_logged_job_controller_count_(0) {}
108 41
109 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { 42 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() {
110 DCHECK(spdy_session_request_map_.empty()); 43 DCHECK(spdy_session_request_map_.empty());
111 UMA_HISTOGRAM_COUNTS_1M("Net.JobControllerSet.CountOfJobControllerAtShutDown", 44 UMA_HISTOGRAM_COUNTS_1M("Net.JobControllerSet.CountOfJobControllerAtShutDown",
112 job_controller_set_.size()); 45 job_controller_set_.size());
113 } 46 }
114 47
115 HttpStreamRequest* HttpStreamFactoryImpl::RequestStream( 48 std::unique_ptr<HttpStreamRequest> HttpStreamFactoryImpl::RequestStream(
116 const HttpRequestInfo& request_info, 49 const HttpRequestInfo& request_info,
117 RequestPriority priority, 50 RequestPriority priority,
118 const SSLConfig& server_ssl_config, 51 const SSLConfig& server_ssl_config,
119 const SSLConfig& proxy_ssl_config, 52 const SSLConfig& proxy_ssl_config,
120 HttpStreamRequest::Delegate* delegate, 53 HttpStreamRequest::Delegate* delegate,
121 bool enable_ip_based_pooling, 54 bool enable_ip_based_pooling,
122 bool enable_alternative_services, 55 bool enable_alternative_services,
123 const NetLogWithSource& net_log) { 56 const NetLogWithSource& net_log) {
124 DCHECK(!for_websockets_); 57 DCHECK(!for_websockets_);
125 return RequestStreamInternal( 58 return RequestStreamInternal(
126 request_info, priority, server_ssl_config, proxy_ssl_config, delegate, 59 request_info, priority, server_ssl_config, proxy_ssl_config, delegate,
127 nullptr, HttpStreamRequest::HTTP_STREAM, enable_ip_based_pooling, 60 nullptr, HttpStreamRequest::HTTP_STREAM, enable_ip_based_pooling,
128 enable_alternative_services, net_log); 61 enable_alternative_services, net_log);
129 } 62 }
130 63
131 HttpStreamRequest* HttpStreamFactoryImpl::RequestWebSocketHandshakeStream( 64 std::unique_ptr<HttpStreamRequest>
65 HttpStreamFactoryImpl::RequestWebSocketHandshakeStream(
132 const HttpRequestInfo& request_info, 66 const HttpRequestInfo& request_info,
133 RequestPriority priority, 67 RequestPriority priority,
134 const SSLConfig& server_ssl_config, 68 const SSLConfig& server_ssl_config,
135 const SSLConfig& proxy_ssl_config, 69 const SSLConfig& proxy_ssl_config,
136 HttpStreamRequest::Delegate* delegate, 70 HttpStreamRequest::Delegate* delegate,
137 WebSocketHandshakeStreamBase::CreateHelper* create_helper, 71 WebSocketHandshakeStreamBase::CreateHelper* create_helper,
138 bool enable_ip_based_pooling, 72 bool enable_ip_based_pooling,
139 bool enable_alternative_services, 73 bool enable_alternative_services,
140 const NetLogWithSource& net_log) { 74 const NetLogWithSource& net_log) {
141 DCHECK(for_websockets_); 75 DCHECK(for_websockets_);
142 DCHECK(create_helper); 76 DCHECK(create_helper);
143 return RequestStreamInternal( 77 return RequestStreamInternal(
144 request_info, priority, server_ssl_config, proxy_ssl_config, delegate, 78 request_info, priority, server_ssl_config, proxy_ssl_config, delegate,
145 create_helper, HttpStreamRequest::HTTP_STREAM, enable_ip_based_pooling, 79 create_helper, HttpStreamRequest::HTTP_STREAM, enable_ip_based_pooling,
146 enable_alternative_services, net_log); 80 enable_alternative_services, net_log);
147 } 81 }
148 82
149 HttpStreamRequest* HttpStreamFactoryImpl::RequestBidirectionalStreamImpl( 83 std::unique_ptr<HttpStreamRequest>
84 HttpStreamFactoryImpl::RequestBidirectionalStreamImpl(
150 const HttpRequestInfo& request_info, 85 const HttpRequestInfo& request_info,
151 RequestPriority priority, 86 RequestPriority priority,
152 const SSLConfig& server_ssl_config, 87 const SSLConfig& server_ssl_config,
153 const SSLConfig& proxy_ssl_config, 88 const SSLConfig& proxy_ssl_config,
154 HttpStreamRequest::Delegate* delegate, 89 HttpStreamRequest::Delegate* delegate,
155 bool enable_ip_based_pooling, 90 bool enable_ip_based_pooling,
156 bool enable_alternative_services, 91 bool enable_alternative_services,
157 const NetLogWithSource& net_log) { 92 const NetLogWithSource& net_log) {
158 DCHECK(!for_websockets_); 93 DCHECK(!for_websockets_);
159 DCHECK(request_info.url.SchemeIs(url::kHttpsScheme)); 94 DCHECK(request_info.url.SchemeIs(url::kHttpsScheme));
160 95
161 return RequestStreamInternal( 96 return RequestStreamInternal(
162 request_info, priority, server_ssl_config, proxy_ssl_config, delegate, 97 request_info, priority, server_ssl_config, proxy_ssl_config, delegate,
163 nullptr, HttpStreamRequest::BIDIRECTIONAL_STREAM, enable_ip_based_pooling, 98 nullptr, HttpStreamRequest::BIDIRECTIONAL_STREAM, enable_ip_based_pooling,
164 enable_alternative_services, net_log); 99 enable_alternative_services, net_log);
165 } 100 }
166 101
167 HttpStreamRequest* HttpStreamFactoryImpl::RequestStreamInternal( 102 std::unique_ptr<HttpStreamRequest> HttpStreamFactoryImpl::RequestStreamInternal(
168 const HttpRequestInfo& request_info, 103 const HttpRequestInfo& request_info,
169 RequestPriority priority, 104 RequestPriority priority,
170 const SSLConfig& server_ssl_config, 105 const SSLConfig& server_ssl_config,
171 const SSLConfig& proxy_ssl_config, 106 const SSLConfig& proxy_ssl_config,
172 HttpStreamRequest::Delegate* delegate, 107 HttpStreamRequest::Delegate* delegate,
173 WebSocketHandshakeStreamBase::CreateHelper* 108 WebSocketHandshakeStreamBase::CreateHelper*
174 websocket_handshake_stream_create_helper, 109 websocket_handshake_stream_create_helper,
175 HttpStreamRequest::StreamType stream_type, 110 HttpStreamRequest::StreamType stream_type,
176 bool enable_ip_based_pooling, 111 bool enable_ip_based_pooling,
177 bool enable_alternative_services, 112 bool enable_alternative_services,
178 const NetLogWithSource& net_log) { 113 const NetLogWithSource& net_log) {
179 AddJobControllerCountToHistograms(); 114 AddJobControllerCountToHistograms();
180 115
181 auto job_controller = base::MakeUnique<JobController>( 116 auto job_controller = base::MakeUnique<JobController>(
182 this, delegate, session_, job_factory_.get(), request_info, 117 this, delegate, session_, job_factory_.get(), request_info,
183 /* is_preconnect = */ false, enable_ip_based_pooling, 118 /* is_preconnect = */ false, enable_ip_based_pooling,
184 enable_alternative_services); 119 enable_alternative_services, server_ssl_config, proxy_ssl_config);
185 JobController* job_controller_raw_ptr = job_controller.get(); 120 JobController* job_controller_raw_ptr = job_controller.get();
186 job_controller_set_.insert(std::move(job_controller)); 121 job_controller_set_.insert(std::move(job_controller));
187 Request* request = job_controller_raw_ptr->Start( 122 return job_controller_raw_ptr->Start(delegate,
188 request_info, delegate, websocket_handshake_stream_create_helper, net_log, 123 websocket_handshake_stream_create_helper,
189 stream_type, priority, server_ssl_config, proxy_ssl_config); 124 net_log, stream_type, priority);
190
191 return request;
192 } 125 }
193 126
194 void HttpStreamFactoryImpl::PreconnectStreams( 127 void HttpStreamFactoryImpl::PreconnectStreams(
195 int num_streams, 128 int num_streams,
196 const HttpRequestInfo& request_info) { 129 const HttpRequestInfo& request_info) {
197 DCHECK(request_info.url.is_valid()); 130 DCHECK(request_info.url.is_valid());
198 131
199 AddJobControllerCountToHistograms(); 132 AddJobControllerCountToHistograms();
200 133
201 SSLConfig server_ssl_config; 134 SSLConfig server_ssl_config;
202 SSLConfig proxy_ssl_config; 135 SSLConfig proxy_ssl_config;
203 session_->GetSSLConfig(request_info, &server_ssl_config, &proxy_ssl_config); 136 session_->GetSSLConfig(request_info, &server_ssl_config, &proxy_ssl_config);
204 // All preconnects should perform EV certificate verification. 137 // All preconnects should perform EV certificate verification.
205 server_ssl_config.verify_ev_cert = true; 138 server_ssl_config.verify_ev_cert = true;
206 proxy_ssl_config.verify_ev_cert = true; 139 proxy_ssl_config.verify_ev_cert = true;
207 140
208 DCHECK(!for_websockets_); 141 DCHECK(!for_websockets_);
209 142
210 auto job_controller = base::MakeUnique<JobController>( 143 auto job_controller = base::MakeUnique<JobController>(
211 this, nullptr, session_, job_factory_.get(), request_info, 144 this, nullptr, session_, job_factory_.get(), request_info,
212 /* is_preconnect = */ true, 145 /* is_preconnect = */ true,
213 /* enable_ip_based_pooling = */ true, 146 /* enable_ip_based_pooling = */ true,
214 /* enable_alternative_services = */ true); 147 /* enable_alternative_services = */ true, server_ssl_config,
148 proxy_ssl_config);
215 JobController* job_controller_raw_ptr = job_controller.get(); 149 JobController* job_controller_raw_ptr = job_controller.get();
216 job_controller_set_.insert(std::move(job_controller)); 150 job_controller_set_.insert(std::move(job_controller));
217 job_controller_raw_ptr->Preconnect(num_streams, request_info, 151 job_controller_raw_ptr->Preconnect(num_streams);
218 server_ssl_config, proxy_ssl_config);
219 } 152 }
220 153
221 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { 154 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const {
222 return &session_->params().host_mapping_rules; 155 return &session_->params().host_mapping_rules;
223 } 156 }
224 157
225 void HttpStreamFactoryImpl::OnNewSpdySessionReady( 158 void HttpStreamFactoryImpl::OnNewSpdySessionReady(
226 const base::WeakPtr<SpdySession>& spdy_session, 159 const base::WeakPtr<SpdySession>& spdy_session,
227 bool direct, 160 bool direct,
228 const SSLConfig& used_ssl_config, 161 const SSLConfig& used_ssl_config,
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 factory_dump->AddScalar("main_job_count", 385 factory_dump->AddScalar("main_job_count",
453 base::trace_event::MemoryAllocatorDump::kUnitsObjects, 386 base::trace_event::MemoryAllocatorDump::kUnitsObjects,
454 main_job_count); 387 main_job_count);
455 // The number of preconnect controllers. 388 // The number of preconnect controllers.
456 factory_dump->AddScalar("preconnect_count", 389 factory_dump->AddScalar("preconnect_count",
457 base::trace_event::MemoryAllocatorDump::kUnitsObjects, 390 base::trace_event::MemoryAllocatorDump::kUnitsObjects,
458 num_controllers_for_preconnect); 391 num_controllers_for_preconnect);
459 } 392 }
460 393
461 } // namespace net 394 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl.h ('k') | net/http/http_stream_factory_impl_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698