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