| 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" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 15 #include "net/base/net_export.h" |
| 15 #include "net/base/request_priority.h" | 16 #include "net/base/request_priority.h" |
| 16 #include "net/http/http_auth.h" | 17 #include "net/http/http_auth.h" |
| 17 #include "net/http/http_auth_controller.h" | 18 #include "net/http/http_auth_controller.h" |
| 18 #include "net/http/http_request_info.h" | 19 #include "net/http/http_request_info.h" |
| 19 #include "net/http/http_stream_factory_impl.h" | 20 #include "net/http/http_stream_factory_impl.h" |
| 20 #include "net/log/net_log.h" | 21 #include "net/log/net_log.h" |
| 21 #include "net/proxy/proxy_service.h" | 22 #include "net/proxy/proxy_service.h" |
| 22 #include "net/quic/quic_stream_factory.h" | 23 #include "net/quic/quic_stream_factory.h" |
| 23 #include "net/socket/client_socket_handle.h" | 24 #include "net/socket/client_socket_handle.h" |
| 24 #include "net/socket/client_socket_pool_manager.h" | 25 #include "net/socket/client_socket_pool_manager.h" |
| 25 #include "net/socket/ssl_client_socket.h" | 26 #include "net/socket/ssl_client_socket.h" |
| 26 #include "net/spdy/spdy_session_key.h" | 27 #include "net/spdy/spdy_session_key.h" |
| 27 #include "net/ssl/ssl_config_service.h" | 28 #include "net/ssl/ssl_config_service.h" |
| 28 | 29 |
| 29 namespace net { | 30 namespace net { |
| 30 | 31 |
| 31 class BidirectionalStreamImpl; | 32 class BidirectionalStreamImpl; |
| 32 class ClientSocketHandle; | 33 class ClientSocketHandle; |
| 33 class HttpAuthController; | 34 class HttpAuthController; |
| 34 class HttpNetworkSession; | 35 class HttpNetworkSession; |
| 35 class HttpStream; | 36 class HttpStream; |
| 36 class SpdySessionPool; | 37 class SpdySessionPool; |
| 37 class QuicHttpStream; | 38 class QuicHttpStream; |
| 39 class TestJobControllerPeer; |
| 38 | 40 |
| 39 // An HttpStreamRequestImpl exists for each stream which is in progress of being | 41 // An HttpStreamRequestImpl exists for each stream which is in progress of being |
| 40 // created for the StreamFactory. | 42 // created for the StreamFactory. |
| 41 class HttpStreamFactoryImpl::Job { | 43 class HttpStreamFactoryImpl::Job { |
| 42 public: | 44 public: |
| 45 class NET_EXPORT_PRIVATE Delegate { |
| 46 public: |
| 47 virtual ~Delegate() {} |
| 48 |
| 49 virtual void OnStreamReady(Job* job, |
| 50 const SSLConfig& used_ssl_config, |
| 51 const ProxyInfo& used_proxy_info) = 0; |
| 52 |
| 53 virtual void OnBidirectionalStreamImplReady( |
| 54 Job* job, |
| 55 const SSLConfig& used_ssl_config, |
| 56 const ProxyInfo& used_proxy_info) = 0; |
| 57 virtual void OnWebSocketHandshakeStreamReady( |
| 58 Job* job, |
| 59 const SSLConfig& used_ssl_config, |
| 60 const ProxyInfo& used_proxy_info, |
| 61 WebSocketHandshakeStreamBase* stream) = 0; |
| 62 |
| 63 virtual void OnStreamFailed(Job* job, |
| 64 int status, |
| 65 const SSLConfig& used_ssl_config, |
| 66 SSLFailureState ssl_failure_state) = 0; |
| 67 |
| 68 virtual void OnCertificateError(Job* job, |
| 69 int status, |
| 70 const SSLConfig& used_ssl_config, |
| 71 const SSLInfo& ssl_info) = 0; |
| 72 |
| 73 virtual void OnHttpsProxyTunnelResponse( |
| 74 Job* job, |
| 75 const HttpResponseInfo& response_info, |
| 76 const SSLConfig& used_ssl_config, |
| 77 const ProxyInfo& used_proxy_info, |
| 78 HttpStream* stream) = 0; |
| 79 |
| 80 virtual void OnNeedsClientAuth(Job* job, |
| 81 const SSLConfig& used_ssl_config, |
| 82 SSLCertRequestInfo* cert_info) = 0; |
| 83 |
| 84 virtual void OnNeedsProxyAuth(Job* job, |
| 85 const HttpResponseInfo& proxy_response, |
| 86 const SSLConfig& used_ssl_config, |
| 87 const ProxyInfo& used_proxy_info, |
| 88 HttpAuthController* auth_controller) = 0; |
| 89 |
| 90 // Invoked to notify the Request and Factory of the readiness of new |
| 91 // SPDY session. |
| 92 virtual void OnNewSpdySessionReady( |
| 93 Job* job, |
| 94 const base::WeakPtr<SpdySession>& spdy_session, |
| 95 bool direct) = 0; |
| 96 |
| 97 // Invoked when the orphaned |job| finishes. |
| 98 virtual void OnOrphanedJobComplete(const Job* job) = 0; |
| 99 |
| 100 // Invoked when the |job| finishes pre-connecting sockets. |
| 101 virtual void OnPreconnectsComplete(Job* job) = 0; |
| 102 |
| 103 // Invoked to record connection attempts made by the socket layer to |
| 104 // Request if |job| is associated with Request. |
| 105 virtual void AddConnectionAttemptsToRequest( |
| 106 Job* job, |
| 107 const ConnectionAttempts& attempts) = 0; |
| 108 |
| 109 // Called when |job| determines the appropriate |spdy_session_key| for the |
| 110 // Request. Note that this does not mean that SPDY is necessarily supported |
| 111 // for this SpdySessionKey, since we may need to wait for NPN to complete |
| 112 // before knowing if SPDY is available. |
| 113 virtual void SetSpdySessionKey(Job* job, |
| 114 const SpdySessionKey& spdy_session_key) = 0; |
| 115 |
| 116 // Remove session from the SpdySessionRequestMap. |
| 117 virtual void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) = 0; |
| 118 |
| 119 virtual const BoundNetLog* GetNetLog(Job* job) const = 0; |
| 120 |
| 121 virtual WebSocketHandshakeStreamBase::CreateHelper* |
| 122 websocket_handshake_stream_create_helper() = 0; |
| 123 |
| 124 virtual bool for_websockets() = 0; |
| 125 }; |
| 126 |
| 43 // Constructor for non-alternative Job. | 127 // Constructor for non-alternative Job. |
| 44 Job(HttpStreamFactoryImpl* stream_factory, | 128 // Job is owned by |delegate|, hence |delegate| is valid for the |
| 129 // lifetime of the Job. |
| 130 Job(Delegate* delegate, |
| 131 JobType job_type, |
| 45 HttpNetworkSession* session, | 132 HttpNetworkSession* session, |
| 46 const HttpRequestInfo& request_info, | 133 const HttpRequestInfo& request_info, |
| 47 RequestPriority priority, | 134 RequestPriority priority, |
| 48 const SSLConfig& server_ssl_config, | 135 const SSLConfig& server_ssl_config, |
| 49 const SSLConfig& proxy_ssl_config, | 136 const SSLConfig& proxy_ssl_config, |
| 50 HostPortPair destination, | 137 HostPortPair destination, |
| 51 GURL origin_url, | 138 GURL origin_url, |
| 52 NetLog* net_log); | 139 NetLog* net_log); |
| 140 |
| 53 // Constructor for alternative Job. | 141 // Constructor for alternative Job. |
| 54 Job(HttpStreamFactoryImpl* stream_factory, | 142 // Job is owned by |delegate|, hence |delegate| is valid for the |
| 143 // lifetime of the Job. |
| 144 Job(Delegate* delegate, |
| 145 JobType job_type, |
| 55 HttpNetworkSession* session, | 146 HttpNetworkSession* session, |
| 56 const HttpRequestInfo& request_info, | 147 const HttpRequestInfo& request_info, |
| 57 RequestPriority priority, | 148 RequestPriority priority, |
| 58 const SSLConfig& server_ssl_config, | 149 const SSLConfig& server_ssl_config, |
| 59 const SSLConfig& proxy_ssl_config, | 150 const SSLConfig& proxy_ssl_config, |
| 60 HostPortPair destination, | 151 HostPortPair destination, |
| 61 GURL origin_url, | 152 GURL origin_url, |
| 62 AlternativeService alternative_service, | 153 AlternativeService alternative_service, |
| 63 NetLog* net_log); | 154 NetLog* net_log); |
| 64 ~Job(); | 155 virtual ~Job(); |
| 65 | 156 |
| 66 // Start initiates the process of creating a new HttpStream. |request| will be | 157 // Start initiates the process of creating a new HttpStream. |
| 67 // notified upon completion if the Job has not been Orphan()'d. | 158 // |delegate_| will be notified upon completion. |
| 68 void Start(Request* request); | 159 virtual void Start(HttpStreamRequest::StreamType stream_type); |
| 69 | 160 |
| 70 // Preconnect will attempt to request |num_streams| sockets from the | 161 // Preconnect will attempt to request |num_streams| sockets from the |
| 71 // appropriate ClientSocketPool. | 162 // appropriate ClientSocketPool. |
| 72 int Preconnect(int num_streams); | 163 int Preconnect(int num_streams); |
| 73 | 164 |
| 74 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); | 165 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); |
| 75 LoadState GetLoadState() const; | 166 LoadState GetLoadState() const; |
| 76 | 167 |
| 77 // Tells |this| to wait for |job| to resume it. | 168 // Tells |this| to wait for |job| to resume it. |
| 78 void WaitFor(Job* job); | 169 void WaitFor(Job* job); |
| 79 | 170 |
| 80 // Tells |this| that |job| has determined it still needs to continue | 171 // Tells |this| that |job| has determined it still needs to continue |
| 81 // connecting, so allow |this| to continue after the specified |delay|. If | 172 // connecting, so allow |this| to continue after the specified |delay|. If |
| 82 // this is not called, then |request_| is expected to cancel |this| by | 173 // this is not called, then |request_| is expected to cancel |this| by |
| 83 // deleting it. | 174 // deleting it. |
| 84 void Resume(Job* job, const base::TimeDelta& delay); | 175 void Resume(Job* job, const base::TimeDelta& delay); |
| 85 | 176 |
| 86 // Used to detach the Job from |request|. | 177 // Called to detach |this| Job. May resume the other Job, will disconnect |
| 87 void Orphan(const Request* request); | 178 // the socket for |this| Job, and notify |delegate| upon completion. |
| 179 void Orphan(); |
| 88 | 180 |
| 89 void SetPriority(RequestPriority priority); | 181 void SetPriority(RequestPriority priority); |
| 90 | 182 |
| 91 RequestPriority priority() const { return priority_; } | 183 RequestPriority priority() const { return priority_; } |
| 92 bool was_npn_negotiated() const; | 184 bool was_npn_negotiated() const; |
| 93 NextProto protocol_negotiated() const; | 185 NextProto protocol_negotiated() const; |
| 94 bool using_spdy() const; | 186 bool using_spdy() const; |
| 95 const BoundNetLog& net_log() const { return net_log_; } | 187 const BoundNetLog& net_log() const { return net_log_; } |
| 96 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } | 188 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } |
| 97 | 189 |
| 190 std::unique_ptr<HttpStream> GetStream() { return std::move(stream_); } |
| 191 |
| 192 void SetStream(HttpStream* http_stream) { stream_.reset(http_stream); } |
| 193 |
| 194 std::unique_ptr<BidirectionalStreamImpl> GetBidirectionalStream() { |
| 195 return std::move(bidirectional_stream_impl_); |
| 196 } |
| 197 |
| 98 const SSLConfig& server_ssl_config() const; | 198 const SSLConfig& server_ssl_config() const; |
| 99 const SSLConfig& proxy_ssl_config() const; | 199 const SSLConfig& proxy_ssl_config() const; |
| 100 const ProxyInfo& proxy_info() const; | 200 const ProxyInfo& proxy_info() const; |
| 101 | 201 |
| 102 // Indicates whether or not this job is performing a preconnect. | |
| 103 bool IsPreconnecting() const; | |
| 104 | |
| 105 // Indicates whether or not this Job has been orphaned by a Request. | |
| 106 bool IsOrphaned() const; | |
| 107 | |
| 108 // Called to indicate that this job succeeded, and some other jobs | 202 // Called to indicate that this job succeeded, and some other jobs |
| 109 // will be orphaned. | 203 // will be orphaned. |
| 110 void ReportJobSucceededForRequest(); | 204 void ReportJobSucceededForRequest(); |
| 111 | 205 |
| 112 // Marks that the other |job| has completed. | 206 // Marks that the other |job| has completed. |
| 113 void MarkOtherJobComplete(const Job& job); | 207 virtual void MarkOtherJobComplete(const Job& job); |
| 208 |
| 209 JobType job_type() const { return job_type_; } |
| 114 | 210 |
| 115 private: | 211 private: |
| 116 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); | 212 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); |
| 213 friend class TestJobControllerPeer; |
| 117 | 214 |
| 118 enum State { | 215 enum State { |
| 119 STATE_START, | 216 STATE_START, |
| 120 STATE_RESOLVE_PROXY, | 217 STATE_RESOLVE_PROXY, |
| 121 STATE_RESOLVE_PROXY_COMPLETE, | 218 STATE_RESOLVE_PROXY_COMPLETE, |
| 122 | 219 |
| 123 // Note that when Alternate-Protocol says we can connect to an alternate | 220 // Note that when Alternate-Protocol says we can connect to an alternate |
| 124 // port using a different protocol, we have the choice of communicating over | 221 // port using a different protocol, we have the choice of communicating over |
| 125 // the original protocol, or speaking the alternate protocol (currently, | 222 // the original protocol, or speaking the alternate protocol (currently, |
| 126 // only npn-spdy) over an alternate port. For a cold page load, the http | 223 // only npn-spdy) over an alternate port. For a cold page load, the http |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // Invoked by the transport socket pool after host resolution is complete | 408 // Invoked by the transport socket pool after host resolution is complete |
| 312 // to allow the connection to be aborted, if a matching SPDY session can | 409 // to allow the connection to be aborted, if a matching SPDY session can |
| 313 // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a | 410 // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a |
| 314 // session is found, and OK otherwise. | 411 // session is found, and OK otherwise. |
| 315 static int OnHostResolution(SpdySessionPool* spdy_session_pool, | 412 static int OnHostResolution(SpdySessionPool* spdy_session_pool, |
| 316 const SpdySessionKey& spdy_session_key, | 413 const SpdySessionKey& spdy_session_key, |
| 317 const GURL& origin_url, | 414 const GURL& origin_url, |
| 318 const AddressList& addresses, | 415 const AddressList& addresses, |
| 319 const BoundNetLog& net_log); | 416 const BoundNetLog& net_log); |
| 320 | 417 |
| 321 Request* request_; | |
| 322 | |
| 323 const HttpRequestInfo request_info_; | 418 const HttpRequestInfo request_info_; |
| 324 RequestPriority priority_; | 419 RequestPriority priority_; |
| 325 ProxyInfo proxy_info_; | 420 ProxyInfo proxy_info_; |
| 326 SSLConfig server_ssl_config_; | 421 SSLConfig server_ssl_config_; |
| 327 SSLConfig proxy_ssl_config_; | 422 SSLConfig proxy_ssl_config_; |
| 328 const BoundNetLog net_log_; | 423 const BoundNetLog net_log_; |
| 329 | 424 |
| 330 CompletionCallback io_callback_; | 425 CompletionCallback io_callback_; |
| 331 std::unique_ptr<ClientSocketHandle> connection_; | 426 std::unique_ptr<ClientSocketHandle> connection_; |
| 332 HttpNetworkSession* const session_; | 427 HttpNetworkSession* const session_; |
| 333 HttpStreamFactoryImpl* const stream_factory_; | |
| 334 State next_state_; | 428 State next_state_; |
| 335 ProxyService::PacRequest* pac_request_; | 429 ProxyService::PacRequest* pac_request_; |
| 336 SSLInfo ssl_info_; | 430 SSLInfo ssl_info_; |
| 337 | 431 |
| 338 // The server we are trying to reach, could be that of the origin or of the | 432 // The server we are trying to reach, could be that of the origin or of the |
| 339 // alternative service (after applying host mapping rules). | 433 // alternative service (after applying host mapping rules). |
| 340 HostPortPair destination_; | 434 HostPortPair destination_; |
| 341 | 435 |
| 342 // The origin url we're trying to reach. This url may be different from the | 436 // The origin url we're trying to reach. This url may be different from the |
| 343 // original request when host mapping rules are set-up. | 437 // original request when host mapping rules are set-up. |
| 344 GURL origin_url_; | 438 GURL origin_url_; |
| 345 | 439 |
| 346 // AlternativeService for this Job if this is an alternative Job. | 440 // AlternativeService for this Job if this is an alternative Job. |
| 347 const AlternativeService alternative_service_; | 441 const AlternativeService alternative_service_; |
| 348 | 442 |
| 349 // AlternativeService for the other Job if this is not an alternative Job. | 443 // AlternativeService for the other Job if this is not an alternative Job. |
| 350 AlternativeService other_job_alternative_service_; | 444 AlternativeService other_job_alternative_service_; |
| 351 | 445 |
| 446 // Unowned. |this| job is owned by |delegate_|. |
| 447 Delegate* delegate_; |
| 448 |
| 449 JobType job_type_; |
| 450 |
| 352 // This is the Job we're dependent on. It will notify us if/when it's OK to | 451 // This is the Job we're dependent on. It will notify us if/when it's OK to |
| 353 // proceed. | 452 // proceed. |
| 354 Job* blocking_job_; | 453 Job* blocking_job_; |
| 355 | 454 |
| 356 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection. | 455 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection. |
| 357 // If |this| is unable to do so, we'll notify |waiting_job_| that it's ok to | 456 // If |this| is unable to do so, we'll notify |waiting_job_| that it's ok to |
| 358 // proceed and then race the two Jobs. | 457 // proceed and then race the two Jobs. |
| 359 Job* waiting_job_; | 458 Job* waiting_job_; |
| 360 | 459 |
| 361 base::TimeDelta wait_time_; | 460 base::TimeDelta wait_time_; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 HttpStreamRequest::StreamType stream_type_; | 518 HttpStreamRequest::StreamType stream_type_; |
| 420 | 519 |
| 421 base::WeakPtrFactory<Job> ptr_factory_; | 520 base::WeakPtrFactory<Job> ptr_factory_; |
| 422 | 521 |
| 423 DISALLOW_COPY_AND_ASSIGN(Job); | 522 DISALLOW_COPY_AND_ASSIGN(Job); |
| 424 }; | 523 }; |
| 425 | 524 |
| 426 } // namespace net | 525 } // namespace net |
| 427 | 526 |
| 428 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 527 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| OLD | NEW |