| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // |job_controller_| will be notified upon completion. | 74 // |job_controller_| will be notified upon completion. |
| 75 void Start(HttpStreamRequest::StreamType stream_type); | 75 void Start(HttpStreamRequest::StreamType stream_type); |
| 76 | 76 |
| 77 // Preconnect will attempt to request |num_streams| sockets from the | 77 // Preconnect will attempt to request |num_streams| sockets from the |
| 78 // appropriate ClientSocketPool. | 78 // appropriate ClientSocketPool. |
| 79 int Preconnect(int num_streams); | 79 int Preconnect(int num_streams); |
| 80 | 80 |
| 81 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); | 81 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); |
| 82 LoadState GetLoadState() const; | 82 LoadState GetLoadState() const; |
| 83 | 83 |
| 84 // Tells |this| to wait for |job| to resume it. | |
| 85 void WaitFor(Job* job); | |
| 86 | |
| 87 // Tells |this| that |job| has determined it still needs to continue | 84 // Tells |this| that |job| has determined it still needs to continue |
| 88 // connecting, so allow |this| to continue after the specified |delay|. If | 85 // connecting, so allow |this| to continue after the specified |delay|. If |
| 89 // this is not called, then |request_| is expected to cancel |this| by | 86 // this is not called, then |request_| is expected to cancel |this| by |
| 90 // deleting it. | 87 // deleting it. |
| 91 void Resume(Job* job, const base::TimeDelta& delay); | 88 void Resume(const base::TimeDelta& delay); |
| 92 | 89 |
| 93 // Used to detach the Job. | 90 // Used to detach the Job. |
| 94 void Orphan(); | 91 void Orphan(); |
| 95 | 92 |
| 96 void SetPriority(RequestPriority priority); | 93 void SetPriority(RequestPriority priority); |
| 97 | 94 |
| 98 RequestPriority priority() const { return priority_; } | 95 RequestPriority priority() const { return priority_; } |
| 99 bool was_npn_negotiated() const; | 96 bool was_npn_negotiated() const; |
| 100 NextProto protocol_negotiated() const; | 97 NextProto protocol_negotiated() const; |
| 101 bool using_spdy() const; | 98 bool using_spdy() const; |
| 102 const BoundNetLog& net_log() const { return net_log_; } | 99 const BoundNetLog& net_log() const { return net_log_; } |
| 103 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } | 100 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } |
| 104 | 101 |
| 105 HttpStream* ReleaseStream() { return stream_.release(); } | 102 HttpStream* ReleaseStream() { return stream_.release(); } |
| 106 | 103 |
| 107 BidirectionalStreamImpl* ReleaseBidirectionalStream() { | 104 BidirectionalStreamImpl* ReleaseBidirectionalStream() { |
| 108 return bidirectional_stream_impl_.release(); | 105 return bidirectional_stream_impl_.release(); |
| 109 } | 106 } |
| 110 | 107 |
| 111 const SSLConfig& server_ssl_config() const; | 108 const SSLConfig& server_ssl_config() const; |
| 112 const SSLConfig& proxy_ssl_config() const; | 109 const SSLConfig& proxy_ssl_config() const; |
| 113 const ProxyInfo& proxy_info() const; | 110 const ProxyInfo& proxy_info() const; |
| 114 | 111 |
| 115 // Called to indicate that this job succeeded, and some other jobs | 112 // Called to indicate that this job succeeded, and some other jobs |
| 116 // will be orphaned. | 113 // will be orphaned. |
| 117 void ReportJobSucceededForRequest(); | 114 void ReportJobSucceededForRequest(); |
| 118 | 115 |
| 116 // Resume the |this| job after the specified |wait_time_|. |
| 117 void ResumeAfterDelay(); |
| 118 |
| 119 // Marks that the other |job| has completed. | 119 // Marks that the other |job| has completed. |
| 120 void MarkOtherJobComplete(const Job& job); | 120 void MarkOtherJobComplete(const Job& job); |
| 121 | 121 |
| 122 void SetNextState(State state) { next_state_ = state; } |
| 123 |
| 122 JobType job_type() const { return job_type_; } | 124 JobType job_type() const { return job_type_; } |
| 123 | 125 |
| 126 base::TimeDelta wait_time() const { return wait_time_; } |
| 127 |
| 124 private: | 128 private: |
| 125 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); | 129 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); |
| 126 | 130 |
| 127 enum State { | |
| 128 STATE_START, | |
| 129 STATE_RESOLVE_PROXY, | |
| 130 STATE_RESOLVE_PROXY_COMPLETE, | |
| 131 | |
| 132 // Note that when Alternate-Protocol says we can connect to an alternate | |
| 133 // port using a different protocol, we have the choice of communicating over | |
| 134 // the original protocol, or speaking the alternate protocol (currently, | |
| 135 // only npn-spdy) over an alternate port. For a cold page load, the http | |
| 136 // connection that delivers the http response that has the | |
| 137 // Alternate-Protocol header will already be warm. So, blocking the next | |
| 138 // http request on establishing a new npn-spdy connection would incur extra | |
| 139 // latency. Even if the http connection was not reused, establishing a new | |
| 140 // http connection is typically faster than npn-spdy, since npn-spdy | |
| 141 // requires a SSL handshake. Therefore, we start both the http and the | |
| 142 // npn-spdy jobs in parallel. In order not to unnecessarily waste sockets, | |
| 143 // we have the http job block on the npn-spdy job after proxy resolution. | |
| 144 // The npn-spdy job will Resume() the http job if, in | |
| 145 // STATE_INIT_CONNECTION_COMPLETE, it detects an error or does not find an | |
| 146 // existing SpdySession. In that case, the http and npn-spdy jobs will race. | |
| 147 // When QUIC protocol is used by the npn-spdy job, then http job will wait | |
| 148 // for |wait_time_| when the http job was resumed. | |
| 149 STATE_WAIT_FOR_JOB, | |
| 150 STATE_WAIT_FOR_JOB_COMPLETE, | |
| 151 | |
| 152 STATE_INIT_CONNECTION, | |
| 153 STATE_INIT_CONNECTION_COMPLETE, | |
| 154 STATE_WAITING_USER_ACTION, | |
| 155 STATE_RESTART_TUNNEL_AUTH, | |
| 156 STATE_RESTART_TUNNEL_AUTH_COMPLETE, | |
| 157 STATE_CREATE_STREAM, | |
| 158 STATE_CREATE_STREAM_COMPLETE, | |
| 159 STATE_DRAIN_BODY_FOR_AUTH_RESTART, | |
| 160 STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE, | |
| 161 STATE_DONE, | |
| 162 STATE_NONE | |
| 163 }; | |
| 164 | |
| 165 enum JobStatus { | 131 enum JobStatus { |
| 166 STATUS_RUNNING, | 132 STATUS_RUNNING, |
| 167 STATUS_FAILED, | 133 STATUS_FAILED, |
| 168 STATUS_BROKEN, | 134 STATUS_BROKEN, |
| 169 STATUS_SUCCEEDED | 135 STATUS_SUCCEEDED |
| 170 }; | 136 }; |
| 171 | 137 |
| 172 // Wrapper class for SpdySessionPool methods to enforce certificate | 138 // Wrapper class for SpdySessionPool methods to enforce certificate |
| 173 // requirements for SpdySessions. | 139 // requirements for SpdySessions. |
| 174 class ValidSpdySessionPool { | 140 class ValidSpdySessionPool { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 // the Job is not a SPDY alternative job, or if |spdy_session| is null. | 173 // the Job is not a SPDY alternative job, or if |spdy_session| is null. |
| 208 // Returns appropriate error code otherwise. | 174 // Returns appropriate error code otherwise. |
| 209 int CheckAlternativeServiceValidityForOrigin( | 175 int CheckAlternativeServiceValidityForOrigin( |
| 210 base::WeakPtr<SpdySession> spdy_session); | 176 base::WeakPtr<SpdySession> spdy_session); |
| 211 | 177 |
| 212 SpdySessionPool* const spdy_session_pool_; | 178 SpdySessionPool* const spdy_session_pool_; |
| 213 const GURL origin_url_; | 179 const GURL origin_url_; |
| 214 const bool is_spdy_alternative_; | 180 const bool is_spdy_alternative_; |
| 215 }; | 181 }; |
| 216 | 182 |
| 217 // Resume the |this| job after the specified |wait_time_|. | |
| 218 void ResumeAfterDelay(); | |
| 219 | |
| 220 void OnStreamReadyCallback(); | 183 void OnStreamReadyCallback(); |
| 221 void OnBidirectionalStreamImplReadyCallback(); | 184 void OnBidirectionalStreamImplReadyCallback(); |
| 222 void OnWebSocketHandshakeStreamReadyCallback(); | 185 void OnWebSocketHandshakeStreamReadyCallback(); |
| 223 // This callback function is called when a new SPDY session is created. | 186 // This callback function is called when a new SPDY session is created. |
| 224 void OnNewSpdySessionReadyCallback(); | 187 void OnNewSpdySessionReadyCallback(); |
| 225 void OnStreamFailedCallback(int result); | 188 void OnStreamFailedCallback(int result); |
| 226 void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info); | 189 void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info); |
| 227 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info, | 190 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info, |
| 228 HttpAuthController* auth_controller); | 191 HttpAuthController* auth_controller); |
| 229 void OnNeedsClientAuthCallback(SSLCertRequestInfo* cert_info); | 192 void OnNeedsClientAuthCallback(SSLCertRequestInfo* cert_info); |
| 230 void OnHttpsProxyTunnelResponseCallback(const HttpResponseInfo& response_info, | 193 void OnHttpsProxyTunnelResponseCallback(const HttpResponseInfo& response_info, |
| 231 HttpStream* stream); | 194 HttpStream* stream); |
| 232 void OnPreconnectsComplete(); | 195 void OnPreconnectsComplete(); |
| 233 | 196 |
| 234 void OnIOComplete(int result); | 197 void OnIOComplete(int result); |
| 235 int RunLoop(int result); | 198 int RunLoop(int result); |
| 236 int DoLoop(int result); | 199 int DoLoop(int result); |
| 237 int StartInternal(); | 200 int StartInternal(); |
| 238 | 201 |
| 239 // Each of these methods corresponds to a State value. Those with an input | 202 // Each of these methods corresponds to a State value. Those with an input |
| 240 // argument receive the result from the previous state. If a method returns | 203 // argument receive the result from the previous state. If a method returns |
| 241 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the | 204 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the |
| 242 // next state method as the result arg. | 205 // next state method as the result arg. |
| 243 int DoStart(); | 206 int DoStart(); |
| 244 int DoResolveProxy(); | 207 int DoResolveProxy(); |
| 245 int DoResolveProxyComplete(int result); | 208 int DoResolveProxyComplete(int result); |
| 246 int DoWaitForJob(); | |
| 247 int DoWaitForJobComplete(int result); | 209 int DoWaitForJobComplete(int result); |
| 248 int DoInitConnection(); | 210 int DoInitConnection(); |
| 249 int DoInitConnectionComplete(int result); | 211 int DoInitConnectionComplete(int result); |
| 250 int DoWaitingUserAction(int result); | 212 int DoWaitingUserAction(int result); |
| 251 int DoCreateStream(); | 213 int DoCreateStream(); |
| 252 int DoCreateStreamComplete(int result); | 214 int DoCreateStreamComplete(int result); |
| 253 int DoRestartTunnelAuth(); | 215 int DoRestartTunnelAuth(); |
| 254 int DoRestartTunnelAuthComplete(int result); | 216 int DoRestartTunnelAuthComplete(int result); |
| 255 | 217 |
| 256 // Creates a SpdyHttpStream or a BidirectionalStreamImpl from the given values | 218 // Creates a SpdyHttpStream or a BidirectionalStreamImpl from the given values |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 const AlternativeService alternative_service_; | 315 const AlternativeService alternative_service_; |
| 354 | 316 |
| 355 // AlternativeService for the other Job if this is not an alternative Job. | 317 // AlternativeService for the other Job if this is not an alternative Job. |
| 356 AlternativeService other_job_alternative_service_; | 318 AlternativeService other_job_alternative_service_; |
| 357 | 319 |
| 358 // Unowned. |this| job is owned by |job_controller_|. | 320 // Unowned. |this| job is owned by |job_controller_|. |
| 359 JobController* job_controller_; | 321 JobController* job_controller_; |
| 360 | 322 |
| 361 JobType job_type_; | 323 JobType job_type_; |
| 362 | 324 |
| 363 // This is the Job we're dependent on. It will notify us if/when it's OK to | |
| 364 // proceed. | |
| 365 Job* blocking_job_; | |
| 366 | |
| 367 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection. | |
| 368 // If |this| is unable to do so, we'll notify |waiting_job_| that it's ok to | |
| 369 // proceed and then race the two Jobs. | |
| 370 Job* waiting_job_; | |
| 371 | |
| 372 base::TimeDelta wait_time_; | 325 base::TimeDelta wait_time_; |
| 373 | 326 |
| 374 // True if handling a HTTPS request, or using SPDY with SSL | 327 // True if handling a HTTPS request, or using SPDY with SSL |
| 375 bool using_ssl_; | 328 bool using_ssl_; |
| 376 | 329 |
| 377 // True if this network transaction is using SPDY instead of HTTP. | 330 // True if this network transaction is using SPDY instead of HTTP. |
| 378 bool using_spdy_; | 331 bool using_spdy_; |
| 379 | 332 |
| 380 // True if this network transaction is using QUIC instead of HTTP. | 333 // True if this network transaction is using QUIC instead of HTTP. |
| 381 bool using_quic_; | 334 bool using_quic_; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 HttpStreamRequest::StreamType stream_type_; | 383 HttpStreamRequest::StreamType stream_type_; |
| 431 | 384 |
| 432 base::WeakPtrFactory<Job> ptr_factory_; | 385 base::WeakPtrFactory<Job> ptr_factory_; |
| 433 | 386 |
| 434 DISALLOW_COPY_AND_ASSIGN(Job); | 387 DISALLOW_COPY_AND_ASSIGN(Job); |
| 435 }; | 388 }; |
| 436 | 389 |
| 437 } // namespace net | 390 } // namespace net |
| 438 | 391 |
| 439 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 392 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| OLD | NEW |