| 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 23 matching lines...) Expand all Loading... |
| 34 class HttpNetworkSession; | 34 class HttpNetworkSession; |
| 35 class HttpStream; | 35 class HttpStream; |
| 36 class SpdySessionPool; | 36 class SpdySessionPool; |
| 37 class QuicHttpStream; | 37 class QuicHttpStream; |
| 38 | 38 |
| 39 // An HttpStreamRequestImpl exists for each stream which is in progress of being | 39 // An HttpStreamRequestImpl exists for each stream which is in progress of being |
| 40 // created for the StreamFactory. | 40 // created for the StreamFactory. |
| 41 class HttpStreamFactoryImpl::Job { | 41 class HttpStreamFactoryImpl::Job { |
| 42 public: | 42 public: |
| 43 // Constructor for non-alternative Job. | 43 // Constructor for non-alternative Job. |
| 44 Job(HttpStreamFactoryImpl* stream_factory, | 44 // Job is owned by JobController, hence |job_controller| is valid for the |
| 45 // lifetime of the Job. |
| 46 Job(JobController* job_controller, |
| 47 JobType job_type, |
| 45 HttpNetworkSession* session, | 48 HttpNetworkSession* session, |
| 46 const HttpRequestInfo& request_info, | 49 const HttpRequestInfo& request_info, |
| 47 RequestPriority priority, | 50 RequestPriority priority, |
| 48 const SSLConfig& server_ssl_config, | 51 const SSLConfig& server_ssl_config, |
| 49 const SSLConfig& proxy_ssl_config, | 52 const SSLConfig& proxy_ssl_config, |
| 50 HostPortPair destination, | 53 HostPortPair destination, |
| 51 GURL origin_url, | 54 GURL origin_url, |
| 52 NetLog* net_log); | 55 NetLog* net_log); |
| 56 |
| 53 // Constructor for alternative Job. | 57 // Constructor for alternative Job. |
| 54 Job(HttpStreamFactoryImpl* stream_factory, | 58 Job(JobController* job_controller, |
| 59 JobType job_type, |
| 55 HttpNetworkSession* session, | 60 HttpNetworkSession* session, |
| 56 const HttpRequestInfo& request_info, | 61 const HttpRequestInfo& request_info, |
| 57 RequestPriority priority, | 62 RequestPriority priority, |
| 58 const SSLConfig& server_ssl_config, | 63 const SSLConfig& server_ssl_config, |
| 59 const SSLConfig& proxy_ssl_config, | 64 const SSLConfig& proxy_ssl_config, |
| 60 HostPortPair destination, | 65 HostPortPair destination, |
| 61 GURL origin_url, | 66 GURL origin_url, |
| 62 AlternativeService alternative_service, | 67 AlternativeService alternative_service, |
| 63 NetLog* net_log); | 68 NetLog* net_log); |
| 64 ~Job(); | 69 ~Job(); |
| 65 | 70 |
| 66 // Start initiates the process of creating a new HttpStream. |request| will be | 71 // Start initiates the process of creating a new HttpStream. |
| 67 // notified upon completion if the Job has not been Orphan()'d. | 72 // |job_controller_| will be notified upon completion. |
| 68 void Start(Request* request); | 73 void Start(HttpStreamRequest::StreamType stream_type); |
| 69 | 74 |
| 70 // Preconnect will attempt to request |num_streams| sockets from the | 75 // Preconnect will attempt to request |num_streams| sockets from the |
| 71 // appropriate ClientSocketPool. | 76 // appropriate ClientSocketPool. |
| 72 int Preconnect(int num_streams); | 77 int Preconnect(int num_streams); |
| 73 | 78 |
| 74 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); | 79 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); |
| 75 LoadState GetLoadState() const; | 80 LoadState GetLoadState() const; |
| 76 | 81 |
| 77 // Tells |this| to wait for |job| to resume it. | 82 // Tells |this| to wait for |job| to resume it. |
| 78 void WaitFor(Job* job); | 83 void WaitFor(Job* job); |
| 79 | 84 |
| 80 // Tells |this| that |job| has determined it still needs to continue | 85 // Tells |this| that |job| has determined it still needs to continue |
| 81 // connecting, so allow |this| to continue after the specified |delay|. If | 86 // connecting, so allow |this| to continue after the specified |delay|. If |
| 82 // this is not called, then |request_| is expected to cancel |this| by | 87 // this is not called, then |request_| is expected to cancel |this| by |
| 83 // deleting it. | 88 // deleting it. |
| 84 void Resume(Job* job, const base::TimeDelta& delay); | 89 void Resume(Job* job, const base::TimeDelta& delay); |
| 85 | 90 |
| 86 // Used to detach the Job from |request|. | 91 // Used to detach the Job from |request|. |
| 87 void Orphan(const Request* request); | 92 void Orphan(); |
| 88 | 93 |
| 89 void SetPriority(RequestPriority priority); | 94 void SetPriority(RequestPriority priority); |
| 90 | 95 |
| 91 RequestPriority priority() const { return priority_; } | 96 RequestPriority priority() const { return priority_; } |
| 92 bool was_npn_negotiated() const; | 97 bool was_npn_negotiated() const; |
| 93 NextProto protocol_negotiated() const; | 98 NextProto protocol_negotiated() const; |
| 94 bool using_spdy() const; | 99 bool using_spdy() const; |
| 95 const BoundNetLog& net_log() const { return net_log_; } | 100 const BoundNetLog& net_log() const { return net_log_; } |
| 96 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } | 101 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } |
| 97 | 102 |
| 103 HttpStream* ReleaseStream() { return stream_.release(); } |
| 104 |
| 105 BidirectionalStreamImpl* ReleaseBidirectionalStream() { |
| 106 return bidirectional_stream_impl_.release(); |
| 107 } |
| 108 |
| 98 const SSLConfig& server_ssl_config() const; | 109 const SSLConfig& server_ssl_config() const; |
| 99 const SSLConfig& proxy_ssl_config() const; | 110 const SSLConfig& proxy_ssl_config() const; |
| 100 const ProxyInfo& proxy_info() const; | 111 const ProxyInfo& proxy_info() const; |
| 101 | 112 |
| 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 | 113 // Called to indicate that this job succeeded, and some other jobs |
| 109 // will be orphaned. | 114 // will be orphaned. |
| 110 void ReportJobSucceededForRequest(); | 115 void ReportJobSucceededForRequest(); |
| 111 | 116 |
| 112 // Marks that the other |job| has completed. | 117 // Marks that the other |job| has completed. |
| 113 void MarkOtherJobComplete(const Job& job); | 118 void MarkOtherJobComplete(const Job& job); |
| 114 | 119 |
| 120 JobType job_type() const { return job_type_; } |
| 121 |
| 115 private: | 122 private: |
| 116 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); | 123 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); |
| 117 | 124 |
| 118 enum State { | 125 enum State { |
| 119 STATE_START, | 126 STATE_START, |
| 120 STATE_RESOLVE_PROXY, | 127 STATE_RESOLVE_PROXY, |
| 121 STATE_RESOLVE_PROXY_COMPLETE, | 128 STATE_RESOLVE_PROXY_COMPLETE, |
| 122 | 129 |
| 123 // Note that when Alternate-Protocol says we can connect to an alternate | 130 // 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 | 131 // port using a different protocol, we have the choice of communicating over |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // Invoked by the transport socket pool after host resolution is complete | 318 // 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 | 319 // 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 | 320 // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a |
| 314 // session is found, and OK otherwise. | 321 // session is found, and OK otherwise. |
| 315 static int OnHostResolution(SpdySessionPool* spdy_session_pool, | 322 static int OnHostResolution(SpdySessionPool* spdy_session_pool, |
| 316 const SpdySessionKey& spdy_session_key, | 323 const SpdySessionKey& spdy_session_key, |
| 317 const GURL& origin_url, | 324 const GURL& origin_url, |
| 318 const AddressList& addresses, | 325 const AddressList& addresses, |
| 319 const BoundNetLog& net_log); | 326 const BoundNetLog& net_log); |
| 320 | 327 |
| 321 Request* request_; | |
| 322 | |
| 323 const HttpRequestInfo request_info_; | 328 const HttpRequestInfo request_info_; |
| 324 RequestPriority priority_; | 329 RequestPriority priority_; |
| 325 ProxyInfo proxy_info_; | 330 ProxyInfo proxy_info_; |
| 326 SSLConfig server_ssl_config_; | 331 SSLConfig server_ssl_config_; |
| 327 SSLConfig proxy_ssl_config_; | 332 SSLConfig proxy_ssl_config_; |
| 328 const BoundNetLog net_log_; | 333 const BoundNetLog net_log_; |
| 329 | 334 |
| 330 CompletionCallback io_callback_; | 335 CompletionCallback io_callback_; |
| 331 std::unique_ptr<ClientSocketHandle> connection_; | 336 std::unique_ptr<ClientSocketHandle> connection_; |
| 332 HttpNetworkSession* const session_; | 337 HttpNetworkSession* const session_; |
| 333 HttpStreamFactoryImpl* const stream_factory_; | |
| 334 State next_state_; | 338 State next_state_; |
| 335 ProxyService::PacRequest* pac_request_; | 339 ProxyService::PacRequest* pac_request_; |
| 336 SSLInfo ssl_info_; | 340 SSLInfo ssl_info_; |
| 337 | 341 |
| 338 // The server we are trying to reach, could be that of the origin or of the | 342 // The server we are trying to reach, could be that of the origin or of the |
| 339 // alternative service (after applying host mapping rules). | 343 // alternative service (after applying host mapping rules). |
| 340 HostPortPair destination_; | 344 HostPortPair destination_; |
| 341 | 345 |
| 342 // The origin url we're trying to reach. This url may be different from the | 346 // 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. | 347 // original request when host mapping rules are set-up. |
| 344 GURL origin_url_; | 348 GURL origin_url_; |
| 345 | 349 |
| 346 // AlternativeService for this Job if this is an alternative Job. | 350 // AlternativeService for this Job if this is an alternative Job. |
| 347 const AlternativeService alternative_service_; | 351 const AlternativeService alternative_service_; |
| 348 | 352 |
| 349 // AlternativeService for the other Job if this is not an alternative Job. | 353 // AlternativeService for the other Job if this is not an alternative Job. |
| 350 AlternativeService other_job_alternative_service_; | 354 AlternativeService other_job_alternative_service_; |
| 351 | 355 |
| 356 // Unowned. |this| job is owned by |job_controller_|. |
| 357 JobController* job_controller_; |
| 358 |
| 359 JobType job_type_; |
| 360 |
| 352 // This is the Job we're dependent on. It will notify us if/when it's OK to | 361 // This is the Job we're dependent on. It will notify us if/when it's OK to |
| 353 // proceed. | 362 // proceed. |
| 354 Job* blocking_job_; | 363 Job* blocking_job_; |
| 355 | 364 |
| 356 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection. | 365 // |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 | 366 // 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. | 367 // proceed and then race the two Jobs. |
| 359 Job* waiting_job_; | 368 Job* waiting_job_; |
| 360 | 369 |
| 361 base::TimeDelta wait_time_; | 370 base::TimeDelta wait_time_; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 HttpStreamRequest::StreamType stream_type_; | 428 HttpStreamRequest::StreamType stream_type_; |
| 420 | 429 |
| 421 base::WeakPtrFactory<Job> ptr_factory_; | 430 base::WeakPtrFactory<Job> ptr_factory_; |
| 422 | 431 |
| 423 DISALLOW_COPY_AND_ASSIGN(Job); | 432 DISALLOW_COPY_AND_ASSIGN(Job); |
| 424 }; | 433 }; |
| 425 | 434 |
| 426 } // namespace net | 435 } // namespace net |
| 427 | 436 |
| 428 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 437 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| OLD | NEW |