Chromium Code Reviews| 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_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 virtual const NetLogWithSource* GetNetLog() const = 0; | 138 virtual const NetLogWithSource* GetNetLog() const = 0; |
| 139 | 139 |
| 140 virtual WebSocketHandshakeStreamBase::CreateHelper* | 140 virtual WebSocketHandshakeStreamBase::CreateHelper* |
| 141 websocket_handshake_stream_create_helper() = 0; | 141 websocket_handshake_stream_create_helper() = 0; |
| 142 | 142 |
| 143 virtual void MaybeSetWaitTimeForMainJob(const base::TimeDelta& delay) = 0; | 143 virtual void MaybeSetWaitTimeForMainJob(const base::TimeDelta& delay) = 0; |
| 144 | 144 |
| 145 virtual bool for_websockets() = 0; | 145 virtual bool for_websockets() = 0; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 // Constructor for non-alternative Job. | 148 // Job is owned by |delegate|, hence |delegate| is valid for the lifetime of |
| 149 // Job is owned by |delegate|, hence |delegate| is valid for the | 149 // the Job. |
| 150 // lifetime of the Job. | 150 // |
| 151 // |alternative_protocol| is the protocol required by Alternative Service, if | |
| 152 // any: | |
| 153 // * |alternative_protocol == kProtoUnknown| means that the Job can pool to an | |
| 154 // existing SpdySession, or bind to a idle TCP socket that might use either | |
| 155 // HTTP/1.1 or HTTP/2. | |
| 156 // * |alternative_protocol == kProtoHTTP2| means that the Job can pool to an | |
| 157 // existing SpdySession, or bind to a idle TCP socket. In the latter case, | |
| 158 // if the socket does not use HTTP/2, then the Job fails. | |
| 159 // * |alternative_protocol == kProtoQUIC| means that the Job can pool to an | |
| 160 // existing QUIC connection or open a new one. | |
| 161 // Note that this can be overwritten by using a QUIC proxy, or by setting | |
|
xunjieli
2017/06/14 18:28:01
Just to be explicit. Could you specify that the QU
Bence
2017/06/14 19:33:30
It's good that you bring it up: in fact it is prox
| |
| 162 // HttpNetworkSession::Params::origins_to_force_quic_on. | |
| 163 // | |
| 164 // If |alternative_proxy_server| is a valid proxy server, then the Job will | |
| 165 // use that instead of using ProxyService for proxy resolution. Further, if | |
| 166 // |alternative_proxy_server| is a valid but bad proxy, then fallback proxies | |
| 167 // are not used. It is illegal to call this constructor with a valid | |
| 168 // |alternative_proxy_server| and an |alternate_protocol| different from | |
| 169 // kProtoUnknown. | |
| 151 Job(Delegate* delegate, | 170 Job(Delegate* delegate, |
| 152 JobType job_type, | 171 JobType job_type, |
| 153 HttpNetworkSession* session, | 172 HttpNetworkSession* session, |
| 154 const HttpRequestInfo& request_info, | 173 const HttpRequestInfo& request_info, |
| 155 RequestPriority priority, | 174 RequestPriority priority, |
| 156 const ProxyInfo& proxy_info, | 175 const ProxyInfo& proxy_info, |
| 157 const SSLConfig& server_ssl_config, | 176 const SSLConfig& server_ssl_config, |
| 158 const SSLConfig& proxy_ssl_config, | 177 const SSLConfig& proxy_ssl_config, |
| 159 HostPortPair destination, | 178 HostPortPair destination, |
| 160 GURL origin_url, | 179 GURL origin_url, |
| 161 bool enable_ip_based_pooling, | 180 NextProto alternative_protocol, |
| 162 NetLog* net_log); | |
| 163 | |
| 164 // Constructor for the alternative Job. The Job is owned by |delegate|, hence | |
| 165 // |delegate| is valid for the lifetime of the Job. If |alternative_service| | |
| 166 // is initialized, then the Job will use the alternative service. On the | |
| 167 // other hand, if |alternative_proxy_server| is a valid proxy server, then the | |
| 168 // job will use that instead of using ProxyService for proxy resolution. | |
| 169 // Further, if |alternative_proxy_server| is a valid but bad proxy, then | |
| 170 // fallback proxies are not used. It is illegal to call this with an | |
| 171 // initialized |alternative_service|, and a valid |alternative_proxy_server|. | |
| 172 Job(Delegate* delegate, | |
| 173 JobType job_type, | |
| 174 HttpNetworkSession* session, | |
| 175 const HttpRequestInfo& request_info, | |
| 176 RequestPriority priority, | |
| 177 const ProxyInfo& proxy_info, | |
| 178 const SSLConfig& server_ssl_config, | |
| 179 const SSLConfig& proxy_ssl_config, | |
| 180 HostPortPair destination, | |
| 181 GURL origin_url, | |
| 182 AlternativeService alternative_service, | |
| 183 const ProxyServer& alternative_proxy_server, | 181 const ProxyServer& alternative_proxy_server, |
| 184 bool enable_ip_based_pooling, | 182 bool enable_ip_based_pooling, |
| 185 NetLog* net_log); | 183 NetLog* net_log); |
| 186 virtual ~Job(); | 184 virtual ~Job(); |
| 187 | 185 |
| 188 // Start initiates the process of creating a new HttpStream. | 186 // Start initiates the process of creating a new HttpStream. |
| 189 // |delegate_| will be notified upon completion. | 187 // |delegate_| will be notified upon completion. |
| 190 void Start(HttpStreamRequest::StreamType stream_type); | 188 void Start(HttpStreamRequest::StreamType stream_type); |
| 191 | 189 |
| 192 // Preconnect will attempt to request |num_streams| sockets from the | 190 // Preconnect will attempt to request |num_streams| sockets from the |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 // Returns the estimated memory usage in bytes. | 222 // Returns the estimated memory usage in bytes. |
| 225 size_t EstimateMemoryUsage() const; | 223 size_t EstimateMemoryUsage() const; |
| 226 | 224 |
| 227 bool is_waiting() const { return next_state_ == STATE_WAIT_COMPLETE; } | 225 bool is_waiting() const { return next_state_ == STATE_WAIT_COMPLETE; } |
| 228 const SSLConfig& server_ssl_config() const; | 226 const SSLConfig& server_ssl_config() const; |
| 229 const SSLConfig& proxy_ssl_config() const; | 227 const SSLConfig& proxy_ssl_config() const; |
| 230 const ProxyInfo& proxy_info() const; | 228 const ProxyInfo& proxy_info() const; |
| 231 | 229 |
| 232 JobType job_type() const { return job_type_; } | 230 JobType job_type() const { return job_type_; } |
| 233 | 231 |
| 234 const AlternativeService alternative_service() const { | |
| 235 return alternative_service_; | |
| 236 } | |
| 237 | |
| 238 const ProxyServer alternative_proxy_server() const { | 232 const ProxyServer alternative_proxy_server() const { |
| 239 return alternative_proxy_server_; | 233 return alternative_proxy_server_; |
| 240 } | 234 } |
| 241 | 235 |
| 242 bool using_existing_quic_session() const { | 236 bool using_existing_quic_session() const { |
| 243 return using_existing_quic_session_; | 237 return using_existing_quic_session_; |
| 244 } | 238 } |
| 245 | 239 |
| 246 bool should_reconsider_proxy() const { return should_reconsider_proxy_; } | 240 bool should_reconsider_proxy() const { return should_reconsider_proxy_; } |
| 247 | 241 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 int SetSpdyHttpStreamOrBidirectionalStreamImpl( | 321 int SetSpdyHttpStreamOrBidirectionalStreamImpl( |
| 328 base::WeakPtr<SpdySession> session, | 322 base::WeakPtr<SpdySession> session, |
| 329 bool direct); | 323 bool direct); |
| 330 | 324 |
| 331 // Returns to STATE_INIT_CONNECTION and resets some state. | 325 // Returns to STATE_INIT_CONNECTION and resets some state. |
| 332 void ReturnToStateInitConnection(bool close_connection); | 326 void ReturnToStateInitConnection(bool close_connection); |
| 333 | 327 |
| 334 // Set the motivation for this request onto the underlying socket. | 328 // Set the motivation for this request onto the underlying socket. |
| 335 void SetSocketMotivation(); | 329 void SetSocketMotivation(); |
| 336 | 330 |
| 337 // Is this a SPDY or QUIC alternative Job? | |
| 338 bool IsSpdyAlternative() const; | |
| 339 bool IsQuicAlternative() const; | |
| 340 | |
| 341 // Sets several fields of |ssl_config| based on the proxy info and other | 331 // Sets several fields of |ssl_config| based on the proxy info and other |
| 342 // factors. | 332 // factors. |
| 343 void InitSSLConfig(SSLConfig* ssl_config, bool is_proxy) const; | 333 void InitSSLConfig(SSLConfig* ssl_config, bool is_proxy) const; |
| 344 | 334 |
| 345 // Retrieve SSLInfo from our SSL Socket. | 335 // Retrieve SSLInfo from our SSL Socket. |
| 346 // This must only be called when we are using an SSLSocket. | 336 // This must only be called when we are using an SSLSocket. |
| 347 void GetSSLInfo(SSLInfo* ssl_info); | 337 void GetSSLInfo(SSLInfo* ssl_info); |
| 348 | 338 |
| 339 // Called in Job constructor: should Job be forced to use QUIC. | |
| 340 static bool ShouldForceQuic(HttpNetworkSession* session, | |
| 341 const HostPortPair& destination, | |
| 342 GURL origin_url, | |
|
xunjieli
2017/06/14 18:28:01
nit: const GURL&
Bence
2017/06/14 19:33:30
Done.
| |
| 343 const ProxyInfo& proxy_info); | |
| 344 | |
| 349 // Called in Job constructor. Use |spdy_session_key_| after construction. | 345 // Called in Job constructor. Use |spdy_session_key_| after construction. |
| 350 SpdySessionKey GetSpdySessionKey() const; | 346 static SpdySessionKey GetSpdySessionKey(bool spdy_session_direct, |
| 347 const ProxyServer& proxy_server, | |
| 348 const GURL& origin_url, | |
| 349 PrivacyMode privacy_mode); | |
| 351 | 350 |
| 352 // Returns true if the current request can use an existing spdy session. | 351 // Returns true if the current request can use an existing spdy session. |
| 353 bool CanUseExistingSpdySession() const; | 352 bool CanUseExistingSpdySession() const; |
| 354 | 353 |
| 355 // Called when we encounter a network error that could be resolved by trying | 354 // Called when we encounter a network error that could be resolved by trying |
| 356 // a new proxy configuration. If there is another proxy configuration to try | 355 // a new proxy configuration. If there is another proxy configuration to try |
| 357 // then this method sets next_state_ appropriately and returns either OK or | 356 // then this method sets next_state_ appropriately and returns either OK or |
| 358 // ERR_IO_PENDING depending on whether or not the new proxy configuration is | 357 // ERR_IO_PENDING depending on whether or not the new proxy configuration is |
| 359 // available synchronously or asynchronously. Otherwise, the given error | 358 // available synchronously or asynchronously. Otherwise, the given error |
| 360 // code is simply returned. | 359 // code is simply returned. |
| 361 int ReconsiderProxyAfterError(int error); | 360 int ReconsiderProxyAfterError(int error); |
| 362 | 361 |
| 363 // Called to handle a certificate error. Stores the certificate in the | 362 // Called to handle a certificate error. Stores the certificate in the |
| 364 // allowed_bad_certs list, and checks if the error can be ignored. Returns | 363 // allowed_bad_certs list, and checks if the error can be ignored. Returns |
| 365 // OK if it can be ignored, or the error code otherwise. | 364 // OK if it can be ignored, or the error code otherwise. |
| 366 int HandleCertificateError(int error); | 365 int HandleCertificateError(int error); |
| 367 | 366 |
| 368 // Called to handle a client certificate request. | 367 // Called to handle a client certificate request. |
| 369 int HandleCertificateRequest(int error); | 368 int HandleCertificateRequest(int error); |
| 370 | 369 |
| 371 // Should we force QUIC for this stream request. | |
| 372 bool ShouldForceQuic() const; | |
| 373 | |
| 374 ClientSocketPoolManager::SocketGroupType GetSocketGroup() const; | 370 ClientSocketPoolManager::SocketGroupType GetSocketGroup() const; |
| 375 | 371 |
| 376 void MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 372 void MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
| 377 | 373 |
| 378 // Record histograms of latency until Connect() completes. | 374 // Record histograms of latency until Connect() completes. |
| 379 static void LogHttpConnectedMetrics(const ClientSocketHandle& handle); | 375 static void LogHttpConnectedMetrics(const ClientSocketHandle& handle); |
| 380 | 376 |
| 381 // Invoked by the transport socket pool after host resolution is complete | 377 // Invoked by the transport socket pool after host resolution is complete |
| 382 // to allow the connection to be aborted, if a matching SPDY session can | 378 // to allow the connection to be aborted, if a matching SPDY session can |
| 383 // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a | 379 // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 406 State next_state_; | 402 State next_state_; |
| 407 | 403 |
| 408 // The server we are trying to reach, could be that of the origin or of the | 404 // The server we are trying to reach, could be that of the origin or of the |
| 409 // alternative service (after applying host mapping rules). | 405 // alternative service (after applying host mapping rules). |
| 410 const HostPortPair destination_; | 406 const HostPortPair destination_; |
| 411 | 407 |
| 412 // The origin url we're trying to reach. This url may be different from the | 408 // The origin url we're trying to reach. This url may be different from the |
| 413 // original request when host mapping rules are set-up. | 409 // original request when host mapping rules are set-up. |
| 414 const GURL origin_url_; | 410 const GURL origin_url_; |
| 415 | 411 |
| 416 // AlternativeService for this Job if this is an alternative Job. | |
| 417 const AlternativeService alternative_service_; | |
| 418 | |
| 419 // Alternative proxy server that should be used by |this| to fetch the | 412 // Alternative proxy server that should be used by |this| to fetch the |
| 420 // request. | 413 // request. |
| 421 const ProxyServer alternative_proxy_server_; | 414 const ProxyServer alternative_proxy_server_; |
| 422 | 415 |
| 423 // Enable pooling to a SpdySession with matching IP and certificate | 416 // Enable pooling to a SpdySession with matching IP and certificate |
| 424 // even if the SpdySessionKey is different. | 417 // even if the SpdySessionKey is different. |
| 425 const bool enable_ip_based_pooling_; | 418 const bool enable_ip_based_pooling_; |
| 426 | 419 |
| 427 // Unowned. |this| job is owned by |delegate_|. | 420 // Unowned. |this| job is owned by |delegate_|. |
| 428 Delegate* const delegate_; | 421 Delegate* const delegate_; |
| 429 | 422 |
| 430 const JobType job_type_; | 423 const JobType job_type_; |
| 431 | 424 |
| 432 // True if handling a HTTPS request. | 425 // True if handling a HTTPS request. |
| 433 const bool using_ssl_; | 426 const bool using_ssl_; |
| 434 | 427 |
| 435 // True if this network transaction is using SPDY instead of HTTP. | 428 // True if Job uses QUIC. |
| 429 const bool using_quic_; | |
| 430 | |
| 431 // True if Alternative Service protocol field requires that HTTP/2 is used. | |
| 432 // In this case, Job fails if it cannot pool to an existing SpdySession and | |
| 433 // the server does not negotiate HTTP/2 on a new socket. | |
| 434 const bool expect_spdy_; | |
| 435 | |
| 436 // True if Job actually uses HTTP/2. | |
| 436 bool using_spdy_; | 437 bool using_spdy_; |
| 437 | 438 |
| 438 // True if this network transaction is using QUIC instead of HTTP. | |
| 439 bool using_quic_; | |
| 440 | |
| 441 // True if this job might succeed with a different proxy config. | 439 // True if this job might succeed with a different proxy config. |
| 442 bool should_reconsider_proxy_; | 440 bool should_reconsider_proxy_; |
| 443 | 441 |
| 444 QuicStreamRequest quic_request_; | 442 QuicStreamRequest quic_request_; |
| 445 | 443 |
| 446 // True if this job used an existing QUIC session. | 444 // True if this job used an existing QUIC session. |
| 447 bool using_existing_quic_session_; | 445 bool using_existing_quic_session_; |
| 448 | 446 |
| 449 // True when the tunnel is in the process of being established - we can't | 447 // True when the tunnel is in the process of being established - we can't |
| 450 // read from the socket until the tunnel is done. | 448 // read from the socket until the tunnel is done. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 HttpStreamFactoryImpl::Job::Delegate* delegate, | 508 HttpStreamFactoryImpl::Job::Delegate* delegate, |
| 511 HttpStreamFactoryImpl::JobType job_type, | 509 HttpStreamFactoryImpl::JobType job_type, |
| 512 HttpNetworkSession* session, | 510 HttpNetworkSession* session, |
| 513 const HttpRequestInfo& request_info, | 511 const HttpRequestInfo& request_info, |
| 514 RequestPriority priority, | 512 RequestPriority priority, |
| 515 const ProxyInfo& proxy_info, | 513 const ProxyInfo& proxy_info, |
| 516 const SSLConfig& server_ssl_config, | 514 const SSLConfig& server_ssl_config, |
| 517 const SSLConfig& proxy_ssl_config, | 515 const SSLConfig& proxy_ssl_config, |
| 518 HostPortPair destination, | 516 HostPortPair destination, |
| 519 GURL origin_url, | 517 GURL origin_url, |
| 520 AlternativeService alternative_service, | 518 NextProto alternative_protocol, |
| 521 bool enable_ip_based_pooling, | 519 bool enable_ip_based_pooling, |
| 522 NetLog* net_log); | 520 NetLog* net_log); |
| 523 | 521 |
| 524 virtual std::unique_ptr<HttpStreamFactoryImpl::Job> CreateAltProxyJob( | 522 virtual std::unique_ptr<HttpStreamFactoryImpl::Job> CreateAltProxyJob( |
| 525 HttpStreamFactoryImpl::Job::Delegate* delegate, | 523 HttpStreamFactoryImpl::Job::Delegate* delegate, |
| 526 HttpStreamFactoryImpl::JobType job_type, | 524 HttpStreamFactoryImpl::JobType job_type, |
| 527 HttpNetworkSession* session, | 525 HttpNetworkSession* session, |
| 528 const HttpRequestInfo& request_info, | 526 const HttpRequestInfo& request_info, |
| 529 RequestPriority priority, | 527 RequestPriority priority, |
| 530 const ProxyInfo& proxy_info, | 528 const ProxyInfo& proxy_info, |
| 531 const SSLConfig& server_ssl_config, | 529 const SSLConfig& server_ssl_config, |
| 532 const SSLConfig& proxy_ssl_config, | 530 const SSLConfig& proxy_ssl_config, |
| 533 HostPortPair destination, | 531 HostPortPair destination, |
| 534 GURL origin_url, | 532 GURL origin_url, |
| 535 const ProxyServer& alternative_proxy_server, | 533 const ProxyServer& alternative_proxy_server, |
| 536 bool enable_ip_based_pooling, | 534 bool enable_ip_based_pooling, |
| 537 NetLog* net_log); | 535 NetLog* net_log); |
| 538 }; | 536 }; |
| 539 | 537 |
| 540 } // namespace net | 538 } // namespace net |
| 541 | 539 |
| 542 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 540 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| OLD | NEW |