| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 156 |
| 155 // Called when |job| determines the appropriate |spdy_session_key| for the | 157 // Called when |job| determines the appropriate |spdy_session_key| for the |
| 156 // Request. Note that this does not mean that SPDY is necessarily supported | 158 // Request. Note that this does not mean that SPDY is necessarily supported |
| 157 // for this SpdySessionKey, since we may need to wait for NPN to complete | 159 // for this SpdySessionKey, since we may need to wait for NPN to complete |
| 158 // before knowing if SPDY is available. | 160 // before knowing if SPDY is available. |
| 159 void SetSpdySessionKey(Job* job, | 161 void SetSpdySessionKey(Job* job, |
| 160 const SpdySessionKey& spdy_session_key) override; | 162 const SpdySessionKey& spdy_session_key) override; |
| 161 | 163 |
| 162 // Remove session from the SpdySessionRequestMap. | 164 // Remove session from the SpdySessionRequestMap. |
| 163 void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) override; | 165 void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) override; |
| 166 |
| 164 const NetLogWithSource* GetNetLog(Job* job) const override; | 167 const NetLogWithSource* GetNetLog(Job* job) const override; |
| 165 | 168 |
| 166 void MaybeSetWaitTimeForMainJob(const base::TimeDelta& delay) override; | 169 void MaybeSetWaitTimeForMainJob(const base::TimeDelta& delay) override; |
| 167 | 170 |
| 168 WebSocketHandshakeStreamBase::CreateHelper* | 171 WebSocketHandshakeStreamBase::CreateHelper* |
| 169 websocket_handshake_stream_create_helper() override; | 172 websocket_handshake_stream_create_helper() override; |
| 170 | 173 |
| 171 bool is_preconnect() const { return is_preconnect_; } | 174 bool is_preconnect() const { return is_preconnect_; } |
| 172 | 175 |
| 173 // Returns true if |this| has a pending main job that is not completed. | 176 // Returns true if |this| has a pending main job that is not completed. |
| 174 bool HasPendingMainJob() const; | 177 bool HasPendingMainJob() const; |
| 175 | 178 |
| 176 // Returns true if |this| has a pending alternative job that is not completed. | 179 // Returns true if |this| has a pending alternative job that is not completed. |
| 177 bool HasPendingAltJob() const; | 180 bool HasPendingAltJob() const; |
| 178 | 181 |
| 179 // Returns the estimated memory usage in bytes. | 182 // Returns the estimated memory usage in bytes. |
| 180 size_t EstimateMemoryUsage() const; | 183 size_t EstimateMemoryUsage() const; |
| 181 | 184 |
| 182 private: | 185 private: |
| 183 friend class JobControllerPeer; | 186 friend class JobControllerPeer; |
| 184 | 187 |
| 185 // Creates Job(s) for |request_|. Job(s) will be owned by |this|. | 188 // Creates Job(s) for |request_|. Job(s) will be owned by |this|. |
| 186 void CreateJobs(const HttpRequestInfo& request_info, | 189 void CreateJobs(const HttpRequestInfo& request_info, |
| 187 RequestPriority priority, | 190 RequestPriority priority, |
| 188 const SSLConfig& server_ssl_config, | 191 const SSLConfig& server_ssl_config, |
| 189 const SSLConfig& proxy_ssl_config, | 192 const SSLConfig& proxy_ssl_config, |
| 190 HttpStreamRequest::Delegate* delegate, | 193 HttpStreamRequest::Delegate* delegate, |
| 191 HttpStreamRequest::StreamType stream_type, | 194 HttpStreamRequest::StreamType stream_type); |
| 192 const NetLogWithSource& net_log); | |
| 193 | 195 |
| 194 // Attaches |job| to |request_|. Does not mean that |request_| will use |job|. | 196 // Attaches |job| to |request_|. Does not mean that |request_| will use |job|. |
| 195 void AttachJob(Job* job); | 197 void AttachJob(Job* job); |
| 196 | 198 |
| 197 // Called to bind |job| to the |request_| and orphan all other jobs that are | 199 // Called to bind |job| to the |request_| and orphan all other jobs that are |
| 198 // still associated with |request_|. | 200 // still associated with |request_|. |
| 199 void BindJob(Job* job); | 201 void BindJob(Job* job); |
| 200 | 202 |
| 201 // Called when |request_| is destructed. | 203 // Called when |request_| is destructed. |
| 202 // Job(s) associated with but not bound to |request_| will be deleted. | 204 // Job(s) associated with but not bound to |request_| will be deleted. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 275 |
| 274 // 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 |
| 275 // reference and is safe as |request_| will notify |this| JobController | 277 // reference and is safe as |request_| will notify |this| JobController |
| 276 // when it's destructed by calling OnRequestComplete(), which nulls | 278 // when it's destructed by calling OnRequestComplete(), which nulls |
| 277 // |request_|. | 279 // |request_|. |
| 278 Request* request_; | 280 Request* request_; |
| 279 | 281 |
| 280 HttpStreamRequest::Delegate* const delegate_; | 282 HttpStreamRequest::Delegate* const delegate_; |
| 281 | 283 |
| 282 // True if this JobController is used to preconnect streams. | 284 // True if this JobController is used to preconnect streams. |
| 283 bool is_preconnect_; | 285 const bool is_preconnect_; |
| 284 | 286 |
| 285 // |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 |
| 286 // 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 |
| 287 // |main_job_| to proceed and then race the two jobs. | 289 // |main_job_| to proceed and then race the two jobs. |
| 288 std::unique_ptr<Job> main_job_; | 290 std::unique_ptr<Job> main_job_; |
| 289 std::unique_ptr<Job> alternative_job_; | 291 std::unique_ptr<Job> alternative_job_; |
| 290 | 292 |
| 291 // Net error code of the failed alternative job. Set to OK by default. | 293 // Net error code of the failed alternative job. Set to OK by default. |
| 292 int alternative_job_net_error_; | 294 int alternative_job_net_error_; |
| 293 | 295 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 308 // At the point where a Job is irrevocably tied to |request_|, we set this. | 310 // At the point where a Job is irrevocably tied to |request_|, we set this. |
| 309 // It will be nulled when the |request_| is finished. | 311 // It will be nulled when the |request_| is finished. |
| 310 Job* bound_job_; | 312 Job* bound_job_; |
| 311 | 313 |
| 312 // True if an alternative proxy server job can be started to fetch |request_|. | 314 // True if an alternative proxy server job can be started to fetch |request_|. |
| 313 bool can_start_alternative_proxy_job_; | 315 bool can_start_alternative_proxy_job_; |
| 314 | 316 |
| 315 // Privacy mode that should be used for fetching the resource. | 317 // Privacy mode that should be used for fetching the resource. |
| 316 PrivacyMode privacy_mode_; | 318 PrivacyMode privacy_mode_; |
| 317 | 319 |
| 320 const NetLogWithSource net_log_; |
| 321 |
| 318 base::WeakPtrFactory<JobController> ptr_factory_; | 322 base::WeakPtrFactory<JobController> ptr_factory_; |
| 319 }; | 323 }; |
| 320 | 324 |
| 321 } // namespace net | 325 } // namespace net |
| 322 | 326 |
| 323 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ | 327 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ |
| OLD | NEW |