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

Side by Side Diff: net/http/http_stream_factory_impl_job.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_job.h" 5 #include "net/http/http_stream_factory_impl_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 17 matching lines...) Expand all
28 #include "net/base/port_util.h" 28 #include "net/base/port_util.h"
29 #include "net/cert/cert_verifier.h" 29 #include "net/cert/cert_verifier.h"
30 #include "net/http/bidirectional_stream_impl.h" 30 #include "net/http/bidirectional_stream_impl.h"
31 #include "net/http/http_basic_stream.h" 31 #include "net/http/http_basic_stream.h"
32 #include "net/http/http_network_session.h" 32 #include "net/http/http_network_session.h"
33 #include "net/http/http_proxy_client_socket.h" 33 #include "net/http/http_proxy_client_socket.h"
34 #include "net/http/http_proxy_client_socket_pool.h" 34 #include "net/http/http_proxy_client_socket_pool.h"
35 #include "net/http/http_request_info.h" 35 #include "net/http/http_request_info.h"
36 #include "net/http/http_server_properties.h" 36 #include "net/http/http_server_properties.h"
37 #include "net/http/http_stream_factory.h" 37 #include "net/http/http_stream_factory.h"
38 #include "net/http/http_stream_factory_impl_job_controller.h"
38 #include "net/http/http_stream_factory_impl_request.h" 39 #include "net/http/http_stream_factory_impl_request.h"
39 #include "net/log/net_log.h" 40 #include "net/log/net_log.h"
40 #include "net/quic/quic_http_stream.h" 41 #include "net/quic/quic_http_stream.h"
41 #include "net/socket/client_socket_handle.h" 42 #include "net/socket/client_socket_handle.h"
42 #include "net/socket/client_socket_pool.h" 43 #include "net/socket/client_socket_pool.h"
43 #include "net/socket/client_socket_pool_manager.h" 44 #include "net/socket/client_socket_pool_manager.h"
44 #include "net/socket/socks_client_socket_pool.h" 45 #include "net/socket/socks_client_socket_pool.h"
45 #include "net/socket/ssl_client_socket.h" 46 #include "net/socket/ssl_client_socket.h"
46 #include "net/socket/ssl_client_socket_pool.h" 47 #include "net/socket/ssl_client_socket_pool.h"
47 #include "net/spdy/bidirectional_stream_spdy_impl.h" 48 #include "net/spdy/bidirectional_stream_spdy_impl.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 const std::string* proto, 148 const std::string* proto,
148 NetLogCaptureMode /* capture_mode */) { 149 NetLogCaptureMode /* capture_mode */) {
149 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 150 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
150 151
151 dict->SetString("next_proto_status", 152 dict->SetString("next_proto_status",
152 SSLClientSocket::NextProtoStatusToString(status)); 153 SSLClientSocket::NextProtoStatusToString(status));
153 dict->SetString("proto", *proto); 154 dict->SetString("proto", *proto);
154 return std::move(dict); 155 return std::move(dict);
155 } 156 }
156 157
157 HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, 158 HttpStreamFactoryImpl::Job::Job(JobController* job_controller,
158 HttpNetworkSession* session, 159 HttpNetworkSession* session,
159 const HttpRequestInfo& request_info, 160 const HttpRequestInfo& request_info,
160 RequestPriority priority, 161 RequestPriority priority,
161 const SSLConfig& server_ssl_config, 162 const SSLConfig& server_ssl_config,
162 const SSLConfig& proxy_ssl_config, 163 const SSLConfig& proxy_ssl_config,
163 HostPortPair destination, 164 HostPortPair destination,
164 GURL origin_url, 165 GURL origin_url,
165 NetLog* net_log) 166 NetLog* net_log)
166 : Job(stream_factory, 167 : Job(job_controller,
167 session, 168 session,
168 request_info, 169 request_info,
169 priority, 170 priority,
170 server_ssl_config, 171 server_ssl_config,
171 proxy_ssl_config, 172 proxy_ssl_config,
172 destination, 173 destination,
173 origin_url, 174 origin_url,
174 AlternativeService(), 175 AlternativeService(),
175 net_log) {} 176 net_log) {}
176 177
177 HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, 178 HttpStreamFactoryImpl::Job::Job(JobController* job_controller,
178 HttpNetworkSession* session, 179 HttpNetworkSession* session,
179 const HttpRequestInfo& request_info, 180 const HttpRequestInfo& request_info,
180 RequestPriority priority, 181 RequestPriority priority,
181 const SSLConfig& server_ssl_config, 182 const SSLConfig& server_ssl_config,
182 const SSLConfig& proxy_ssl_config, 183 const SSLConfig& proxy_ssl_config,
183 HostPortPair destination, 184 HostPortPair destination,
184 GURL origin_url, 185 GURL origin_url,
185 AlternativeService alternative_service, 186 AlternativeService alternative_service,
186 NetLog* net_log) 187 NetLog* net_log)
187 : request_(NULL), 188 : request_info_(request_info),
188 request_info_(request_info),
189 priority_(priority), 189 priority_(priority),
190 server_ssl_config_(server_ssl_config), 190 server_ssl_config_(server_ssl_config),
191 proxy_ssl_config_(proxy_ssl_config), 191 proxy_ssl_config_(proxy_ssl_config),
192 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)), 192 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)),
193 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), 193 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))),
194 connection_(new ClientSocketHandle), 194 connection_(new ClientSocketHandle),
195 session_(session), 195 session_(session),
196 stream_factory_(stream_factory),
197 next_state_(STATE_NONE), 196 next_state_(STATE_NONE),
198 pac_request_(NULL), 197 pac_request_(NULL),
199 destination_(destination), 198 destination_(destination),
200 origin_url_(origin_url), 199 origin_url_(origin_url),
201 alternative_service_(alternative_service), 200 alternative_service_(alternative_service),
201 job_controller_(job_controller),
202 blocking_job_(NULL), 202 blocking_job_(NULL),
203 waiting_job_(NULL), 203 waiting_job_(NULL),
204 orphaned_(false),
204 using_ssl_(false), 205 using_ssl_(false),
205 using_spdy_(false), 206 using_spdy_(false),
206 using_quic_(false), 207 using_quic_(false),
207 quic_request_(session_->quic_stream_factory()), 208 quic_request_(session_->quic_stream_factory()),
208 using_existing_quic_session_(false), 209 using_existing_quic_session_(false),
209 spdy_certificate_error_(OK), 210 spdy_certificate_error_(OK),
210 establishing_tunnel_(false), 211 establishing_tunnel_(false),
211 was_npn_negotiated_(false), 212 was_npn_negotiated_(false),
212 protocol_negotiated_(kProtoUnknown), 213 protocol_negotiated_(kProtoUnknown),
213 num_streams_(0), 214 num_streams_(0),
214 spdy_session_direct_(false), 215 spdy_session_direct_(false),
215 job_status_(STATUS_RUNNING), 216 job_status_(STATUS_RUNNING),
216 other_job_status_(STATUS_RUNNING), 217 other_job_status_(STATUS_RUNNING),
217 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), 218 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM),
218 ptr_factory_(this) { 219 ptr_factory_(this) {
219 DCHECK(stream_factory);
220 DCHECK(session); 220 DCHECK(session);
221 if (IsQuicAlternative()) { 221 if (IsQuicAlternative()) {
222 DCHECK(session_->params().enable_quic); 222 DCHECK(session_->params().enable_quic);
223 using_quic_ = true; 223 using_quic_ = true;
224 } 224 }
225 } 225 }
226 226
227 HttpStreamFactoryImpl::Job::~Job() { 227 HttpStreamFactoryImpl::Job::~Job() {
228 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_JOB); 228 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_JOB);
229 229
230 // When we're in a partially constructed state, waiting for the user to 230 // When we're in a partially constructed state, waiting for the user to
231 // provide certificate handling information or authentication, we can't reuse 231 // provide certificate handling information or authentication, we can't reuse
232 // this stream at all. 232 // this stream at all.
233 if (next_state_ == STATE_WAITING_USER_ACTION) { 233 if (next_state_ == STATE_WAITING_USER_ACTION) {
234 connection_->socket()->Disconnect(); 234 connection_->socket()->Disconnect();
235 connection_.reset(); 235 connection_.reset();
236 } 236 }
237 237
238 if (pac_request_) 238 if (pac_request_)
239 session_->proxy_service()->CancelPacRequest(pac_request_); 239 session_->proxy_service()->CancelPacRequest(pac_request_);
240 240
241 // The stream could be in a partial state. It is not reusable. 241 // The stream could be in a partial state. It is not reusable.
242 if (stream_.get() && next_state_ != STATE_DONE) 242 if (stream_.get() && next_state_ != STATE_DONE)
243 stream_->Close(true /* not reusable */); 243 stream_->Close(true /* not reusable */);
244 } 244 }
245 245
246 void HttpStreamFactoryImpl::Job::Start(Request* request) { 246 void HttpStreamFactoryImpl::Job::Start(Request* request) {
247 DCHECK(request); 247 DCHECK(request);
248 request_ = request; 248 stream_type_ = request->stream_type();
Ryan Hamilton 2016/05/06 20:49:01 nit: In that case, I'd just pass in the stream_typ
Randy Smith (Not in Mondays) 2016/05/09 21:42:09 Agreed. Specifically, the design flow sorta promi
Zhongyi Shi 2016/05/12 07:26:23 Done. It's actually done in a subsequent CL, but I
249 // Saves |stream_type_|, since request is nulled when job is orphaned.
250 stream_type_ = request_->stream_type();
251 StartInternal(); 249 StartInternal();
252 } 250 }
253 251
254 int HttpStreamFactoryImpl::Job::Preconnect(int num_streams) { 252 int HttpStreamFactoryImpl::Job::Preconnect(int num_streams) {
255 DCHECK_GT(num_streams, 0); 253 DCHECK_GT(num_streams, 0);
256 base::WeakPtr<HttpServerProperties> http_server_properties = 254 base::WeakPtr<HttpServerProperties> http_server_properties =
257 session_->http_server_properties(); 255 session_->http_server_properties();
258 if (http_server_properties && 256 if (http_server_properties &&
259 http_server_properties->SupportsRequestPriority( 257 http_server_properties->SupportsRequestPriority(
260 url::SchemeHostPort(request_info_.url))) { 258 url::SchemeHostPort(request_info_.url))) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // be delayed by the |wait_time_| when it resumes. 317 // be delayed by the |wait_time_| when it resumes.
320 if (next_state_ == STATE_NONE || next_state_ <= STATE_WAIT_FOR_JOB_COMPLETE) 318 if (next_state_ == STATE_NONE || next_state_ <= STATE_WAIT_FOR_JOB_COMPLETE)
321 wait_time_ = delay; 319 wait_time_ = delay;
322 320
323 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE. 321 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE.
324 // Unblock |this|. 322 // Unblock |this|.
325 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE) 323 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE)
326 ResumeAfterDelay(); 324 ResumeAfterDelay();
327 } 325 }
328 326
329 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) { 327 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) {
Randy Smith (Not in Mondays) 2016/05/09 21:42:09 This routine no longer uses the request argument;
Zhongyi Shi 2016/05/12 07:26:23 Done.
330 DCHECK_EQ(request_, request); 328 DCHECK(!orphaned_);
331 request_ = NULL; 329 if (!IsPreconnecting())
Ryan Hamilton 2016/05/06 20:49:01 Why not set this true for the preconnect case?
Randy Smith (Not in Mondays) 2016/05/09 20:42:18 I think to keep the old behavior--IsOrphaned() use
Zhongyi Shi 2016/05/12 07:26:23 orphaned_ indicates whether |this| job has ever be
330 orphaned_ = true;
332 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED); 331 net_log_.AddEvent(NetLog::TYPE_HTTP_STREAM_JOB_ORPHANED);
333 if (blocking_job_) { 332 if (blocking_job_) {
334 // We've been orphaned, but there's a job we're blocked on. Don't bother 333 // We've been orphaned, but there's a job we're blocked on. Don't bother
335 // racing, just cancel ourself. 334 // racing, just cancel ourself.
336 DCHECK(blocking_job_->waiting_job_); 335 DCHECK(blocking_job_->waiting_job_);
337 blocking_job_->waiting_job_ = NULL; 336 blocking_job_->waiting_job_ = NULL;
338 blocking_job_ = NULL; 337 blocking_job_ = NULL;
339 if (stream_factory_->for_websockets_ && 338 if (job_controller_->for_websockets() && connection_ &&
Randy Smith (Not in Mondays) 2016/05/09 20:42:18 What aspects of your change changed the lifecycle
Randy Smith (Not in Mondays) 2016/05/09 21:42:09 Whoops, sorry, missed that this is identical to pr
340 connection_ && connection_->socket()) { 339 connection_->socket()) {
341 connection_->socket()->Disconnect(); 340 connection_->socket()->Disconnect();
342 } 341 }
343 stream_factory_->OnOrphanedJobComplete(this); 342 job_controller_->OnOrphanedJobComplete(this);
344 } else if (stream_factory_->for_websockets_) { 343 } else if (job_controller_->for_websockets()) {
345 // We cancel this job because a WebSocketHandshakeStream can't be created 344 // We cancel this job because a WebSocketHandshakeStream can't be created
346 // without a WebSocketHandshakeStreamBase::CreateHelper which is stored in 345 // without a WebSocketHandshakeStreamBase::CreateHelper which is stored in
347 // the Request class and isn't accessible from this job. 346 // the Request class and isn't accessible from this job.
348 if (connection_ && connection_->socket()) { 347 if (connection_ && connection_->socket()) {
349 connection_->socket()->Disconnect(); 348 connection_->socket()->Disconnect();
350 } 349 }
351 stream_factory_->OnOrphanedJobComplete(this); 350 job_controller_->OnOrphanedJobComplete(this);
352 } 351 }
353 } 352 }
354 353
355 void HttpStreamFactoryImpl::Job::SetPriority(RequestPriority priority) { 354 void HttpStreamFactoryImpl::Job::SetPriority(RequestPriority priority) {
356 priority_ = priority; 355 priority_ = priority;
357 // TODO(akalin): Propagate this to |connection_| and maybe the 356 // TODO(akalin): Propagate this to |connection_| and maybe the
358 // preconnect state. 357 // preconnect state.
359 } 358 }
360 359
361 bool HttpStreamFactoryImpl::Job::was_npn_negotiated() const { 360 bool HttpStreamFactoryImpl::Job::was_npn_negotiated() const {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 // https://crbug.com/133176 410 // https://crbug.com/133176
412 // TODO(ricea): Add "wss" back to this list when SPDY WebSocket support is 411 // TODO(ricea): Add "wss" back to this list when SPDY WebSocket support is
413 // working. 412 // working.
414 return origin_url_.SchemeIs("https") || 413 return origin_url_.SchemeIs("https") ||
415 proxy_info_.proxy_server().is_https() || IsSpdyAlternative(); 414 proxy_info_.proxy_server().is_https() || IsSpdyAlternative();
416 } 415 }
417 416
418 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() { 417 void HttpStreamFactoryImpl::Job::OnStreamReadyCallback() {
419 DCHECK(stream_.get()); 418 DCHECK(stream_.get());
420 DCHECK(!IsPreconnecting()); 419 DCHECK(!IsPreconnecting());
421 DCHECK(!stream_factory_->for_websockets_); 420 DCHECK(!job_controller_->for_websockets());
422 421
423 UMA_HISTOGRAM_TIMES("Net.HttpStreamFactoryJob.StreamReadyCallbackTime", 422 UMA_HISTOGRAM_TIMES("Net.HttpStreamFactoryJob.StreamReadyCallbackTime",
424 base::TimeTicks::Now() - job_stream_ready_start_time_); 423 base::TimeTicks::Now() - job_stream_ready_start_time_);
425 424
426 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 425 MaybeCopyConnectionAttemptsFromSocketOrHandle();
427 426
428 if (IsOrphaned()) { 427 if (IsOrphaned()) {
Ryan Hamilton 2016/05/06 20:49:01 Ooo! You're going to love (or probably) hate this
Randy Smith (Not in Mondays) 2016/05/09 21:42:09 +1, if it can be done.
Zhongyi Shi 2016/05/12 07:26:23 Done.
429 stream_factory_->OnOrphanedJobComplete(this); 428 job_controller_->OnOrphanedJobComplete(this);
430 } else { 429 } else {
431 request_->Complete(was_npn_negotiated(), protocol_negotiated(), 430 job_controller_->MarkRequestComplete(was_npn_negotiated(),
432 using_spdy()); 431 protocol_negotiated(), using_spdy());
433 request_->OnStreamReady(this, server_ssl_config_, proxy_info_, 432 job_controller_->OnStreamReady(this, server_ssl_config_, proxy_info_,
434 stream_.release()); 433 stream_.release());
435 } 434 }
436 // |this| may be deleted after this call. 435 // |this| may be deleted after this call.
437 } 436 }
438 437
439 void HttpStreamFactoryImpl::Job::OnWebSocketHandshakeStreamReadyCallback() { 438 void HttpStreamFactoryImpl::Job::OnWebSocketHandshakeStreamReadyCallback() {
440 DCHECK(websocket_stream_); 439 DCHECK(websocket_stream_);
441 DCHECK(!IsPreconnecting()); 440 DCHECK(!IsPreconnecting());
442 DCHECK(stream_factory_->for_websockets_); 441 DCHECK(job_controller_->for_websockets());
443 // An orphaned WebSocket job will be closed immediately and 442 // An orphaned WebSocket job will be closed immediately and
444 // never be ready. 443 // never be ready.
445 DCHECK(!IsOrphaned()); 444 DCHECK(!IsOrphaned());
446 445
447 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 446 MaybeCopyConnectionAttemptsFromSocketOrHandle();
448 447
449 request_->Complete(was_npn_negotiated(), protocol_negotiated(), using_spdy()); 448 job_controller_->MarkRequestComplete(was_npn_negotiated(),
450 request_->OnWebSocketHandshakeStreamReady(this, 449 protocol_negotiated(), using_spdy());
451 server_ssl_config_, 450 job_controller_->OnWebSocketHandshakeStreamReady(
452 proxy_info_, 451 this, server_ssl_config_, proxy_info_, websocket_stream_.release());
453 websocket_stream_.release());
454 // |this| may be deleted after this call. 452 // |this| may be deleted after this call.
455 } 453 }
456 454
457 void HttpStreamFactoryImpl::Job::OnBidirectionalStreamImplReadyCallback() { 455 void HttpStreamFactoryImpl::Job::OnBidirectionalStreamImplReadyCallback() {
458 DCHECK(bidirectional_stream_impl_); 456 DCHECK(bidirectional_stream_impl_);
459 457
460 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 458 MaybeCopyConnectionAttemptsFromSocketOrHandle();
461 459
462 if (IsOrphaned()) { 460 if (IsOrphaned()) {
463 stream_factory_->OnOrphanedJobComplete(this); 461 job_controller_->OnOrphanedJobComplete(this);
464 } else { 462 } else {
465 request_->Complete(was_npn_negotiated(), protocol_negotiated(), 463 job_controller_->MarkRequestComplete(was_npn_negotiated(),
466 using_spdy()); 464 protocol_negotiated(), using_spdy());
467 request_->OnBidirectionalStreamImplReady( 465 job_controller_->OnBidirectionalStreamImplReady(
468 this, server_ssl_config_, proxy_info_, 466 this, server_ssl_config_, proxy_info_,
469 bidirectional_stream_impl_.release()); 467 bidirectional_stream_impl_.release());
470 } 468 }
471 // |this| may be deleted after this call. 469 // |this| may be deleted after this call.
472 } 470 }
473 471
474 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { 472 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() {
475 DCHECK(stream_.get() || bidirectional_stream_impl_.get()); 473 DCHECK(stream_.get() || bidirectional_stream_impl_.get());
476 DCHECK(!IsPreconnecting()); 474 DCHECK(!IsPreconnecting());
477 DCHECK(using_spdy()); 475 DCHECK(using_spdy());
478 // Note: an event loop iteration has passed, so |new_spdy_session_| may be 476 // Note: an event loop iteration has passed, so |new_spdy_session_| may be
479 // NULL at this point if the SpdySession closed immediately after creation. 477 // NULL at this point if the SpdySession closed immediately after creation.
480 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_; 478 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_;
481 new_spdy_session_.reset(); 479 new_spdy_session_.reset();
482 480
483 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 481 MaybeCopyConnectionAttemptsFromSocketOrHandle();
484 482
485 // TODO(jgraettinger): Notify the factory, and let that notify |request_|, 483 // Notify the JobController, and let that notify Request and Factory.
486 // rather than notifying |request_| directly.
487 if (IsOrphaned()) { 484 if (IsOrphaned()) {
488 if (spdy_session) { 485 if (spdy_session) {
489 stream_factory_->OnNewSpdySessionReady( 486 job_controller_->OnNewSpdySessionReady(
490 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, 487 this, /*spdy_http_stream=*/nullptr,
491 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); 488 /* bidirectional_stream_impl=*/nullptr, spdy_session,
489 spdy_session_direct_);
492 } 490 }
493 stream_factory_->OnOrphanedJobComplete(this); 491 job_controller_->OnOrphanedJobComplete(this);
494 } else { 492 } else {
495 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { 493 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
496 DCHECK(bidirectional_stream_impl_); 494 DCHECK(bidirectional_stream_impl_);
497 request_->OnNewSpdySessionReady(this, /*spdy_http_stream=*/nullptr, 495 job_controller_->OnNewSpdySessionReady(
498 std::move(bidirectional_stream_impl_), 496 this, /*spdy_http_stream=*/nullptr,
499 spdy_session, spdy_session_direct_); 497 std::move(bidirectional_stream_impl_), spdy_session,
498 spdy_session_direct_);
500 } else { 499 } else {
501 DCHECK(stream_); 500 DCHECK(stream_);
502 request_->OnNewSpdySessionReady(this, std::move(stream_), 501 job_controller_->OnNewSpdySessionReady(
503 /** bidirectional_stream_impl=*/nullptr, 502 this, std::move(stream_),
504 spdy_session, spdy_session_direct_); 503 /* bidirectional_stream_impl=*/nullptr, spdy_session,
504 spdy_session_direct_);
505 } 505 }
506 } 506 }
507 // |this| may be deleted after this call. 507 // |this| may be deleted after this call.
508 } 508 }
509 509
510 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { 510 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) {
511 DCHECK(!IsPreconnecting()); 511 DCHECK(!IsPreconnecting());
512 512
513 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 513 MaybeCopyConnectionAttemptsFromSocketOrHandle();
514 514
515 if (IsOrphaned()) { 515 if (IsOrphaned()) {
516 stream_factory_->OnOrphanedJobComplete(this); 516 job_controller_->OnOrphanedJobComplete(this);
517 } else { 517 } else {
518 SSLFailureState ssl_failure_state = 518 SSLFailureState ssl_failure_state =
519 connection_ ? connection_->ssl_failure_state() : SSL_FAILURE_NONE; 519 connection_ ? connection_->ssl_failure_state() : SSL_FAILURE_NONE;
520 request_->OnStreamFailed(this, result, server_ssl_config_, 520 job_controller_->OnStreamFailed(this, result, server_ssl_config_,
521 ssl_failure_state); 521 ssl_failure_state);
522 } 522 }
523 // |this| may be deleted after this call. 523 // |this| may be deleted after this call.
524 } 524 }
525 525
526 void HttpStreamFactoryImpl::Job::OnCertificateErrorCallback( 526 void HttpStreamFactoryImpl::Job::OnCertificateErrorCallback(
527 int result, const SSLInfo& ssl_info) { 527 int result, const SSLInfo& ssl_info) {
528 DCHECK(!IsPreconnecting()); 528 DCHECK(!IsPreconnecting());
529 529
530 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 530 MaybeCopyConnectionAttemptsFromSocketOrHandle();
531 531
532 if (IsOrphaned()) 532 if (IsOrphaned())
533 stream_factory_->OnOrphanedJobComplete(this); 533 job_controller_->OnOrphanedJobComplete(this);
534 else 534 else
535 request_->OnCertificateError(this, result, server_ssl_config_, ssl_info); 535 job_controller_->OnCertificateError(this, result, server_ssl_config_,
536 ssl_info);
536 // |this| may be deleted after this call. 537 // |this| may be deleted after this call.
537 } 538 }
538 539
539 void HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback( 540 void HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback(
540 const HttpResponseInfo& response, 541 const HttpResponseInfo& response,
541 HttpAuthController* auth_controller) { 542 HttpAuthController* auth_controller) {
542 DCHECK(!IsPreconnecting()); 543 DCHECK(!IsPreconnecting());
543 if (IsOrphaned()) 544 if (IsOrphaned())
544 stream_factory_->OnOrphanedJobComplete(this); 545 job_controller_->OnOrphanedJobComplete(this);
545 else 546 else
546 request_->OnNeedsProxyAuth( 547 job_controller_->OnNeedsProxyAuth(this, response, server_ssl_config_,
547 this, response, server_ssl_config_, proxy_info_, auth_controller); 548 proxy_info_, auth_controller);
548 // |this| may be deleted after this call. 549 // |this| may be deleted after this call.
549 } 550 }
550 551
551 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback( 552 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback(
552 SSLCertRequestInfo* cert_info) { 553 SSLCertRequestInfo* cert_info) {
553 DCHECK(!IsPreconnecting()); 554 DCHECK(!IsPreconnecting());
554 if (IsOrphaned()) 555 if (IsOrphaned())
555 stream_factory_->OnOrphanedJobComplete(this); 556 job_controller_->OnOrphanedJobComplete(this);
556 else 557 else
557 request_->OnNeedsClientAuth(this, server_ssl_config_, cert_info); 558 job_controller_->OnNeedsClientAuth(this, server_ssl_config_, cert_info);
558 // |this| may be deleted after this call. 559 // |this| may be deleted after this call.
559 } 560 }
560 561
561 void HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback( 562 void HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback(
562 const HttpResponseInfo& response_info, 563 const HttpResponseInfo& response_info,
563 HttpStream* stream) { 564 HttpStream* stream) {
564 DCHECK(!IsPreconnecting()); 565 DCHECK(!IsPreconnecting());
565 if (IsOrphaned()) 566 if (IsOrphaned())
566 stream_factory_->OnOrphanedJobComplete(this); 567 job_controller_->OnOrphanedJobComplete(this);
567 else 568 else
568 request_->OnHttpsProxyTunnelResponse( 569 job_controller_->OnHttpsProxyTunnelResponse(
569 this, response_info, server_ssl_config_, proxy_info_, stream); 570 this, response_info, server_ssl_config_, proxy_info_, stream);
570 // |this| may be deleted after this call. 571 // |this| may be deleted after this call.
571 } 572 }
572 573
573 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() { 574 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() {
574 DCHECK(!request_);
575 if (new_spdy_session_.get()) { 575 if (new_spdy_session_.get()) {
576 stream_factory_->OnNewSpdySessionReady(new_spdy_session_, 576 job_controller_->OnNewSpdySessionReady(
577 spdy_session_direct_, 577 this, nullptr, nullptr, new_spdy_session_, spdy_session_direct_);
578 server_ssl_config_,
579 proxy_info_,
580 was_npn_negotiated(),
581 protocol_negotiated(),
582 using_spdy(),
583 net_log_);
584 } 578 }
585 stream_factory_->OnPreconnectsComplete(this); 579 job_controller_->OnPreconnectsComplete(this);
586 // |this| may be deleted after this call. 580 // |this| may be deleted after this call.
587 } 581 }
588 582
589 // static 583 // static
590 int HttpStreamFactoryImpl::Job::OnHostResolution( 584 int HttpStreamFactoryImpl::Job::OnHostResolution(
591 SpdySessionPool* spdy_session_pool, 585 SpdySessionPool* spdy_session_pool,
592 const SpdySessionKey& spdy_session_key, 586 const SpdySessionKey& spdy_session_key,
593 const GURL& origin_url, 587 const GURL& origin_url,
594 const AddressList& addresses, 588 const AddressList& addresses,
595 const BoundNetLog& net_log) { 589 const BoundNetLog& net_log) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 } 679 }
686 680
687 case OK: 681 case OK:
688 job_status_ = STATUS_SUCCEEDED; 682 job_status_ = STATUS_SUCCEEDED;
689 MaybeMarkAlternativeServiceBroken(); 683 MaybeMarkAlternativeServiceBroken();
690 next_state_ = STATE_DONE; 684 next_state_ = STATE_DONE;
691 if (new_spdy_session_.get()) { 685 if (new_spdy_session_.get()) {
692 base::ThreadTaskRunnerHandle::Get()->PostTask( 686 base::ThreadTaskRunnerHandle::Get()->PostTask(
693 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, 687 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback,
694 ptr_factory_.GetWeakPtr())); 688 ptr_factory_.GetWeakPtr()));
695 } else if (stream_factory_->for_websockets_) { 689 } else if (job_controller_->for_websockets()) {
696 DCHECK(websocket_stream_); 690 DCHECK(websocket_stream_);
697 base::ThreadTaskRunnerHandle::Get()->PostTask( 691 base::ThreadTaskRunnerHandle::Get()->PostTask(
698 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, 692 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback,
699 ptr_factory_.GetWeakPtr())); 693 ptr_factory_.GetWeakPtr()));
700 } else if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { 694 } else if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
701 if (!bidirectional_stream_impl_) { 695 if (!bidirectional_stream_impl_) {
702 base::ThreadTaskRunnerHandle::Get()->PostTask( 696 base::ThreadTaskRunnerHandle::Get()->PostTask(
703 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, 697 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback,
704 ptr_factory_.GetWeakPtr(), ERR_FAILED)); 698 ptr_factory_.GetWeakPtr(), ERR_FAILED));
705 } else { 699 } else {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 return rv; 795 return rv;
802 } 796 }
803 797
804 int HttpStreamFactoryImpl::Job::DoStart() { 798 int HttpStreamFactoryImpl::Job::DoStart() {
805 valid_spdy_session_pool_.reset(new ValidSpdySessionPool( 799 valid_spdy_session_pool_.reset(new ValidSpdySessionPool(
806 session_->spdy_session_pool(), origin_url_, IsSpdyAlternative())); 800 session_->spdy_session_pool(), origin_url_, IsSpdyAlternative()));
807 801
808 net_log_.BeginEvent( 802 net_log_.BeginEvent(
809 NetLog::TYPE_HTTP_STREAM_JOB, 803 NetLog::TYPE_HTTP_STREAM_JOB,
810 base::Bind(&NetLogHttpStreamJobCallback, 804 base::Bind(&NetLogHttpStreamJobCallback,
811 request_ ? request_->net_log().source() : NetLog::Source(), 805 (!IsPreconnecting() && !orphaned_)
806 ? job_controller_->GetNetLogFromRequest().source()
807 : NetLog::Source(),
Randy Smith (Not in Mondays) 2016/05/09 21:42:09 Hmmm. Parallel to Ryan's suggestions above, I'd b
Zhongyi Shi 2016/05/12 07:26:23 Done.
812 &request_info_.url, &origin_url_, &alternative_service_, 808 &request_info_.url, &origin_url_, &alternative_service_,
813 priority_)); 809 priority_));
814 if (request_) { 810 if (!IsPreconnecting() && !orphaned_) {
815 request_->net_log().AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB, 811 job_controller_->GetNetLogFromRequest().AddEvent(
816 net_log_.source().ToEventParametersCallback()); 812 NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB,
813 net_log_.source().ToEventParametersCallback());
817 } 814 }
818 815
819 // Don't connect to restricted ports. 816 // Don't connect to restricted ports.
820 if (!IsPortAllowedForScheme(destination_.port(), 817 if (!IsPortAllowedForScheme(destination_.port(),
821 request_info_.url.scheme())) { 818 request_info_.url.scheme())) {
822 if (waiting_job_) { 819 if (waiting_job_) {
823 waiting_job_->Resume(this, base::TimeDelta()); 820 waiting_job_->Resume(this, base::TimeDelta());
824 waiting_job_ = NULL; 821 waiting_job_ = NULL;
825 } 822 }
826 return ERR_UNSAFE_PORT; 823 return ERR_UNSAFE_PORT;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 // If we're preconnecting, but we already have a SpdySession, we don't 1046 // If we're preconnecting, but we already have a SpdySession, we don't
1050 // actually need to preconnect any sockets, so we're done. 1047 // actually need to preconnect any sockets, so we're done.
1051 if (IsPreconnecting()) 1048 if (IsPreconnecting())
1052 return OK; 1049 return OK;
1053 using_spdy_ = true; 1050 using_spdy_ = true;
1054 next_state_ = STATE_CREATE_STREAM; 1051 next_state_ = STATE_CREATE_STREAM;
1055 existing_spdy_session_ = spdy_session; 1052 existing_spdy_session_ = spdy_session;
1056 return OK; 1053 return OK;
1057 } 1054 }
1058 } 1055 }
1059 if (request_ && !request_->HasSpdySessionKey() && using_ssl_) { 1056 if (!IsPreconnecting() && !orphaned_ && using_ssl_) {
1060 // Update the spdy session key for the request that launched this job. 1057 // Ask |job_controller_| to update the spdy session key for the request
1061 request_->SetSpdySessionKey(spdy_session_key); 1058 // that launched this job.
1059 job_controller_->SetSpdySessionKey(spdy_session_key);
1062 } 1060 }
1063 1061
1064 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's 1062 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's
1065 // paused. 1063 // paused.
1066 if (waiting_job_) { 1064 if (waiting_job_) {
1067 waiting_job_->Resume(this, base::TimeDelta()); 1065 waiting_job_->Resume(this, base::TimeDelta());
1068 waiting_job_ = NULL; 1066 waiting_job_ = NULL;
1069 } 1067 }
1070 1068
1071 if (proxy_info_.is_http() || proxy_info_.is_https()) 1069 if (proxy_info_.is_http() || proxy_info_.is_https())
1072 establishing_tunnel_ = using_ssl_; 1070 establishing_tunnel_ = using_ssl_;
1073 1071
1074 const bool expect_spdy = IsSpdyAlternative(); 1072 const bool expect_spdy = IsSpdyAlternative();
1075 1073
1076 base::WeakPtr<HttpServerProperties> http_server_properties = 1074 base::WeakPtr<HttpServerProperties> http_server_properties =
1077 session_->http_server_properties(); 1075 session_->http_server_properties();
1078 if (http_server_properties) { 1076 if (http_server_properties) {
1079 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); 1077 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_);
1080 if (proxy_info_.is_http() || proxy_info_.is_https()) { 1078 if (proxy_info_.is_http() || proxy_info_.is_https()) {
1081 http_server_properties->MaybeForceHTTP11( 1079 http_server_properties->MaybeForceHTTP11(
1082 proxy_info_.proxy_server().host_port_pair(), &proxy_ssl_config_); 1080 proxy_info_.proxy_server().host_port_pair(), &proxy_ssl_config_);
1083 } 1081 }
1084 } 1082 }
1085 1083
1086 if (IsPreconnecting()) { 1084 if (IsPreconnecting()) {
1087 DCHECK(!stream_factory_->for_websockets_); 1085 DCHECK(!job_controller_->for_websockets());
1088 return PreconnectSocketsForHttpRequest( 1086 return PreconnectSocketsForHttpRequest(
1089 GetSocketGroup(), destination_, request_info_.extra_headers, 1087 GetSocketGroup(), destination_, request_info_.extra_headers,
1090 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, 1088 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy,
1091 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, 1089 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode,
1092 net_log_, num_streams_); 1090 net_log_, num_streams_);
1093 } 1091 }
1094 1092
1095 // If we can't use a SPDY session, don't bother checking for one after 1093 // If we can't use a SPDY session, don't bother checking for one after
1096 // the hostname is resolved. 1094 // the hostname is resolved.
1097 OnHostResolutionCallback resolution_callback = 1095 OnHostResolutionCallback resolution_callback =
1098 CanUseExistingSpdySession() 1096 CanUseExistingSpdySession()
1099 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), 1097 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(),
1100 spdy_session_key, origin_url_) 1098 spdy_session_key, origin_url_)
1101 : OnHostResolutionCallback(); 1099 : OnHostResolutionCallback();
1102 if (stream_factory_->for_websockets_) { 1100 if (job_controller_->for_websockets()) {
1103 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported. 1101 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported.
1104 SSLConfig websocket_server_ssl_config = server_ssl_config_; 1102 SSLConfig websocket_server_ssl_config = server_ssl_config_;
1105 websocket_server_ssl_config.alpn_protos.clear(); 1103 websocket_server_ssl_config.alpn_protos.clear();
1106 websocket_server_ssl_config.npn_protos.clear(); 1104 websocket_server_ssl_config.npn_protos.clear();
1107 return InitSocketHandleForWebSocketRequest( 1105 return InitSocketHandleForWebSocketRequest(
1108 GetSocketGroup(), destination_, request_info_.extra_headers, 1106 GetSocketGroup(), destination_, request_info_.extra_headers,
1109 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, 1107 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy,
1110 websocket_server_ssl_config, proxy_ssl_config_, 1108 websocket_server_ssl_config, proxy_ssl_config_,
1111 request_info_.privacy_mode, net_log_, connection_.get(), 1109 request_info_.privacy_mode, net_log_, connection_.get(),
1112 resolution_callback, io_callback_); 1110 resolution_callback, io_callback_);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 1308
1311 // We're always waiting here for the delegate to call us back. 1309 // We're always waiting here for the delegate to call us back.
1312 return ERR_IO_PENDING; 1310 return ERR_IO_PENDING;
1313 } 1311 }
1314 1312
1315 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamImpl( 1313 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamImpl(
1316 base::WeakPtr<SpdySession> session, 1314 base::WeakPtr<SpdySession> session,
1317 bool direct) { 1315 bool direct) {
1318 // TODO(ricea): Restore the code for WebSockets over SPDY once it's 1316 // TODO(ricea): Restore the code for WebSockets over SPDY once it's
1319 // implemented. 1317 // implemented.
1320 if (stream_factory_->for_websockets_) 1318 if (job_controller_->for_websockets())
1321 return ERR_NOT_IMPLEMENTED; 1319 return ERR_NOT_IMPLEMENTED;
1322 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { 1320 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
1323 bidirectional_stream_impl_.reset(new BidirectionalStreamSpdyImpl(session)); 1321 bidirectional_stream_impl_.reset(new BidirectionalStreamSpdyImpl(session));
1324 return OK; 1322 return OK;
1325 } 1323 }
1326 1324
1327 // TODO(willchan): Delete this code, because eventually, the 1325 // TODO(willchan): Delete this code, because eventually, the
1328 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it 1326 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it
1329 // will know when SpdySessions become available. 1327 // will know when SpdySessions become available.
1330 1328
(...skipping 24 matching lines...) Expand all
1355 // need to plumb this through to the connect level. 1353 // need to plumb this through to the connect level.
1356 if (connection_->socket() && !connection_->is_reused()) 1354 if (connection_->socket() && !connection_->is_reused())
1357 SetSocketMotivation(); 1355 SetSocketMotivation();
1358 1356
1359 if (!using_spdy_) { 1357 if (!using_spdy_) {
1360 DCHECK(!IsSpdyAlternative()); 1358 DCHECK(!IsSpdyAlternative());
1361 // We may get ftp scheme when fetching ftp resources through proxy. 1359 // We may get ftp scheme when fetching ftp resources through proxy.
1362 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && 1360 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) &&
1363 (request_info_.url.SchemeIs("http") || 1361 (request_info_.url.SchemeIs("http") ||
1364 request_info_.url.SchemeIs("ftp")); 1362 request_info_.url.SchemeIs("ftp"));
1365 if (stream_factory_->for_websockets_) { 1363 if (job_controller_->for_websockets()) {
1366 DCHECK(request_); 1364 DCHECK(!IsPreconnecting() && !orphaned_);
1367 DCHECK(request_->websocket_handshake_stream_create_helper()); 1365 DCHECK(job_controller_->websocket_handshake_stream_create_helper());
1368 websocket_stream_.reset( 1366 websocket_stream_.reset(
1369 request_->websocket_handshake_stream_create_helper() 1367 job_controller_->websocket_handshake_stream_create_helper()
1370 ->CreateBasicStream(std::move(connection_), using_proxy)); 1368 ->CreateBasicStream(std::move(connection_), using_proxy));
1371 } else { 1369 } else {
1372 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy)); 1370 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy));
1373 } 1371 }
1374 return OK; 1372 return OK;
1375 } 1373 }
1376 1374
1377 CHECK(!stream_.get()); 1375 CHECK(!stream_.get());
1378 1376
1379 bool direct = !IsHttpsProxyAndHttpUrl(); 1377 bool direct = !IsHttpsProxyAndHttpUrl();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 1479
1482 return ReconsiderProxyAfterError(result); 1480 return ReconsiderProxyAfterError(result);
1483 } 1481 }
1484 1482
1485 void HttpStreamFactoryImpl::Job::ReturnToStateInitConnection( 1483 void HttpStreamFactoryImpl::Job::ReturnToStateInitConnection(
1486 bool close_connection) { 1484 bool close_connection) {
1487 if (close_connection && connection_->socket()) 1485 if (close_connection && connection_->socket())
1488 connection_->socket()->Disconnect(); 1486 connection_->socket()->Disconnect();
1489 connection_->Reset(); 1487 connection_->Reset();
1490 1488
1491 if (request_) 1489 if (!IsPreconnecting() && !orphaned_) {
1492 request_->RemoveRequestFromSpdySessionRequestMap(); 1490 job_controller_->RemoveRequestFromSpdySessionRequestMap();
1491 }
1493 1492
1494 next_state_ = STATE_INIT_CONNECTION; 1493 next_state_ = STATE_INIT_CONNECTION;
1495 } 1494 }
1496 1495
1497 void HttpStreamFactoryImpl::Job::SetSocketMotivation() { 1496 void HttpStreamFactoryImpl::Job::SetSocketMotivation() {
1498 if (request_info_.motivation == HttpRequestInfo::PRECONNECT_MOTIVATED) 1497 if (request_info_.motivation == HttpRequestInfo::PRECONNECT_MOTIVATED)
1499 connection_->socket()->SetSubresourceSpeculation(); 1498 connection_->socket()->SetSubresourceSpeculation();
1500 else if (request_info_.motivation == HttpRequestInfo::OMNIBOX_MOTIVATED) 1499 else if (request_info_.motivation == HttpRequestInfo::OMNIBOX_MOTIVATED)
1501 connection_->socket()->SetOmniboxSpeculation(); 1500 connection_->socket()->SetOmniboxSpeculation();
1502 // TODO(mbelshe): Add other motivations (like EARLY_LOAD_MOTIVATED). 1501 // TODO(mbelshe): Add other motivations (like EARLY_LOAD_MOTIVATED).
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 int rv = session_->proxy_service()->ReconsiderProxyAfterError( 1623 int rv = session_->proxy_service()->ReconsiderProxyAfterError(
1625 request_info_.url, request_info_.method, request_info_.load_flags, error, 1624 request_info_.url, request_info_.method, request_info_.load_flags, error,
1626 &proxy_info_, io_callback_, &pac_request_, 1625 &proxy_info_, io_callback_, &pac_request_,
1627 session_->params().proxy_delegate, net_log_); 1626 session_->params().proxy_delegate, net_log_);
1628 if (rv == OK || rv == ERR_IO_PENDING) { 1627 if (rv == OK || rv == ERR_IO_PENDING) {
1629 // If the error was during connection setup, there is no socket to 1628 // If the error was during connection setup, there is no socket to
1630 // disconnect. 1629 // disconnect.
1631 if (connection_->socket()) 1630 if (connection_->socket())
1632 connection_->socket()->Disconnect(); 1631 connection_->socket()->Disconnect();
1633 connection_->Reset(); 1632 connection_->Reset();
1634 if (request_) 1633 if (!IsPreconnecting() && !orphaned_) {
1635 request_->RemoveRequestFromSpdySessionRequestMap(); 1634 job_controller_->RemoveRequestFromSpdySessionRequestMap();
1635 }
1636 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; 1636 next_state_ = STATE_RESOLVE_PROXY_COMPLETE;
1637 } else { 1637 } else {
1638 // If ReconsiderProxyAfterError() failed synchronously, it means 1638 // If ReconsiderProxyAfterError() failed synchronously, it means
1639 // there was nothing left to fall-back to, so fail the transaction 1639 // there was nothing left to fall-back to, so fail the transaction
1640 // with the last connection error we got. 1640 // with the last connection error we got.
1641 // TODO(eroman): This is a confusing contract, make it more obvious. 1641 // TODO(eroman): This is a confusing contract, make it more obvious.
1642 rv = error; 1642 rv = error;
1643 } 1643 }
1644 1644
1645 return rv; 1645 return rv;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 void HttpStreamFactoryImpl::Job::SwitchToSpdyMode() { 1681 void HttpStreamFactoryImpl::Job::SwitchToSpdyMode() {
1682 if (HttpStreamFactory::spdy_enabled()) 1682 if (HttpStreamFactory::spdy_enabled())
1683 using_spdy_ = true; 1683 using_spdy_ = true;
1684 } 1684 }
1685 1685
1686 bool HttpStreamFactoryImpl::Job::IsPreconnecting() const { 1686 bool HttpStreamFactoryImpl::Job::IsPreconnecting() const {
1687 DCHECK_GE(num_streams_, 0); 1687 DCHECK_GE(num_streams_, 0);
1688 return num_streams_ > 0; 1688 return num_streams_ > 0;
1689 } 1689 }
1690 1690
1691 bool HttpStreamFactoryImpl::Job::IsOrphaned() const {
1692 return !IsPreconnecting() && !request_;
1693 }
1694
1695 void HttpStreamFactoryImpl::Job::ReportJobSucceededForRequest() { 1691 void HttpStreamFactoryImpl::Job::ReportJobSucceededForRequest() {
1696 if (using_existing_quic_session_) { 1692 if (using_existing_quic_session_) {
1697 // If an existing session was used, then no TCP connection was 1693 // If an existing session was used, then no TCP connection was
1698 // started. 1694 // started.
1699 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE); 1695 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE);
1700 } else if (IsSpdyAlternative() || IsQuicAlternative()) { 1696 } else if (IsSpdyAlternative() || IsQuicAlternative()) {
1701 // This Job was the alternative Job, and hence won the race. 1697 // This Job was the alternative Job, and hence won the race.
1702 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE); 1698 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE);
1703 } else { 1699 } else {
1704 // This Job was the normal Job, and hence the alternative Job lost the race. 1700 // This Job was the normal Job, and hence the alternative Job lost the race.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 return ClientSocketPoolManager::NORMAL_GROUP; 1791 return ClientSocketPoolManager::NORMAL_GROUP;
1796 } 1792 }
1797 1793
1798 // If the connection succeeds, failed connection attempts leading up to the 1794 // If the connection succeeds, failed connection attempts leading up to the
1799 // success will be returned via the successfully connected socket. If the 1795 // success will be returned via the successfully connected socket. If the
1800 // connection fails, failed connection attempts will be returned via the 1796 // connection fails, failed connection attempts will be returned via the
1801 // ClientSocketHandle. Check whether a socket was returned and copy the 1797 // ClientSocketHandle. Check whether a socket was returned and copy the
1802 // connection attempts from the proper place. 1798 // connection attempts from the proper place.
1803 void HttpStreamFactoryImpl::Job:: 1799 void HttpStreamFactoryImpl::Job::
1804 MaybeCopyConnectionAttemptsFromSocketOrHandle() { 1800 MaybeCopyConnectionAttemptsFromSocketOrHandle() {
1805 if (IsOrphaned() || !connection_) 1801 if (IsPreconnecting() || IsOrphaned() || !connection_)
1806 return; 1802 return;
1807 1803
1808 if (connection_->socket()) { 1804 if (connection_->socket()) {
1809 ConnectionAttempts socket_attempts; 1805 ConnectionAttempts socket_attempts;
1810 connection_->socket()->GetConnectionAttempts(&socket_attempts); 1806 connection_->socket()->GetConnectionAttempts(&socket_attempts);
1811 request_->AddConnectionAttempts(socket_attempts); 1807 job_controller_->AddConnectionAttemptsToRequest(socket_attempts);
1812 } else { 1808 } else {
1813 request_->AddConnectionAttempts(connection_->connection_attempts()); 1809 job_controller_->AddConnectionAttemptsToRequest(
1810 connection_->connection_attempts());
1814 } 1811 }
1815 } 1812 }
1816 1813
1817 } // namespace net 1814 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698