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

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: comment fix 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,
159 JobType job_type,
158 HttpNetworkSession* session, 160 HttpNetworkSession* session,
159 const HttpRequestInfo& request_info, 161 const HttpRequestInfo& request_info,
160 RequestPriority priority, 162 RequestPriority priority,
161 const SSLConfig& server_ssl_config, 163 const SSLConfig& server_ssl_config,
162 const SSLConfig& proxy_ssl_config, 164 const SSLConfig& proxy_ssl_config,
163 HostPortPair destination, 165 HostPortPair destination,
164 GURL origin_url, 166 GURL origin_url,
165 NetLog* net_log) 167 NetLog* net_log)
166 : Job(stream_factory, 168 : Job(job_controller,
169 job_type,
167 session, 170 session,
168 request_info, 171 request_info,
169 priority, 172 priority,
170 server_ssl_config, 173 server_ssl_config,
171 proxy_ssl_config, 174 proxy_ssl_config,
172 destination, 175 destination,
173 origin_url, 176 origin_url,
174 AlternativeService(), 177 AlternativeService(),
175 net_log) {} 178 net_log) {}
176 179
177 HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory, 180 HttpStreamFactoryImpl::Job::Job(JobController* job_controller,
181 JobType job_type,
178 HttpNetworkSession* session, 182 HttpNetworkSession* session,
179 const HttpRequestInfo& request_info, 183 const HttpRequestInfo& request_info,
180 RequestPriority priority, 184 RequestPriority priority,
181 const SSLConfig& server_ssl_config, 185 const SSLConfig& server_ssl_config,
182 const SSLConfig& proxy_ssl_config, 186 const SSLConfig& proxy_ssl_config,
183 HostPortPair destination, 187 HostPortPair destination,
184 GURL origin_url, 188 GURL origin_url,
185 AlternativeService alternative_service, 189 AlternativeService alternative_service,
186 NetLog* net_log) 190 NetLog* net_log)
187 : request_(NULL), 191 : request_info_(request_info),
188 request_info_(request_info),
189 priority_(priority), 192 priority_(priority),
190 server_ssl_config_(server_ssl_config), 193 server_ssl_config_(server_ssl_config),
191 proxy_ssl_config_(proxy_ssl_config), 194 proxy_ssl_config_(proxy_ssl_config),
192 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)), 195 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_HTTP_STREAM_JOB)),
193 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), 196 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))),
194 connection_(new ClientSocketHandle), 197 connection_(new ClientSocketHandle),
195 session_(session), 198 session_(session),
196 stream_factory_(stream_factory),
197 next_state_(STATE_NONE), 199 next_state_(STATE_NONE),
198 pac_request_(NULL), 200 pac_request_(NULL),
199 destination_(destination), 201 destination_(destination),
200 origin_url_(origin_url), 202 origin_url_(origin_url),
201 alternative_service_(alternative_service), 203 alternative_service_(alternative_service),
204 job_controller_(job_controller),
205 job_type_(job_type),
202 blocking_job_(NULL), 206 blocking_job_(NULL),
203 waiting_job_(NULL), 207 waiting_job_(NULL),
204 using_ssl_(false), 208 using_ssl_(false),
205 using_spdy_(false), 209 using_spdy_(false),
206 using_quic_(false), 210 using_quic_(false),
207 quic_request_(session_->quic_stream_factory()), 211 quic_request_(session_->quic_stream_factory()),
208 using_existing_quic_session_(false), 212 using_existing_quic_session_(false),
209 spdy_certificate_error_(OK), 213 spdy_certificate_error_(OK),
210 establishing_tunnel_(false), 214 establishing_tunnel_(false),
211 was_npn_negotiated_(false), 215 was_npn_negotiated_(false),
212 protocol_negotiated_(kProtoUnknown), 216 protocol_negotiated_(kProtoUnknown),
213 num_streams_(0), 217 num_streams_(0),
214 spdy_session_direct_(false), 218 spdy_session_direct_(false),
215 job_status_(STATUS_RUNNING), 219 job_status_(STATUS_RUNNING),
216 other_job_status_(STATUS_RUNNING), 220 other_job_status_(STATUS_RUNNING),
217 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), 221 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM),
218 ptr_factory_(this) { 222 ptr_factory_(this) {
219 DCHECK(stream_factory);
220 DCHECK(session); 223 DCHECK(session);
221 if (IsQuicAlternative()) { 224 if (IsQuicAlternative()) {
222 DCHECK(session_->params().enable_quic); 225 DCHECK(session_->params().enable_quic);
223 using_quic_ = true; 226 using_quic_ = true;
224 } 227 }
225 } 228 }
226 229
227 HttpStreamFactoryImpl::Job::~Job() { 230 HttpStreamFactoryImpl::Job::~Job() {
228 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_JOB); 231 net_log_.EndEvent(NetLog::TYPE_HTTP_STREAM_JOB);
229 232
230 // When we're in a partially constructed state, waiting for the user to 233 // When we're in a partially constructed state, waiting for the user to
231 // provide certificate handling information or authentication, we can't reuse 234 // provide certificate handling information or authentication, we can't reuse
232 // this stream at all. 235 // this stream at all.
233 if (next_state_ == STATE_WAITING_USER_ACTION) { 236 if (next_state_ == STATE_WAITING_USER_ACTION) {
234 connection_->socket()->Disconnect(); 237 connection_->socket()->Disconnect();
235 connection_.reset(); 238 connection_.reset();
236 } 239 }
237 240
238 if (pac_request_) 241 if (pac_request_)
239 session_->proxy_service()->CancelPacRequest(pac_request_); 242 session_->proxy_service()->CancelPacRequest(pac_request_);
240 243
241 // The stream could be in a partial state. It is not reusable. 244 // The stream could be in a partial state. It is not reusable.
242 if (stream_.get() && next_state_ != STATE_DONE) 245 if (stream_.get() && next_state_ != STATE_DONE)
243 stream_->Close(true /* not reusable */); 246 stream_->Close(true /* not reusable */);
244 } 247 }
245 248
246 void HttpStreamFactoryImpl::Job::Start(Request* request) { 249 void HttpStreamFactoryImpl::Job::Start(
247 DCHECK(request); 250 HttpStreamRequest::StreamType stream_type) {
248 request_ = request; 251 stream_type_ = stream_type;
249 // Saves |stream_type_|, since request is nulled when job is orphaned.
250 stream_type_ = request_->stream_type();
251 StartInternal(); 252 StartInternal();
252 } 253 }
253 254
254 int HttpStreamFactoryImpl::Job::Preconnect(int num_streams) { 255 int HttpStreamFactoryImpl::Job::Preconnect(int num_streams) {
255 DCHECK_GT(num_streams, 0); 256 DCHECK_GT(num_streams, 0);
256 base::WeakPtr<HttpServerProperties> http_server_properties = 257 base::WeakPtr<HttpServerProperties> http_server_properties =
257 session_->http_server_properties(); 258 session_->http_server_properties();
258 if (http_server_properties && 259 if (http_server_properties &&
259 http_server_properties->SupportsRequestPriority( 260 http_server_properties->SupportsRequestPriority(
260 url::SchemeHostPort(request_info_.url))) { 261 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. 320 // be delayed by the |wait_time_| when it resumes.
320 if (next_state_ == STATE_NONE || next_state_ <= STATE_WAIT_FOR_JOB_COMPLETE) 321 if (next_state_ == STATE_NONE || next_state_ <= STATE_WAIT_FOR_JOB_COMPLETE)
321 wait_time_ = delay; 322 wait_time_ = delay;
322 323
323 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE. 324 // We know we're blocked if the next_state_ is STATE_WAIT_FOR_JOB_COMPLETE.
324 // Unblock |this|. 325 // Unblock |this|.
325 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE) 326 if (next_state_ == STATE_WAIT_FOR_JOB_COMPLETE)
326 ResumeAfterDelay(); 327 ResumeAfterDelay();
327 } 328 }
328 329
329 void HttpStreamFactoryImpl::Job::Orphan(const Request* request) { 330 void HttpStreamFactoryImpl::Job::Orphan() {
330 DCHECK_EQ(request_, request);
331 request_ = NULL;
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_ &&
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 retrievable by 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 // https (the normal case) or if we're connection to a SPDY proxy. 409 // https (the normal case) or if we're connection to a SPDY proxy.
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(job_type_ != PRECONNECT);
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 job_controller_->OnStreamReady(this, server_ssl_config_, proxy_info_);
429 stream_factory_->OnOrphanedJobComplete(this);
430 } else {
431 request_->Complete(was_npn_negotiated(), protocol_negotiated(),
432 using_spdy());
433 request_->OnStreamReady(this, server_ssl_config_, proxy_info_,
434 stream_.release());
435 }
436 // |this| may be deleted after this call. 428 // |this| may be deleted after this call.
437 } 429 }
438 430
439 void HttpStreamFactoryImpl::Job::OnWebSocketHandshakeStreamReadyCallback() { 431 void HttpStreamFactoryImpl::Job::OnWebSocketHandshakeStreamReadyCallback() {
440 DCHECK(websocket_stream_); 432 DCHECK(websocket_stream_);
441 DCHECK(!IsPreconnecting()); 433 DCHECK(job_type_ != PRECONNECT);
442 DCHECK(stream_factory_->for_websockets_); 434 DCHECK(job_controller_->for_websockets());
443 // An orphaned WebSocket job will be closed immediately and
444 // never be ready.
445 DCHECK(!IsOrphaned());
446 435
447 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 436 MaybeCopyConnectionAttemptsFromSocketOrHandle();
448 437
449 request_->Complete(was_npn_negotiated(), protocol_negotiated(), using_spdy()); 438 job_controller_->OnWebSocketHandshakeStreamReady(
450 request_->OnWebSocketHandshakeStreamReady(this, 439 this, server_ssl_config_, proxy_info_, websocket_stream_.release());
451 server_ssl_config_,
452 proxy_info_,
453 websocket_stream_.release());
454 // |this| may be deleted after this call. 440 // |this| may be deleted after this call.
455 } 441 }
456 442
457 void HttpStreamFactoryImpl::Job::OnBidirectionalStreamImplReadyCallback() { 443 void HttpStreamFactoryImpl::Job::OnBidirectionalStreamImplReadyCallback() {
458 DCHECK(bidirectional_stream_impl_); 444 DCHECK(bidirectional_stream_impl_);
459 445
460 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 446 MaybeCopyConnectionAttemptsFromSocketOrHandle();
461 447
462 if (IsOrphaned()) { 448 job_controller_->OnBidirectionalStreamImplReady(this, server_ssl_config_,
463 stream_factory_->OnOrphanedJobComplete(this); 449 proxy_info_);
464 } else { 450 // |this| may be deleted after this call.
465 request_->Complete(was_npn_negotiated(), protocol_negotiated(),
466 using_spdy());
467 request_->OnBidirectionalStreamImplReady(
468 this, server_ssl_config_, proxy_info_,
469 bidirectional_stream_impl_.release());
470 }
471 // |this| may be deleted after this call.
472 } 451 }
473 452
474 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { 453 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() {
475 DCHECK(stream_.get() || bidirectional_stream_impl_.get()); 454 DCHECK(stream_.get() || bidirectional_stream_impl_.get());
476 DCHECK(!IsPreconnecting()); 455 DCHECK(job_type_ != PRECONNECT);
477 DCHECK(using_spdy()); 456 DCHECK(using_spdy());
478 // Note: an event loop iteration has passed, so |new_spdy_session_| may be 457 // 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. 458 // NULL at this point if the SpdySession closed immediately after creation.
480 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_; 459 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_;
481 new_spdy_session_.reset(); 460 new_spdy_session_.reset();
482 461
483 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 462 MaybeCopyConnectionAttemptsFromSocketOrHandle();
484 463
485 // TODO(jgraettinger): Notify the factory, and let that notify |request_|, 464 job_controller_->OnNewSpdySessionReady(this, spdy_session,
486 // rather than notifying |request_| directly. 465 spdy_session_direct_);
487 if (IsOrphaned()) { 466
488 if (spdy_session) {
489 stream_factory_->OnNewSpdySessionReady(
490 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_,
491 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_);
492 }
493 stream_factory_->OnOrphanedJobComplete(this);
494 } else {
495 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
496 DCHECK(bidirectional_stream_impl_);
497 request_->OnNewSpdySessionReady(this, /*spdy_http_stream=*/nullptr,
498 std::move(bidirectional_stream_impl_),
499 spdy_session, spdy_session_direct_);
500 } else {
501 DCHECK(stream_);
502 request_->OnNewSpdySessionReady(this, std::move(stream_),
503 /** bidirectional_stream_impl=*/nullptr,
504 spdy_session, spdy_session_direct_);
505 }
506 }
507 // |this| may be deleted after this call. 467 // |this| may be deleted after this call.
508 } 468 }
509 469
510 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) { 470 void HttpStreamFactoryImpl::Job::OnStreamFailedCallback(int result) {
511 DCHECK(!IsPreconnecting()); 471 DCHECK(job_type_ != PRECONNECT);
512 472
513 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 473 MaybeCopyConnectionAttemptsFromSocketOrHandle();
514 474
515 if (IsOrphaned()) { 475 SSLFailureState ssl_failure_state =
516 stream_factory_->OnOrphanedJobComplete(this); 476 connection_ ? connection_->ssl_failure_state() : SSL_FAILURE_NONE;
517 } else { 477
518 SSLFailureState ssl_failure_state = 478 job_controller_->OnStreamFailed(this, result, server_ssl_config_,
519 connection_ ? connection_->ssl_failure_state() : SSL_FAILURE_NONE; 479 ssl_failure_state);
520 request_->OnStreamFailed(this, result, server_ssl_config_,
521 ssl_failure_state);
522 }
523 // |this| may be deleted after this call. 480 // |this| may be deleted after this call.
524 } 481 }
525 482
526 void HttpStreamFactoryImpl::Job::OnCertificateErrorCallback( 483 void HttpStreamFactoryImpl::Job::OnCertificateErrorCallback(
527 int result, const SSLInfo& ssl_info) { 484 int result, const SSLInfo& ssl_info) {
528 DCHECK(!IsPreconnecting()); 485 DCHECK(job_type_ != PRECONNECT);
529 486
530 MaybeCopyConnectionAttemptsFromSocketOrHandle(); 487 MaybeCopyConnectionAttemptsFromSocketOrHandle();
531 488
532 if (IsOrphaned()) 489 job_controller_->OnCertificateError(this, result, server_ssl_config_,
533 stream_factory_->OnOrphanedJobComplete(this); 490 ssl_info);
534 else
535 request_->OnCertificateError(this, result, server_ssl_config_, ssl_info);
536 // |this| may be deleted after this call. 491 // |this| may be deleted after this call.
537 } 492 }
538 493
539 void HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback( 494 void HttpStreamFactoryImpl::Job::OnNeedsProxyAuthCallback(
540 const HttpResponseInfo& response, 495 const HttpResponseInfo& response,
541 HttpAuthController* auth_controller) { 496 HttpAuthController* auth_controller) {
542 DCHECK(!IsPreconnecting()); 497 DCHECK(job_type_ != PRECONNECT);
543 if (IsOrphaned()) 498
544 stream_factory_->OnOrphanedJobComplete(this); 499 job_controller_->OnNeedsProxyAuth(this, response, server_ssl_config_,
545 else 500 proxy_info_, auth_controller);
546 request_->OnNeedsProxyAuth(
547 this, response, server_ssl_config_, proxy_info_, auth_controller);
548 // |this| may be deleted after this call. 501 // |this| may be deleted after this call.
549 } 502 }
550 503
551 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback( 504 void HttpStreamFactoryImpl::Job::OnNeedsClientAuthCallback(
552 SSLCertRequestInfo* cert_info) { 505 SSLCertRequestInfo* cert_info) {
553 DCHECK(!IsPreconnecting()); 506 DCHECK(job_type_ != PRECONNECT);
554 if (IsOrphaned()) 507
555 stream_factory_->OnOrphanedJobComplete(this); 508 job_controller_->OnNeedsClientAuth(this, server_ssl_config_, cert_info);
556 else
557 request_->OnNeedsClientAuth(this, server_ssl_config_, cert_info);
558 // |this| may be deleted after this call. 509 // |this| may be deleted after this call.
559 } 510 }
560 511
561 void HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback( 512 void HttpStreamFactoryImpl::Job::OnHttpsProxyTunnelResponseCallback(
562 const HttpResponseInfo& response_info, 513 const HttpResponseInfo& response_info,
563 HttpStream* stream) { 514 HttpStream* stream) {
564 DCHECK(!IsPreconnecting()); 515 DCHECK(job_type_ != PRECONNECT);
565 if (IsOrphaned()) 516
566 stream_factory_->OnOrphanedJobComplete(this); 517 job_controller_->OnHttpsProxyTunnelResponse(
567 else 518 this, response_info, server_ssl_config_, proxy_info_, stream);
568 request_->OnHttpsProxyTunnelResponse(
569 this, response_info, server_ssl_config_, proxy_info_, stream);
570 // |this| may be deleted after this call. 519 // |this| may be deleted after this call.
571 } 520 }
572 521
573 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() { 522 void HttpStreamFactoryImpl::Job::OnPreconnectsComplete() {
574 DCHECK(!request_);
575 if (new_spdy_session_.get()) { 523 if (new_spdy_session_.get()) {
576 stream_factory_->OnNewSpdySessionReady(new_spdy_session_, 524 job_controller_->OnNewSpdySessionReady(this, new_spdy_session_,
577 spdy_session_direct_, 525 spdy_session_direct_);
578 server_ssl_config_,
579 proxy_info_,
580 was_npn_negotiated(),
581 protocol_negotiated(),
582 using_spdy(),
583 net_log_);
584 } 526 }
585 stream_factory_->OnPreconnectsComplete(this); 527 job_controller_->OnPreconnectsComplete(this);
586 // |this| may be deleted after this call. 528 // |this| may be deleted after this call.
587 } 529 }
588 530
589 // static 531 // static
590 int HttpStreamFactoryImpl::Job::OnHostResolution( 532 int HttpStreamFactoryImpl::Job::OnHostResolution(
591 SpdySessionPool* spdy_session_pool, 533 SpdySessionPool* spdy_session_pool,
592 const SpdySessionKey& spdy_session_key, 534 const SpdySessionKey& spdy_session_key,
593 const GURL& origin_url, 535 const GURL& origin_url,
594 const AddressList& addresses, 536 const AddressList& addresses,
595 const BoundNetLog& net_log) { 537 const BoundNetLog& net_log) {
(...skipping 17 matching lines...) Expand all
613 "HttpStreamFactoryImpl::Job::RunLoop"); 555 "HttpStreamFactoryImpl::Job::RunLoop");
614 result = DoLoop(result); 556 result = DoLoop(result);
615 557
616 if (result == ERR_IO_PENDING) 558 if (result == ERR_IO_PENDING)
617 return result; 559 return result;
618 560
619 // If there was an error, we should have already resumed the |waiting_job_|, 561 // If there was an error, we should have already resumed the |waiting_job_|,
620 // if there was one. 562 // if there was one.
621 DCHECK(result == OK || waiting_job_ == NULL); 563 DCHECK(result == OK || waiting_job_ == NULL);
622 564
623 if (IsPreconnecting()) { 565 if (job_type_ == PRECONNECT) {
624 base::ThreadTaskRunnerHandle::Get()->PostTask( 566 base::ThreadTaskRunnerHandle::Get()->PostTask(
625 FROM_HERE, 567 FROM_HERE,
626 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete, 568 base::Bind(&HttpStreamFactoryImpl::Job::OnPreconnectsComplete,
627 ptr_factory_.GetWeakPtr())); 569 ptr_factory_.GetWeakPtr()));
628 return ERR_IO_PENDING; 570 return ERR_IO_PENDING;
629 } 571 }
630 572
631 if (IsCertificateError(result)) { 573 if (IsCertificateError(result)) {
632 // Retrieve SSL information from the socket. 574 // Retrieve SSL information from the socket.
633 GetSSLInfo(); 575 GetSSLInfo();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 } 627 }
686 628
687 case OK: 629 case OK:
688 job_status_ = STATUS_SUCCEEDED; 630 job_status_ = STATUS_SUCCEEDED;
689 MaybeMarkAlternativeServiceBroken(); 631 MaybeMarkAlternativeServiceBroken();
690 next_state_ = STATE_DONE; 632 next_state_ = STATE_DONE;
691 if (new_spdy_session_.get()) { 633 if (new_spdy_session_.get()) {
692 base::ThreadTaskRunnerHandle::Get()->PostTask( 634 base::ThreadTaskRunnerHandle::Get()->PostTask(
693 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, 635 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback,
694 ptr_factory_.GetWeakPtr())); 636 ptr_factory_.GetWeakPtr()));
695 } else if (stream_factory_->for_websockets_) { 637 } else if (job_controller_->for_websockets()) {
696 DCHECK(websocket_stream_); 638 DCHECK(websocket_stream_);
697 base::ThreadTaskRunnerHandle::Get()->PostTask( 639 base::ThreadTaskRunnerHandle::Get()->PostTask(
698 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, 640 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback,
699 ptr_factory_.GetWeakPtr())); 641 ptr_factory_.GetWeakPtr()));
700 } else if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { 642 } else if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
701 if (!bidirectional_stream_impl_) { 643 if (!bidirectional_stream_impl_) {
702 base::ThreadTaskRunnerHandle::Get()->PostTask( 644 base::ThreadTaskRunnerHandle::Get()->PostTask(
703 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, 645 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback,
704 ptr_factory_.GetWeakPtr(), ERR_FAILED)); 646 ptr_factory_.GetWeakPtr(), ERR_FAILED));
705 } else { 647 } else {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 CHECK_EQ(STATE_NONE, next_state_); 739 CHECK_EQ(STATE_NONE, next_state_);
798 next_state_ = STATE_START; 740 next_state_ = STATE_START;
799 int rv = RunLoop(OK); 741 int rv = RunLoop(OK);
800 DCHECK_EQ(ERR_IO_PENDING, rv); 742 DCHECK_EQ(ERR_IO_PENDING, rv);
801 return rv; 743 return rv;
802 } 744 }
803 745
804 int HttpStreamFactoryImpl::Job::DoStart() { 746 int HttpStreamFactoryImpl::Job::DoStart() {
805 valid_spdy_session_pool_.reset(new ValidSpdySessionPool( 747 valid_spdy_session_pool_.reset(new ValidSpdySessionPool(
806 session_->spdy_session_pool(), origin_url_, IsSpdyAlternative())); 748 session_->spdy_session_pool(), origin_url_, IsSpdyAlternative()));
749 const BoundNetLog* net_log = job_controller_->GetNetLog(this);
807 750
808 net_log_.BeginEvent( 751 if (net_log) {
809 NetLog::TYPE_HTTP_STREAM_JOB, 752 net_log_.BeginEvent(
810 base::Bind(&NetLogHttpStreamJobCallback, 753 NetLog::TYPE_HTTP_STREAM_JOB,
811 request_ ? request_->net_log().source() : NetLog::Source(), 754 base::Bind(&NetLogHttpStreamJobCallback, net_log->source(),
812 &request_info_.url, &origin_url_, &alternative_service_, 755 &request_info_.url, &origin_url_, &alternative_service_,
813 priority_)); 756 priority_));
814 if (request_) { 757 net_log->AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB,
815 request_->net_log().AddEvent(NetLog::TYPE_HTTP_STREAM_REQUEST_STARTED_JOB, 758 net_log_.source().ToEventParametersCallback());
816 net_log_.source().ToEventParametersCallback());
817 } 759 }
818 760
819 // Don't connect to restricted ports. 761 // Don't connect to restricted ports.
820 if (!IsPortAllowedForScheme(destination_.port(), 762 if (!IsPortAllowedForScheme(destination_.port(),
821 request_info_.url.scheme())) { 763 request_info_.url.scheme())) {
822 if (waiting_job_) { 764 if (waiting_job_) {
823 waiting_job_->Resume(this, base::TimeDelta()); 765 waiting_job_->Resume(this, base::TimeDelta());
824 waiting_job_ = NULL; 766 waiting_job_ = NULL;
825 } 767 }
826 return ERR_UNSAFE_PORT; 768 return ERR_UNSAFE_PORT;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 // straight to using that. 983 // straight to using that.
1042 if (CanUseExistingSpdySession()) { 984 if (CanUseExistingSpdySession()) {
1043 base::WeakPtr<SpdySession> spdy_session; 985 base::WeakPtr<SpdySession> spdy_session;
1044 int result = valid_spdy_session_pool_->FindAvailableSession( 986 int result = valid_spdy_session_pool_->FindAvailableSession(
1045 spdy_session_key, net_log_, &spdy_session); 987 spdy_session_key, net_log_, &spdy_session);
1046 if (result != OK) 988 if (result != OK)
1047 return result; 989 return result;
1048 if (spdy_session) { 990 if (spdy_session) {
1049 // If we're preconnecting, but we already have a SpdySession, we don't 991 // If we're preconnecting, but we already have a SpdySession, we don't
1050 // actually need to preconnect any sockets, so we're done. 992 // actually need to preconnect any sockets, so we're done.
1051 if (IsPreconnecting()) 993 if (job_type_ == PRECONNECT)
1052 return OK; 994 return OK;
1053 using_spdy_ = true; 995 using_spdy_ = true;
1054 next_state_ = STATE_CREATE_STREAM; 996 next_state_ = STATE_CREATE_STREAM;
1055 existing_spdy_session_ = spdy_session; 997 existing_spdy_session_ = spdy_session;
1056 return OK; 998 return OK;
1057 } 999 }
1058 } 1000 }
1059 if (request_ && !request_->HasSpdySessionKey() && using_ssl_) { 1001 if (using_ssl_) {
1060 // Update the spdy session key for the request that launched this job. 1002 // Ask |job_controller_| to update the spdy session key for the request
1061 request_->SetSpdySessionKey(spdy_session_key); 1003 // that launched this job.
1004 job_controller_->SetSpdySessionKey(this, spdy_session_key);
1062 } 1005 }
1063 1006
1064 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's 1007 // OK, there's no available SPDY session. Let |waiting_job_| resume if it's
1065 // paused. 1008 // paused.
1066 if (waiting_job_) { 1009 if (waiting_job_) {
1067 waiting_job_->Resume(this, base::TimeDelta()); 1010 waiting_job_->Resume(this, base::TimeDelta());
1068 waiting_job_ = NULL; 1011 waiting_job_ = NULL;
1069 } 1012 }
1070 1013
1071 if (proxy_info_.is_http() || proxy_info_.is_https()) 1014 if (proxy_info_.is_http() || proxy_info_.is_https())
1072 establishing_tunnel_ = using_ssl_; 1015 establishing_tunnel_ = using_ssl_;
1073 1016
1074 const bool expect_spdy = IsSpdyAlternative(); 1017 const bool expect_spdy = IsSpdyAlternative();
1075 1018
1076 base::WeakPtr<HttpServerProperties> http_server_properties = 1019 base::WeakPtr<HttpServerProperties> http_server_properties =
1077 session_->http_server_properties(); 1020 session_->http_server_properties();
1078 if (http_server_properties) { 1021 if (http_server_properties) {
1079 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_); 1022 http_server_properties->MaybeForceHTTP11(destination_, &server_ssl_config_);
1080 if (proxy_info_.is_http() || proxy_info_.is_https()) { 1023 if (proxy_info_.is_http() || proxy_info_.is_https()) {
1081 http_server_properties->MaybeForceHTTP11( 1024 http_server_properties->MaybeForceHTTP11(
1082 proxy_info_.proxy_server().host_port_pair(), &proxy_ssl_config_); 1025 proxy_info_.proxy_server().host_port_pair(), &proxy_ssl_config_);
1083 } 1026 }
1084 } 1027 }
1085 1028
1086 if (IsPreconnecting()) { 1029 if (job_type_ == PRECONNECT) {
1087 DCHECK(!stream_factory_->for_websockets_); 1030 DCHECK(!job_controller_->for_websockets());
1088 return PreconnectSocketsForHttpRequest( 1031 return PreconnectSocketsForHttpRequest(
1089 GetSocketGroup(), destination_, request_info_.extra_headers, 1032 GetSocketGroup(), destination_, request_info_.extra_headers,
1090 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, 1033 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy,
1091 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, 1034 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode,
1092 net_log_, num_streams_); 1035 net_log_, num_streams_);
1093 } 1036 }
1094 1037
1095 // If we can't use a SPDY session, don't bother checking for one after 1038 // If we can't use a SPDY session, don't bother checking for one after
1096 // the hostname is resolved. 1039 // the hostname is resolved.
1097 OnHostResolutionCallback resolution_callback = 1040 OnHostResolutionCallback resolution_callback =
1098 CanUseExistingSpdySession() 1041 CanUseExistingSpdySession()
1099 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), 1042 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(),
1100 spdy_session_key, origin_url_) 1043 spdy_session_key, origin_url_)
1101 : OnHostResolutionCallback(); 1044 : OnHostResolutionCallback();
1102 if (stream_factory_->for_websockets_) { 1045 if (job_controller_->for_websockets()) {
1103 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported. 1046 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported.
1104 SSLConfig websocket_server_ssl_config = server_ssl_config_; 1047 SSLConfig websocket_server_ssl_config = server_ssl_config_;
1105 websocket_server_ssl_config.alpn_protos.clear(); 1048 websocket_server_ssl_config.alpn_protos.clear();
1106 websocket_server_ssl_config.npn_protos.clear(); 1049 websocket_server_ssl_config.npn_protos.clear();
1107 return InitSocketHandleForWebSocketRequest( 1050 return InitSocketHandleForWebSocketRequest(
1108 GetSocketGroup(), destination_, request_info_.extra_headers, 1051 GetSocketGroup(), destination_, request_info_.extra_headers,
1109 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, 1052 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy,
1110 websocket_server_ssl_config, proxy_ssl_config_, 1053 websocket_server_ssl_config, proxy_ssl_config_,
1111 request_info_.privacy_mode, net_log_, connection_.get(), 1054 request_info_.privacy_mode, net_log_, connection_.get(),
1112 resolution_callback, io_callback_); 1055 resolution_callback, io_callback_);
1113 } 1056 }
1114 1057
1115 return InitSocketHandleForHttpRequest( 1058 return InitSocketHandleForHttpRequest(
1116 GetSocketGroup(), destination_, request_info_.extra_headers, 1059 GetSocketGroup(), destination_, request_info_.extra_headers,
1117 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, 1060 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy,
1118 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, 1061 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode,
1119 net_log_, connection_.get(), resolution_callback, io_callback_); 1062 net_log_, connection_.get(), resolution_callback, io_callback_);
1120 } 1063 }
1121 1064
1122 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) { 1065 int HttpStreamFactoryImpl::Job::DoInitConnectionComplete(int result) {
1123 if (using_quic_ && result < 0 && waiting_job_) { 1066 if (using_quic_ && result < 0 && waiting_job_) {
1124 waiting_job_->Resume(this, base::TimeDelta()); 1067 waiting_job_->Resume(this, base::TimeDelta());
1125 waiting_job_ = NULL; 1068 waiting_job_ = NULL;
1126 } 1069 }
1127 if (IsPreconnecting()) { 1070 if (job_type_ == PRECONNECT) {
1128 if (using_quic_) 1071 if (using_quic_)
1129 return result; 1072 return result;
1130 DCHECK_EQ(OK, result); 1073 DCHECK_EQ(OK, result);
1131 return OK; 1074 return OK;
1132 } 1075 }
1133 1076
1134 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { 1077 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) {
1135 // We found a SPDY connection after resolving the host. This is 1078 // We found a SPDY connection after resolving the host. This is
1136 // probably an IP pooled connection. 1079 // probably an IP pooled connection.
1137 SpdySessionKey spdy_session_key = GetSpdySessionKey(); 1080 SpdySessionKey spdy_session_key = GetSpdySessionKey();
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 1253
1311 // We're always waiting here for the delegate to call us back. 1254 // We're always waiting here for the delegate to call us back.
1312 return ERR_IO_PENDING; 1255 return ERR_IO_PENDING;
1313 } 1256 }
1314 1257
1315 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamImpl( 1258 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamImpl(
1316 base::WeakPtr<SpdySession> session, 1259 base::WeakPtr<SpdySession> session,
1317 bool direct) { 1260 bool direct) {
1318 // TODO(ricea): Restore the code for WebSockets over SPDY once it's 1261 // TODO(ricea): Restore the code for WebSockets over SPDY once it's
1319 // implemented. 1262 // implemented.
1320 if (stream_factory_->for_websockets_) 1263 if (job_controller_->for_websockets())
1321 return ERR_NOT_IMPLEMENTED; 1264 return ERR_NOT_IMPLEMENTED;
1322 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { 1265 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
1323 bidirectional_stream_impl_.reset(new BidirectionalStreamSpdyImpl(session)); 1266 bidirectional_stream_impl_.reset(new BidirectionalStreamSpdyImpl(session));
1324 return OK; 1267 return OK;
1325 } 1268 }
1326 1269
1327 // TODO(willchan): Delete this code, because eventually, the 1270 // TODO(willchan): Delete this code, because eventually, the
1328 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it 1271 // HttpStreamFactoryImpl will be creating all the SpdyHttpStreams, since it
1329 // will know when SpdySessions become available. 1272 // will know when SpdySessions become available.
1330 1273
(...skipping 24 matching lines...) Expand all
1355 // need to plumb this through to the connect level. 1298 // need to plumb this through to the connect level.
1356 if (connection_->socket() && !connection_->is_reused()) 1299 if (connection_->socket() && !connection_->is_reused())
1357 SetSocketMotivation(); 1300 SetSocketMotivation();
1358 1301
1359 if (!using_spdy_) { 1302 if (!using_spdy_) {
1360 DCHECK(!IsSpdyAlternative()); 1303 DCHECK(!IsSpdyAlternative());
1361 // We may get ftp scheme when fetching ftp resources through proxy. 1304 // We may get ftp scheme when fetching ftp resources through proxy.
1362 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && 1305 bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) &&
1363 (request_info_.url.SchemeIs("http") || 1306 (request_info_.url.SchemeIs("http") ||
1364 request_info_.url.SchemeIs("ftp")); 1307 request_info_.url.SchemeIs("ftp"));
1365 if (stream_factory_->for_websockets_) { 1308 if (job_controller_->for_websockets()) {
1366 DCHECK(request_); 1309 DCHECK(job_type_ != PRECONNECT);
1367 DCHECK(request_->websocket_handshake_stream_create_helper()); 1310 DCHECK(job_controller_->websocket_handshake_stream_create_helper());
1368 websocket_stream_.reset( 1311 websocket_stream_.reset(
1369 request_->websocket_handshake_stream_create_helper() 1312 job_controller_->websocket_handshake_stream_create_helper()
1370 ->CreateBasicStream(std::move(connection_), using_proxy)); 1313 ->CreateBasicStream(std::move(connection_), using_proxy));
1371 } else { 1314 } else {
1372 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy)); 1315 stream_.reset(new HttpBasicStream(connection_.release(), using_proxy));
1373 } 1316 }
1374 return OK; 1317 return OK;
1375 } 1318 }
1376 1319
1377 CHECK(!stream_.get()); 1320 CHECK(!stream_.get());
1378 1321
1379 bool direct = !IsHttpsProxyAndHttpUrl(); 1322 bool direct = !IsHttpsProxyAndHttpUrl();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 1424
1482 return ReconsiderProxyAfterError(result); 1425 return ReconsiderProxyAfterError(result);
1483 } 1426 }
1484 1427
1485 void HttpStreamFactoryImpl::Job::ReturnToStateInitConnection( 1428 void HttpStreamFactoryImpl::Job::ReturnToStateInitConnection(
1486 bool close_connection) { 1429 bool close_connection) {
1487 if (close_connection && connection_->socket()) 1430 if (close_connection && connection_->socket())
1488 connection_->socket()->Disconnect(); 1431 connection_->socket()->Disconnect();
1489 connection_->Reset(); 1432 connection_->Reset();
1490 1433
1491 if (request_) 1434 job_controller_->RemoveRequestFromSpdySessionRequestMap(this);
1492 request_->RemoveRequestFromSpdySessionRequestMap();
1493 1435
1494 next_state_ = STATE_INIT_CONNECTION; 1436 next_state_ = STATE_INIT_CONNECTION;
1495 } 1437 }
1496 1438
1497 void HttpStreamFactoryImpl::Job::SetSocketMotivation() { 1439 void HttpStreamFactoryImpl::Job::SetSocketMotivation() {
1498 if (request_info_.motivation == HttpRequestInfo::PRECONNECT_MOTIVATED) 1440 if (request_info_.motivation == HttpRequestInfo::PRECONNECT_MOTIVATED)
1499 connection_->socket()->SetSubresourceSpeculation(); 1441 connection_->socket()->SetSubresourceSpeculation();
1500 else if (request_info_.motivation == HttpRequestInfo::OMNIBOX_MOTIVATED) 1442 else if (request_info_.motivation == HttpRequestInfo::OMNIBOX_MOTIVATED)
1501 connection_->socket()->SetOmniboxSpeculation(); 1443 connection_->socket()->SetOmniboxSpeculation();
1502 // TODO(mbelshe): Add other motivations (like EARLY_LOAD_MOTIVATED). 1444 // 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( 1566 int rv = session_->proxy_service()->ReconsiderProxyAfterError(
1625 request_info_.url, request_info_.method, request_info_.load_flags, error, 1567 request_info_.url, request_info_.method, request_info_.load_flags, error,
1626 &proxy_info_, io_callback_, &pac_request_, 1568 &proxy_info_, io_callback_, &pac_request_,
1627 session_->params().proxy_delegate, net_log_); 1569 session_->params().proxy_delegate, net_log_);
1628 if (rv == OK || rv == ERR_IO_PENDING) { 1570 if (rv == OK || rv == ERR_IO_PENDING) {
1629 // If the error was during connection setup, there is no socket to 1571 // If the error was during connection setup, there is no socket to
1630 // disconnect. 1572 // disconnect.
1631 if (connection_->socket()) 1573 if (connection_->socket())
1632 connection_->socket()->Disconnect(); 1574 connection_->socket()->Disconnect();
1633 connection_->Reset(); 1575 connection_->Reset();
1634 if (request_) 1576 job_controller_->RemoveRequestFromSpdySessionRequestMap(this);
1635 request_->RemoveRequestFromSpdySessionRequestMap();
1636 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; 1577 next_state_ = STATE_RESOLVE_PROXY_COMPLETE;
1637 } else { 1578 } else {
1638 // If ReconsiderProxyAfterError() failed synchronously, it means 1579 // If ReconsiderProxyAfterError() failed synchronously, it means
1639 // there was nothing left to fall-back to, so fail the transaction 1580 // there was nothing left to fall-back to, so fail the transaction
1640 // with the last connection error we got. 1581 // with the last connection error we got.
1641 // TODO(eroman): This is a confusing contract, make it more obvious. 1582 // TODO(eroman): This is a confusing contract, make it more obvious.
1642 rv = error; 1583 rv = error;
1643 } 1584 }
1644 1585
1645 return rv; 1586 return rv;
(...skipping 30 matching lines...) Expand all
1676 if (ssl_socket->IgnoreCertError(error, load_flags)) 1617 if (ssl_socket->IgnoreCertError(error, load_flags))
1677 return OK; 1618 return OK;
1678 return error; 1619 return error;
1679 } 1620 }
1680 1621
1681 void HttpStreamFactoryImpl::Job::SwitchToSpdyMode() { 1622 void HttpStreamFactoryImpl::Job::SwitchToSpdyMode() {
1682 if (HttpStreamFactory::spdy_enabled()) 1623 if (HttpStreamFactory::spdy_enabled())
1683 using_spdy_ = true; 1624 using_spdy_ = true;
1684 } 1625 }
1685 1626
1686 bool HttpStreamFactoryImpl::Job::IsPreconnecting() const {
1687 DCHECK_GE(num_streams_, 0);
1688 return num_streams_ > 0;
1689 }
1690
1691 bool HttpStreamFactoryImpl::Job::IsOrphaned() const {
1692 return !IsPreconnecting() && !request_;
1693 }
1694
1695 void HttpStreamFactoryImpl::Job::ReportJobSucceededForRequest() { 1627 void HttpStreamFactoryImpl::Job::ReportJobSucceededForRequest() {
1696 if (using_existing_quic_session_) { 1628 if (using_existing_quic_session_) {
1697 // If an existing session was used, then no TCP connection was 1629 // If an existing session was used, then no TCP connection was
1698 // started. 1630 // started.
1699 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE); 1631 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE);
1700 } else if (IsSpdyAlternative() || IsQuicAlternative()) { 1632 } else if (IsSpdyAlternative() || IsQuicAlternative()) {
1701 // This Job was the alternative Job, and hence won the race. 1633 // This Job was the alternative Job, and hence won the race.
1702 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE); 1634 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE);
1703 } else { 1635 } else {
1704 // This Job was the normal Job, and hence the alternative Job lost the race. 1636 // 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; 1727 return ClientSocketPoolManager::NORMAL_GROUP;
1796 } 1728 }
1797 1729
1798 // If the connection succeeds, failed connection attempts leading up to the 1730 // If the connection succeeds, failed connection attempts leading up to the
1799 // success will be returned via the successfully connected socket. If the 1731 // success will be returned via the successfully connected socket. If the
1800 // connection fails, failed connection attempts will be returned via the 1732 // connection fails, failed connection attempts will be returned via the
1801 // ClientSocketHandle. Check whether a socket was returned and copy the 1733 // ClientSocketHandle. Check whether a socket was returned and copy the
1802 // connection attempts from the proper place. 1734 // connection attempts from the proper place.
1803 void HttpStreamFactoryImpl::Job:: 1735 void HttpStreamFactoryImpl::Job::
1804 MaybeCopyConnectionAttemptsFromSocketOrHandle() { 1736 MaybeCopyConnectionAttemptsFromSocketOrHandle() {
1805 if (IsOrphaned() || !connection_) 1737 if (!connection_)
1806 return; 1738 return;
1807 1739
1740 ConnectionAttempts socket_attempts = connection_->connection_attempts();
1808 if (connection_->socket()) { 1741 if (connection_->socket()) {
1809 ConnectionAttempts socket_attempts;
1810 connection_->socket()->GetConnectionAttempts(&socket_attempts); 1742 connection_->socket()->GetConnectionAttempts(&socket_attempts);
1811 request_->AddConnectionAttempts(socket_attempts);
1812 } else {
1813 request_->AddConnectionAttempts(connection_->connection_attempts());
1814 } 1743 }
1744
1745 job_controller_->AddConnectionAttemptsToRequest(this, socket_attempts);
1815 } 1746 }
1816 1747
1817 } // namespace net 1748 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698