| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_CONTROLLER_H_ | 5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ |
| 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ | 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "net/base/host_port_pair.h" | 8 #include "net/base/host_port_pair.h" |
| 9 #include "net/http/http_stream_factory_impl_job.h" | 9 #include "net/http/http_stream_factory_impl_job.h" |
| 10 #include "net/http/http_stream_factory_impl_request.h" | 10 #include "net/http/http_stream_factory_impl_request.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 class NetLogWithSource; | 14 class NetLogWithSource; |
| 15 | 15 |
| 16 // HttpStreamFactoryImpl::JobController manages Request and Job(s). | 16 // HttpStreamFactoryImpl::JobController manages Request and Job(s). |
| 17 class HttpStreamFactoryImpl::JobController | 17 class HttpStreamFactoryImpl::JobController |
| 18 : public HttpStreamFactoryImpl::Job::Delegate, | 18 : public HttpStreamFactoryImpl::Job::Delegate, |
| 19 public HttpStreamFactoryImpl::Request::Helper { | 19 public HttpStreamFactoryImpl::Request::Helper { |
| 20 public: | 20 public: |
| 21 JobController(HttpStreamFactoryImpl* factory, | 21 JobController(HttpStreamFactoryImpl* factory, |
| 22 HttpStreamRequest::Delegate* delegate, | 22 HttpStreamRequest::Delegate* delegate, |
| 23 HttpNetworkSession* session, | 23 HttpNetworkSession* session, |
| 24 JobFactory* job_factory); | 24 JobFactory* job_factory, |
| 25 bool is_preconnect, |
| 26 const NetLogWithSource& net_log); |
| 25 | 27 |
| 26 ~JobController() override; | 28 ~JobController() override; |
| 27 | 29 |
| 28 bool for_websockets() override; | 30 bool for_websockets() override; |
| 29 | 31 |
| 30 // Used in tests only for verification purpose. | 32 // Used in tests only for verification purpose. |
| 31 const Job* main_job() const { return main_job_.get(); } | 33 const Job* main_job() const { return main_job_.get(); } |
| 32 const Job* alternative_job() const { return alternative_job_.get(); } | 34 const Job* alternative_job() const { return alternative_job_.get(); } |
| 33 | 35 |
| 34 GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint); | 36 GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint); |
| 35 | 37 |
| 36 // Methods below are called by HttpStreamFactoryImpl only. | 38 // Methods below are called by HttpStreamFactoryImpl only. |
| 37 // Creates request and hands out to HttpStreamFactoryImpl, this will also | 39 // Creates request and hands out to HttpStreamFactoryImpl, this will also |
| 38 // create Job(s) and start serving the created request. | 40 // create Job(s) and start serving the created request. |
| 39 Request* Start(const HttpRequestInfo& request_info, | 41 Request* Start(const HttpRequestInfo& request_info, |
| 40 HttpStreamRequest::Delegate* delegate, | 42 HttpStreamRequest::Delegate* delegate, |
| 41 WebSocketHandshakeStreamBase::CreateHelper* | 43 WebSocketHandshakeStreamBase::CreateHelper* |
| 42 websocket_handshake_stream_create_helper, | 44 websocket_handshake_stream_create_helper, |
| 43 const NetLogWithSource& net_log, | |
| 44 HttpStreamRequest::StreamType stream_type, | 45 HttpStreamRequest::StreamType stream_type, |
| 45 RequestPriority priority, | 46 RequestPriority priority, |
| 46 const SSLConfig& server_ssl_config, | 47 const SSLConfig& server_ssl_config, |
| 47 const SSLConfig& proxy_ssl_config); | 48 const SSLConfig& proxy_ssl_config); |
| 48 | 49 |
| 49 void Preconnect(int num_streams, | 50 void Preconnect(int num_streams, |
| 50 const HttpRequestInfo& request_info, | 51 const HttpRequestInfo& request_info, |
| 51 const SSLConfig& server_ssl_config, | 52 const SSLConfig& server_ssl_config, |
| 52 const SSLConfig& proxy_ssl_config); | 53 const SSLConfig& proxy_ssl_config); |
| 53 | 54 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 172 |
| 172 private: | 173 private: |
| 173 friend class JobControllerPeer; | 174 friend class JobControllerPeer; |
| 174 | 175 |
| 175 // Creates Job(s) for |request_|. Job(s) will be owned by |this|. | 176 // Creates Job(s) for |request_|. Job(s) will be owned by |this|. |
| 176 void CreateJobs(const HttpRequestInfo& request_info, | 177 void CreateJobs(const HttpRequestInfo& request_info, |
| 177 RequestPriority priority, | 178 RequestPriority priority, |
| 178 const SSLConfig& server_ssl_config, | 179 const SSLConfig& server_ssl_config, |
| 179 const SSLConfig& proxy_ssl_config, | 180 const SSLConfig& proxy_ssl_config, |
| 180 HttpStreamRequest::Delegate* delegate, | 181 HttpStreamRequest::Delegate* delegate, |
| 181 HttpStreamRequest::StreamType stream_type, | 182 HttpStreamRequest::StreamType stream_type); |
| 182 const NetLogWithSource& net_log); | |
| 183 | 183 |
| 184 // Attaches |job| to |request_|. Does not mean that |request_| will use |job|. | 184 // Attaches |job| to |request_|. Does not mean that |request_| will use |job|. |
| 185 void AttachJob(Job* job); | 185 void AttachJob(Job* job); |
| 186 | 186 |
| 187 // Called to bind |job| to the |request_| and orphan all other jobs that are | 187 // Called to bind |job| to the |request_| and orphan all other jobs that are |
| 188 // still associated with |request_|. | 188 // still associated with |request_|. |
| 189 void BindJob(Job* job); | 189 void BindJob(Job* job); |
| 190 | 190 |
| 191 // Called when |request_| is destructed. | 191 // Called when |request_| is destructed. |
| 192 // Job(s) associated with but not bound to |request_| will be deleted. | 192 // Job(s) associated with but not bound to |request_| will be deleted. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 262 |
| 263 // Request will be handed out to factory once created. This just keeps an | 263 // Request will be handed out to factory once created. This just keeps an |
| 264 // reference and is safe as |request_| will notify |this| JobController | 264 // reference and is safe as |request_| will notify |this| JobController |
| 265 // when it's destructed by calling OnRequestComplete(), which nulls | 265 // when it's destructed by calling OnRequestComplete(), which nulls |
| 266 // |request_|. | 266 // |request_|. |
| 267 Request* request_; | 267 Request* request_; |
| 268 | 268 |
| 269 HttpStreamRequest::Delegate* const delegate_; | 269 HttpStreamRequest::Delegate* const delegate_; |
| 270 | 270 |
| 271 // True if this JobController is used to preconnect streams. | 271 // True if this JobController is used to preconnect streams. |
| 272 bool is_preconnect_; | 272 const bool is_preconnect_; |
| 273 | 273 |
| 274 // |main_job_| is a job waiting to see if |alternative_job_| can reuse a | 274 // |main_job_| is a job waiting to see if |alternative_job_| can reuse a |
| 275 // connection. If |alternative_job_| is unable to do so, |this| will notify | 275 // connection. If |alternative_job_| is unable to do so, |this| will notify |
| 276 // |main_job_| to proceed and then race the two jobs. | 276 // |main_job_| to proceed and then race the two jobs. |
| 277 std::unique_ptr<Job> main_job_; | 277 std::unique_ptr<Job> main_job_; |
| 278 std::unique_ptr<Job> alternative_job_; | 278 std::unique_ptr<Job> alternative_job_; |
| 279 | 279 |
| 280 // True if |alternative_job_| uses alternative service/proxy server and it | 280 // True if |alternative_job_| uses alternative service/proxy server and it |
| 281 // fails. | 281 // fails. |
| 282 bool alternative_job_failed_; | 282 bool alternative_job_failed_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 295 // Waiting time for the main job before it is resumed. | 295 // Waiting time for the main job before it is resumed. |
| 296 base::TimeDelta main_job_wait_time_; | 296 base::TimeDelta main_job_wait_time_; |
| 297 | 297 |
| 298 // At the point where a Job is irrevocably tied to |request_|, we set this. | 298 // At the point where a Job is irrevocably tied to |request_|, we set this. |
| 299 // It will be nulled when the |request_| is finished. | 299 // It will be nulled when the |request_| is finished. |
| 300 Job* bound_job_; | 300 Job* bound_job_; |
| 301 | 301 |
| 302 // True if an alternative proxy server job can be started to fetch |request_|. | 302 // True if an alternative proxy server job can be started to fetch |request_|. |
| 303 bool can_start_alternative_proxy_job_; | 303 bool can_start_alternative_proxy_job_; |
| 304 | 304 |
| 305 const NetLogWithSource net_log_; |
| 306 |
| 305 base::WeakPtrFactory<JobController> ptr_factory_; | 307 base::WeakPtrFactory<JobController> ptr_factory_; |
| 306 }; | 308 }; |
| 307 | 309 |
| 308 } // namespace net | 310 } // namespace net |
| 309 | 311 |
| 310 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ | 312 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ |
| OLD | NEW |