| 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/base/privacy_mode.h" | 9 #include "net/base/privacy_mode.h" |
| 10 #include "net/http/http_stream_factory_impl_job.h" | 10 #include "net/http/http_stream_factory_impl_job.h" |
| 11 #include "net/http/http_stream_factory_impl_request.h" | 11 #include "net/http/http_stream_factory_impl_request.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 | 14 |
| 15 class NetLogWithSource; | 15 class NetLogWithSource; |
| 16 | 16 |
| 17 // HttpStreamFactoryImpl::JobController manages Request and Job(s). | 17 // HttpStreamFactoryImpl::JobController manages Request and Job(s). |
| 18 class HttpStreamFactoryImpl::JobController | 18 class HttpStreamFactoryImpl::JobController |
| 19 : public HttpStreamFactoryImpl::Job::Delegate, | 19 : public HttpStreamFactoryImpl::Job::Delegate, |
| 20 public HttpStreamFactoryImpl::Request::Helper { | 20 public HttpStreamFactoryImpl::Request::Helper { |
| 21 public: | 21 public: |
| 22 JobController(HttpStreamFactoryImpl* factory, | 22 JobController(HttpStreamFactoryImpl* factory, |
| 23 HttpStreamRequest::Delegate* delegate, | 23 HttpStreamRequest::Delegate* delegate, |
| 24 HttpNetworkSession* session, | 24 HttpNetworkSession* session, |
| 25 JobFactory* job_factory); | 25 JobFactory* job_factory, |
| 26 const HttpRequestInfo& request_info, |
| 27 bool is_preconnect); |
| 26 | 28 |
| 27 ~JobController() override; | 29 ~JobController() override; |
| 28 | 30 |
| 29 bool for_websockets() override; | 31 bool for_websockets() override; |
| 30 | 32 |
| 31 // Used in tests only for verification purpose. | 33 // Used in tests only for verification purpose. |
| 32 const Job* main_job() const { return main_job_.get(); } | 34 const Job* main_job() const { return main_job_.get(); } |
| 33 const Job* alternative_job() const { return alternative_job_.get(); } | 35 const Job* alternative_job() const { return alternative_job_.get(); } |
| 34 | 36 |
| 35 GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint); | 37 GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint); |
| 36 | 38 |
| 37 // Methods below are called by HttpStreamFactoryImpl only. | 39 // Methods below are called by HttpStreamFactoryImpl only. |
| 38 // Creates request and hands out to HttpStreamFactoryImpl, this will also | 40 // Creates request and hands out to HttpStreamFactoryImpl, this will also |
| 39 // create Job(s) and start serving the created request. | 41 // create Job(s) and start serving the created request. |
| 40 Request* Start(const HttpRequestInfo& request_info, | 42 Request* Start(const HttpRequestInfo& request_info, |
| 41 HttpStreamRequest::Delegate* delegate, | 43 HttpStreamRequest::Delegate* delegate, |
| 42 WebSocketHandshakeStreamBase::CreateHelper* | 44 WebSocketHandshakeStreamBase::CreateHelper* |
| 43 websocket_handshake_stream_create_helper, | 45 websocket_handshake_stream_create_helper, |
| 44 const NetLogWithSource& net_log, | 46 const NetLogWithSource& source_net_log, |
| 45 HttpStreamRequest::StreamType stream_type, | 47 HttpStreamRequest::StreamType stream_type, |
| 46 RequestPriority priority, | 48 RequestPriority priority, |
| 47 const SSLConfig& server_ssl_config, | 49 const SSLConfig& server_ssl_config, |
| 48 const SSLConfig& proxy_ssl_config); | 50 const SSLConfig& proxy_ssl_config); |
| 49 | 51 |
| 50 void Preconnect(int num_streams, | 52 void Preconnect(int num_streams, |
| 51 const HttpRequestInfo& request_info, | 53 const HttpRequestInfo& request_info, |
| 52 const SSLConfig& server_ssl_config, | 54 const SSLConfig& server_ssl_config, |
| 53 const SSLConfig& proxy_ssl_config); | 55 const SSLConfig& proxy_ssl_config); |
| 54 | 56 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 183 |
| 182 private: | 184 private: |
| 183 friend class JobControllerPeer; | 185 friend class JobControllerPeer; |
| 184 | 186 |
| 185 // Creates Job(s) for |request_|. Job(s) will be owned by |this|. | 187 // Creates Job(s) for |request_|. Job(s) will be owned by |this|. |
| 186 void CreateJobs(const HttpRequestInfo& request_info, | 188 void CreateJobs(const HttpRequestInfo& request_info, |
| 187 RequestPriority priority, | 189 RequestPriority priority, |
| 188 const SSLConfig& server_ssl_config, | 190 const SSLConfig& server_ssl_config, |
| 189 const SSLConfig& proxy_ssl_config, | 191 const SSLConfig& proxy_ssl_config, |
| 190 HttpStreamRequest::Delegate* delegate, | 192 HttpStreamRequest::Delegate* delegate, |
| 191 HttpStreamRequest::StreamType stream_type, | 193 HttpStreamRequest::StreamType stream_type); |
| 192 const NetLogWithSource& net_log); | |
| 193 | 194 |
| 194 // Attaches |job| to |request_|. Does not mean that |request_| will use |job|. | 195 // Attaches |job| to |request_|. Does not mean that |request_| will use |job|. |
| 195 void AttachJob(Job* job); | 196 void AttachJob(Job* job); |
| 196 | 197 |
| 197 // Called to bind |job| to the |request_| and orphan all other jobs that are | 198 // Called to bind |job| to the |request_| and orphan all other jobs that are |
| 198 // still associated with |request_|. | 199 // still associated with |request_|. |
| 199 void BindJob(Job* job); | 200 void BindJob(Job* job); |
| 200 | 201 |
| 201 // Called when |request_| is destructed. | 202 // Called when |request_| is destructed. |
| 202 // Job(s) associated with but not bound to |request_| will be deleted. | 203 // 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... |
| 272 | 273 |
| 273 // Request will be handed out to factory once created. This just keeps an | 274 // Request will be handed out to factory once created. This just keeps an |
| 274 // reference and is safe as |request_| will notify |this| JobController | 275 // reference and is safe as |request_| will notify |this| JobController |
| 275 // when it's destructed by calling OnRequestComplete(), which nulls | 276 // when it's destructed by calling OnRequestComplete(), which nulls |
| 276 // |request_|. | 277 // |request_|. |
| 277 Request* request_; | 278 Request* request_; |
| 278 | 279 |
| 279 HttpStreamRequest::Delegate* const delegate_; | 280 HttpStreamRequest::Delegate* const delegate_; |
| 280 | 281 |
| 281 // True if this JobController is used to preconnect streams. | 282 // True if this JobController is used to preconnect streams. |
| 282 bool is_preconnect_; | 283 const bool is_preconnect_; |
| 283 | 284 |
| 284 // |main_job_| is a job waiting to see if |alternative_job_| can reuse a | 285 // |main_job_| is a job waiting to see if |alternative_job_| can reuse a |
| 285 // connection. If |alternative_job_| is unable to do so, |this| will notify | 286 // connection. If |alternative_job_| is unable to do so, |this| will notify |
| 286 // |main_job_| to proceed and then race the two jobs. | 287 // |main_job_| to proceed and then race the two jobs. |
| 287 std::unique_ptr<Job> main_job_; | 288 std::unique_ptr<Job> main_job_; |
| 288 std::unique_ptr<Job> alternative_job_; | 289 std::unique_ptr<Job> alternative_job_; |
| 289 | 290 |
| 290 // True if |alternative_job_| uses alternative service/proxy server and it | 291 // True if |alternative_job_| uses alternative service/proxy server and it |
| 291 // fails. | 292 // fails. |
| 292 bool alternative_job_failed_; | 293 bool alternative_job_failed_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 308 // At the point where a Job is irrevocably tied to |request_|, we set this. | 309 // At the point where a Job is irrevocably tied to |request_|, we set this. |
| 309 // It will be nulled when the |request_| is finished. | 310 // It will be nulled when the |request_| is finished. |
| 310 Job* bound_job_; | 311 Job* bound_job_; |
| 311 | 312 |
| 312 // True if an alternative proxy server job can be started to fetch |request_|. | 313 // True if an alternative proxy server job can be started to fetch |request_|. |
| 313 bool can_start_alternative_proxy_job_; | 314 bool can_start_alternative_proxy_job_; |
| 314 | 315 |
| 315 // Privacy mode that should be used for fetching the resource. | 316 // Privacy mode that should be used for fetching the resource. |
| 316 PrivacyMode privacy_mode_; | 317 PrivacyMode privacy_mode_; |
| 317 | 318 |
| 319 const NetLogWithSource net_log_; |
| 320 |
| 318 base::WeakPtrFactory<JobController> ptr_factory_; | 321 base::WeakPtrFactory<JobController> ptr_factory_; |
| 319 }; | 322 }; |
| 320 | 323 |
| 321 } // namespace net | 324 } // namespace net |
| 322 | 325 |
| 323 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ | 326 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ |
| OLD | NEW |