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

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

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

Powered by Google App Engine
This is Rietveld 408576698