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 |
68 // Called to resume the HttpStream creation process when necessary | 64 // Called to resume the HttpStream creation process when necessary |
69 // Proxy authentication credentials are collected. | 65 // Proxy authentication credentials are collected. |
70 int RestartTunnelWithProxyAuth() override; | 66 int RestartTunnelWithProxyAuth() override; |
71 | 67 |
| 68 // Called when we encounter a network error that could be resolved by trying |
| 69 // a new proxy configuration. If there is another proxy configuration to try |
| 70 // then this method sets next_state_ appropriately and returns either OK or |
| 71 // ERR_IO_PENDING depending on whether or not the new proxy configuration is |
| 72 // available synchronously or asynchronously. Otherwise, the given error |
| 73 // code is simply returned. |
| 74 int ReconsiderProxyAfterError(Job* job, int error); |
| 75 |
72 // Called when the priority of transaction changes. | 76 // Called when the priority of transaction changes. |
73 void SetPriority(RequestPriority priority) override; | 77 void SetPriority(RequestPriority priority) override; |
74 | 78 |
75 // From HttpStreamFactoryImpl::Job::Delegate. | 79 // From HttpStreamFactoryImpl::Job::Delegate. |
76 // Invoked when |job| has an HttpStream ready. | 80 // Invoked when |job| has an HttpStream ready. |
77 void OnStreamReady(Job* job, const SSLConfig& used_ssl_config) override; | 81 void OnStreamReady(Job* job, const SSLConfig& used_ssl_config) override; |
78 | 82 |
79 // Invoked when |job| has a BidirectionalStream ready. | 83 // Invoked when |job| has a BidirectionalStream ready. |
80 void OnBidirectionalStreamImplReady( | 84 void OnBidirectionalStreamImplReady( |
81 Job* job, | 85 Job* job, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 119 |
116 // Invoked when |job| needs proxy authentication. | 120 // Invoked when |job| needs proxy authentication. |
117 void OnNeedsProxyAuth(Job* job, | 121 void OnNeedsProxyAuth(Job* job, |
118 const HttpResponseInfo& proxy_response, | 122 const HttpResponseInfo& proxy_response, |
119 const SSLConfig& used_ssl_config, | 123 const SSLConfig& used_ssl_config, |
120 const ProxyInfo& used_proxy_info, | 124 const ProxyInfo& used_proxy_info, |
121 HttpAuthController* auth_controller) override; | 125 HttpAuthController* auth_controller) override; |
122 | 126 |
123 bool OnInitConnection(const ProxyInfo& proxy_info) override; | 127 bool OnInitConnection(const ProxyInfo& proxy_info) override; |
124 | 128 |
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 | 129 |
133 // Invoked to notify the Request and Factory of the readiness of new | 130 // Invoked to notify the Request and Factory of the readiness of new |
134 // SPDY session. | 131 // SPDY session. |
135 void OnNewSpdySessionReady(Job* job, | 132 void OnNewSpdySessionReady(Job* job, |
136 const base::WeakPtr<SpdySession>& spdy_session, | 133 const base::WeakPtr<SpdySession>& spdy_session, |
137 bool direct) override; | 134 bool direct) override; |
138 | 135 |
139 // Invoked when the |job| finishes pre-connecting sockets. | 136 // Invoked when the |job| finishes pre-connecting sockets. |
140 void OnPreconnectsComplete(Job* job) override; | 137 void OnPreconnectsComplete(Job* job) override; |
141 | 138 |
(...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 | 181 // TODO(xunjieli): Added to investigate crbug.com/711721. Remove when no |
185 // longer needed. | 182 // longer needed. |
186 void LogHistograms() const; | 183 void LogHistograms() const; |
187 | 184 |
188 // Returns the estimated memory usage in bytes. | 185 // Returns the estimated memory usage in bytes. |
189 size_t EstimateMemoryUsage() const; | 186 size_t EstimateMemoryUsage() const; |
190 | 187 |
191 private: | 188 private: |
192 friend class JobControllerPeer; | 189 friend class JobControllerPeer; |
193 | 190 |
| 191 enum State { |
| 192 STATE_RESOLVE_PROXY, |
| 193 STATE_RESOLVE_PROXY_COMPLETE, |
| 194 |
| 195 STATE_CREATE_JOBS, |
| 196 // STATE_CREATE_JOBS_COMPLETE, |
| 197 STATE_NONE |
| 198 }; |
| 199 |
| 200 void OnIOComplete(int result); |
| 201 void OnResolveProxyError(int error); |
| 202 void RunLoop(int result); |
| 203 void DoResolveProxy(); |
| 204 void DoResolveProxyComplete(int result); |
194 // Creates Job(s) for |request_|. Job(s) will be owned by |this|. | 205 // Creates Job(s) for |request_|. Job(s) will be owned by |this|. |
195 void CreateJobs(const HttpRequestInfo& request_info, | 206 void 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 | 207 |
202 // Called to bind |job| to the |request_| and orphan all other jobs that are | 208 // Called to bind |job| to the |request_| and orphan all other jobs that are |
203 // still associated with |request_|. | 209 // still associated with |request_|. |
204 void BindJob(Job* job); | 210 void BindJob(Job* job); |
205 | 211 |
206 // Called when |request_| is destructed. | 212 // Called when |request_| is destructed. |
207 // Job(s) associated with but not bound to |request_| will be deleted. | 213 // Job(s) associated with but not bound to |request_| will be deleted. |
208 void CancelJobs(); | 214 void CancelJobs(); |
209 | 215 |
210 // Called after BindJob() to notify the unbound job that its result should be | 216 // 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 | 217 // ignored by JobController. The unbound job can be canceled or continue until |
212 // completion. | 218 // completion. |
213 void OrphanUnboundJob(); | 219 void OrphanUnboundJob(); |
214 | 220 |
215 // Invoked when the orphaned |job| finishes. | 221 // Invoked when the orphaned |job| finishes. |
216 void OnOrphanedJobComplete(const Job* job); | 222 void OnOrphanedJobComplete(const Job* job); |
217 | 223 |
218 // Called when a Job succeeds. | 224 // Called when a Job succeeds. |
219 void OnJobSucceeded(Job* job); | 225 void OnJobSucceeded(Job* job); |
220 | 226 |
221 // Marks completion of the |request_|. | 227 // Marks completion of the |request_|. |
222 void MarkRequestComplete(bool was_alpn_negotiated, | 228 void MarkRequestComplete(bool was_alpn_negotiated, |
223 NextProto negotiated_protocol, | 229 NextProto negotiated_protocol, |
224 bool using_spdy); | 230 bool using_spdy); |
225 | 231 |
226 // Must be called when the alternative job fails. |net_error| is the net error | 232 // Must be called when the alternative job fails. |net_error| is the net error |
227 // of the failed alternative job. | 233 // of the failed alternative job. |
228 void OnAlternativeJobFailed(int net_error); | 234 void OnAlternativeJobFailed(int net_error); |
229 | 235 |
| 236 void OnAlternativeProxyJobFailed(int net_error); |
| 237 |
230 // Called to report to http_server_properties to mark alternative service | 238 // Called to report to http_server_properties to mark alternative service |
231 // broken. | 239 // broken. |
232 void ReportBrokenAlternativeService(); | 240 void ReportBrokenAlternativeService(); |
233 | 241 |
234 void MaybeNotifyFactoryOfCompletion(); | 242 void MaybeNotifyFactoryOfCompletion(); |
235 | 243 |
236 // Called to resume the main job with delay. Main job is resumed only when | 244 // 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. | 245 // |alternative_job_| has failed or |main_job_wait_time_| elapsed. |
238 void MaybeResumeMainJob(Job* job, const base::TimeDelta& delay); | 246 void MaybeResumeMainJob(Job* job, const base::TimeDelta& delay); |
239 | 247 |
(...skipping 14 matching lines...) Expand all Loading... |
254 HttpStreamRequest::StreamType stream_type); | 262 HttpStreamRequest::StreamType stream_type); |
255 | 263 |
256 // Remove session from the SpdySessionRequestMap. | 264 // Remove session from the SpdySessionRequestMap. |
257 void RemoveRequestFromSpdySessionRequestMap(); | 265 void RemoveRequestFromSpdySessionRequestMap(); |
258 | 266 |
259 // Returns true if the |request_| can be fetched via an alternative | 267 // Returns true if the |request_| can be fetched via an alternative |
260 // proxy server, and sets |alternative_proxy_server| to the available | 268 // proxy server, and sets |alternative_proxy_server| to the available |
261 // alternative proxy server. |alternative_proxy_server| should not be null, | 269 // alternative proxy server. |alternative_proxy_server| should not be null, |
262 // and is owned by the caller. | 270 // and is owned by the caller. |
263 bool ShouldCreateAlternativeProxyServerJob( | 271 bool ShouldCreateAlternativeProxyServerJob( |
264 Job* job, | |
265 const ProxyInfo& proxy_info_, | 272 const ProxyInfo& proxy_info_, |
266 const GURL& url, | 273 const GURL& url, |
267 ProxyServer* alternative_proxy_server) const; | 274 ProxyServer* alternative_proxy_server) const; |
268 | 275 |
269 // Records histogram metrics for the usage of alternative protocol. Must be | 276 // Records histogram metrics for the usage of alternative protocol. Must be |
270 // called when |job| has succeeded and the other job will be orphaned. | 277 // called when |job| has succeeded and the other job will be orphaned. |
271 void ReportAlternateProtocolUsage(Job* job) const; | 278 void ReportAlternateProtocolUsage(Job* job) const; |
272 | 279 |
273 // Starts the |alternative_job_|. | 280 // Starts the |alternative_job_|. |
274 void StartAlternativeProxyServerJob(); | 281 void StartAlternativeProxyServerJob(); |
(...skipping 24 matching lines...) Expand all Loading... |
299 const bool enable_alternative_services_; | 306 const bool enable_alternative_services_; |
300 | 307 |
301 // |main_job_| is a job waiting to see if |alternative_job_| can reuse a | 308 // |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 | 309 // connection. If |alternative_job_| is unable to do so, |this| will notify |
303 // |main_job_| to proceed and then race the two jobs. | 310 // |main_job_| to proceed and then race the two jobs. |
304 std::unique_ptr<Job> main_job_; | 311 std::unique_ptr<Job> main_job_; |
305 std::unique_ptr<Job> alternative_job_; | 312 std::unique_ptr<Job> alternative_job_; |
306 | 313 |
307 // Net error code of the failed alternative job. Set to OK by default. | 314 // Net error code of the failed alternative job. Set to OK by default. |
308 int alternative_job_net_error_; | 315 int alternative_job_net_error_; |
309 | 316 // 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_; | 317 AlternativeService failed_alternative_service_; |
313 ProxyServer failed_alternative_proxy_server_; | |
314 | 318 |
315 // True if a Job has ever been bound to the |request_|. | 319 // True if a Job has ever been bound to the |request_|. |
316 bool job_bound_; | 320 bool job_bound_; |
317 | 321 |
318 // True if the main job has to wait for the alternative job: i.e., the main | 322 // 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. | 323 // job must not create a connection until it is resumed. |
320 bool main_job_is_blocked_; | 324 bool main_job_is_blocked_; |
321 | 325 |
322 // True if the main job was blocked and has been resumed in ResumeMainJob(). | 326 // True if the main job was blocked and has been resumed in ResumeMainJob(). |
323 bool main_job_is_resumed_; | 327 bool main_job_is_resumed_; |
324 | 328 |
325 // Waiting time for the main job before it is resumed. | 329 // Waiting time for the main job before it is resumed. |
326 base::TimeDelta main_job_wait_time_; | 330 base::TimeDelta main_job_wait_time_; |
327 | 331 |
328 // At the point where a Job is irrevocably tied to |request_|, we set this. | 332 // At the point where a Job is irrevocably tied to |request_|, we set this. |
329 // It will be nulled when the |request_| is finished. | 333 // It will be nulled when the |request_| is finished. |
330 Job* bound_job_; | 334 Job* bound_job_; |
331 | 335 |
332 // True if an alternative proxy server job can be started to fetch |request_|. | 336 // True if an alternative proxy server job can be started to fetch |request_|. |
333 bool can_start_alternative_proxy_job_; | 337 bool can_start_alternative_proxy_job_; |
334 | 338 |
335 // Privacy mode that should be used for fetching the resource. | 339 // Privacy mode that should be used for fetching the resource. |
336 PrivacyMode privacy_mode_; | 340 PrivacyMode privacy_mode_; |
337 | 341 |
| 342 State next_state_; |
| 343 ProxyService::PacRequest* pac_request_; |
| 344 |
338 const NetLogWithSource net_log_; | 345 const NetLogWithSource net_log_; |
339 | 346 |
| 347 CompletionCallback io_callback_; |
| 348 const HttpRequestInfo request_info_; |
| 349 ProxyInfo proxy_info_; |
| 350 const SSLConfig server_ssl_config_; |
| 351 const SSLConfig proxy_ssl_config_; |
| 352 int num_streams_; |
| 353 |
| 354 HttpStreamRequest::StreamType stream_type_; |
| 355 RequestPriority priority_; |
| 356 |
340 base::WeakPtrFactory<JobController> ptr_factory_; | 357 base::WeakPtrFactory<JobController> ptr_factory_; |
341 }; | 358 }; |
342 | 359 |
343 } // namespace net | 360 } // namespace net |
344 | 361 |
345 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ | 362 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ |
OLD | NEW |