| OLD | NEW |
| 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/quic/chromium/quic_stream_factory.h" | 5 #include "net/quic/chromium/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 void OnComplete() { | 279 void OnComplete() { |
| 280 UMA_HISTOGRAM_TIMES("Net.QuicSession.CertVerifierJob.CompleteTime", | 280 UMA_HISTOGRAM_TIMES("Net.QuicSession.CertVerifierJob.CompleteTime", |
| 281 base::TimeTicks::Now() - start_time_); | 281 base::TimeTicks::Now() - start_time_); |
| 282 if (!callback_.is_null()) | 282 if (!callback_.is_null()) |
| 283 base::ResetAndReturn(&callback_).Run(OK); | 283 base::ResetAndReturn(&callback_).Run(OK); |
| 284 } | 284 } |
| 285 | 285 |
| 286 const QuicServerId& server_id() const { return server_id_; } | 286 const QuicServerId& server_id() const { return server_id_; } |
| 287 | 287 |
| 288 private: | 288 private: |
| 289 QuicServerId server_id_; | 289 const QuicServerId server_id_; |
| 290 ProofVerifierCallbackImpl* verify_callback_; | 290 ProofVerifierCallbackImpl* verify_callback_; |
| 291 std::unique_ptr<ProofVerifyContext> verify_context_; | 291 std::unique_ptr<ProofVerifyContext> verify_context_; |
| 292 std::unique_ptr<ProofVerifyDetails> verify_details_; | 292 std::unique_ptr<ProofVerifyDetails> verify_details_; |
| 293 std::string verify_error_details_; | 293 std::string verify_error_details_; |
| 294 base::TimeTicks start_time_; | 294 const base::TimeTicks start_time_; |
| 295 const NetLogWithSource net_log_; | 295 const NetLogWithSource net_log_; |
| 296 CompletionCallback callback_; | 296 CompletionCallback callback_; |
| 297 base::WeakPtrFactory<CertVerifierJob> weak_factory_; | 297 base::WeakPtrFactory<CertVerifierJob> weak_factory_; |
| 298 | 298 |
| 299 DISALLOW_COPY_AND_ASSIGN(CertVerifierJob); | 299 DISALLOW_COPY_AND_ASSIGN(CertVerifierJob); |
| 300 }; | 300 }; |
| 301 | 301 |
| 302 // Responsible for creating a new QUIC session to the specified server, and | 302 // Responsible for creating a new QUIC session to the specified server, and |
| 303 // for notifying any associated requests when complete. | 303 // for notifying any associated requests when complete. |
| 304 class QuicStreamFactory::Job { | 304 class QuicStreamFactory::Job { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 321 ~Job(); | 321 ~Job(); |
| 322 | 322 |
| 323 int Run(const CompletionCallback& callback); | 323 int Run(const CompletionCallback& callback); |
| 324 | 324 |
| 325 int DoLoop(int rv); | 325 int DoLoop(int rv); |
| 326 int DoResolveHost(); | 326 int DoResolveHost(); |
| 327 int DoResolveHostComplete(int rv); | 327 int DoResolveHostComplete(int rv); |
| 328 int DoLoadServerInfo(); | 328 int DoLoadServerInfo(); |
| 329 int DoLoadServerInfoComplete(int rv); | 329 int DoLoadServerInfoComplete(int rv); |
| 330 int DoConnect(); | 330 int DoConnect(); |
| 331 int DoResumeConnect(); | |
| 332 int DoConnectComplete(int rv); | 331 int DoConnectComplete(int rv); |
| 333 | 332 |
| 334 void OnIOComplete(int rv); | 333 void OnIOComplete(int rv); |
| 335 | 334 |
| 336 void RunAuxilaryJob(); | 335 void RunAuxilaryJob(); |
| 337 | 336 |
| 338 void Cancel(); | 337 void Cancel(); |
| 339 | 338 |
| 340 void CancelWaitForDataReadyCallback(); | 339 void CancelWaitForDataReadyCallback(); |
| 341 | 340 |
| 342 const QuicSessionKey& key() const { return key_; } | 341 const QuicSessionKey& key() const { return key_; } |
| 343 | 342 |
| 344 base::WeakPtr<Job> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } | 343 base::WeakPtr<Job> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } |
| 345 | 344 |
| 346 private: | 345 private: |
| 347 enum IoState { | 346 enum IoState { |
| 348 STATE_NONE, | 347 STATE_NONE, |
| 349 STATE_RESOLVE_HOST, | 348 STATE_RESOLVE_HOST, |
| 350 STATE_RESOLVE_HOST_COMPLETE, | 349 STATE_RESOLVE_HOST_COMPLETE, |
| 351 STATE_LOAD_SERVER_INFO, | 350 STATE_LOAD_SERVER_INFO, |
| 352 STATE_LOAD_SERVER_INFO_COMPLETE, | 351 STATE_LOAD_SERVER_INFO_COMPLETE, |
| 353 STATE_CONNECT, | 352 STATE_CONNECT, |
| 354 STATE_RESUME_CONNECT, | |
| 355 STATE_CONNECT_COMPLETE, | 353 STATE_CONNECT_COMPLETE, |
| 356 }; | 354 }; |
| 357 IoState io_state_; | 355 IoState io_state_; |
| 358 | 356 |
| 359 QuicStreamFactory* factory_; | 357 QuicStreamFactory* factory_; |
| 360 HostResolver* host_resolver_; | 358 HostResolver* host_resolver_; |
| 361 std::unique_ptr<HostResolver::Request> request_; | 359 std::unique_ptr<HostResolver::Request> request_; |
| 362 QuicSessionKey key_; | 360 const QuicSessionKey key_; |
| 363 int cert_verify_flags_; | 361 const int cert_verify_flags_; |
| 364 bool was_alternative_service_recently_broken_; | 362 const bool was_alternative_service_recently_broken_; |
| 365 std::unique_ptr<QuicServerInfo> server_info_; | 363 std::unique_ptr<QuicServerInfo> server_info_; |
| 366 bool started_another_job_; | 364 bool started_another_job_; |
| 367 const NetLogWithSource net_log_; | 365 const NetLogWithSource net_log_; |
| 368 int num_sent_client_hellos_; | 366 int num_sent_client_hellos_; |
| 369 QuicChromiumClientSession* session_; | 367 QuicChromiumClientSession* session_; |
| 370 CompletionCallback callback_; | 368 CompletionCallback callback_; |
| 371 AddressList address_list_; | 369 AddressList address_list_; |
| 372 base::TimeTicks dns_resolution_start_time_; | 370 base::TimeTicks dns_resolution_start_time_; |
| 373 base::TimeTicks dns_resolution_end_time_; | 371 base::TimeTicks dns_resolution_end_time_; |
| 374 base::WeakPtrFactory<Job> weak_factory_; | 372 base::WeakPtrFactory<Job> weak_factory_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 389 cert_verify_flags_(cert_verify_flags), | 387 cert_verify_flags_(cert_verify_flags), |
| 390 was_alternative_service_recently_broken_( | 388 was_alternative_service_recently_broken_( |
| 391 was_alternative_service_recently_broken), | 389 was_alternative_service_recently_broken), |
| 392 server_info_(std::move(server_info)), | 390 server_info_(std::move(server_info)), |
| 393 started_another_job_(false), | 391 started_another_job_(false), |
| 394 net_log_(net_log), | 392 net_log_(net_log), |
| 395 num_sent_client_hellos_(0), | 393 num_sent_client_hellos_(0), |
| 396 session_(nullptr), | 394 session_(nullptr), |
| 397 weak_factory_(this) {} | 395 weak_factory_(this) {} |
| 398 | 396 |
| 399 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, | |
| 400 HostResolver* host_resolver, | |
| 401 QuicChromiumClientSession* session, | |
| 402 const QuicSessionKey& key) | |
| 403 : io_state_(STATE_RESUME_CONNECT), | |
| 404 factory_(factory), | |
| 405 host_resolver_(host_resolver), // unused | |
| 406 key_(key), | |
| 407 cert_verify_flags_(0), // unused | |
| 408 was_alternative_service_recently_broken_(false), // unused | |
| 409 started_another_job_(false), // unused | |
| 410 net_log_(session->net_log()), // unused | |
| 411 num_sent_client_hellos_(0), | |
| 412 session_(session), | |
| 413 weak_factory_(this) {} | |
| 414 | |
| 415 QuicStreamFactory::Job::~Job() { | 397 QuicStreamFactory::Job::~Job() { |
| 416 DCHECK(callback_.is_null()); | 398 DCHECK(callback_.is_null()); |
| 417 | 399 |
| 418 // If disk cache has a pending WaitForDataReadyCallback, cancel that callback. | 400 // If disk cache has a pending WaitForDataReadyCallback, cancel that callback. |
| 419 if (server_info_) | 401 if (server_info_) |
| 420 server_info_->ResetWaitForDataReadyCallback(); | 402 server_info_->ResetWaitForDataReadyCallback(); |
| 421 } | 403 } |
| 422 | 404 |
| 423 int QuicStreamFactory::Job::Run(const CompletionCallback& callback) { | 405 int QuicStreamFactory::Job::Run(const CompletionCallback& callback) { |
| 424 int rv = DoLoop(OK); | 406 int rv = DoLoop(OK); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 445 CHECK_EQ(OK, rv); | 427 CHECK_EQ(OK, rv); |
| 446 rv = DoLoadServerInfo(); | 428 rv = DoLoadServerInfo(); |
| 447 break; | 429 break; |
| 448 case STATE_LOAD_SERVER_INFO_COMPLETE: | 430 case STATE_LOAD_SERVER_INFO_COMPLETE: |
| 449 rv = DoLoadServerInfoComplete(rv); | 431 rv = DoLoadServerInfoComplete(rv); |
| 450 break; | 432 break; |
| 451 case STATE_CONNECT: | 433 case STATE_CONNECT: |
| 452 CHECK_EQ(OK, rv); | 434 CHECK_EQ(OK, rv); |
| 453 rv = DoConnect(); | 435 rv = DoConnect(); |
| 454 break; | 436 break; |
| 455 case STATE_RESUME_CONNECT: | |
| 456 CHECK_EQ(OK, rv); | |
| 457 rv = DoResumeConnect(); | |
| 458 break; | |
| 459 case STATE_CONNECT_COMPLETE: | 437 case STATE_CONNECT_COMPLETE: |
| 460 rv = DoConnectComplete(rv); | 438 rv = DoConnectComplete(rv); |
| 461 break; | 439 break; |
| 462 default: | 440 default: |
| 463 NOTREACHED() << "io_state_: " << io_state_; | 441 NOTREACHED() << "io_state_: " << io_state_; |
| 464 break; | 442 break; |
| 465 } | 443 } |
| 466 } while (io_state_ != STATE_NONE && rv != ERR_IO_PENDING); | 444 } while (io_state_ != STATE_NONE && rv != ERR_IO_PENDING); |
| 467 return rv; | 445 return rv; |
| 468 } | 446 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); | 592 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); |
| 615 | 593 |
| 616 if (!session_->connection()->connected() && | 594 if (!session_->connection()->connected() && |
| 617 session_->error() == QUIC_PROOF_INVALID) { | 595 session_->error() == QUIC_PROOF_INVALID) { |
| 618 return ERR_QUIC_HANDSHAKE_FAILED; | 596 return ERR_QUIC_HANDSHAKE_FAILED; |
| 619 } | 597 } |
| 620 | 598 |
| 621 return rv; | 599 return rv; |
| 622 } | 600 } |
| 623 | 601 |
| 624 int QuicStreamFactory::Job::DoResumeConnect() { | |
| 625 io_state_ = STATE_CONNECT_COMPLETE; | |
| 626 | |
| 627 int rv = session_->ResumeCryptoConnect( | |
| 628 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); | |
| 629 | |
| 630 return rv; | |
| 631 } | |
| 632 | |
| 633 int QuicStreamFactory::Job::DoConnectComplete(int rv) { | 602 int QuicStreamFactory::Job::DoConnectComplete(int rv) { |
| 634 if (session_ && session_->error() == QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { | 603 if (session_ && session_->error() == QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { |
| 635 num_sent_client_hellos_ += session_->GetNumSentClientHellos(); | 604 num_sent_client_hellos_ += session_->GetNumSentClientHellos(); |
| 636 if (num_sent_client_hellos_ >= QuicCryptoClientStream::kMaxClientHellos) | 605 if (num_sent_client_hellos_ >= QuicCryptoClientStream::kMaxClientHellos) |
| 637 return ERR_QUIC_HANDSHAKE_FAILED; | 606 return ERR_QUIC_HANDSHAKE_FAILED; |
| 638 // The handshake was rejected statelessly, so create another connection | 607 // The handshake was rejected statelessly, so create another connection |
| 639 // to resume the handshake. | 608 // to resume the handshake. |
| 640 io_state_ = STATE_CONNECT; | 609 io_state_ = STATE_CONNECT; |
| 641 return OK; | 610 return OK; |
| 642 } | 611 } |
| (...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1985 void QuicStreamFactory::OpenFactory() { | 1954 void QuicStreamFactory::OpenFactory() { |
| 1986 status_ = OPEN; | 1955 status_ = OPEN; |
| 1987 } | 1956 } |
| 1988 | 1957 |
| 1989 void QuicStreamFactory::MaybeClearConsecutiveDisabledCount() { | 1958 void QuicStreamFactory::MaybeClearConsecutiveDisabledCount() { |
| 1990 if (status_ == OPEN) | 1959 if (status_ == OPEN) |
| 1991 consecutive_disabled_count_ = 0; | 1960 consecutive_disabled_count_ = 0; |
| 1992 } | 1961 } |
| 1993 | 1962 |
| 1994 } // namespace net | 1963 } // namespace net |
| OLD | NEW |