Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(614)

Side by Side Diff: net/http/http_stream_factory_impl_job_controller.h

Issue 2814633003: Extract Proxy Resolution out of HttpStreamFactoryImpl::Job (Closed)
Patch Set: unstage unrelated changes Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
Ryan Hamilton 2017/05/09 19:22:07 nit: avoid first person in comments.
xunjieli 2017/05/10 00:26:25 Done.
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
tbansal1 2017/05/09 20:38:48 s/next_state_/|next_state_|/
xunjieli 2017/05/10 00:26:25 Done.
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);
tbansal1 2017/05/09 20:38:48 Can this be a private method?
xunjieli 2017/05/10 00:26:25 Done. Good point!
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
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
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,
Ryan Hamilton 2017/05/09 19:22:06 Should this be removed?
xunjieli 2017/05/10 00:26:25 Done. Ah, Good catch!
197 STATE_NONE
198 };
199
200 void OnIOComplete(int result);
201 void OnResolveProxyError(int error);
202 void RunLoop(int result);
203 int DoLoop(int result);
204 int DoResolveProxy();
205 int DoResolveProxyComplete(int result);
194 // Creates Job(s) for |request_|. Job(s) will be owned by |this|. 206 // Creates Job(s) for |request_|. Job(s) will be owned by |this|.
195 void CreateJobs(const HttpRequestInfo& request_info, 207 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 208
202 // Called to bind |job| to the |request_| and orphan all other jobs that are 209 // Called to bind |job| to the |request_| and orphan all other jobs that are
203 // still associated with |request_|. 210 // still associated with |request_|.
204 void BindJob(Job* job); 211 void BindJob(Job* job);
205 212
206 // Called when |request_| is destructed. 213 // Called when |request_| is destructed.
207 // Job(s) associated with but not bound to |request_| will be deleted. 214 // Job(s) associated with but not bound to |request_| will be deleted.
208 void CancelJobs(); 215 void CancelJobs();
209 216
210 // Called after BindJob() to notify the unbound job that its result should be 217 // 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 218 // ignored by JobController. The unbound job can be canceled or continue until
212 // completion. 219 // completion.
213 void OrphanUnboundJob(); 220 void OrphanUnboundJob();
214 221
215 // Invoked when the orphaned |job| finishes. 222 // Invoked when the orphaned |job| finishes.
216 void OnOrphanedJobComplete(const Job* job); 223 void OnOrphanedJobComplete(const Job* job);
217 224
218 // Called when a Job succeeds. 225 // Called when a Job succeeds.
219 void OnJobSucceeded(Job* job); 226 void OnJobSucceeded(Job* job);
220 227
221 // Marks completion of the |request_|. 228 // Marks completion of the |request_|.
222 void MarkRequestComplete(bool was_alpn_negotiated, 229 void MarkRequestComplete(bool was_alpn_negotiated,
223 NextProto negotiated_protocol, 230 NextProto negotiated_protocol,
224 bool using_spdy); 231 bool using_spdy);
225 232
226 // Must be called when the alternative job fails. |net_error| is the net error 233 // Must be called when the alternative job fails. |net_error| is the net error
227 // of the failed alternative job. 234 // of the failed alternative job.
228 void OnAlternativeJobFailed(int net_error); 235 void OnAlternativeJobFailed(int net_error);
229 236
237 void OnAlternativeProxyJobFailed(int net_error);
238
230 // Called to report to http_server_properties to mark alternative service 239 // Called to report to http_server_properties to mark alternative service
231 // broken. 240 // broken.
232 void ReportBrokenAlternativeService(); 241 void ReportBrokenAlternativeService();
233 242
234 void MaybeNotifyFactoryOfCompletion(); 243 void MaybeNotifyFactoryOfCompletion();
235 244
236 // Called to resume the main job with delay. Main job is resumed only when 245 // 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. 246 // |alternative_job_| has failed or |main_job_wait_time_| elapsed.
238 void MaybeResumeMainJob(Job* job, const base::TimeDelta& delay); 247 void MaybeResumeMainJob(Job* job, const base::TimeDelta& delay);
239 248
(...skipping 14 matching lines...) Expand all
254 HttpStreamRequest::StreamType stream_type); 263 HttpStreamRequest::StreamType stream_type);
255 264
256 // Remove session from the SpdySessionRequestMap. 265 // Remove session from the SpdySessionRequestMap.
257 void RemoveRequestFromSpdySessionRequestMap(); 266 void RemoveRequestFromSpdySessionRequestMap();
258 267
259 // Returns true if the |request_| can be fetched via an alternative 268 // Returns true if the |request_| can be fetched via an alternative
260 // proxy server, and sets |alternative_proxy_server| to the available 269 // proxy server, and sets |alternative_proxy_server| to the available
261 // alternative proxy server. |alternative_proxy_server| should not be null, 270 // alternative proxy server. |alternative_proxy_server| should not be null,
262 // and is owned by the caller. 271 // and is owned by the caller.
263 bool ShouldCreateAlternativeProxyServerJob( 272 bool ShouldCreateAlternativeProxyServerJob(
264 Job* job,
265 const ProxyInfo& proxy_info_, 273 const ProxyInfo& proxy_info_,
266 const GURL& url, 274 const GURL& url,
267 ProxyServer* alternative_proxy_server) const; 275 ProxyServer* alternative_proxy_server) const;
268 276
269 // Records histogram metrics for the usage of alternative protocol. Must be 277 // Records histogram metrics for the usage of alternative protocol. Must be
270 // called when |job| has succeeded and the other job will be orphaned. 278 // called when |job| has succeeded and the other job will be orphaned.
271 void ReportAlternateProtocolUsage(Job* job) const; 279 void ReportAlternateProtocolUsage(Job* job) const;
272 280
273 // Starts the |alternative_job_|. 281 // Starts the |alternative_job_|.
274 void StartAlternativeProxyServerJob(); 282 void StartAlternativeProxyServerJob();
(...skipping 24 matching lines...) Expand all
299 const bool enable_alternative_services_; 307 const bool enable_alternative_services_;
300 308
301 // |main_job_| is a job waiting to see if |alternative_job_| can reuse a 309 // |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 310 // connection. If |alternative_job_| is unable to do so, |this| will notify
303 // |main_job_| to proceed and then race the two jobs. 311 // |main_job_| to proceed and then race the two jobs.
304 std::unique_ptr<Job> main_job_; 312 std::unique_ptr<Job> main_job_;
305 std::unique_ptr<Job> alternative_job_; 313 std::unique_ptr<Job> alternative_job_;
306 314
307 // Net error code of the failed alternative job. Set to OK by default. 315 // Net error code of the failed alternative job. Set to OK by default.
308 int alternative_job_net_error_; 316 int alternative_job_net_error_;
309 317 // 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_; 318 AlternativeService failed_alternative_service_;
313 ProxyServer failed_alternative_proxy_server_;
314 319
315 // True if a Job has ever been bound to the |request_|. 320 // True if a Job has ever been bound to the |request_|.
316 bool job_bound_; 321 bool job_bound_;
317 322
318 // True if the main job has to wait for the alternative job: i.e., the main 323 // 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. 324 // job must not create a connection until it is resumed.
320 bool main_job_is_blocked_; 325 bool main_job_is_blocked_;
321 326
322 // True if the main job was blocked and has been resumed in ResumeMainJob(). 327 // True if the main job was blocked and has been resumed in ResumeMainJob().
323 bool main_job_is_resumed_; 328 bool main_job_is_resumed_;
324 329
325 // Waiting time for the main job before it is resumed. 330 // Waiting time for the main job before it is resumed.
326 base::TimeDelta main_job_wait_time_; 331 base::TimeDelta main_job_wait_time_;
327 332
328 // At the point where a Job is irrevocably tied to |request_|, we set this. 333 // At the point where a Job is irrevocably tied to |request_|, we set this.
329 // It will be nulled when the |request_| is finished. 334 // It will be nulled when the |request_| is finished.
330 Job* bound_job_; 335 Job* bound_job_;
331 336
332 // True if an alternative proxy server job can be started to fetch |request_|. 337 // True if an alternative proxy server job can be started to fetch |request_|.
333 bool can_start_alternative_proxy_job_; 338 bool can_start_alternative_proxy_job_;
334 339
335 // Privacy mode that should be used for fetching the resource. 340 // Privacy mode that should be used for fetching the resource.
336 PrivacyMode privacy_mode_; 341 PrivacyMode privacy_mode_;
337 342
343 State next_state_;
344 ProxyService::PacRequest* pac_request_;
345
338 const NetLogWithSource net_log_; 346 const NetLogWithSource net_log_;
tbansal1 2017/05/09 20:38:48 nit: |net_log_| should be the last entry (before W
xunjieli 2017/05/10 00:26:25 Done.
339 347
348 CompletionCallback io_callback_;
349 const HttpRequestInfo request_info_;
350 ProxyInfo proxy_info_;
351 const SSLConfig server_ssl_config_;
352 const SSLConfig proxy_ssl_config_;
353 int num_streams_;
354
355 HttpStreamRequest::StreamType stream_type_;
356 RequestPriority priority_;
357
340 base::WeakPtrFactory<JobController> ptr_factory_; 358 base::WeakPtrFactory<JobController> ptr_factory_;
341 }; 359 };
342 360
343 } // namespace net 361 } // namespace net
344 362
345 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ 363 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698