| 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 #ifndef NET_QUIC_QUIC_STREAM_FACTORY_H_ | 5 #ifndef NET_QUIC_QUIC_STREAM_FACTORY_H_ |
| 6 #define NET_QUIC_QUIC_STREAM_FACTORY_H_ | 6 #define NET_QUIC_QUIC_STREAM_FACTORY_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 // |cert_verify_flags| is bitwise OR'd of CertVerifier::VerifyFlags and it is | 103 // |cert_verify_flags| is bitwise OR'd of CertVerifier::VerifyFlags and it is |
| 104 // passed to CertVerifier::Verify. | 104 // passed to CertVerifier::Verify. |
| 105 // |destination| will be resolved and resulting IPEndPoint used to open a | 105 // |destination| will be resolved and resulting IPEndPoint used to open a |
| 106 // QuicConnection. This can be different than HostPortPair::FromURL(url). | 106 // QuicConnection. This can be different than HostPortPair::FromURL(url). |
| 107 int Request(const HostPortPair& destination, | 107 int Request(const HostPortPair& destination, |
| 108 PrivacyMode privacy_mode, | 108 PrivacyMode privacy_mode, |
| 109 int cert_verify_flags, | 109 int cert_verify_flags, |
| 110 const GURL& url, | 110 const GURL& url, |
| 111 base::StringPiece method, | 111 base::StringPiece method, |
| 112 const BoundNetLog& net_log, | 112 const NetLogWithSource& net_log, |
| 113 const CompletionCallback& callback); | 113 const CompletionCallback& callback); |
| 114 | 114 |
| 115 void OnRequestComplete(int rv); | 115 void OnRequestComplete(int rv); |
| 116 | 116 |
| 117 // Helper method that calls |factory_|'s GetTimeDelayForWaitingJob(). It | 117 // Helper method that calls |factory_|'s GetTimeDelayForWaitingJob(). It |
| 118 // returns the amount of time waiting job should be delayed. | 118 // returns the amount of time waiting job should be delayed. |
| 119 base::TimeDelta GetTimeDelayForWaitingJob() const; | 119 base::TimeDelta GetTimeDelayForWaitingJob() const; |
| 120 | 120 |
| 121 std::unique_ptr<QuicHttpStream> CreateStream(); | 121 std::unique_ptr<QuicHttpStream> CreateStream(); |
| 122 | 122 |
| 123 std::unique_ptr<BidirectionalStreamImpl> CreateBidirectionalStreamImpl(); | 123 std::unique_ptr<BidirectionalStreamImpl> CreateBidirectionalStreamImpl(); |
| 124 | 124 |
| 125 // Sets |session_|. | 125 // Sets |session_|. |
| 126 void SetSession(QuicChromiumClientSession* session); | 126 void SetSession(QuicChromiumClientSession* session); |
| 127 | 127 |
| 128 const QuicServerId& server_id() const { return server_id_; } | 128 const QuicServerId& server_id() const { return server_id_; } |
| 129 | 129 |
| 130 const BoundNetLog& net_log() const { return net_log_; } | 130 const NetLogWithSource& net_log() const { return net_log_; } |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 QuicStreamFactory* factory_; | 133 QuicStreamFactory* factory_; |
| 134 QuicServerId server_id_; | 134 QuicServerId server_id_; |
| 135 BoundNetLog net_log_; | 135 NetLogWithSource net_log_; |
| 136 CompletionCallback callback_; | 136 CompletionCallback callback_; |
| 137 base::WeakPtr<QuicChromiumClientSession> session_; | 137 base::WeakPtr<QuicChromiumClientSession> session_; |
| 138 | 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(QuicStreamRequest); | 139 DISALLOW_COPY_AND_ASSIGN(QuicStreamRequest); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 // A factory for creating new QuicHttpStreams on top of a pool of | 142 // A factory for creating new QuicHttpStreams on top of a pool of |
| 143 // QuicChromiumClientSessions. | 143 // QuicChromiumClientSessions. |
| 144 class NET_EXPORT_PRIVATE QuicStreamFactory | 144 class NET_EXPORT_PRIVATE QuicStreamFactory |
| 145 : public NetworkChangeNotifier::IPAddressObserver, | 145 : public NetworkChangeNotifier::IPAddressObserver, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 // Creates a new QuicHttpStream to |host_port_pair| which will be | 225 // Creates a new QuicHttpStream to |host_port_pair| which will be |
| 226 // owned by |request|. | 226 // owned by |request|. |
| 227 // If a matching session already exists, this method will return OK. If no | 227 // If a matching session already exists, this method will return OK. If no |
| 228 // matching session exists, this will return ERR_IO_PENDING and will invoke | 228 // matching session exists, this will return ERR_IO_PENDING and will invoke |
| 229 // OnRequestComplete asynchronously. | 229 // OnRequestComplete asynchronously. |
| 230 int Create(const QuicServerId& server_id, | 230 int Create(const QuicServerId& server_id, |
| 231 const HostPortPair& destination, | 231 const HostPortPair& destination, |
| 232 int cert_verify_flags, | 232 int cert_verify_flags, |
| 233 const GURL& url, | 233 const GURL& url, |
| 234 base::StringPiece method, | 234 base::StringPiece method, |
| 235 const BoundNetLog& net_log, | 235 const NetLogWithSource& net_log, |
| 236 QuicStreamRequest* request); | 236 QuicStreamRequest* request); |
| 237 | 237 |
| 238 // Called when the handshake for |session| is confirmed. If QUIC is disabled | 238 // Called when the handshake for |session| is confirmed. If QUIC is disabled |
| 239 // currently disabled, then it closes the connection and returns true. | 239 // currently disabled, then it closes the connection and returns true. |
| 240 bool OnHandshakeConfirmed(QuicChromiumClientSession* session); | 240 bool OnHandshakeConfirmed(QuicChromiumClientSession* session); |
| 241 | 241 |
| 242 // Called when a TCP job completes for an origin that QUIC potentially | 242 // Called when a TCP job completes for an origin that QUIC potentially |
| 243 // could be used for. | 243 // could be used for. |
| 244 void OnTcpJobCompleted(bool succeeded); | 244 void OnTcpJobCompleted(bool succeeded); |
| 245 | 245 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 // are left unchanged. Sessions with non-migratable streams are closed | 292 // are left unchanged. Sessions with non-migratable streams are closed |
| 293 // if |close_if_cannot_migrate| is true, and continue using their current | 293 // if |close_if_cannot_migrate| is true, and continue using their current |
| 294 // network otherwise. | 294 // network otherwise. |
| 295 // | 295 // |
| 296 // If |new_network| is NetworkChangeNotifier::kInvalidNetworkHandle, | 296 // If |new_network| is NetworkChangeNotifier::kInvalidNetworkHandle, |
| 297 // there is no new network to migrate sessions onto, and all sessions are | 297 // there is no new network to migrate sessions onto, and all sessions are |
| 298 // closed. | 298 // closed. |
| 299 void MaybeMigrateOrCloseSessions( | 299 void MaybeMigrateOrCloseSessions( |
| 300 NetworkChangeNotifier::NetworkHandle new_network, | 300 NetworkChangeNotifier::NetworkHandle new_network, |
| 301 bool close_if_cannot_migrate, | 301 bool close_if_cannot_migrate, |
| 302 const BoundNetLog& bound_net_log); | 302 const NetLogWithSource& net_log); |
| 303 | 303 |
| 304 // Method that initiates migration of |session| if |session| is | 304 // Method that initiates migration of |session| if |session| is |
| 305 // active and if there is an alternate network than the one to which | 305 // active and if there is an alternate network than the one to which |
| 306 // |session| is currently bound. | 306 // |session| is currently bound. |
| 307 MigrationResult MaybeMigrateSingleSession(QuicChromiumClientSession* session, | 307 MigrationResult MaybeMigrateSingleSession(QuicChromiumClientSession* session, |
| 308 MigrationCause migration_cause); | 308 MigrationCause migration_cause); |
| 309 | 309 |
| 310 // Migrates |session| over to using |network|. If |network| is | 310 // Migrates |session| over to using |network|. If |network| is |
| 311 // kInvalidNetworkHandle, default network is used. | 311 // kInvalidNetworkHandle, default network is used. |
| 312 MigrationResult MigrateSessionToNewNetwork( | 312 MigrationResult MigrateSessionToNewNetwork( |
| 313 QuicChromiumClientSession* session, | 313 QuicChromiumClientSession* session, |
| 314 NetworkChangeNotifier::NetworkHandle network, | 314 NetworkChangeNotifier::NetworkHandle network, |
| 315 bool close_session_on_error, | 315 bool close_session_on_error, |
| 316 const BoundNetLog& bound_net_log); | 316 const NetLogWithSource& net_log); |
| 317 | 317 |
| 318 // Migrates |session| over to using |peer_address|. Causes a PING frame | 318 // Migrates |session| over to using |peer_address|. Causes a PING frame |
| 319 // to be sent to the new peer address. | 319 // to be sent to the new peer address. |
| 320 void MigrateSessionToNewPeerAddress(QuicChromiumClientSession* session, | 320 void MigrateSessionToNewPeerAddress(QuicChromiumClientSession* session, |
| 321 IPEndPoint peer_address, | 321 IPEndPoint peer_address, |
| 322 const BoundNetLog& bound_net_log); | 322 const NetLogWithSource& net_log); |
| 323 | 323 |
| 324 // NetworkChangeNotifier::IPAddressObserver methods: | 324 // NetworkChangeNotifier::IPAddressObserver methods: |
| 325 | 325 |
| 326 // Until the servers support roaming, close all connections when the local | 326 // Until the servers support roaming, close all connections when the local |
| 327 // IP address changes. | 327 // IP address changes. |
| 328 void OnIPAddressChanged() override; | 328 void OnIPAddressChanged() override; |
| 329 | 329 |
| 330 // NetworkChangeNotifier::NetworkObserver methods: | 330 // NetworkChangeNotifier::NetworkObserver methods: |
| 331 void OnNetworkConnected( | 331 void OnNetworkConnected( |
| 332 NetworkChangeNotifier::NetworkHandle network) override; | 332 NetworkChangeNotifier::NetworkHandle network) override; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 enum FactoryStatus { | 406 enum FactoryStatus { |
| 407 OPEN, // New streams may be created. | 407 OPEN, // New streams may be created. |
| 408 CLOSED, // No new streams may be created temporarily. | 408 CLOSED, // No new streams may be created temporarily. |
| 409 DISABLED // No more streams may be created until the network changes. | 409 DISABLED // No more streams may be created until the network changes. |
| 410 }; | 410 }; |
| 411 | 411 |
| 412 // Creates a job which doesn't wait for server config to be loaded from the | 412 // Creates a job which doesn't wait for server config to be loaded from the |
| 413 // disk cache. This job is started via a PostTask. | 413 // disk cache. This job is started via a PostTask. |
| 414 void CreateAuxilaryJob(const QuicSessionKey& key, | 414 void CreateAuxilaryJob(const QuicSessionKey& key, |
| 415 int cert_verify_flags, | 415 int cert_verify_flags, |
| 416 const BoundNetLog& net_log); | 416 const NetLogWithSource& net_log); |
| 417 | 417 |
| 418 // Returns a newly created QuicHttpStream owned by the caller. | 418 // Returns a newly created QuicHttpStream owned by the caller. |
| 419 std::unique_ptr<QuicHttpStream> CreateFromSession( | 419 std::unique_ptr<QuicHttpStream> CreateFromSession( |
| 420 QuicChromiumClientSession* session); | 420 QuicChromiumClientSession* session); |
| 421 | 421 |
| 422 bool OnResolution(const QuicSessionKey& key, const AddressList& address_list); | 422 bool OnResolution(const QuicSessionKey& key, const AddressList& address_list); |
| 423 void OnJobComplete(Job* job, int rv); | 423 void OnJobComplete(Job* job, int rv); |
| 424 void OnCertVerifyJobComplete(CertVerifierJob* job, int rv); | 424 void OnCertVerifyJobComplete(CertVerifierJob* job, int rv); |
| 425 bool HasActiveSession(const QuicServerId& server_id) const; | 425 bool HasActiveSession(const QuicServerId& server_id) const; |
| 426 bool HasActiveJob(const QuicServerId& server_id) const; | 426 bool HasActiveJob(const QuicServerId& server_id) const; |
| 427 bool HasActiveCertVerifierJob(const QuicServerId& server_id) const; | 427 bool HasActiveCertVerifierJob(const QuicServerId& server_id) const; |
| 428 int CreateSession(const QuicSessionKey& key, | 428 int CreateSession(const QuicSessionKey& key, |
| 429 int cert_verify_flags, | 429 int cert_verify_flags, |
| 430 std::unique_ptr<QuicServerInfo> quic_server_info, | 430 std::unique_ptr<QuicServerInfo> quic_server_info, |
| 431 const AddressList& address_list, | 431 const AddressList& address_list, |
| 432 base::TimeTicks dns_resolution_start_time, | 432 base::TimeTicks dns_resolution_start_time, |
| 433 base::TimeTicks dns_resolution_end_time, | 433 base::TimeTicks dns_resolution_end_time, |
| 434 const BoundNetLog& net_log, | 434 const NetLogWithSource& net_log, |
| 435 QuicChromiumClientSession** session); | 435 QuicChromiumClientSession** session); |
| 436 void ActivateSession(const QuicSessionKey& key, | 436 void ActivateSession(const QuicSessionKey& key, |
| 437 QuicChromiumClientSession* session); | 437 QuicChromiumClientSession* session); |
| 438 | 438 |
| 439 // Returns |srtt| in micro seconds from ServerNetworkStats. Returns 0 if there | 439 // Returns |srtt| in micro seconds from ServerNetworkStats. Returns 0 if there |
| 440 // is no |http_server_properties_| or if |http_server_properties_| doesn't | 440 // is no |http_server_properties_| or if |http_server_properties_| doesn't |
| 441 // have ServerNetworkStats for the given |server_id|. | 441 // have ServerNetworkStats for the given |server_id|. |
| 442 int64_t GetServerNetworkStatsSmoothedRttInMicroseconds( | 442 int64_t GetServerNetworkStatsSmoothedRttInMicroseconds( |
| 443 const QuicServerId& server_id) const; | 443 const QuicServerId& server_id) const; |
| 444 | 444 |
| 445 // Helper methods. | 445 // Helper methods. |
| 446 bool WasQuicRecentlyBroken(const QuicServerId& server_id) const; | 446 bool WasQuicRecentlyBroken(const QuicServerId& server_id) const; |
| 447 | 447 |
| 448 bool CryptoConfigCacheIsEmpty(const QuicServerId& server_id); | 448 bool CryptoConfigCacheIsEmpty(const QuicServerId& server_id); |
| 449 | 449 |
| 450 // Starts an asynchronous job for cert verification if | 450 // Starts an asynchronous job for cert verification if |
| 451 // |race_cert_verification_| is enabled and if there are cached certs for the | 451 // |race_cert_verification_| is enabled and if there are cached certs for the |
| 452 // given |server_id|. | 452 // given |server_id|. |
| 453 QuicAsyncStatus StartCertVerifyJob(const QuicServerId& server_id, | 453 QuicAsyncStatus StartCertVerifyJob(const QuicServerId& server_id, |
| 454 int cert_verify_flags, | 454 int cert_verify_flags, |
| 455 const BoundNetLog& net_log); | 455 const NetLogWithSource& net_log); |
| 456 | 456 |
| 457 // Initializes the cached state associated with |server_id| in | 457 // Initializes the cached state associated with |server_id| in |
| 458 // |crypto_config_| with the information in |server_info|. Populates | 458 // |crypto_config_| with the information in |server_info|. Populates |
| 459 // |connection_id| with the next server designated connection id, | 459 // |connection_id| with the next server designated connection id, |
| 460 // if any, and otherwise leaves it unchanged. | 460 // if any, and otherwise leaves it unchanged. |
| 461 void InitializeCachedStateInCryptoConfig( | 461 void InitializeCachedStateInCryptoConfig( |
| 462 const QuicServerId& server_id, | 462 const QuicServerId& server_id, |
| 463 const std::unique_ptr<QuicServerInfo>& server_info, | 463 const std::unique_ptr<QuicServerInfo>& server_info, |
| 464 QuicConnectionId* connection_id); | 464 QuicConnectionId* connection_id); |
| 465 | 465 |
| 466 // Initialize |quic_supported_servers_at_startup_| with the list of servers | 466 // Initialize |quic_supported_servers_at_startup_| with the list of servers |
| 467 // that supported QUIC at start up and also initialize in-memory cache of | 467 // that supported QUIC at start up and also initialize in-memory cache of |
| 468 // QuicServerInfo objects from HttpServerProperties. | 468 // QuicServerInfo objects from HttpServerProperties. |
| 469 void MaybeInitialize(); | 469 void MaybeInitialize(); |
| 470 | 470 |
| 471 void ProcessGoingAwaySession(QuicChromiumClientSession* session, | 471 void ProcessGoingAwaySession(QuicChromiumClientSession* session, |
| 472 const QuicServerId& server_id, | 472 const QuicServerId& server_id, |
| 473 bool was_session_active); | 473 bool was_session_active); |
| 474 | 474 |
| 475 // Internal method that migrates |session| over to using | 475 // Internal method that migrates |session| over to using |
| 476 // |peer_address| and |network|. If |network| is | 476 // |peer_address| and |network|. If |network| is |
| 477 // kInvalidNetworkHandle, default network is used. If the migration | 477 // kInvalidNetworkHandle, default network is used. If the migration |
| 478 // fails and |close_session_on_error| is true, connection is closed. | 478 // fails and |close_session_on_error| is true, connection is closed. |
| 479 MigrationResult MigrateSessionInner( | 479 MigrationResult MigrateSessionInner( |
| 480 QuicChromiumClientSession* session, | 480 QuicChromiumClientSession* session, |
| 481 IPEndPoint peer_address, | 481 IPEndPoint peer_address, |
| 482 NetworkChangeNotifier::NetworkHandle network, | 482 NetworkChangeNotifier::NetworkHandle network, |
| 483 bool close_session_on_error, | 483 bool close_session_on_error, |
| 484 const BoundNetLog& bound_net_log); | 484 const NetLogWithSource& net_log); |
| 485 | 485 |
| 486 // Called to re-enable QUIC when QUIC has been disabled. | 486 // Called to re-enable QUIC when QUIC has been disabled. |
| 487 void OpenFactory(); | 487 void OpenFactory(); |
| 488 // If QUIC has been working well after having been recently | 488 // If QUIC has been working well after having been recently |
| 489 // disabled, clear the |consecutive_disabled_count_|. | 489 // disabled, clear the |consecutive_disabled_count_|. |
| 490 void MaybeClearConsecutiveDisabledCount(); | 490 void MaybeClearConsecutiveDisabledCount(); |
| 491 | 491 |
| 492 bool require_confirmation_; | 492 bool require_confirmation_; |
| 493 NetLog* net_log_; | 493 NetLog* net_log_; |
| 494 HostResolver* host_resolver_; | 494 HostResolver* host_resolver_; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 const scoped_refptr<SSLConfigService> ssl_config_service_; | 647 const scoped_refptr<SSLConfigService> ssl_config_service_; |
| 648 | 648 |
| 649 base::WeakPtrFactory<QuicStreamFactory> weak_factory_; | 649 base::WeakPtrFactory<QuicStreamFactory> weak_factory_; |
| 650 | 650 |
| 651 DISALLOW_COPY_AND_ASSIGN(QuicStreamFactory); | 651 DISALLOW_COPY_AND_ASSIGN(QuicStreamFactory); |
| 652 }; | 652 }; |
| 653 | 653 |
| 654 } // namespace net | 654 } // namespace net |
| 655 | 655 |
| 656 #endif // NET_QUIC_QUIC_STREAM_FACTORY_H_ | 656 #endif // NET_QUIC_QUIC_STREAM_FACTORY_H_ |
| OLD | NEW |