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

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

Issue 1941083002: JobController 1: Adding a new class HttpStreamFactoryImpl::JobController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "net/http/http_network_session.h" 12 #include "net/http/http_network_session.h"
13 #include "net/http/http_server_properties.h" 13 #include "net/http/http_server_properties.h"
14 #include "net/http/http_stream_factory_impl_job.h" 14 #include "net/http/http_stream_factory_impl_job.h"
15 #include "net/http/http_stream_factory_impl_job_controller.h"
15 #include "net/http/http_stream_factory_impl_request.h" 16 #include "net/http/http_stream_factory_impl_request.h"
16 #include "net/http/transport_security_state.h" 17 #include "net/http/transport_security_state.h"
17 #include "net/log/net_log.h" 18 #include "net/log/net_log.h"
18 #include "net/quic/quic_server_id.h" 19 #include "net/quic/quic_server_id.h"
19 #include "net/spdy/bidirectional_stream_spdy_impl.h" 20 #include "net/spdy/bidirectional_stream_spdy_impl.h"
20 #include "net/spdy/spdy_http_stream.h" 21 #include "net/spdy/spdy_http_stream.h"
21 #include "url/gurl.h" 22 #include "url/gurl.h"
22 23
23 namespace net { 24 namespace net {
24 25
25 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, 26 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session,
26 bool for_websockets) 27 bool for_websockets)
27 : session_(session), 28 : session_(session),
28 for_websockets_(for_websockets) {} 29 for_websockets_(for_websockets) {}
29 30
30 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { 31 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() {
31 DCHECK(request_map_.empty()); 32 DCHECK(request_map_.empty());
32 DCHECK(spdy_session_request_map_.empty()); 33 DCHECK(spdy_session_request_map_.empty());
33 34 STLDeleteElements(&job_controller_set_);
34 std::set<const Job*> tmp_job_set;
35 tmp_job_set.swap(orphaned_job_set_);
36 STLDeleteContainerPointers(tmp_job_set.begin(), tmp_job_set.end());
37 DCHECK(orphaned_job_set_.empty());
38
39 tmp_job_set.clear();
40 tmp_job_set.swap(preconnect_job_set_);
41 STLDeleteContainerPointers(tmp_job_set.begin(), tmp_job_set.end());
42 DCHECK(preconnect_job_set_.empty());
43 } 35 }
44 36
45 HttpStreamRequest* HttpStreamFactoryImpl::RequestStream( 37 HttpStreamRequest* HttpStreamFactoryImpl::RequestStream(
46 const HttpRequestInfo& request_info, 38 const HttpRequestInfo& request_info,
47 RequestPriority priority, 39 RequestPriority priority,
48 const SSLConfig& server_ssl_config, 40 const SSLConfig& server_ssl_config,
49 const SSLConfig& proxy_ssl_config, 41 const SSLConfig& proxy_ssl_config,
50 HttpStreamRequest::Delegate* delegate, 42 HttpStreamRequest::Delegate* delegate,
51 const BoundNetLog& net_log) { 43 const BoundNetLog& net_log) {
52 DCHECK(!for_websockets_); 44 DCHECK(!for_websockets_);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 HttpStreamRequest* HttpStreamFactoryImpl::RequestStreamInternal( 80 HttpStreamRequest* HttpStreamFactoryImpl::RequestStreamInternal(
89 const HttpRequestInfo& request_info, 81 const HttpRequestInfo& request_info,
90 RequestPriority priority, 82 RequestPriority priority,
91 const SSLConfig& server_ssl_config, 83 const SSLConfig& server_ssl_config,
92 const SSLConfig& proxy_ssl_config, 84 const SSLConfig& proxy_ssl_config,
93 HttpStreamRequest::Delegate* delegate, 85 HttpStreamRequest::Delegate* delegate,
94 WebSocketHandshakeStreamBase::CreateHelper* 86 WebSocketHandshakeStreamBase::CreateHelper*
95 websocket_handshake_stream_create_helper, 87 websocket_handshake_stream_create_helper,
96 HttpStreamRequest::StreamType stream_type, 88 HttpStreamRequest::StreamType stream_type,
97 const BoundNetLog& net_log) { 89 const BoundNetLog& net_log) {
98 Request* request = new Request(request_info.url, this, delegate, 90 JobController* job_controller = new JobController(this);
99 websocket_handshake_stream_create_helper, 91 job_controller_set_.insert(job_controller);
100 net_log, stream_type);
101 HostPortPair destination(HostPortPair::FromURL(request_info.url));
102 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination);
103 92
104 Job* job = 93 Request* request = job_controller->CreatRequest(
105 new Job(this, session_, request_info, priority, server_ssl_config, 94 request_info, delegate, websocket_handshake_stream_create_helper, net_log,
106 proxy_ssl_config, destination, origin_url, net_log.net_log()); 95 stream_type);
107 request->AttachJob(job);
108 96
109 const AlternativeService alternative_service = 97 job_controller->Start(session_, request_info, priority, server_ssl_config,
110 GetAlternativeServiceFor(request_info, delegate, stream_type); 98 proxy_ssl_config, delegate, stream_type, net_log);
Ryan Hamilton 2016/05/06 20:49:01 If this is the only place we call Start and CreatR
Zhongyi Shi 2016/05/12 07:26:23 I have renamed the old public method Start() to pr
111 99
112 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) {
113 // Never share connection with other jobs for FTP requests.
114 DVLOG(1) << "Selected alternative service (host: "
115 << alternative_service.host_port_pair().host()
116 << " port: " << alternative_service.host_port_pair().port() << ")";
117
118 DCHECK(!request_info.url.SchemeIs("ftp"));
119 HostPortPair alternative_destination(alternative_service.host_port_pair());
120 ignore_result(
121 ApplyHostMappingRules(request_info.url, &alternative_destination));
122
123 Job* alternative_job =
124 new Job(this, session_, request_info, priority, server_ssl_config,
125 proxy_ssl_config, alternative_destination, origin_url,
126 alternative_service, net_log.net_log());
127 request->AttachJob(alternative_job);
128
129 job->WaitFor(alternative_job);
130 // Make sure to wait until we call WaitFor(), before starting
131 // |alternative_job|, otherwise |alternative_job| will not notify |job|
132 // appropriately.
133 alternative_job->Start(request);
134 }
135
136 // Even if |alternative_job| has already finished, it will not have notified
137 // the request yet, since we defer that to the next iteration of the
138 // MessageLoop, so starting |job| is always safe.
139 job->Start(request);
140 return request; 100 return request;
141 } 101 }
142 102
143 void HttpStreamFactoryImpl::PreconnectStreams( 103 void HttpStreamFactoryImpl::PreconnectStreams(
144 int num_streams, 104 int num_streams,
145 const HttpRequestInfo& request_info) { 105 const HttpRequestInfo& request_info) {
146 SSLConfig server_ssl_config; 106 SSLConfig server_ssl_config;
147 SSLConfig proxy_ssl_config; 107 SSLConfig proxy_ssl_config;
148 session_->GetSSLConfig(request_info, &server_ssl_config, &proxy_ssl_config); 108 session_->GetSSLConfig(request_info, &server_ssl_config, &proxy_ssl_config);
149 // All preconnects should perform EV certificate verification. 109 // All preconnects should perform EV certificate verification.
150 server_ssl_config.verify_ev_cert = true; 110 server_ssl_config.verify_ev_cert = true;
151 proxy_ssl_config.verify_ev_cert = true; 111 proxy_ssl_config.verify_ev_cert = true;
152 112
153 DCHECK(!for_websockets_); 113 DCHECK(!for_websockets_);
154 AlternativeService alternative_service = GetAlternativeServiceFor( 114
155 request_info, nullptr, HttpStreamRequest::HTTP_STREAM); 115 JobController* job_controller = new JobController(this);
156 HostPortPair destination(HostPortPair::FromURL(request_info.url)); 116 job_controller_set_.insert(job_controller);
157 GURL origin_url = ApplyHostMappingRules(request_info.url, &destination); 117 job_controller->Preconnect(num_streams, session_, request_info,
158 if (alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { 118 server_ssl_config, proxy_ssl_config);
159 if (session_->params().quic_disable_preconnect_if_0rtt &&
160 alternative_service.protocol == QUIC &&
161 session_->quic_stream_factory()->ZeroRTTEnabledFor(QuicServerId(
162 alternative_service.host_port_pair(), request_info.privacy_mode))) {
163 return;
164 }
165 destination = alternative_service.host_port_pair();
166 ignore_result(ApplyHostMappingRules(request_info.url, &destination));
167 }
168 // Due to how the socket pools handle priorities and idle sockets, only IDLE
169 // priority currently makes sense for preconnects. The priority for
170 // preconnects is currently ignored (see RequestSocketsForPool()), but could
171 // be used at some point for proxy resolution or something.
172 Job* job = new Job(this, session_, request_info, IDLE, server_ssl_config,
173 proxy_ssl_config, destination, origin_url,
174 alternative_service, session_->net_log());
175 preconnect_job_set_.insert(job);
176 job->Preconnect(num_streams);
177 } 119 }
178 120
179 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { 121 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const {
180 return session_->params().host_mapping_rules; 122 return session_->params().host_mapping_rules;
181 } 123 }
182 124
183 AlternativeService HttpStreamFactoryImpl::GetAlternativeServiceFor( 125 AlternativeService HttpStreamFactoryImpl::GetAlternativeServiceFor(
184 const HttpRequestInfo& request_info, 126 const HttpRequestInfo& request_info,
185 HttpStreamRequest::Delegate* delegate, 127 HttpStreamRequest::Delegate* delegate,
186 HttpStreamRequest::StreamType stream_type) { 128 HttpStreamRequest::StreamType stream_type) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 first_alternative_service = alternative_service; 224 first_alternative_service = alternative_service;
283 } 225 }
284 226
285 // Ask delegate to mark QUIC as broken for the origin. 227 // Ask delegate to mark QUIC as broken for the origin.
286 if (quic_advertised && quic_all_broken && delegate != nullptr) 228 if (quic_advertised && quic_all_broken && delegate != nullptr)
287 delegate->OnQuicBroken(); 229 delegate->OnQuicBroken();
288 230
289 return first_alternative_service; 231 return first_alternative_service;
290 } 232 }
291 233
292 void HttpStreamFactoryImpl::OrphanJob(Job* job, const Request* request) {
293 DCHECK(ContainsKey(request_map_, job));
294 DCHECK_EQ(request_map_[job], request);
295 DCHECK(!ContainsKey(orphaned_job_set_, job));
296
297 request_map_.erase(job);
298
299 orphaned_job_set_.insert(job);
300 job->Orphan(request);
301 }
302
303 void HttpStreamFactoryImpl::OnNewSpdySessionReady( 234 void HttpStreamFactoryImpl::OnNewSpdySessionReady(
304 const base::WeakPtr<SpdySession>& spdy_session, 235 const base::WeakPtr<SpdySession>& spdy_session,
305 bool direct, 236 bool direct,
306 const SSLConfig& used_ssl_config, 237 const SSLConfig& used_ssl_config,
307 const ProxyInfo& used_proxy_info, 238 const ProxyInfo& used_proxy_info,
308 bool was_npn_negotiated, 239 bool was_npn_negotiated,
309 NextProto protocol_negotiated, 240 NextProto protocol_negotiated,
310 bool using_spdy, 241 bool using_spdy,
311 const BoundNetLog& net_log) { 242 const BoundNetLog& net_log) {
312 while (true) { 243 while (true) {
(...skipping 11 matching lines...) Expand all
324 break; 255 break;
325 Request* request = *spdy_session_request_map_[spdy_session_key].begin(); 256 Request* request = *spdy_session_request_map_[spdy_session_key].begin();
326 request->Complete(was_npn_negotiated, protocol_negotiated, using_spdy); 257 request->Complete(was_npn_negotiated, protocol_negotiated, using_spdy);
327 if (for_websockets_) { 258 if (for_websockets_) {
328 // TODO(ricea): Restore this code path when WebSocket over SPDY 259 // TODO(ricea): Restore this code path when WebSocket over SPDY
329 // implementation is ready. 260 // implementation is ready.
330 NOTREACHED(); 261 NOTREACHED();
331 } else if (request->stream_type() == 262 } else if (request->stream_type() ==
332 HttpStreamRequest::BIDIRECTIONAL_STREAM) { 263 HttpStreamRequest::BIDIRECTIONAL_STREAM) {
333 request->OnBidirectionalStreamImplReady( 264 request->OnBidirectionalStreamImplReady(
334 nullptr, used_ssl_config, used_proxy_info, 265 used_ssl_config, used_proxy_info,
335 new BidirectionalStreamSpdyImpl(spdy_session)); 266 new BidirectionalStreamSpdyImpl(spdy_session));
336 } else { 267 } else {
337 bool use_relative_url = direct || request->url().SchemeIs("https"); 268 bool use_relative_url = direct || request->url().SchemeIs("https");
338 request->OnStreamReady( 269 request->OnStreamReady(
339 nullptr, used_ssl_config, used_proxy_info, 270 used_ssl_config, used_proxy_info,
340 new SpdyHttpStream(spdy_session, use_relative_url)); 271 new SpdyHttpStream(spdy_session, use_relative_url));
341 } 272 }
342 } 273 }
343 // TODO(mbelshe): Alert other valid requests. 274 // TODO(mbelshe): Alert other valid requests.
344 } 275 }
345 276
346 void HttpStreamFactoryImpl::OnOrphanedJobComplete(const Job* job) { 277 void HttpStreamFactoryImpl::OnJobControllerComplete(JobController* controller) {
347 orphaned_job_set_.erase(job); 278 job_controller_set_.erase(controller);
348 delete job; 279 delete controller;
349 }
350
351 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) {
352 preconnect_job_set_.erase(job);
353 delete job;
354 OnPreconnectsCompleteInternal();
355 } 280 }
356 281
357 bool HttpStreamFactoryImpl::IsQuicWhitelistedForHost(const std::string& host) { 282 bool HttpStreamFactoryImpl::IsQuicWhitelistedForHost(const std::string& host) {
358 bool whitelist_needed = false; 283 bool whitelist_needed = false;
359 for (QuicVersion version : session_->params().quic_supported_versions) { 284 for (QuicVersion version : session_->params().quic_supported_versions) {
360 if (version <= QUIC_VERSION_30) { 285 if (version <= QUIC_VERSION_30) {
361 whitelist_needed = true; 286 whitelist_needed = true;
362 break; 287 break;
363 } 288 }
364 } 289 }
365 290
366 // The QUIC whitelist is not needed in QUIC versions after 30. 291 // The QUIC whitelist is not needed in QUIC versions after 30.
367 if (!whitelist_needed) 292 if (!whitelist_needed)
368 return true; 293 return true;
369 294
370 if (session_->params().transport_security_state->IsGooglePinnedHost(host)) 295 if (session_->params().transport_security_state->IsGooglePinnedHost(host))
371 return true; 296 return true;
372 297
373 return ContainsKey(session_->params().quic_host_whitelist, 298 return ContainsKey(session_->params().quic_host_whitelist,
374 base::ToLowerASCII(host)); 299 base::ToLowerASCII(host));
375 } 300 }
376 301
377 } // namespace net 302 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698