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, | 26 const HttpRequestInfo& request_info, |
27 bool is_preconnect, | 27 bool is_preconnect, |
28 bool enable_ip_based_pooling, | 28 bool enable_ip_based_pooling, |
29 bool enable_alternative_services); | 29 bool enable_alternative_services, |
| 30 const SSLConfig& server_ssl_config, |
| 31 const SSLConfig& proxy_ssl_config); |
30 | 32 |
31 ~JobController() override; | 33 ~JobController() override; |
32 | 34 |
33 bool for_websockets() override; | 35 bool for_websockets() override; |
34 | 36 |
35 // Used in tests only for verification purpose. | 37 // Used in tests only for verification purpose. |
36 const Job* main_job() const { return main_job_.get(); } | 38 const Job* main_job() const { return main_job_.get(); } |
37 const Job* alternative_job() const { return alternative_job_.get(); } | 39 const Job* alternative_job() const { return alternative_job_.get(); } |
38 | 40 |
39 GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint); | 41 GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint); |
40 | 42 |
41 // Methods below are called by HttpStreamFactoryImpl only. | 43 // Methods below are called by HttpStreamFactoryImpl only. |
42 // Creates request and hands out to HttpStreamFactoryImpl, this will also | 44 // Creates request and hands out to HttpStreamFactoryImpl, this will also |
43 // create Job(s) and start serving the created request. | 45 // create Job(s) and start serving the created request. |
44 Request* Start(const HttpRequestInfo& request_info, | 46 Request* Start(HttpStreamRequest::Delegate* delegate, |
45 HttpStreamRequest::Delegate* delegate, | |
46 WebSocketHandshakeStreamBase::CreateHelper* | 47 WebSocketHandshakeStreamBase::CreateHelper* |
47 websocket_handshake_stream_create_helper, | 48 websocket_handshake_stream_create_helper, |
48 const NetLogWithSource& source_net_log, | 49 const NetLogWithSource& source_net_log, |
49 HttpStreamRequest::StreamType stream_type, | 50 HttpStreamRequest::StreamType stream_type, |
50 RequestPriority priority, | 51 RequestPriority priority); |
51 const SSLConfig& server_ssl_config, | |
52 const SSLConfig& proxy_ssl_config); | |
53 | 52 |
54 void Preconnect(int num_streams, | 53 void Preconnect(int num_streams); |
55 const HttpRequestInfo& request_info, | |
56 const SSLConfig& server_ssl_config, | |
57 const SSLConfig& proxy_ssl_config); | |
58 | 54 |
59 // From HttpStreamFactoryImpl::Request::Helper. | 55 // From HttpStreamFactoryImpl::Request::Helper. |
60 // Returns the LoadState for Request. | 56 // Returns the LoadState for Request. |
61 LoadState GetLoadState() const override; | 57 LoadState GetLoadState() const override; |
62 | 58 |
63 // Called when Request is destructed. Job(s) associated with but not bound to | 59 // Called when Request is destructed. Job(s) associated with but not bound to |
64 // |request_| will be deleted. |request_| and |bound_job_| will be nulled if | 60 // |request_| will be deleted. |request_| and |bound_job_| will be nulled if |
65 // ever set. | 61 // ever set. |
66 void OnRequestComplete() override; | 62 void OnRequestComplete() override; |
67 | 63 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 111 |
116 // Invoked when |job| needs proxy authentication. | 112 // Invoked when |job| needs proxy authentication. |
117 void OnNeedsProxyAuth(Job* job, | 113 void OnNeedsProxyAuth(Job* job, |
118 const HttpResponseInfo& proxy_response, | 114 const HttpResponseInfo& proxy_response, |
119 const SSLConfig& used_ssl_config, | 115 const SSLConfig& used_ssl_config, |
120 const ProxyInfo& used_proxy_info, | 116 const ProxyInfo& used_proxy_info, |
121 HttpAuthController* auth_controller) override; | 117 HttpAuthController* auth_controller) override; |
122 | 118 |
123 bool OnInitConnection(const ProxyInfo& proxy_info) override; | 119 bool OnInitConnection(const ProxyInfo& proxy_info) override; |
124 | 120 |
125 void OnResolveProxyComplete( | |
126 Job* job, | |
127 const HttpRequestInfo& request_info, | |
128 RequestPriority priority, | |
129 const SSLConfig& server_ssl_config, | |
130 const SSLConfig& proxy_ssl_config, | |
131 HttpStreamRequest::StreamType stream_type) override; | |
132 | 121 |
133 // Invoked to notify the Request and Factory of the readiness of new | 122 // Invoked to notify the Request and Factory of the readiness of new |
134 // SPDY session. | 123 // SPDY session. |
135 void OnNewSpdySessionReady(Job* job, | 124 void OnNewSpdySessionReady(Job* job, |
136 const base::WeakPtr<SpdySession>& spdy_session, | 125 const base::WeakPtr<SpdySession>& spdy_session, |
137 bool direct) override; | 126 bool direct) override; |
138 | 127 |
139 // Invoked when the |job| finishes pre-connecting sockets. | 128 // Invoked when the |job| finishes pre-connecting sockets. |
140 void OnPreconnectsComplete(Job* job) override; | 129 void OnPreconnectsComplete(Job* job) override; |
141 | 130 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // TODO(xunjieli): Added to investigate crbug.com/711721. Remove when no | 173 // TODO(xunjieli): Added to investigate crbug.com/711721. Remove when no |
185 // longer needed. | 174 // longer needed. |
186 void LogHistograms() const; | 175 void LogHistograms() const; |
187 | 176 |
188 // Returns the estimated memory usage in bytes. | 177 // Returns the estimated memory usage in bytes. |
189 size_t EstimateMemoryUsage() const; | 178 size_t EstimateMemoryUsage() const; |
190 | 179 |
191 private: | 180 private: |
192 friend class JobControllerPeer; | 181 friend class JobControllerPeer; |
193 | 182 |
| 183 enum State { |
| 184 STATE_RESOLVE_PROXY, |
| 185 STATE_RESOLVE_PROXY_COMPLETE, |
| 186 |
| 187 STATE_CREATE_JOBS, |
| 188 STATE_NONE |
| 189 }; |
| 190 |
| 191 void OnIOComplete(int result); |
| 192 void OnResolveProxyError(int error); |
| 193 void RunLoop(int result); |
| 194 int DoLoop(int result); |
| 195 int DoResolveProxy(); |
| 196 int DoResolveProxyComplete(int result); |
194 // Creates Job(s) for |request_|. Job(s) will be owned by |this|. | 197 // Creates Job(s) for |request_|. Job(s) will be owned by |this|. |
195 void CreateJobs(const HttpRequestInfo& request_info, | 198 int DoCreateJobs(); |
196 RequestPriority priority, | |
197 const SSLConfig& server_ssl_config, | |
198 const SSLConfig& proxy_ssl_config, | |
199 HttpStreamRequest::Delegate* delegate, | |
200 HttpStreamRequest::StreamType stream_type); | |
201 | 199 |
202 // 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 |
203 // still associated with |request_|. | 201 // still associated with |request_|. |
204 void BindJob(Job* job); | 202 void BindJob(Job* job); |
205 | 203 |
206 // Called when |request_| is destructed. | 204 // Called when |request_| is destructed. |
207 // 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. |
208 void CancelJobs(); | 206 void CancelJobs(); |
209 | 207 |
210 // Called after BindJob() to notify the unbound job that its result should be | 208 // Called after BindJob() to notify the unbound job that its result should be |
211 // ignored by JobController. The unbound job can be canceled or continue until | 209 // ignored by JobController. The unbound job can be canceled or continue until |
212 // completion. | 210 // completion. |
213 void OrphanUnboundJob(); | 211 void OrphanUnboundJob(); |
214 | 212 |
215 // Invoked when the orphaned |job| finishes. | 213 // Invoked when the orphaned |job| finishes. |
216 void OnOrphanedJobComplete(const Job* job); | 214 void OnOrphanedJobComplete(const Job* job); |
217 | 215 |
218 // Called when a Job succeeds. | 216 // Called when a Job succeeds. |
219 void OnJobSucceeded(Job* job); | 217 void OnJobSucceeded(Job* job); |
220 | 218 |
221 // Marks completion of the |request_|. | 219 // Marks completion of the |request_|. |
222 void MarkRequestComplete(bool was_alpn_negotiated, | 220 void MarkRequestComplete(bool was_alpn_negotiated, |
223 NextProto negotiated_protocol, | 221 NextProto negotiated_protocol, |
224 bool using_spdy); | 222 bool using_spdy); |
225 | 223 |
226 // Must be called when the alternative job fails. |net_error| is the net error | 224 // Must be called when the alternative service job fails. |net_error| is the |
227 // of the failed alternative job. | 225 // net error of the failed alternative service job. |
228 void OnAlternativeJobFailed(int net_error); | 226 void OnAlternativeServiceJobFailed(int net_error); |
| 227 |
| 228 // Must be called when the alternative proxy job fails. |net_error| is the |
| 229 // net error of the failed alternative proxy job. |
| 230 void OnAlternativeProxyJobFailed(int net_error); |
229 | 231 |
230 // Called to report to http_server_properties to mark alternative service | 232 // Called to report to http_server_properties to mark alternative service |
231 // broken. | 233 // broken. |
232 void ReportBrokenAlternativeService(); | 234 void ReportBrokenAlternativeService(); |
233 | 235 |
234 void MaybeNotifyFactoryOfCompletion(); | 236 void MaybeNotifyFactoryOfCompletion(); |
235 | 237 |
236 // Called to resume the main job with delay. Main job is resumed only when | 238 // Called to resume the main job with delay. Main job is resumed only when |
237 // |alternative_job_| has failed or |main_job_wait_time_| elapsed. | 239 // |alternative_job_| has failed or |main_job_wait_time_| elapsed. |
238 void MaybeResumeMainJob(Job* job, const base::TimeDelta& delay); | 240 void MaybeResumeMainJob(Job* job, const base::TimeDelta& delay); |
(...skipping 15 matching lines...) Expand all Loading... |
254 HttpStreamRequest::StreamType stream_type); | 256 HttpStreamRequest::StreamType stream_type); |
255 | 257 |
256 // Remove session from the SpdySessionRequestMap. | 258 // Remove session from the SpdySessionRequestMap. |
257 void RemoveRequestFromSpdySessionRequestMap(); | 259 void RemoveRequestFromSpdySessionRequestMap(); |
258 | 260 |
259 // Returns true if the |request_| can be fetched via an alternative | 261 // Returns true if the |request_| can be fetched via an alternative |
260 // proxy server, and sets |alternative_proxy_server| to the available | 262 // proxy server, and sets |alternative_proxy_server| to the available |
261 // alternative proxy server. |alternative_proxy_server| should not be null, | 263 // alternative proxy server. |alternative_proxy_server| should not be null, |
262 // and is owned by the caller. | 264 // and is owned by the caller. |
263 bool ShouldCreateAlternativeProxyServerJob( | 265 bool ShouldCreateAlternativeProxyServerJob( |
264 Job* job, | |
265 const ProxyInfo& proxy_info_, | 266 const ProxyInfo& proxy_info_, |
266 const GURL& url, | 267 const GURL& url, |
267 ProxyServer* alternative_proxy_server) const; | 268 ProxyServer* alternative_proxy_server) const; |
268 | 269 |
269 // Records histogram metrics for the usage of alternative protocol. Must be | 270 // Records histogram metrics for the usage of alternative protocol. Must be |
270 // called when |job| has succeeded and the other job will be orphaned. | 271 // called when |job| has succeeded and the other job will be orphaned. |
271 void ReportAlternateProtocolUsage(Job* job) const; | 272 void ReportAlternateProtocolUsage(Job* job) const; |
272 | 273 |
273 // Starts the |alternative_job_|. | |
274 void StartAlternativeProxyServerJob(); | |
275 | |
276 // Returns whether |job| is an orphaned job. | 274 // Returns whether |job| is an orphaned job. |
277 bool IsJobOrphaned(Job* job) const; | 275 bool IsJobOrphaned(Job* job) const; |
278 | 276 |
| 277 // Called when a Job encountered a network error that could be resolved by |
| 278 // trying a new proxy configuration. If there is another proxy configuration |
| 279 // to try then this method sets |next_state_| appropriately and returns either |
| 280 // OK or ERR_IO_PENDING depending on whether or not the new proxy |
| 281 // configuration is available synchronously or asynchronously. Otherwise, the |
| 282 // given error code is simply returned. |
| 283 int ReconsiderProxyAfterError(Job* job, int error); |
| 284 |
279 HttpStreamFactoryImpl* factory_; | 285 HttpStreamFactoryImpl* factory_; |
280 HttpNetworkSession* session_; | 286 HttpNetworkSession* session_; |
281 JobFactory* job_factory_; | 287 JobFactory* job_factory_; |
282 | 288 |
283 // Request will be handed out to factory once created. This just keeps an | 289 // Request will be handed out to factory once created. This just keeps an |
284 // reference and is safe as |request_| will notify |this| JobController | 290 // reference and is safe as |request_| will notify |this| JobController |
285 // when it's destructed by calling OnRequestComplete(), which nulls | 291 // when it's destructed by calling OnRequestComplete(), which nulls |
286 // |request_|. | 292 // |request_|. |
287 Request* request_; | 293 Request* request_; |
288 | 294 |
(...skipping 10 matching lines...) Expand all Loading... |
299 const bool enable_alternative_services_; | 305 const bool enable_alternative_services_; |
300 | 306 |
301 // |main_job_| is a job waiting to see if |alternative_job_| can reuse a | 307 // |main_job_| is a job waiting to see if |alternative_job_| can reuse a |
302 // connection. If |alternative_job_| is unable to do so, |this| will notify | 308 // connection. If |alternative_job_| is unable to do so, |this| will notify |
303 // |main_job_| to proceed and then race the two jobs. | 309 // |main_job_| to proceed and then race the two jobs. |
304 std::unique_ptr<Job> main_job_; | 310 std::unique_ptr<Job> main_job_; |
305 std::unique_ptr<Job> alternative_job_; | 311 std::unique_ptr<Job> alternative_job_; |
306 | 312 |
307 // Net error code of the failed alternative job. Set to OK by default. | 313 // Net error code of the failed alternative job. Set to OK by default. |
308 int alternative_job_net_error_; | 314 int alternative_job_net_error_; |
309 | 315 // The alternative service server that |alternative_job_| uses failed. |
310 // Either and only one of these records failed alternative service/proxy | |
311 // server that |alternative_job_| uses. | |
312 AlternativeService failed_alternative_service_; | 316 AlternativeService failed_alternative_service_; |
313 ProxyServer failed_alternative_proxy_server_; | |
314 | 317 |
315 // True if a Job has ever been bound to the |request_|. | 318 // True if a Job has ever been bound to the |request_|. |
316 bool job_bound_; | 319 bool job_bound_; |
317 | 320 |
318 // True if the main job has to wait for the alternative job: i.e., the main | 321 // True if the main job has to wait for the alternative job: i.e., the main |
319 // job must not create a connection until it is resumed. | 322 // job must not create a connection until it is resumed. |
320 bool main_job_is_blocked_; | 323 bool main_job_is_blocked_; |
321 | 324 |
322 // True if the main job was blocked and has been resumed in ResumeMainJob(). | 325 // True if the main job was blocked and has been resumed in ResumeMainJob(). |
323 bool main_job_is_resumed_; | 326 bool main_job_is_resumed_; |
324 | 327 |
325 // Waiting time for the main job before it is resumed. | 328 // Waiting time for the main job before it is resumed. |
326 base::TimeDelta main_job_wait_time_; | 329 base::TimeDelta main_job_wait_time_; |
327 | 330 |
328 // At the point where a Job is irrevocably tied to |request_|, we set this. | 331 // At the point where a Job is irrevocably tied to |request_|, we set this. |
329 // It will be nulled when the |request_| is finished. | 332 // It will be nulled when the |request_| is finished. |
330 Job* bound_job_; | 333 Job* bound_job_; |
331 | 334 |
332 // True if an alternative proxy server job can be started to fetch |request_|. | 335 // True if an alternative proxy server job can be started to fetch |request_|. |
333 bool can_start_alternative_proxy_job_; | 336 bool can_start_alternative_proxy_job_; |
334 | 337 |
335 // Privacy mode that should be used for fetching the resource. | 338 // Privacy mode that should be used for fetching the resource. |
336 PrivacyMode privacy_mode_; | 339 PrivacyMode privacy_mode_; |
337 | 340 |
| 341 State next_state_; |
| 342 ProxyService::PacRequest* pac_request_; |
| 343 CompletionCallback io_callback_; |
| 344 const HttpRequestInfo request_info_; |
| 345 ProxyInfo proxy_info_; |
| 346 const SSLConfig server_ssl_config_; |
| 347 const SSLConfig proxy_ssl_config_; |
| 348 int num_streams_; |
| 349 HttpStreamRequest::StreamType stream_type_; |
| 350 RequestPriority priority_; |
338 const NetLogWithSource net_log_; | 351 const NetLogWithSource net_log_; |
339 | 352 |
340 base::WeakPtrFactory<JobController> ptr_factory_; | 353 base::WeakPtrFactory<JobController> ptr_factory_; |
341 }; | 354 }; |
342 | 355 |
343 } // namespace net | 356 } // namespace net |
344 | 357 |
345 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ | 358 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ |
OLD | NEW |