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

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

Issue 1952423002: JobController 2: Remove reference between HttpStreamFactoryImpl::Jobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Job_Controller_1
Patch Set: move resume logic up to controller Created 4 years, 5 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_H_ 5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_
6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 // Invoked when the |job| finishes pre-connecting sockets. 110 // Invoked when the |job| finishes pre-connecting sockets.
111 virtual void OnPreconnectsComplete(Job* job) = 0; 111 virtual void OnPreconnectsComplete(Job* job) = 0;
112 112
113 // Invoked to record connection attempts made by the socket layer to 113 // Invoked to record connection attempts made by the socket layer to
114 // Request if |job| is associated with Request. 114 // Request if |job| is associated with Request.
115 virtual void AddConnectionAttemptsToRequest( 115 virtual void AddConnectionAttemptsToRequest(
116 Job* job, 116 Job* job,
117 const ConnectionAttempts& attempts) = 0; 117 const ConnectionAttempts& attempts) = 0;
118 118
119 // Invoked to resume the main job when |job| initiates a connection but
120 // does not succeed.
121 virtual void OnInitConnectionNotSuccessful(
Ryan Hamilton 2016/06/29 23:12:28 Discussed offline. How about: virtual void OnConn
Zhongyi Shi 2016/06/30 22:53:39 Discussed offline. The controller will need to kno
122 Job* job,
123 const base::TimeDelta& delay) = 0;
124
125 // Return false if |job| has no blocking job and there's no wait time,
126 // i.e., |job| won't call Job::ResumeAfterDelay(). Else return true and
127 // resume |job| with appropriate wait time.
Ryan Hamilton 2016/06/29 23:12:28 How about something like: // Returns false if |jo
Zhongyi Shi 2016/06/30 22:53:39 Done.
128 virtual bool ShoudWait(Job* job) const = 0;
129
119 // Called when |job| determines the appropriate |spdy_session_key| for the 130 // Called when |job| determines the appropriate |spdy_session_key| for the
120 // Request. Note that this does not mean that SPDY is necessarily supported 131 // Request. Note that this does not mean that SPDY is necessarily supported
121 // for this SpdySessionKey, since we may need to wait for NPN to complete 132 // for this SpdySessionKey, since we may need to wait for NPN to complete
122 // before knowing if SPDY is available. 133 // before knowing if SPDY is available.
123 virtual void SetSpdySessionKey(Job* job, 134 virtual void SetSpdySessionKey(Job* job,
124 const SpdySessionKey& spdy_session_key) = 0; 135 const SpdySessionKey& spdy_session_key) = 0;
125 136
126 // Remove session from the SpdySessionRequestMap. 137 // Remove session from the SpdySessionRequestMap.
127 virtual void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) = 0; 138 virtual void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) = 0;
128 139
129 virtual const BoundNetLog* GetNetLog(Job* job) const = 0; 140 virtual const BoundNetLog* GetNetLog(Job* job) const = 0;
130 141
131 virtual WebSocketHandshakeStreamBase::CreateHelper* 142 virtual WebSocketHandshakeStreamBase::CreateHelper*
132 websocket_handshake_stream_create_helper() = 0; 143 websocket_handshake_stream_create_helper() = 0;
133 144
145 virtual bool blocking() = 0;
146 virtual const base::TimeDelta& wait_time_for_main_job() const = 0;
147 virtual void set_wait_time_for_main_job(const base::TimeDelta& delay) = 0;
Ryan Hamilton 2016/06/29 23:12:28 It's not obvious to me why these methods are neede
Zhongyi Shi 2016/06/30 22:53:39 The set method is mainly used for delayed TCP case
148
134 virtual bool for_websockets() = 0; 149 virtual bool for_websockets() = 0;
135 }; 150 };
136 151
137 // Constructor for non-alternative Job. 152 // Constructor for non-alternative Job.
138 // Job is owned by |delegate|, hence |delegate| is valid for the 153 // Job is owned by |delegate|, hence |delegate| is valid for the
139 // lifetime of the Job. 154 // lifetime of the Job.
140 Job(Delegate* delegate, 155 Job(Delegate* delegate,
141 JobType job_type, 156 JobType job_type,
142 HttpNetworkSession* session, 157 HttpNetworkSession* session,
143 const HttpRequestInfo& request_info, 158 const HttpRequestInfo& request_info,
(...skipping 24 matching lines...) Expand all
168 // |delegate_| will be notified upon completion. 183 // |delegate_| will be notified upon completion.
169 virtual void Start(HttpStreamRequest::StreamType stream_type); 184 virtual void Start(HttpStreamRequest::StreamType stream_type);
170 185
171 // Preconnect will attempt to request |num_streams| sockets from the 186 // Preconnect will attempt to request |num_streams| sockets from the
172 // appropriate ClientSocketPool. 187 // appropriate ClientSocketPool.
173 int Preconnect(int num_streams); 188 int Preconnect(int num_streams);
174 189
175 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); 190 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials);
176 LoadState GetLoadState() const; 191 LoadState GetLoadState() const;
177 192
178 // Tells |this| to wait for |job| to resume it. 193 // Tells |this| that |delegate_| has determined it still needs to continue
179 void WaitFor(Job* job); 194 // connecting, so allow |this| to continue after the specified |delay|. If
195 // this is not called, then Request is expected to cancel |this| by
196 // deleting it.
197 virtual void Resume(const base::TimeDelta& delay);
180 198
181 // Tells |this| that |job| has determined it still needs to continue 199 // Resume |this| job after the specified |delay|.
182 // connecting, so allow |this| to continue after the specified |delay|. If 200 void ResumeAfterDelay(const base::TimeDelta& delay);
Ryan Hamilton 2016/06/29 23:12:28 What is the difference between these two methods?
Zhongyi Shi 2016/06/30 22:53:39 In the old world, Resume calles ResumeAfterDelay i
183 // this is not called, then |request_| is expected to cancel |this| by
184 // deleting it.
185 void Resume(Job* job, const base::TimeDelta& delay);
186 201
187 // Called to detach |this| Job. May resume the other Job, will disconnect 202 // Called to detach |this| Job. May resume the other Job, will disconnect
188 // the socket for |this| Job, and notify |delegate| upon completion. 203 // the socket for |this| Job, and notify |delegate| upon completion.
189 void Orphan(); 204 void Orphan();
190 205
191 void SetPriority(RequestPriority priority); 206 void SetPriority(RequestPriority priority);
192 207
193 RequestPriority priority() const { return priority_; } 208 RequestPriority priority() const { return priority_; }
194 bool was_npn_negotiated() const; 209 bool was_npn_negotiated() const;
195 NextProto protocol_negotiated() const; 210 NextProto protocol_negotiated() const;
(...skipping 18 matching lines...) Expand all
214 void ReportJobSucceededForRequest(); 229 void ReportJobSucceededForRequest();
215 230
216 // Marks that the other |job| has completed. 231 // Marks that the other |job| has completed.
217 virtual void MarkOtherJobComplete(const Job& job); 232 virtual void MarkOtherJobComplete(const Job& job);
218 233
219 JobType job_type() const { return job_type_; } 234 JobType job_type() const { return job_type_; }
220 235
221 private: 236 private:
222 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); 237 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob);
223 238
239 friend class HttpStreamFactoryImplJobPeer;
240
224 enum State { 241 enum State {
225 STATE_START, 242 STATE_START,
226 STATE_RESOLVE_PROXY, 243 STATE_RESOLVE_PROXY,
227 STATE_RESOLVE_PROXY_COMPLETE, 244 STATE_RESOLVE_PROXY_COMPLETE,
228 245
229 // Note that when Alternate-Protocol says we can connect to an alternate 246 // Note that when Alternate-Protocol says we can connect to an alternate
230 // port using a different protocol, we have the choice of communicating over 247 // port using a different protocol, we have the choice of communicating over
231 // the original protocol, or speaking the alternate protocol (currently, 248 // the original protocol, or speaking the alternate protocol (currently,
232 // only npn-spdy) over an alternate port. For a cold page load, the http 249 // only npn-spdy) over an alternate port. For a cold page load, the http
233 // connection that delivers the http response that has the 250 // connection that delivers the http response that has the
234 // Alternate-Protocol header will already be warm. So, blocking the next 251 // Alternate-Protocol header will already be warm. So, blocking the next
235 // http request on establishing a new npn-spdy connection would incur extra 252 // http request on establishing a new npn-spdy connection would incur extra
236 // latency. Even if the http connection was not reused, establishing a new 253 // latency. Even if the http connection was not reused, establishing a new
237 // http connection is typically faster than npn-spdy, since npn-spdy 254 // http connection is typically faster than npn-spdy, since npn-spdy
238 // requires a SSL handshake. Therefore, we start both the http and the 255 // requires a SSL handshake. Therefore, we start both the http and the
239 // npn-spdy jobs in parallel. In order not to unnecessarily waste sockets, 256 // npn-spdy jobs in parallel. In order not to unnecessarily waste sockets,
240 // we have the http job block on the npn-spdy job after proxy resolution. 257 // we have the http job block on the npn-spdy job after proxy resolution.
241 // The npn-spdy job will Resume() the http job if, in 258 // The npn-spdy job will Resume() the http job if, in
242 // STATE_INIT_CONNECTION_COMPLETE, it detects an error or does not find an 259 // STATE_INIT_CONNECTION_COMPLETE, it detects an error or does not find an
243 // existing SpdySession. In that case, the http and npn-spdy jobs will race. 260 // existing SpdySession. In that case, the http and npn-spdy jobs will race.
244 // When QUIC protocol is used by the npn-spdy job, then http job will wait 261 // When QUIC protocol is used by the npn-spdy job, then http job will wait
245 // for |wait_time_| when the http job was resumed. 262 // for |wait_time_| when the http job was resumed.
246 STATE_WAIT_FOR_JOB, 263 STATE_WAIT,
247 STATE_WAIT_FOR_JOB_COMPLETE, 264 STATE_WAIT_COMPLETE,
248 265
249 STATE_INIT_CONNECTION, 266 STATE_INIT_CONNECTION,
250 STATE_INIT_CONNECTION_COMPLETE, 267 STATE_INIT_CONNECTION_COMPLETE,
251 STATE_WAITING_USER_ACTION, 268 STATE_WAITING_USER_ACTION,
252 STATE_RESTART_TUNNEL_AUTH, 269 STATE_RESTART_TUNNEL_AUTH,
253 STATE_RESTART_TUNNEL_AUTH_COMPLETE, 270 STATE_RESTART_TUNNEL_AUTH_COMPLETE,
254 STATE_CREATE_STREAM, 271 STATE_CREATE_STREAM,
255 STATE_CREATE_STREAM_COMPLETE, 272 STATE_CREATE_STREAM_COMPLETE,
256 STATE_DRAIN_BODY_FOR_AUTH_RESTART, 273 STATE_DRAIN_BODY_FOR_AUTH_RESTART,
257 STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE, 274 STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // the Job is not a SPDY alternative job, or if |spdy_session| is null. 321 // the Job is not a SPDY alternative job, or if |spdy_session| is null.
305 // Returns appropriate error code otherwise. 322 // Returns appropriate error code otherwise.
306 int CheckAlternativeServiceValidityForOrigin( 323 int CheckAlternativeServiceValidityForOrigin(
307 base::WeakPtr<SpdySession> spdy_session); 324 base::WeakPtr<SpdySession> spdy_session);
308 325
309 SpdySessionPool* const spdy_session_pool_; 326 SpdySessionPool* const spdy_session_pool_;
310 const GURL origin_url_; 327 const GURL origin_url_;
311 const bool is_spdy_alternative_; 328 const bool is_spdy_alternative_;
312 }; 329 };
313 330
314 // Resume the |this| job after the specified |wait_time_|.
315 void ResumeAfterDelay();
316
317 void OnStreamReadyCallback(); 331 void OnStreamReadyCallback();
318 void OnBidirectionalStreamImplReadyCallback(); 332 void OnBidirectionalStreamImplReadyCallback();
319 void OnWebSocketHandshakeStreamReadyCallback(); 333 void OnWebSocketHandshakeStreamReadyCallback();
320 // This callback function is called when a new SPDY session is created. 334 // This callback function is called when a new SPDY session is created.
321 void OnNewSpdySessionReadyCallback(); 335 void OnNewSpdySessionReadyCallback();
322 void OnStreamFailedCallback(int result); 336 void OnStreamFailedCallback(int result);
323 void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info); 337 void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info);
324 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info, 338 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info,
325 HttpAuthController* auth_controller); 339 HttpAuthController* auth_controller);
326 void OnNeedsClientAuthCallback(SSLCertRequestInfo* cert_info); 340 void OnNeedsClientAuthCallback(SSLCertRequestInfo* cert_info);
327 void OnHttpsProxyTunnelResponseCallback(const HttpResponseInfo& response_info, 341 void OnHttpsProxyTunnelResponseCallback(const HttpResponseInfo& response_info,
328 HttpStream* stream); 342 HttpStream* stream);
329 void OnPreconnectsComplete(); 343 void OnPreconnectsComplete();
330 344
331 void OnIOComplete(int result); 345 void OnIOComplete(int result);
332 int RunLoop(int result); 346 int RunLoop(int result);
333 int DoLoop(int result); 347 int DoLoop(int result);
334 int StartInternal(); 348 int StartInternal();
335 349
336 // Each of these methods corresponds to a State value. Those with an input 350 // Each of these methods corresponds to a State value. Those with an input
337 // argument receive the result from the previous state. If a method returns 351 // argument receive the result from the previous state. If a method returns
338 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the 352 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the
339 // next state method as the result arg. 353 // next state method as the result arg.
340 int DoStart(); 354 int DoStart();
341 int DoResolveProxy(); 355 int DoResolveProxy();
342 int DoResolveProxyComplete(int result); 356 int DoResolveProxyComplete(int result);
343 int DoWaitForJob(); 357 int DoWait();
344 int DoWaitForJobComplete(int result); 358 int DoWaitComplete(int result);
345 int DoInitConnection(); 359 int DoInitConnection();
346 int DoInitConnectionComplete(int result); 360 int DoInitConnectionComplete(int result);
347 int DoWaitingUserAction(int result); 361 int DoWaitingUserAction(int result);
348 int DoCreateStream(); 362 int DoCreateStream();
349 int DoCreateStreamComplete(int result); 363 int DoCreateStreamComplete(int result);
350 int DoRestartTunnelAuth(); 364 int DoRestartTunnelAuth();
351 int DoRestartTunnelAuthComplete(int result); 365 int DoRestartTunnelAuthComplete(int result);
352 366
353 // Creates a SpdyHttpStream or a BidirectionalStreamImpl from the given values 367 // Creates a SpdyHttpStream or a BidirectionalStreamImpl from the given values
354 // and sets to |stream_| or |bidirectional_stream_impl_| respectively. Does 368 // and sets to |stream_| or |bidirectional_stream_impl_| respectively. Does
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 const HttpRequestInfo request_info_; 441 const HttpRequestInfo request_info_;
428 RequestPriority priority_; 442 RequestPriority priority_;
429 ProxyInfo proxy_info_; 443 ProxyInfo proxy_info_;
430 SSLConfig server_ssl_config_; 444 SSLConfig server_ssl_config_;
431 SSLConfig proxy_ssl_config_; 445 SSLConfig proxy_ssl_config_;
432 const BoundNetLog net_log_; 446 const BoundNetLog net_log_;
433 447
434 CompletionCallback io_callback_; 448 CompletionCallback io_callback_;
435 std::unique_ptr<ClientSocketHandle> connection_; 449 std::unique_ptr<ClientSocketHandle> connection_;
436 HttpNetworkSession* const session_; 450 HttpNetworkSession* const session_;
451 base::TimeDelta delay_;
452 State state_;
Ryan Hamilton 2016/06/29 23:12:28 nit: as discussed, can we remove this?
Zhongyi Shi 2016/06/30 22:53:39 Done.
437 State next_state_; 453 State next_state_;
438 ProxyService::PacRequest* pac_request_; 454 ProxyService::PacRequest* pac_request_;
439 SSLInfo ssl_info_; 455 SSLInfo ssl_info_;
440 456
441 // The server we are trying to reach, could be that of the origin or of the 457 // The server we are trying to reach, could be that of the origin or of the
442 // alternative service (after applying host mapping rules). 458 // alternative service (after applying host mapping rules).
443 HostPortPair destination_; 459 HostPortPair destination_;
444 460
445 // The origin url we're trying to reach. This url may be different from the 461 // The origin url we're trying to reach. This url may be different from the
446 // original request when host mapping rules are set-up. 462 // original request when host mapping rules are set-up.
447 GURL origin_url_; 463 GURL origin_url_;
448 464
449 // AlternativeService for this Job if this is an alternative Job. 465 // AlternativeService for this Job if this is an alternative Job.
450 const AlternativeService alternative_service_; 466 const AlternativeService alternative_service_;
451 467
452 // AlternativeService for the other Job if this is not an alternative Job. 468 // AlternativeService for the other Job if this is not an alternative Job.
453 AlternativeService other_job_alternative_service_; 469 AlternativeService other_job_alternative_service_;
454 470
455 // Unowned. |this| job is owned by |delegate_|. 471 // Unowned. |this| job is owned by |delegate_|.
456 Delegate* delegate_; 472 Delegate* delegate_;
457 473
458 JobType job_type_; 474 JobType job_type_;
459 475
460 // This is the Job we're dependent on. It will notify us if/when it's OK to
461 // proceed.
462 Job* blocking_job_;
463
464 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection.
465 // If |this| is unable to do so, we'll notify |waiting_job_| that it's ok to
466 // proceed and then race the two Jobs.
467 Job* waiting_job_;
468
469 base::TimeDelta wait_time_;
470
471 // True if handling a HTTPS request, or using SPDY with SSL 476 // True if handling a HTTPS request, or using SPDY with SSL
472 bool using_ssl_; 477 bool using_ssl_;
473 478
474 // True if this network transaction is using SPDY instead of HTTP. 479 // True if this network transaction is using SPDY instead of HTTP.
475 bool using_spdy_; 480 bool using_spdy_;
476 481
477 // True if this network transaction is using QUIC instead of HTTP. 482 // True if this network transaction is using QUIC instead of HTTP.
478 bool using_quic_; 483 bool using_quic_;
479 QuicStreamRequest quic_request_; 484 QuicStreamRequest quic_request_;
480 485
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 const SSLConfig& server_ssl_config, 565 const SSLConfig& server_ssl_config,
561 const SSLConfig& proxy_ssl_config, 566 const SSLConfig& proxy_ssl_config,
562 HostPortPair destination, 567 HostPortPair destination,
563 GURL origin_url, 568 GURL origin_url,
564 NetLog* net_log) = 0; 569 NetLog* net_log) = 0;
565 }; 570 };
566 571
567 } // namespace net 572 } // namespace net
568 573
569 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ 574 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_
OLDNEW
« no previous file with comments | « no previous file | net/http/http_stream_factory_impl_job.cc » ('j') | net/http/http_stream_factory_impl_job.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698