Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 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(JobController* job_controller, | 44 Job(JobController* job_controller, |
| 45 JobType job_type, | |
| 45 HttpNetworkSession* session, | 46 HttpNetworkSession* session, |
| 46 const HttpRequestInfo& request_info, | 47 const HttpRequestInfo& request_info, |
| 47 RequestPriority priority, | 48 RequestPriority priority, |
| 48 const SSLConfig& server_ssl_config, | 49 const SSLConfig& server_ssl_config, |
| 49 const SSLConfig& proxy_ssl_config, | 50 const SSLConfig& proxy_ssl_config, |
| 50 HostPortPair destination, | 51 HostPortPair destination, |
| 51 GURL origin_url, | 52 GURL origin_url, |
| 52 NetLog* net_log); | 53 NetLog* net_log); |
| 53 // Constructor for alternative Job. | 54 // Constructor for alternative Job. |
| 54 Job(JobController* job_controller, | 55 Job(JobController* job_controller, |
| 56 JobType job_type, | |
| 55 HttpNetworkSession* session, | 57 HttpNetworkSession* session, |
| 56 const HttpRequestInfo& request_info, | 58 const HttpRequestInfo& request_info, |
| 57 RequestPriority priority, | 59 RequestPriority priority, |
| 58 const SSLConfig& server_ssl_config, | 60 const SSLConfig& server_ssl_config, |
| 59 const SSLConfig& proxy_ssl_config, | 61 const SSLConfig& proxy_ssl_config, |
| 60 HostPortPair destination, | 62 HostPortPair destination, |
| 61 GURL origin_url, | 63 GURL origin_url, |
| 62 AlternativeService alternative_service, | 64 AlternativeService alternative_service, |
| 63 NetLog* net_log); | 65 NetLog* net_log); |
| 64 ~Job(); | 66 ~Job(); |
| 65 | 67 |
| 66 // Start initiates the process of creating a new HttpStream. |request| will be | 68 // Start initiates the process of creating a new HttpStream. |request| will be |
| 67 // notified upon completion if the Job has not been Orphan()'d. | 69 // notified upon completion if the Job has not been Orphan()'d. |
| 68 void Start(Request* request); | 70 void Start(Request* request); |
| 69 | 71 |
| 70 // Preconnect will attempt to request |num_streams| sockets from the | 72 // Preconnect will attempt to request |num_streams| sockets from the |
| 71 // appropriate ClientSocketPool. | 73 // appropriate ClientSocketPool. |
| 72 int Preconnect(int num_streams); | 74 int Preconnect(int num_streams); |
| 73 | 75 |
| 74 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); | 76 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); |
| 75 LoadState GetLoadState() const; | 77 LoadState GetLoadState() const; |
| 76 | 78 |
| 77 // Tells |this| to wait for |job| to resume it. | |
| 78 void WaitFor(Job* job); | |
| 79 | |
| 80 // Tells |this| that |job| has determined it still needs to continue | 79 // Tells |this| that |job| has determined it still needs to continue |
| 81 // connecting, so allow |this| to continue after the specified |delay|. If | 80 // connecting, so allow |this| to continue after the specified |delay|. If |
| 82 // this is not called, then |request_| is expected to cancel |this| by | 81 // this is not called, then |request_| is expected to cancel |this| by |
| 83 // deleting it. | 82 // deleting it. |
| 84 void Resume(Job* job, const base::TimeDelta& delay); | 83 void Resume(const base::TimeDelta& delay); |
| 85 | 84 |
| 86 // Used to detach the Job from |request|. | 85 // Used to detach the Job from |request|. |
| 87 void Orphan(const Request* request); | 86 void Orphan(const Request* request); |
| 88 | 87 |
| 89 void SetPriority(RequestPriority priority); | 88 void SetPriority(RequestPriority priority); |
| 90 | 89 |
| 91 RequestPriority priority() const { return priority_; } | 90 RequestPriority priority() const { return priority_; } |
| 92 bool was_npn_negotiated() const; | 91 bool was_npn_negotiated() const; |
| 93 NextProto protocol_negotiated() const; | 92 NextProto protocol_negotiated() const; |
| 94 bool using_spdy() const; | 93 bool using_spdy() const; |
| 95 const BoundNetLog& net_log() const { return net_log_; } | 94 const BoundNetLog& net_log() const { return net_log_; } |
| 96 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } | 95 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } |
| 97 | 96 |
| 98 const SSLConfig& server_ssl_config() const; | 97 const SSLConfig& server_ssl_config() const; |
| 99 const SSLConfig& proxy_ssl_config() const; | 98 const SSLConfig& proxy_ssl_config() const; |
| 100 const ProxyInfo& proxy_info() const; | 99 const ProxyInfo& proxy_info() const; |
| 101 | 100 |
| 102 // Indicates whether or not this job is performing a preconnect. | 101 // Indicates whether or not this job is performing a preconnect. |
| 103 bool IsPreconnecting() const; | 102 bool IsPreconnecting() const; |
| 104 | 103 |
| 105 // Indicates whether or not this Job has been orphaned by a Request. | 104 // Indicates whether or not this job has been orphaned by a Request. |
| 106 bool IsOrphaned() const { return orphaned_; }; | 105 bool IsOrphaned() const { return orphaned_; } |
| 107 | 106 |
| 108 // Called to indicate that this job succeeded, and some other jobs | 107 // Called to indicate that this job succeeded, and some other jobs |
| 109 // will be orphaned. | 108 // will be orphaned. |
| 110 void ReportJobSucceededForRequest(); | 109 void ReportJobSucceededForRequest(); |
| 111 | 110 |
| 112 // Marks that the other |job| has completed. | 111 // Marks that the other |job| has completed. |
| 113 void MarkOtherJobComplete(const Job& job); | 112 void MarkOtherJobComplete(const Job& job); |
| 114 | 113 |
| 115 private: | 114 private: |
| 115 friend class JobController; | |
|
Ryan Hamilton
2016/05/06 21:33:14
Can we get away without this friendship?
Zhongyi Shi
2016/05/13 00:31:25
Done.
| |
| 116 | |
| 116 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); | 117 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); |
| 117 | 118 |
| 118 enum State { | 119 enum State { |
| 119 STATE_START, | 120 STATE_START, |
| 120 STATE_RESOLVE_PROXY, | 121 STATE_RESOLVE_PROXY, |
| 121 STATE_RESOLVE_PROXY_COMPLETE, | 122 STATE_RESOLVE_PROXY_COMPLETE, |
| 122 | 123 |
| 123 // Note that when Alternate-Protocol says we can connect to an alternate | 124 // 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 | 125 // port using a different protocol, we have the choice of communicating over |
| 125 // the original protocol, or speaking the alternate protocol (currently, | 126 // the original protocol, or speaking the alternate protocol (currently, |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 GURL origin_url_; | 342 GURL origin_url_; |
| 342 | 343 |
| 343 // AlternativeService for this Job if this is an alternative Job. | 344 // AlternativeService for this Job if this is an alternative Job. |
| 344 const AlternativeService alternative_service_; | 345 const AlternativeService alternative_service_; |
| 345 | 346 |
| 346 // AlternativeService for the other Job if this is not an alternative Job. | 347 // AlternativeService for the other Job if this is not an alternative Job. |
| 347 AlternativeService other_job_alternative_service_; | 348 AlternativeService other_job_alternative_service_; |
| 348 | 349 |
| 349 JobController* job_controller_; | 350 JobController* job_controller_; |
| 350 | 351 |
| 351 // This is the Job we're dependent on. It will notify us if/when it's OK to | 352 JobType job_type_; |
| 352 // proceed. | |
| 353 Job* blocking_job_; | |
| 354 | |
| 355 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection. | |
| 356 // If |this| is unable to do so, we'll notify |waiting_job_| that it's ok to | |
| 357 // proceed and then race the two Jobs. | |
| 358 Job* waiting_job_; | |
| 359 | 353 |
| 360 base::TimeDelta wait_time_; | 354 base::TimeDelta wait_time_; |
| 361 | 355 |
| 362 // True if this job has been launched by a request but orphaned. | 356 // True if this job has been launched by a request but orphaned. |
| 363 bool orphaned_; | 357 bool orphaned_; |
| 364 | 358 |
| 365 // True if handling a HTTPS request, or using SPDY with SSL | 359 // True if handling a HTTPS request, or using SPDY with SSL |
| 366 bool using_ssl_; | 360 bool using_ssl_; |
| 367 | 361 |
| 368 // True if this network transaction is using SPDY instead of HTTP. | 362 // True if this network transaction is using SPDY instead of HTTP. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 HttpStreamRequest::StreamType stream_type_; | 415 HttpStreamRequest::StreamType stream_type_; |
| 422 | 416 |
| 423 base::WeakPtrFactory<Job> ptr_factory_; | 417 base::WeakPtrFactory<Job> ptr_factory_; |
| 424 | 418 |
| 425 DISALLOW_COPY_AND_ASSIGN(Job); | 419 DISALLOW_COPY_AND_ASSIGN(Job); |
| 426 }; | 420 }; |
| 427 | 421 |
| 428 } // namespace net | 422 } // namespace net |
| 429 | 423 |
| 430 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 424 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| OLD | NEW |