| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 108 |
| 109 // Invoked when the |job| finishes pre-connecting sockets. | 109 // Invoked when the |job| finishes pre-connecting sockets. |
| 110 virtual void OnPreconnectsComplete(Job* job) = 0; | 110 virtual void OnPreconnectsComplete(Job* job) = 0; |
| 111 | 111 |
| 112 // Invoked to record connection attempts made by the socket layer to | 112 // Invoked to record connection attempts made by the socket layer to |
| 113 // Request if |job| is associated with Request. | 113 // Request if |job| is associated with Request. |
| 114 virtual void AddConnectionAttemptsToRequest( | 114 virtual void AddConnectionAttemptsToRequest( |
| 115 Job* job, | 115 Job* job, |
| 116 const ConnectionAttempts& attempts) = 0; | 116 const ConnectionAttempts& attempts) = 0; |
| 117 | 117 |
| 118 // Invoked when |job| finishes initiating a connection. |
| 119 virtual void OnConnectionInitialized(Job* job, int rv) = 0; |
| 120 |
| 121 // Return false if |job| can advance to the next state. Otherwise, |job| |
| 122 // will wait for Job::Resume() to be called before advancing. |
| 123 virtual bool ShouldWait(Job* job) = 0; |
| 124 |
| 118 // Called when |job| determines the appropriate |spdy_session_key| for the | 125 // Called when |job| determines the appropriate |spdy_session_key| for the |
| 119 // Request. Note that this does not mean that SPDY is necessarily supported | 126 // Request. Note that this does not mean that SPDY is necessarily supported |
| 120 // for this SpdySessionKey, since we may need to wait for NPN to complete | 127 // for this SpdySessionKey, since we may need to wait for NPN to complete |
| 121 // before knowing if SPDY is available. | 128 // before knowing if SPDY is available. |
| 122 virtual void SetSpdySessionKey(Job* job, | 129 virtual void SetSpdySessionKey(Job* job, |
| 123 const SpdySessionKey& spdy_session_key) = 0; | 130 const SpdySessionKey& spdy_session_key) = 0; |
| 124 | 131 |
| 125 // Remove session from the SpdySessionRequestMap. | 132 // Remove session from the SpdySessionRequestMap. |
| 126 virtual void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) = 0; | 133 virtual void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) = 0; |
| 127 | 134 |
| 128 virtual const BoundNetLog* GetNetLog(Job* job) const = 0; | 135 virtual const BoundNetLog* GetNetLog(Job* job) const = 0; |
| 129 | 136 |
| 130 virtual WebSocketHandshakeStreamBase::CreateHelper* | 137 virtual WebSocketHandshakeStreamBase::CreateHelper* |
| 131 websocket_handshake_stream_create_helper() = 0; | 138 websocket_handshake_stream_create_helper() = 0; |
| 132 | 139 |
| 140 virtual void MaybeSetWaitTimeForMainJob(const base::TimeDelta& delay) = 0; |
| 141 |
| 133 virtual bool for_websockets() = 0; | 142 virtual bool for_websockets() = 0; |
| 134 }; | 143 }; |
| 135 | 144 |
| 136 // Constructor for non-alternative Job. | 145 // Constructor for non-alternative Job. |
| 137 // Job is owned by |delegate|, hence |delegate| is valid for the | 146 // Job is owned by |delegate|, hence |delegate| is valid for the |
| 138 // lifetime of the Job. | 147 // lifetime of the Job. |
| 139 Job(Delegate* delegate, | 148 Job(Delegate* delegate, |
| 140 JobType job_type, | 149 JobType job_type, |
| 141 HttpNetworkSession* session, | 150 HttpNetworkSession* session, |
| 142 const HttpRequestInfo& request_info, | 151 const HttpRequestInfo& request_info, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 158 const SSLConfig& server_ssl_config, | 167 const SSLConfig& server_ssl_config, |
| 159 const SSLConfig& proxy_ssl_config, | 168 const SSLConfig& proxy_ssl_config, |
| 160 HostPortPair destination, | 169 HostPortPair destination, |
| 161 GURL origin_url, | 170 GURL origin_url, |
| 162 AlternativeService alternative_service, | 171 AlternativeService alternative_service, |
| 163 NetLog* net_log); | 172 NetLog* net_log); |
| 164 virtual ~Job(); | 173 virtual ~Job(); |
| 165 | 174 |
| 166 // Start initiates the process of creating a new HttpStream. | 175 // Start initiates the process of creating a new HttpStream. |
| 167 // |delegate_| will be notified upon completion. | 176 // |delegate_| will be notified upon completion. |
| 168 virtual void Start(HttpStreamRequest::StreamType stream_type); | 177 void Start(HttpStreamRequest::StreamType stream_type); |
| 169 | 178 |
| 170 // Preconnect will attempt to request |num_streams| sockets from the | 179 // Preconnect will attempt to request |num_streams| sockets from the |
| 171 // appropriate ClientSocketPool. | 180 // appropriate ClientSocketPool. |
| 172 int Preconnect(int num_streams); | 181 int Preconnect(int num_streams); |
| 173 | 182 |
| 174 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); | 183 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); |
| 175 LoadState GetLoadState() const; | 184 LoadState GetLoadState() const; |
| 176 | 185 |
| 177 // Tells |this| to wait for |job| to resume it. | 186 // Tells |this| that |delegate_| has determined it still needs to continue |
| 178 void WaitFor(Job* job); | 187 // connecting. |
| 179 | 188 virtual void Resume(); |
| 180 // Tells |this| that |job| has determined it still needs to continue | |
| 181 // connecting, so allow |this| to continue after the specified |delay|. If | |
| 182 // this is not called, then |request_| is expected to cancel |this| by | |
| 183 // deleting it. | |
| 184 void Resume(Job* job, const base::TimeDelta& delay); | |
| 185 | 189 |
| 186 // Called to detach |this| Job. May resume the other Job, will disconnect | 190 // Called to detach |this| Job. May resume the other Job, will disconnect |
| 187 // the socket for |this| Job, and notify |delegate| upon completion. | 191 // the socket for |this| Job, and notify |delegate| upon completion. |
| 188 void Orphan(); | 192 void Orphan(); |
| 189 | 193 |
| 190 void SetPriority(RequestPriority priority); | 194 void SetPriority(RequestPriority priority); |
| 191 | 195 |
| 192 RequestPriority priority() const { return priority_; } | 196 RequestPriority priority() const { return priority_; } |
| 193 bool was_npn_negotiated() const; | 197 bool was_npn_negotiated() const; |
| 194 NextProto protocol_negotiated() const; | 198 NextProto protocol_negotiated() const; |
| 195 bool using_spdy() const; | 199 bool using_spdy() const; |
| 196 const BoundNetLog& net_log() const { return net_log_; } | 200 const BoundNetLog& net_log() const { return net_log_; } |
| 197 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } | 201 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } |
| 198 | 202 |
| 199 std::unique_ptr<HttpStream> ReleaseStream() { return std::move(stream_); } | 203 std::unique_ptr<HttpStream> ReleaseStream() { return std::move(stream_); } |
| 200 | 204 |
| 201 void SetStream(HttpStream* http_stream) { stream_.reset(http_stream); } | 205 void SetStream(HttpStream* http_stream) { stream_.reset(http_stream); } |
| 202 | 206 |
| 203 std::unique_ptr<BidirectionalStreamImpl> ReleaseBidirectionalStream() { | 207 std::unique_ptr<BidirectionalStreamImpl> ReleaseBidirectionalStream() { |
| 204 return std::move(bidirectional_stream_impl_); | 208 return std::move(bidirectional_stream_impl_); |
| 205 } | 209 } |
| 206 | 210 |
| 211 bool is_waiting() const { return next_state_ == STATE_WAIT_COMPLETE; } |
| 207 const SSLConfig& server_ssl_config() const; | 212 const SSLConfig& server_ssl_config() const; |
| 208 const SSLConfig& proxy_ssl_config() const; | 213 const SSLConfig& proxy_ssl_config() const; |
| 209 const ProxyInfo& proxy_info() const; | 214 const ProxyInfo& proxy_info() const; |
| 210 | 215 |
| 211 // Called to indicate that this job succeeded, and some other jobs | 216 // Called to indicate that this job succeeded, and some other jobs |
| 212 // will be orphaned. | 217 // will be orphaned. |
| 213 void ReportJobSucceededForRequest(); | 218 void ReportJobSucceededForRequest(); |
| 214 | 219 |
| 215 // Marks that the other |job| has completed. | 220 // Marks that the other |job| has completed. |
| 216 virtual void MarkOtherJobComplete(const Job& job); | 221 virtual void MarkOtherJobComplete(const Job& job); |
| 217 | 222 |
| 218 JobType job_type() const { return job_type_; } | 223 JobType job_type() const { return job_type_; } |
| 219 | 224 |
| 220 private: | 225 private: |
| 221 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); | 226 friend class HttpStreamFactoryImplJobPeer; |
| 222 | 227 |
| 223 enum State { | 228 enum State { |
| 224 STATE_START, | 229 STATE_START, |
| 225 STATE_RESOLVE_PROXY, | 230 STATE_RESOLVE_PROXY, |
| 226 STATE_RESOLVE_PROXY_COMPLETE, | 231 STATE_RESOLVE_PROXY_COMPLETE, |
| 227 | 232 |
| 228 // Note that when Alternate-Protocol says we can connect to an alternate | 233 // Note that when Alternate-Protocol says we can connect to an alternate |
| 229 // port using a different protocol, we have the choice of communicating over | 234 // port using a different protocol, we have the choice of communicating over |
| 230 // the original protocol, or speaking the alternate protocol (currently, | 235 // the original protocol, or speaking the alternate protocol (currently, |
| 231 // only npn-spdy) over an alternate port. For a cold page load, the http | 236 // only npn-spdy) over an alternate port. For a cold page load, the http |
| 232 // connection that delivers the http response that has the | 237 // connection that delivers the http response that has the |
| 233 // Alternate-Protocol header will already be warm. So, blocking the next | 238 // Alternate-Protocol header will already be warm. So, blocking the next |
| 234 // http request on establishing a new npn-spdy connection would incur extra | 239 // http request on establishing a new npn-spdy connection would incur extra |
| 235 // latency. Even if the http connection was not reused, establishing a new | 240 // latency. Even if the http connection was not reused, establishing a new |
| 236 // http connection is typically faster than npn-spdy, since npn-spdy | 241 // http connection is typically faster than npn-spdy, since npn-spdy |
| 237 // requires a SSL handshake. Therefore, we start both the http and the | 242 // requires a SSL handshake. Therefore, we start both the http and the |
| 238 // npn-spdy jobs in parallel. In order not to unnecessarily waste sockets, | 243 // npn-spdy jobs in parallel. In order not to unnecessarily waste sockets, |
| 239 // we have the http job block on the npn-spdy job after proxy resolution. | 244 // we have the http job block on the npn-spdy job after proxy resolution. |
| 240 // The npn-spdy job will Resume() the http job if, in | 245 // The npn-spdy job will Resume() the http job if, in |
| 241 // STATE_INIT_CONNECTION_COMPLETE, it detects an error or does not find an | 246 // STATE_INIT_CONNECTION_COMPLETE, it detects an error or does not find an |
| 242 // existing SpdySession. In that case, the http and npn-spdy jobs will race. | 247 // existing SpdySession. In that case, the http and npn-spdy jobs will race. |
| 243 // When QUIC protocol is used by the npn-spdy job, then http job will wait | 248 // When QUIC protocol is used by the npn-spdy job, then http job will wait |
| 244 // for |wait_time_| when the http job was resumed. | 249 // for |wait_time_| when the http job was resumed. |
| 245 STATE_WAIT_FOR_JOB, | 250 STATE_WAIT, |
| 246 STATE_WAIT_FOR_JOB_COMPLETE, | 251 STATE_WAIT_COMPLETE, |
| 247 | 252 |
| 248 STATE_INIT_CONNECTION, | 253 STATE_INIT_CONNECTION, |
| 249 STATE_INIT_CONNECTION_COMPLETE, | 254 STATE_INIT_CONNECTION_COMPLETE, |
| 250 STATE_WAITING_USER_ACTION, | 255 STATE_WAITING_USER_ACTION, |
| 251 STATE_RESTART_TUNNEL_AUTH, | 256 STATE_RESTART_TUNNEL_AUTH, |
| 252 STATE_RESTART_TUNNEL_AUTH_COMPLETE, | 257 STATE_RESTART_TUNNEL_AUTH_COMPLETE, |
| 253 STATE_CREATE_STREAM, | 258 STATE_CREATE_STREAM, |
| 254 STATE_CREATE_STREAM_COMPLETE, | 259 STATE_CREATE_STREAM_COMPLETE, |
| 255 STATE_DRAIN_BODY_FOR_AUTH_RESTART, | 260 STATE_DRAIN_BODY_FOR_AUTH_RESTART, |
| 256 STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE, | 261 STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE, |
| 257 STATE_DONE, | 262 STATE_DONE, |
| 258 STATE_NONE | 263 STATE_NONE |
| 259 }; | 264 }; |
| 260 | 265 |
| 261 enum JobStatus { | 266 enum JobStatus { |
| 262 STATUS_RUNNING, | 267 STATUS_RUNNING, |
| 263 STATUS_FAILED, | 268 STATUS_FAILED, |
| 264 STATUS_BROKEN, | 269 STATUS_BROKEN, |
| 265 STATUS_SUCCEEDED | 270 STATUS_SUCCEEDED |
| 266 }; | 271 }; |
| 267 | 272 |
| 268 // Resume the |this| job after the specified |wait_time_|. | |
| 269 void ResumeAfterDelay(); | |
| 270 | |
| 271 void OnStreamReadyCallback(); | 273 void OnStreamReadyCallback(); |
| 272 void OnBidirectionalStreamImplReadyCallback(); | 274 void OnBidirectionalStreamImplReadyCallback(); |
| 273 void OnWebSocketHandshakeStreamReadyCallback(); | 275 void OnWebSocketHandshakeStreamReadyCallback(); |
| 274 // This callback function is called when a new SPDY session is created. | 276 // This callback function is called when a new SPDY session is created. |
| 275 void OnNewSpdySessionReadyCallback(); | 277 void OnNewSpdySessionReadyCallback(); |
| 276 void OnStreamFailedCallback(int result); | 278 void OnStreamFailedCallback(int result); |
| 277 void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info); | 279 void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info); |
| 278 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info, | 280 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info, |
| 279 HttpAuthController* auth_controller); | 281 HttpAuthController* auth_controller); |
| 280 void OnNeedsClientAuthCallback(SSLCertRequestInfo* cert_info); | 282 void OnNeedsClientAuthCallback(SSLCertRequestInfo* cert_info); |
| 281 void OnHttpsProxyTunnelResponseCallback(const HttpResponseInfo& response_info, | 283 void OnHttpsProxyTunnelResponseCallback(const HttpResponseInfo& response_info, |
| 282 HttpStream* stream); | 284 HttpStream* stream); |
| 283 void OnPreconnectsComplete(); | 285 void OnPreconnectsComplete(); |
| 284 | 286 |
| 285 void OnIOComplete(int result); | 287 void OnIOComplete(int result); |
| 286 int RunLoop(int result); | 288 int RunLoop(int result); |
| 287 int DoLoop(int result); | 289 int DoLoop(int result); |
| 288 int StartInternal(); | 290 int StartInternal(); |
| 291 int DoInitConnectionImpl(); |
| 289 | 292 |
| 290 // Each of these methods corresponds to a State value. Those with an input | 293 // Each of these methods corresponds to a State value. Those with an input |
| 291 // argument receive the result from the previous state. If a method returns | 294 // argument receive the result from the previous state. If a method returns |
| 292 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the | 295 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the |
| 293 // next state method as the result arg. | 296 // next state method as the result arg. |
| 294 int DoStart(); | 297 int DoStart(); |
| 295 int DoResolveProxy(); | 298 int DoResolveProxy(); |
| 296 int DoResolveProxyComplete(int result); | 299 int DoResolveProxyComplete(int result); |
| 297 int DoWaitForJob(); | 300 int DoWait(); |
| 298 int DoWaitForJobComplete(int result); | 301 int DoWaitComplete(int result); |
| 299 int DoInitConnection(); | 302 int DoInitConnection(); |
| 300 int DoInitConnectionComplete(int result); | 303 int DoInitConnectionComplete(int result); |
| 301 int DoWaitingUserAction(int result); | 304 int DoWaitingUserAction(int result); |
| 302 int DoCreateStream(); | 305 int DoCreateStream(); |
| 303 int DoCreateStreamComplete(int result); | 306 int DoCreateStreamComplete(int result); |
| 304 int DoRestartTunnelAuth(); | 307 int DoRestartTunnelAuth(); |
| 305 int DoRestartTunnelAuthComplete(int result); | 308 int DoRestartTunnelAuthComplete(int result); |
| 306 | 309 |
| 307 // Creates a SpdyHttpStream or a BidirectionalStreamImpl from the given values | 310 // Creates a SpdyHttpStream or a BidirectionalStreamImpl from the given values |
| 308 // and sets to |stream_| or |bidirectional_stream_impl_| respectively. Does | 311 // and sets to |stream_| or |bidirectional_stream_impl_| respectively. Does |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 const AlternativeService alternative_service_; | 407 const AlternativeService alternative_service_; |
| 405 | 408 |
| 406 // AlternativeService for the other Job if this is not an alternative Job. | 409 // AlternativeService for the other Job if this is not an alternative Job. |
| 407 AlternativeService other_job_alternative_service_; | 410 AlternativeService other_job_alternative_service_; |
| 408 | 411 |
| 409 // Unowned. |this| job is owned by |delegate_|. | 412 // Unowned. |this| job is owned by |delegate_|. |
| 410 Delegate* delegate_; | 413 Delegate* delegate_; |
| 411 | 414 |
| 412 JobType job_type_; | 415 JobType job_type_; |
| 413 | 416 |
| 414 // This is the Job we're dependent on. It will notify us if/when it's OK to | |
| 415 // proceed. | |
| 416 Job* blocking_job_; | |
| 417 | |
| 418 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection. | |
| 419 // If |this| is unable to do so, we'll notify |waiting_job_| that it's ok to | |
| 420 // proceed and then race the two Jobs. | |
| 421 Job* waiting_job_; | |
| 422 | |
| 423 base::TimeDelta wait_time_; | |
| 424 | |
| 425 // True if handling a HTTPS request, or using SPDY with SSL | 417 // True if handling a HTTPS request, or using SPDY with SSL |
| 426 bool using_ssl_; | 418 bool using_ssl_; |
| 427 | 419 |
| 428 // True if this network transaction is using SPDY instead of HTTP. | 420 // True if this network transaction is using SPDY instead of HTTP. |
| 429 bool using_spdy_; | 421 bool using_spdy_; |
| 430 | 422 |
| 431 // True if this network transaction is using QUIC instead of HTTP. | 423 // True if this network transaction is using QUIC instead of HTTP. |
| 432 bool using_quic_; | 424 bool using_quic_; |
| 433 QuicStreamRequest quic_request_; | 425 QuicStreamRequest quic_request_; |
| 434 | 426 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 const SSLConfig& server_ssl_config, | 504 const SSLConfig& server_ssl_config, |
| 513 const SSLConfig& proxy_ssl_config, | 505 const SSLConfig& proxy_ssl_config, |
| 514 HostPortPair destination, | 506 HostPortPair destination, |
| 515 GURL origin_url, | 507 GURL origin_url, |
| 516 NetLog* net_log) = 0; | 508 NetLog* net_log) = 0; |
| 517 }; | 509 }; |
| 518 | 510 |
| 519 } // namespace net | 511 } // namespace net |
| 520 | 512 |
| 521 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 513 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| OLD | NEW |