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