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

Side by Side Diff: net/quic/chromium/quic_stream_factory.cc

Issue 2958133002: Change QuicStreamRequest::Request() to take a preferred QuicVersion so that (Closed)
Patch Set: self review Created 3 years, 5 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/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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 base::WeakPtrFactory<CertVerifierJob> weak_factory_; 319 base::WeakPtrFactory<CertVerifierJob> weak_factory_;
320 320
321 DISALLOW_COPY_AND_ASSIGN(CertVerifierJob); 321 DISALLOW_COPY_AND_ASSIGN(CertVerifierJob);
322 }; 322 };
323 323
324 // Responsible for creating a new QUIC session to the specified server, and 324 // Responsible for creating a new QUIC session to the specified server, and
325 // for notifying any associated requests when complete. 325 // for notifying any associated requests when complete.
326 class QuicStreamFactory::Job { 326 class QuicStreamFactory::Job {
327 public: 327 public:
328 Job(QuicStreamFactory* factory, 328 Job(QuicStreamFactory* factory,
329 const QuicVersion& quic_version,
329 HostResolver* host_resolver, 330 HostResolver* host_resolver,
330 const QuicSessionKey& key, 331 const QuicSessionKey& key,
331 bool was_alternative_service_recently_broken, 332 bool was_alternative_service_recently_broken,
332 int cert_verify_flags, 333 int cert_verify_flags,
333 const NetLogWithSource& net_log); 334 const NetLogWithSource& net_log);
334 335
335 ~Job(); 336 ~Job();
336 337
337 int Run(const CompletionCallback& callback); 338 int Run(const CompletionCallback& callback);
338 339
(...skipping 20 matching lines...) Expand all
359 enum IoState { 360 enum IoState {
360 STATE_NONE, 361 STATE_NONE,
361 STATE_RESOLVE_HOST, 362 STATE_RESOLVE_HOST,
362 STATE_RESOLVE_HOST_COMPLETE, 363 STATE_RESOLVE_HOST_COMPLETE,
363 STATE_CONNECT, 364 STATE_CONNECT,
364 STATE_CONNECT_COMPLETE, 365 STATE_CONNECT_COMPLETE,
365 }; 366 };
366 IoState io_state_; 367 IoState io_state_;
367 368
368 QuicStreamFactory* factory_; 369 QuicStreamFactory* factory_;
370 QuicVersion quic_version_;
369 HostResolver* host_resolver_; 371 HostResolver* host_resolver_;
370 std::unique_ptr<HostResolver::Request> request_; 372 std::unique_ptr<HostResolver::Request> request_;
371 const QuicSessionKey key_; 373 const QuicSessionKey key_;
372 const int cert_verify_flags_; 374 const int cert_verify_flags_;
373 const bool was_alternative_service_recently_broken_; 375 const bool was_alternative_service_recently_broken_;
374 const NetLogWithSource net_log_; 376 const NetLogWithSource net_log_;
375 int num_sent_client_hellos_; 377 int num_sent_client_hellos_;
376 QuicChromiumClientSession* session_; 378 QuicChromiumClientSession* session_;
377 CompletionCallback callback_; 379 CompletionCallback callback_;
378 AddressList address_list_; 380 AddressList address_list_;
379 base::TimeTicks dns_resolution_start_time_; 381 base::TimeTicks dns_resolution_start_time_;
380 base::TimeTicks dns_resolution_end_time_; 382 base::TimeTicks dns_resolution_end_time_;
381 base::WeakPtrFactory<Job> weak_factory_; 383 base::WeakPtrFactory<Job> weak_factory_;
382 DISALLOW_COPY_AND_ASSIGN(Job); 384 DISALLOW_COPY_AND_ASSIGN(Job);
383 }; 385 };
384 386
385 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, 387 QuicStreamFactory::Job::Job(QuicStreamFactory* factory,
388 const QuicVersion& quic_version,
386 HostResolver* host_resolver, 389 HostResolver* host_resolver,
387 const QuicSessionKey& key, 390 const QuicSessionKey& key,
388 bool was_alternative_service_recently_broken, 391 bool was_alternative_service_recently_broken,
389 int cert_verify_flags, 392 int cert_verify_flags,
390 const NetLogWithSource& net_log) 393 const NetLogWithSource& net_log)
391 : io_state_(STATE_RESOLVE_HOST), 394 : io_state_(STATE_RESOLVE_HOST),
392 factory_(factory), 395 factory_(factory),
396 quic_version_(quic_version),
393 host_resolver_(host_resolver), 397 host_resolver_(host_resolver),
394 key_(key), 398 key_(key),
395 cert_verify_flags_(cert_verify_flags), 399 cert_verify_flags_(cert_verify_flags),
396 was_alternative_service_recently_broken_( 400 was_alternative_service_recently_broken_(
397 was_alternative_service_recently_broken), 401 was_alternative_service_recently_broken),
398 net_log_( 402 net_log_(
399 NetLogWithSource::Make(net_log.net_log(), 403 NetLogWithSource::Make(net_log.net_log(),
400 NetLogSourceType::QUIC_STREAM_FACTORY_JOB)), 404 NetLogSourceType::QUIC_STREAM_FACTORY_JOB)),
401 num_sent_client_hellos_(0), 405 num_sent_client_hellos_(0),
402 session_(nullptr), 406 session_(nullptr),
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 505
502 int QuicStreamFactory::Job::DoConnect() { 506 int QuicStreamFactory::Job::DoConnect() {
503 io_state_ = STATE_CONNECT_COMPLETE; 507 io_state_ = STATE_CONNECT_COMPLETE;
504 508
505 bool require_confirmation = factory_->require_confirmation() || 509 bool require_confirmation = factory_->require_confirmation() ||
506 was_alternative_service_recently_broken_; 510 was_alternative_service_recently_broken_;
507 net_log_.BeginEvent( 511 net_log_.BeginEvent(
508 NetLogEventType::QUIC_STREAM_FACTORY_JOB_CONNECT, 512 NetLogEventType::QUIC_STREAM_FACTORY_JOB_CONNECT,
509 NetLog::BoolCallback("require_confirmation", require_confirmation)); 513 NetLog::BoolCallback("require_confirmation", require_confirmation));
510 514
511 int rv = 515 DCHECK_NE(quic_version_, QUIC_VERSION_UNSUPPORTED);
512 factory_->CreateSession(key_, cert_verify_flags_, require_confirmation, 516 int rv = factory_->CreateSession(
513 address_list_, dns_resolution_start_time_, 517 key_, quic_version_, cert_verify_flags_, require_confirmation,
514 dns_resolution_end_time_, net_log_, &session_); 518 address_list_, dns_resolution_start_time_, dns_resolution_end_time_,
519 net_log_, &session_);
515 if (rv != OK) { 520 if (rv != OK) {
516 DCHECK(rv != ERR_IO_PENDING); 521 DCHECK(rv != ERR_IO_PENDING);
517 DCHECK(!session_); 522 DCHECK(!session_);
518 return rv; 523 return rv;
519 } 524 }
520 525
521 if (!session_->connection()->connected()) 526 if (!session_->connection()->connected())
522 return ERR_CONNECTION_CLOSED; 527 return ERR_CONNECTION_CLOSED;
523 528
524 session_->StartReading(); 529 session_->StartReading();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 579
575 QuicStreamRequest::QuicStreamRequest(QuicStreamFactory* factory) 580 QuicStreamRequest::QuicStreamRequest(QuicStreamFactory* factory)
576 : factory_(factory) {} 581 : factory_(factory) {}
577 582
578 QuicStreamRequest::~QuicStreamRequest() { 583 QuicStreamRequest::~QuicStreamRequest() {
579 if (factory_ && !callback_.is_null()) 584 if (factory_ && !callback_.is_null())
580 factory_->CancelRequest(this); 585 factory_->CancelRequest(this);
581 } 586 }
582 587
583 int QuicStreamRequest::Request(const HostPortPair& destination, 588 int QuicStreamRequest::Request(const HostPortPair& destination,
589 QuicVersion quic_version,
584 PrivacyMode privacy_mode, 590 PrivacyMode privacy_mode,
585 int cert_verify_flags, 591 int cert_verify_flags,
586 const GURL& url, 592 const GURL& url,
587 QuicStringPiece method, 593 QuicStringPiece method,
588 const NetLogWithSource& net_log, 594 const NetLogWithSource& net_log,
589 const CompletionCallback& callback) { 595 const CompletionCallback& callback) {
596 DCHECK_NE(quic_version, QUIC_VERSION_UNSUPPORTED);
590 DCHECK(callback_.is_null()); 597 DCHECK(callback_.is_null());
591 DCHECK(factory_); 598 DCHECK(factory_);
592 server_id_ = QuicServerId(HostPortPair::FromURL(url), privacy_mode); 599 server_id_ = QuicServerId(HostPortPair::FromURL(url), privacy_mode);
593 600
594 int rv = factory_->Create(server_id_, destination, cert_verify_flags, url, 601 int rv = factory_->Create(server_id_, destination, quic_version,
595 method, net_log, this); 602 cert_verify_flags, url, method, net_log, this);
596 if (rv == ERR_IO_PENDING) { 603 if (rv == ERR_IO_PENDING) {
597 net_log_ = net_log; 604 net_log_ = net_log;
598 callback_ = callback; 605 callback_ = callback;
599 } else { 606 } else {
600 factory_ = nullptr; 607 factory_ = nullptr;
601 } 608 }
602 if (rv == OK) 609 if (rv == OK)
603 DCHECK(session_); 610 DCHECK(session_);
604 return rv; 611 return rv;
605 } 612 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 session->CanPool(server_id.host(), server_id.privacy_mode())) { 849 session->CanPool(server_id.host(), server_id.privacy_mode())) {
843 return true; 850 return true;
844 } 851 }
845 } 852 }
846 853
847 return false; 854 return false;
848 } 855 }
849 856
850 int QuicStreamFactory::Create(const QuicServerId& server_id, 857 int QuicStreamFactory::Create(const QuicServerId& server_id,
851 const HostPortPair& destination, 858 const HostPortPair& destination,
859 QuicVersion quic_version,
852 int cert_verify_flags, 860 int cert_verify_flags,
853 const GURL& url, 861 const GURL& url,
854 QuicStringPiece method, 862 QuicStringPiece method,
855 const NetLogWithSource& net_log, 863 const NetLogWithSource& net_log,
856 QuicStreamRequest* request) { 864 QuicStreamRequest* request) {
857 if (clock_skew_detector_.ClockSkewDetected(base::TimeTicks::Now(), 865 if (clock_skew_detector_.ClockSkewDetected(base::TimeTicks::Now(),
858 base::Time::Now())) { 866 base::Time::Now())) {
859 while (!active_sessions_.empty()) { 867 while (!active_sessions_.empty()) {
860 QuicChromiumClientSession* session = active_sessions_.begin()->second; 868 QuicChromiumClientSession* session = active_sessions_.begin()->second;
861 OnSessionGoingAway(session); 869 OnSessionGoingAway(session);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 928
921 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_ 929 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_
922 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed. 930 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed.
923 if (!task_runner_) 931 if (!task_runner_)
924 task_runner_ = base::ThreadTaskRunnerHandle::Get().get(); 932 task_runner_ = base::ThreadTaskRunnerHandle::Get().get();
925 933
926 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log)); 934 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log));
927 935
928 QuicSessionKey key(destination, server_id); 936 QuicSessionKey key(destination, server_id);
929 std::unique_ptr<Job> job = base::MakeUnique<Job>( 937 std::unique_ptr<Job> job = base::MakeUnique<Job>(
930 this, host_resolver_, key, WasQuicRecentlyBroken(server_id), 938 this, quic_version, host_resolver_, key, WasQuicRecentlyBroken(server_id),
931 cert_verify_flags, net_log); 939 cert_verify_flags, net_log);
932 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, 940 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete,
933 base::Unretained(this), job.get())); 941 base::Unretained(this), job.get()));
934 if (rv == ERR_IO_PENDING) { 942 if (rv == ERR_IO_PENDING) {
935 job_requests_map_[server_id].insert(request); 943 job_requests_map_[server_id].insert(request);
936 active_jobs_[server_id] = std::move(job); 944 active_jobs_[server_id] = std::move(job);
937 return rv; 945 return rv;
938 } 946 }
939 if (rv == OK) { 947 if (rv == OK) {
940 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty() 948 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty()
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 IPAddress last_address; 1459 IPAddress last_address;
1452 if (http_server_properties_->GetSupportsQuic(&last_address) && 1460 if (http_server_properties_->GetSupportsQuic(&last_address) &&
1453 last_address == local_address_.address()) { 1461 last_address == local_address_.address()) {
1454 require_confirmation_ = false; 1462 require_confirmation_ = false;
1455 } 1463 }
1456 } 1464 }
1457 1465
1458 return OK; 1466 return OK;
1459 } 1467 }
1460 1468
1461 int QuicStreamFactory::CreateSession( 1469 int QuicStreamFactory::CreateSession(const QuicSessionKey& key,
1462 const QuicSessionKey& key, 1470 const QuicVersion& quic_version,
1463 int cert_verify_flags, 1471 int cert_verify_flags,
1464 bool require_confirmation, 1472 bool require_confirmation,
1465 const AddressList& address_list, 1473 const AddressList& address_list,
1466 base::TimeTicks dns_resolution_start_time, 1474 base::TimeTicks dns_resolution_start_time,
1467 base::TimeTicks dns_resolution_end_time, 1475 base::TimeTicks dns_resolution_end_time,
1468 const NetLogWithSource& net_log, 1476 const NetLogWithSource& net_log,
1469 QuicChromiumClientSession** session) { 1477 QuicChromiumClientSession** session) {
1470 TRACE_EVENT0(kNetTracingCategory, "QuicStreamFactory::CreateSession"); 1478 TRACE_EVENT0(kNetTracingCategory, "QuicStreamFactory::CreateSession");
1471 IPEndPoint addr = *address_list.begin(); 1479 IPEndPoint addr = *address_list.begin();
1472 const QuicServerId& server_id = key.server_id(); 1480 const QuicServerId& server_id = key.server_id();
1473 DatagramSocket::BindType bind_type = DatagramSocket::DEFAULT_BIND; 1481 DatagramSocket::BindType bind_type = DatagramSocket::DEFAULT_BIND;
1474 std::unique_ptr<DatagramClientSocket> socket( 1482 std::unique_ptr<DatagramClientSocket> socket(
1475 client_socket_factory_->CreateDatagramClientSocket( 1483 client_socket_factory_->CreateDatagramClientSocket(
1476 bind_type, RandIntCallback(), net_log.net_log(), net_log.source())); 1484 bind_type, RandIntCallback(), net_log.net_log(), net_log.source()));
1477 1485
1478 // Passing in kInvalidNetworkHandle binds socket to default network. 1486 // Passing in kInvalidNetworkHandle binds socket to default network.
1479 int rv = ConfigureSocket(socket.get(), addr, 1487 int rv = ConfigureSocket(socket.get(), addr,
(...skipping 15 matching lines...) Expand all
1495 if (store_server_configs_in_properties_) { 1503 if (store_server_configs_in_properties_) {
1496 server_info = base::MakeUnique<PropertiesBasedQuicServerInfo>( 1504 server_info = base::MakeUnique<PropertiesBasedQuicServerInfo>(
1497 server_id, http_server_properties_); 1505 server_id, http_server_properties_);
1498 } 1506 }
1499 InitializeCachedStateInCryptoConfig(server_id, server_info, &connection_id); 1507 InitializeCachedStateInCryptoConfig(server_id, server_info, &connection_id);
1500 1508
1501 QuicChromiumPacketWriter* writer = new QuicChromiumPacketWriter(socket.get()); 1509 QuicChromiumPacketWriter* writer = new QuicChromiumPacketWriter(socket.get());
1502 QuicConnection* connection = new QuicConnection( 1510 QuicConnection* connection = new QuicConnection(
1503 connection_id, QuicSocketAddress(QuicSocketAddressImpl(addr)), 1511 connection_id, QuicSocketAddress(QuicSocketAddressImpl(addr)),
1504 helper_.get(), alarm_factory_.get(), writer, true /* owns_writer */, 1512 helper_.get(), alarm_factory_.get(), writer, true /* owns_writer */,
1505 Perspective::IS_CLIENT, supported_versions_); 1513 Perspective::IS_CLIENT, {quic_version});
Ryan Hamilton 2017/07/06 13:27:45 Can we get rid of the supported_versions_ member?
1506 connection->set_ping_timeout(ping_timeout_); 1514 connection->set_ping_timeout(ping_timeout_);
1507 connection->SetMaxPacketLength(max_packet_length_); 1515 connection->SetMaxPacketLength(max_packet_length_);
1508 1516
1509 QuicConfig config = config_; 1517 QuicConfig config = config_;
1510 config.set_max_undecryptable_packets(kMaxUndecryptablePackets); 1518 config.set_max_undecryptable_packets(kMaxUndecryptablePackets);
1511 config.SetInitialSessionFlowControlWindowToSend( 1519 config.SetInitialSessionFlowControlWindowToSend(
1512 kQuicSessionMaxRecvWindowSize); 1520 kQuicSessionMaxRecvWindowSize);
1513 config.SetInitialStreamFlowControlWindowToSend(kQuicStreamMaxRecvWindowSize); 1521 config.SetInitialStreamFlowControlWindowToSend(kQuicStreamMaxRecvWindowSize);
1514 config.SetBytesForConnectionIdToSend(0); 1522 config.SetBytesForConnectionIdToSend(0);
1515 ConfigureInitialRttEstimate(server_id, &config); 1523 ConfigureInitialRttEstimate(server_id, &config);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 // Since the session was active, there's no longer an 1721 // Since the session was active, there's no longer an
1714 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP 1722 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP
1715 // job also fails. So to avoid not using QUIC when we otherwise could, we mark 1723 // job also fails. So to avoid not using QUIC when we otherwise could, we mark
1716 // it as recently broken, which means that 0-RTT will be disabled but we'll 1724 // it as recently broken, which means that 0-RTT will be disabled but we'll
1717 // still race. 1725 // still race.
1718 http_server_properties_->MarkAlternativeServiceRecentlyBroken( 1726 http_server_properties_->MarkAlternativeServiceRecentlyBroken(
1719 alternative_service); 1727 alternative_service);
1720 } 1728 }
1721 1729
1722 } // namespace net 1730 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698