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