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 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 | 109 |
| 110 // Invoked when the |job| finishes pre-connecting sockets. | 110 // Invoked when the |job| finishes pre-connecting sockets. |
| 111 virtual void OnPreconnectsComplete(Job* job) = 0; | 111 virtual void OnPreconnectsComplete(Job* job) = 0; |
| 112 | 112 |
| 113 // Invoked to record connection attempts made by the socket layer to | 113 // Invoked to record connection attempts made by the socket layer to |
| 114 // Request if |job| is associated with Request. | 114 // Request if |job| is associated with Request. |
| 115 virtual void AddConnectionAttemptsToRequest( | 115 virtual void AddConnectionAttemptsToRequest( |
| 116 Job* job, | 116 Job* job, |
| 117 const ConnectionAttempts& attempts) = 0; | 117 const ConnectionAttempts& attempts) = 0; |
| 118 | 118 |
| 119 // Invoked when |job| finishes initiating a connection. | |
| 120 virtual void OnConnectionInitialized(Job* job, int rv) = 0; | |
| 121 | |
| 122 // Return false if |job| can advance to the next state. Otherwise, |job| | |
| 123 // will wait for Job::OnIOComplete() to be called before advancing. | |
| 124 virtual bool ShouldWait(Job* job) const = 0; | |
| 125 | |
| 119 // Called when |job| determines the appropriate |spdy_session_key| for the | 126 // Called when |job| determines the appropriate |spdy_session_key| for the |
| 120 // Request. Note that this does not mean that SPDY is necessarily supported | 127 // Request. Note that this does not mean that SPDY is necessarily supported |
| 121 // for this SpdySessionKey, since we may need to wait for NPN to complete | 128 // for this SpdySessionKey, since we may need to wait for NPN to complete |
| 122 // before knowing if SPDY is available. | 129 // before knowing if SPDY is available. |
| 123 virtual void SetSpdySessionKey(Job* job, | 130 virtual void SetSpdySessionKey(Job* job, |
| 124 const SpdySessionKey& spdy_session_key) = 0; | 131 const SpdySessionKey& spdy_session_key) = 0; |
| 125 | 132 |
| 126 // Remove session from the SpdySessionRequestMap. | 133 // Remove session from the SpdySessionRequestMap. |
| 127 virtual void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) = 0; | 134 virtual void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) = 0; |
| 128 | 135 |
| 129 virtual const BoundNetLog* GetNetLog(Job* job) const = 0; | 136 virtual const BoundNetLog* GetNetLog(Job* job) const = 0; |
| 130 | 137 |
| 131 virtual WebSocketHandshakeStreamBase::CreateHelper* | 138 virtual WebSocketHandshakeStreamBase::CreateHelper* |
| 132 websocket_handshake_stream_create_helper() = 0; | 139 websocket_handshake_stream_create_helper() = 0; |
| 133 | 140 |
| 141 virtual bool main_job_is_blocked() = 0; | |
|
Ryan Hamilton
2016/07/01 00:13:30
Do we need this method? I would think this should
Zhongyi Shi
2016/07/11 23:04:56
Done.
| |
| 142 virtual const base::TimeDelta& wait_time_for_main_job() const = 0; | |
|
Ryan Hamilton
2016/07/01 00:13:30
ditto
Zhongyi Shi
2016/07/11 23:04:57
Removed. Used in the request_unittests. But I have
| |
| 143 virtual void set_wait_time_for_main_job(const base::TimeDelta& delay) = 0; | |
|
Ryan Hamilton
2016/07/01 00:13:30
This needs to be CamelCase, since it's virtual.
Zhongyi Shi
2016/07/11 23:04:56
Done.
| |
| 144 | |
| 134 virtual bool for_websockets() = 0; | 145 virtual bool for_websockets() = 0; |
| 135 }; | 146 }; |
| 136 | 147 |
| 137 // Constructor for non-alternative Job. | 148 // Constructor for non-alternative Job. |
| 138 // Job is owned by |delegate|, hence |delegate| is valid for the | 149 // Job is owned by |delegate|, hence |delegate| is valid for the |
| 139 // lifetime of the Job. | 150 // lifetime of the Job. |
| 140 Job(Delegate* delegate, | 151 Job(Delegate* delegate, |
| 141 JobType job_type, | 152 JobType job_type, |
| 142 HttpNetworkSession* session, | 153 HttpNetworkSession* session, |
| 143 const HttpRequestInfo& request_info, | 154 const HttpRequestInfo& request_info, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 168 // |delegate_| will be notified upon completion. | 179 // |delegate_| will be notified upon completion. |
| 169 virtual void Start(HttpStreamRequest::StreamType stream_type); | 180 virtual void Start(HttpStreamRequest::StreamType stream_type); |
| 170 | 181 |
| 171 // Preconnect will attempt to request |num_streams| sockets from the | 182 // Preconnect will attempt to request |num_streams| sockets from the |
| 172 // appropriate ClientSocketPool. | 183 // appropriate ClientSocketPool. |
| 173 int Preconnect(int num_streams); | 184 int Preconnect(int num_streams); |
| 174 | 185 |
| 175 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); | 186 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); |
| 176 LoadState GetLoadState() const; | 187 LoadState GetLoadState() const; |
| 177 | 188 |
| 178 // Tells |this| to wait for |job| to resume it. | 189 // Tells |this| that |delegate_| has determined it still needs to continue |
| 179 void WaitFor(Job* job); | |
| 180 | |
| 181 // Tells |this| that |job| has determined it still needs to continue | |
| 182 // connecting, so allow |this| to continue after the specified |delay|. If | 190 // connecting, so allow |this| to continue after the specified |delay|. If |
| 183 // this is not called, then |request_| is expected to cancel |this| by | 191 // this is not called, then Request is expected to cancel |this| by |
|
Ryan Hamilton
2016/07/01 00:13:30
The request will not actually cancel the job, righ
| |
| 184 // deleting it. | 192 // deleting it. |
| 185 void Resume(Job* job, const base::TimeDelta& delay); | 193 virtual void Resume(const base::TimeDelta& delay); |
| 186 | 194 |
| 187 // Called to detach |this| Job. May resume the other Job, will disconnect | 195 // Called to detach |this| Job. May resume the other Job, will disconnect |
| 188 // the socket for |this| Job, and notify |delegate| upon completion. | 196 // the socket for |this| Job, and notify |delegate| upon completion. |
| 189 void Orphan(); | 197 void Orphan(); |
| 190 | 198 |
| 191 void SetPriority(RequestPriority priority); | 199 void SetPriority(RequestPriority priority); |
| 192 | 200 |
| 193 RequestPriority priority() const { return priority_; } | 201 RequestPriority priority() const { return priority_; } |
| 194 bool was_npn_negotiated() const; | 202 bool was_npn_negotiated() const; |
| 195 NextProto protocol_negotiated() const; | 203 NextProto protocol_negotiated() const; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 214 void ReportJobSucceededForRequest(); | 222 void ReportJobSucceededForRequest(); |
| 215 | 223 |
| 216 // Marks that the other |job| has completed. | 224 // Marks that the other |job| has completed. |
| 217 virtual void MarkOtherJobComplete(const Job& job); | 225 virtual void MarkOtherJobComplete(const Job& job); |
| 218 | 226 |
| 219 JobType job_type() const { return job_type_; } | 227 JobType job_type() const { return job_type_; } |
| 220 | 228 |
| 221 private: | 229 private: |
| 222 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); | 230 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); |
| 223 | 231 |
| 232 friend class HttpStreamFactoryImplJobPeer; | |
| 233 | |
| 224 enum State { | 234 enum State { |
| 225 STATE_START, | 235 STATE_START, |
| 226 STATE_RESOLVE_PROXY, | 236 STATE_RESOLVE_PROXY, |
| 227 STATE_RESOLVE_PROXY_COMPLETE, | 237 STATE_RESOLVE_PROXY_COMPLETE, |
| 228 | 238 |
| 229 // Note that when Alternate-Protocol says we can connect to an alternate | 239 // Note that when Alternate-Protocol says we can connect to an alternate |
| 230 // port using a different protocol, we have the choice of communicating over | 240 // port using a different protocol, we have the choice of communicating over |
| 231 // the original protocol, or speaking the alternate protocol (currently, | 241 // the original protocol, or speaking the alternate protocol (currently, |
| 232 // only npn-spdy) over an alternate port. For a cold page load, the http | 242 // only npn-spdy) over an alternate port. For a cold page load, the http |
| 233 // connection that delivers the http response that has the | 243 // connection that delivers the http response that has the |
| 234 // Alternate-Protocol header will already be warm. So, blocking the next | 244 // Alternate-Protocol header will already be warm. So, blocking the next |
| 235 // http request on establishing a new npn-spdy connection would incur extra | 245 // http request on establishing a new npn-spdy connection would incur extra |
| 236 // latency. Even if the http connection was not reused, establishing a new | 246 // latency. Even if the http connection was not reused, establishing a new |
| 237 // http connection is typically faster than npn-spdy, since npn-spdy | 247 // http connection is typically faster than npn-spdy, since npn-spdy |
| 238 // requires a SSL handshake. Therefore, we start both the http and the | 248 // requires a SSL handshake. Therefore, we start both the http and the |
| 239 // npn-spdy jobs in parallel. In order not to unnecessarily waste sockets, | 249 // npn-spdy jobs in parallel. In order not to unnecessarily waste sockets, |
| 240 // we have the http job block on the npn-spdy job after proxy resolution. | 250 // we have the http job block on the npn-spdy job after proxy resolution. |
| 241 // The npn-spdy job will Resume() the http job if, in | 251 // The npn-spdy job will Resume() the http job if, in |
| 242 // STATE_INIT_CONNECTION_COMPLETE, it detects an error or does not find an | 252 // STATE_INIT_CONNECTION_COMPLETE, it detects an error or does not find an |
| 243 // existing SpdySession. In that case, the http and npn-spdy jobs will race. | 253 // existing SpdySession. In that case, the http and npn-spdy jobs will race. |
| 244 // When QUIC protocol is used by the npn-spdy job, then http job will wait | 254 // When QUIC protocol is used by the npn-spdy job, then http job will wait |
| 245 // for |wait_time_| when the http job was resumed. | 255 // for |wait_time_| when the http job was resumed. |
| 246 STATE_WAIT_FOR_JOB, | 256 STATE_WAIT, |
| 247 STATE_WAIT_FOR_JOB_COMPLETE, | 257 STATE_WAIT_COMPLETE, |
| 248 | 258 |
| 249 STATE_INIT_CONNECTION, | 259 STATE_INIT_CONNECTION, |
| 250 STATE_INIT_CONNECTION_COMPLETE, | 260 STATE_INIT_CONNECTION_COMPLETE, |
| 251 STATE_WAITING_USER_ACTION, | 261 STATE_WAITING_USER_ACTION, |
| 252 STATE_RESTART_TUNNEL_AUTH, | 262 STATE_RESTART_TUNNEL_AUTH, |
| 253 STATE_RESTART_TUNNEL_AUTH_COMPLETE, | 263 STATE_RESTART_TUNNEL_AUTH_COMPLETE, |
| 254 STATE_CREATE_STREAM, | 264 STATE_CREATE_STREAM, |
| 255 STATE_CREATE_STREAM_COMPLETE, | 265 STATE_CREATE_STREAM_COMPLETE, |
| 256 STATE_DRAIN_BODY_FOR_AUTH_RESTART, | 266 STATE_DRAIN_BODY_FOR_AUTH_RESTART, |
| 257 STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE, | 267 STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 // the Job is not a SPDY alternative job, or if |spdy_session| is null. | 314 // the Job is not a SPDY alternative job, or if |spdy_session| is null. |
| 305 // Returns appropriate error code otherwise. | 315 // Returns appropriate error code otherwise. |
| 306 int CheckAlternativeServiceValidityForOrigin( | 316 int CheckAlternativeServiceValidityForOrigin( |
| 307 base::WeakPtr<SpdySession> spdy_session); | 317 base::WeakPtr<SpdySession> spdy_session); |
| 308 | 318 |
| 309 SpdySessionPool* const spdy_session_pool_; | 319 SpdySessionPool* const spdy_session_pool_; |
| 310 const GURL origin_url_; | 320 const GURL origin_url_; |
| 311 const bool is_spdy_alternative_; | 321 const bool is_spdy_alternative_; |
| 312 }; | 322 }; |
| 313 | 323 |
| 314 // Resume the |this| job after the specified |wait_time_|. | |
| 315 void ResumeAfterDelay(); | |
| 316 | |
| 317 void OnStreamReadyCallback(); | 324 void OnStreamReadyCallback(); |
| 318 void OnBidirectionalStreamImplReadyCallback(); | 325 void OnBidirectionalStreamImplReadyCallback(); |
| 319 void OnWebSocketHandshakeStreamReadyCallback(); | 326 void OnWebSocketHandshakeStreamReadyCallback(); |
| 320 // This callback function is called when a new SPDY session is created. | 327 // This callback function is called when a new SPDY session is created. |
| 321 void OnNewSpdySessionReadyCallback(); | 328 void OnNewSpdySessionReadyCallback(); |
| 322 void OnStreamFailedCallback(int result); | 329 void OnStreamFailedCallback(int result); |
| 323 void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info); | 330 void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info); |
| 324 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info, | 331 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info, |
| 325 HttpAuthController* auth_controller); | 332 HttpAuthController* auth_controller); |
| 326 void OnNeedsClientAuthCallback(SSLCertRequestInfo* cert_info); | 333 void OnNeedsClientAuthCallback(SSLCertRequestInfo* cert_info); |
| 327 void OnHttpsProxyTunnelResponseCallback(const HttpResponseInfo& response_info, | 334 void OnHttpsProxyTunnelResponseCallback(const HttpResponseInfo& response_info, |
| 328 HttpStream* stream); | 335 HttpStream* stream); |
| 329 void OnPreconnectsComplete(); | 336 void OnPreconnectsComplete(); |
| 330 | 337 |
| 331 void OnIOComplete(int result); | 338 void OnIOComplete(int result); |
| 332 int RunLoop(int result); | 339 int RunLoop(int result); |
| 333 int DoLoop(int result); | 340 int DoLoop(int result); |
| 334 int StartInternal(); | 341 int StartInternal(); |
| 342 int DoInitConnectionImpl(); | |
| 335 | 343 |
| 336 // Each of these methods corresponds to a State value. Those with an input | 344 // Each of these methods corresponds to a State value. Those with an input |
| 337 // argument receive the result from the previous state. If a method returns | 345 // argument receive the result from the previous state. If a method returns |
| 338 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the | 346 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the |
| 339 // next state method as the result arg. | 347 // next state method as the result arg. |
| 340 int DoStart(); | 348 int DoStart(); |
| 341 int DoResolveProxy(); | 349 int DoResolveProxy(); |
| 342 int DoResolveProxyComplete(int result); | 350 int DoResolveProxyComplete(int result); |
| 343 int DoWaitForJob(); | 351 int DoWait(); |
| 344 int DoWaitForJobComplete(int result); | 352 int DoWaitComplete(int result); |
| 345 int DoInitConnection(); | 353 int DoInitConnection(); |
| 346 int DoInitConnectionComplete(int result); | 354 int DoInitConnectionComplete(int result); |
| 347 int DoWaitingUserAction(int result); | 355 int DoWaitingUserAction(int result); |
| 348 int DoCreateStream(); | 356 int DoCreateStream(); |
| 349 int DoCreateStreamComplete(int result); | 357 int DoCreateStreamComplete(int result); |
| 350 int DoRestartTunnelAuth(); | 358 int DoRestartTunnelAuth(); |
| 351 int DoRestartTunnelAuthComplete(int result); | 359 int DoRestartTunnelAuthComplete(int result); |
| 352 | 360 |
| 353 // Creates a SpdyHttpStream or a BidirectionalStreamImpl from the given values | 361 // Creates a SpdyHttpStream or a BidirectionalStreamImpl from the given values |
| 354 // and sets to |stream_| or |bidirectional_stream_impl_| respectively. Does | 362 // and sets to |stream_| or |bidirectional_stream_impl_| respectively. Does |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 const AlternativeService alternative_service_; | 458 const AlternativeService alternative_service_; |
| 451 | 459 |
| 452 // AlternativeService for the other Job if this is not an alternative Job. | 460 // AlternativeService for the other Job if this is not an alternative Job. |
| 453 AlternativeService other_job_alternative_service_; | 461 AlternativeService other_job_alternative_service_; |
| 454 | 462 |
| 455 // Unowned. |this| job is owned by |delegate_|. | 463 // Unowned. |this| job is owned by |delegate_|. |
| 456 Delegate* delegate_; | 464 Delegate* delegate_; |
| 457 | 465 |
| 458 JobType job_type_; | 466 JobType job_type_; |
| 459 | 467 |
| 460 // This is the Job we're dependent on. It will notify us if/when it's OK to | |
| 461 // proceed. | |
| 462 Job* blocking_job_; | |
| 463 | |
| 464 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection. | |
| 465 // If |this| is unable to do so, we'll notify |waiting_job_| that it's ok to | |
| 466 // proceed and then race the two Jobs. | |
| 467 Job* waiting_job_; | |
| 468 | |
| 469 base::TimeDelta wait_time_; | |
| 470 | |
| 471 // True if handling a HTTPS request, or using SPDY with SSL | 468 // True if handling a HTTPS request, or using SPDY with SSL |
| 472 bool using_ssl_; | 469 bool using_ssl_; |
| 473 | 470 |
| 474 // True if this network transaction is using SPDY instead of HTTP. | 471 // True if this network transaction is using SPDY instead of HTTP. |
| 475 bool using_spdy_; | 472 bool using_spdy_; |
| 476 | 473 |
| 477 // True if this network transaction is using QUIC instead of HTTP. | 474 // True if this network transaction is using QUIC instead of HTTP. |
| 478 bool using_quic_; | 475 bool using_quic_; |
| 479 QuicStreamRequest quic_request_; | 476 QuicStreamRequest quic_request_; |
| 480 | 477 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 const SSLConfig& server_ssl_config, | 557 const SSLConfig& server_ssl_config, |
| 561 const SSLConfig& proxy_ssl_config, | 558 const SSLConfig& proxy_ssl_config, |
| 562 HostPortPair destination, | 559 HostPortPair destination, |
| 563 GURL origin_url, | 560 GURL origin_url, |
| 564 NetLog* net_log) = 0; | 561 NetLog* net_log) = 0; |
| 565 }; | 562 }; |
| 566 | 563 |
| 567 } // namespace net | 564 } // namespace net |
| 568 | 565 |
| 569 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 566 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| OLD | NEW |