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

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

Powered by Google App Engine
This is Rietveld 408576698