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

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: More tests with Resume logic 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 when |job| finishes initiating a connection.
120 virtual void OnConnectionInitialized(Job* job, int rv) = 0;
121
122 // Return false if |job| can advance to the next state. Otherwise, |job|
123 // will wait for Job::OnIOComplete() to be called before advancing.
Ryan Hamilton 2016/07/12 00:21:45 Resume() not OnIOComplete(), right?
Zhongyi Shi 2016/07/12 23:03:12 Done.
124 virtual bool ShouldWait(Job* job) = 0;
125
119 // Called when |job| determines the appropriate |spdy_session_key| for the 126 // Called when |job| determines the appropriate |spdy_session_key| for the
120 // Request. Note that this does not mean that SPDY is necessarily supported 127 // 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 128 // for this SpdySessionKey, since we may need to wait for NPN to complete
122 // before knowing if SPDY is available. 129 // before knowing if SPDY is available.
123 virtual void SetSpdySessionKey(Job* job, 130 virtual void SetSpdySessionKey(Job* job,
124 const SpdySessionKey& spdy_session_key) = 0; 131 const SpdySessionKey& spdy_session_key) = 0;
125 132
126 // Remove session from the SpdySessionRequestMap. 133 // Remove session from the SpdySessionRequestMap.
127 virtual void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) = 0; 134 virtual void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) = 0;
128 135
129 virtual const BoundNetLog* GetNetLog(Job* job) const = 0; 136 virtual const BoundNetLog* GetNetLog(Job* job) const = 0;
130 137
131 virtual WebSocketHandshakeStreamBase::CreateHelper* 138 virtual WebSocketHandshakeStreamBase::CreateHelper*
132 websocket_handshake_stream_create_helper() = 0; 139 websocket_handshake_stream_create_helper() = 0;
133 140
141 virtual void SetWaitTimeForMainJob(const base::TimeDelta& delay) = 0;
142
134 virtual bool for_websockets() = 0; 143 virtual bool for_websockets() = 0;
135 }; 144 };
136 145
137 // Constructor for non-alternative Job. 146 // Constructor for non-alternative Job.
138 // Job is owned by |delegate|, hence |delegate| is valid for the 147 // Job is owned by |delegate|, hence |delegate| is valid for the
139 // lifetime of the Job. 148 // lifetime of the Job.
140 Job(Delegate* delegate, 149 Job(Delegate* delegate,
141 JobType job_type, 150 JobType job_type,
142 HttpNetworkSession* session, 151 HttpNetworkSession* session,
143 const HttpRequestInfo& request_info, 152 const HttpRequestInfo& request_info,
(...skipping 24 matching lines...) Expand all
168 // |delegate_| will be notified upon completion. 177 // |delegate_| will be notified upon completion.
169 virtual void Start(HttpStreamRequest::StreamType stream_type); 178 virtual void Start(HttpStreamRequest::StreamType stream_type);
170 179
171 // Preconnect will attempt to request |num_streams| sockets from the 180 // Preconnect will attempt to request |num_streams| sockets from the
172 // appropriate ClientSocketPool. 181 // appropriate ClientSocketPool.
173 int Preconnect(int num_streams); 182 int Preconnect(int num_streams);
174 183
175 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); 184 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials);
176 LoadState GetLoadState() const; 185 LoadState GetLoadState() const;
177 186
178 // Tells |this| to wait for |job| to resume it. 187 // Tells |this| that |delegate_| has determined it still needs to continue
179 void WaitFor(Job* job); 188 // connecting.
180 189 virtual void Resume();
181 // Tells |this| that |job| has determined it still needs to continue
182 // connecting, so allow |this| to continue after the specified |delay|. If
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 190
187 // Called to detach |this| Job. May resume the other Job, will disconnect 191 // Called to detach |this| Job. May resume the other Job, will disconnect
188 // the socket for |this| Job, and notify |delegate| upon completion. 192 // the socket for |this| Job, and notify |delegate| upon completion.
189 void Orphan(); 193 void Orphan();
190 194
191 void SetPriority(RequestPriority priority); 195 void SetPriority(RequestPriority priority);
192 196
193 RequestPriority priority() const { return priority_; } 197 RequestPriority priority() const { return priority_; }
194 bool was_npn_negotiated() const; 198 bool was_npn_negotiated() const;
195 NextProto protocol_negotiated() const; 199 NextProto protocol_negotiated() const;
196 bool using_spdy() const; 200 bool using_spdy() const;
197 const BoundNetLog& net_log() const { return net_log_; } 201 const BoundNetLog& net_log() const { return net_log_; }
198 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } 202 HttpStreamRequest::StreamType stream_type() const { return stream_type_; }
199 203
200 std::unique_ptr<HttpStream> ReleaseStream() { return std::move(stream_); } 204 std::unique_ptr<HttpStream> ReleaseStream() { return std::move(stream_); }
201 205
202 void SetStream(HttpStream* http_stream) { stream_.reset(http_stream); } 206 void SetStream(HttpStream* http_stream) { stream_.reset(http_stream); }
203 207
204 std::unique_ptr<BidirectionalStreamImpl> ReleaseBidirectionalStream() { 208 std::unique_ptr<BidirectionalStreamImpl> ReleaseBidirectionalStream() {
205 return std::move(bidirectional_stream_impl_); 209 return std::move(bidirectional_stream_impl_);
206 } 210 }
207 211
212 bool is_waiting() const { return next_state_ == STATE_WAIT_COMPLETE; }
208 const SSLConfig& server_ssl_config() const; 213 const SSLConfig& server_ssl_config() const;
209 const SSLConfig& proxy_ssl_config() const; 214 const SSLConfig& proxy_ssl_config() const;
210 const ProxyInfo& proxy_info() const; 215 const ProxyInfo& proxy_info() const;
211 216
212 // Called to indicate that this job succeeded, and some other jobs 217 // Called to indicate that this job succeeded, and some other jobs
213 // will be orphaned. 218 // will be orphaned.
214 void ReportJobSucceededForRequest(); 219 void ReportJobSucceededForRequest();
215 220
216 // Marks that the other |job| has completed. 221 // Marks that the other |job| has completed.
217 virtual void MarkOtherJobComplete(const Job& job); 222 virtual void MarkOtherJobComplete(const Job& job);
218 223
219 JobType job_type() const { return job_type_; } 224 JobType job_type() const { return job_type_; }
220 225
221 private: 226 private:
222 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); 227 friend class HttpStreamFactoryImplJobPeer;
223 228
224 enum State { 229 enum State {
225 STATE_START, 230 STATE_START,
226 STATE_RESOLVE_PROXY, 231 STATE_RESOLVE_PROXY,
227 STATE_RESOLVE_PROXY_COMPLETE, 232 STATE_RESOLVE_PROXY_COMPLETE,
228 233
229 // Note that when Alternate-Protocol says we can connect to an alternate 234 // 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 235 // port using a different protocol, we have the choice of communicating over
231 // the original protocol, or speaking the alternate protocol (currently, 236 // the original protocol, or speaking the alternate protocol (currently,
232 // only npn-spdy) over an alternate port. For a cold page load, the http 237 // only npn-spdy) over an alternate port. For a cold page load, the http
233 // connection that delivers the http response that has the 238 // connection that delivers the http response that has the
234 // Alternate-Protocol header will already be warm. So, blocking the next 239 // Alternate-Protocol header will already be warm. So, blocking the next
235 // http request on establishing a new npn-spdy connection would incur extra 240 // 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 241 // latency. Even if the http connection was not reused, establishing a new
237 // http connection is typically faster than npn-spdy, since npn-spdy 242 // http connection is typically faster than npn-spdy, since npn-spdy
238 // requires a SSL handshake. Therefore, we start both the http and the 243 // 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, 244 // 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. 245 // 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 246 // 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 247 // 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. 248 // 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 249 // 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. 250 // for |wait_time_| when the http job was resumed.
246 STATE_WAIT_FOR_JOB, 251 STATE_WAIT,
247 STATE_WAIT_FOR_JOB_COMPLETE, 252 STATE_WAIT_COMPLETE,
248 253
249 STATE_INIT_CONNECTION, 254 STATE_INIT_CONNECTION,
250 STATE_INIT_CONNECTION_COMPLETE, 255 STATE_INIT_CONNECTION_COMPLETE,
251 STATE_WAITING_USER_ACTION, 256 STATE_WAITING_USER_ACTION,
252 STATE_RESTART_TUNNEL_AUTH, 257 STATE_RESTART_TUNNEL_AUTH,
253 STATE_RESTART_TUNNEL_AUTH_COMPLETE, 258 STATE_RESTART_TUNNEL_AUTH_COMPLETE,
254 STATE_CREATE_STREAM, 259 STATE_CREATE_STREAM,
255 STATE_CREATE_STREAM_COMPLETE, 260 STATE_CREATE_STREAM_COMPLETE,
256 STATE_DRAIN_BODY_FOR_AUTH_RESTART, 261 STATE_DRAIN_BODY_FOR_AUTH_RESTART,
257 STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE, 262 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. 309 // the Job is not a SPDY alternative job, or if |spdy_session| is null.
305 // Returns appropriate error code otherwise. 310 // Returns appropriate error code otherwise.
306 int CheckAlternativeServiceValidityForOrigin( 311 int CheckAlternativeServiceValidityForOrigin(
307 base::WeakPtr<SpdySession> spdy_session); 312 base::WeakPtr<SpdySession> spdy_session);
308 313
309 SpdySessionPool* const spdy_session_pool_; 314 SpdySessionPool* const spdy_session_pool_;
310 const GURL origin_url_; 315 const GURL origin_url_;
311 const bool is_spdy_alternative_; 316 const bool is_spdy_alternative_;
312 }; 317 };
313 318
314 // Resume the |this| job after the specified |wait_time_|.
315 void ResumeAfterDelay();
316
317 void OnStreamReadyCallback(); 319 void OnStreamReadyCallback();
318 void OnBidirectionalStreamImplReadyCallback(); 320 void OnBidirectionalStreamImplReadyCallback();
319 void OnWebSocketHandshakeStreamReadyCallback(); 321 void OnWebSocketHandshakeStreamReadyCallback();
320 // This callback function is called when a new SPDY session is created. 322 // This callback function is called when a new SPDY session is created.
321 void OnNewSpdySessionReadyCallback(); 323 void OnNewSpdySessionReadyCallback();
322 void OnStreamFailedCallback(int result); 324 void OnStreamFailedCallback(int result);
323 void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info); 325 void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info);
324 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info, 326 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info,
325 HttpAuthController* auth_controller); 327 HttpAuthController* auth_controller);
326 void OnNeedsClientAuthCallback(SSLCertRequestInfo* cert_info); 328 void OnNeedsClientAuthCallback(SSLCertRequestInfo* cert_info);
327 void OnHttpsProxyTunnelResponseCallback(const HttpResponseInfo& response_info, 329 void OnHttpsProxyTunnelResponseCallback(const HttpResponseInfo& response_info,
328 HttpStream* stream); 330 HttpStream* stream);
329 void OnPreconnectsComplete(); 331 void OnPreconnectsComplete();
330 332
331 void OnIOComplete(int result); 333 void OnIOComplete(int result);
332 int RunLoop(int result); 334 int RunLoop(int result);
333 int DoLoop(int result); 335 int DoLoop(int result);
334 int StartInternal(); 336 int StartInternal();
337 int DoInitConnectionImpl();
335 338
336 // Each of these methods corresponds to a State value. Those with an input 339 // 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 340 // 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 341 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the
339 // next state method as the result arg. 342 // next state method as the result arg.
340 int DoStart(); 343 int DoStart();
341 int DoResolveProxy(); 344 int DoResolveProxy();
342 int DoResolveProxyComplete(int result); 345 int DoResolveProxyComplete(int result);
343 int DoWaitForJob(); 346 int DoWait();
344 int DoWaitForJobComplete(int result); 347 int DoWaitComplete(int result);
345 int DoInitConnection(); 348 int DoInitConnection();
346 int DoInitConnectionComplete(int result); 349 int DoInitConnectionComplete(int result);
347 int DoWaitingUserAction(int result); 350 int DoWaitingUserAction(int result);
348 int DoCreateStream(); 351 int DoCreateStream();
349 int DoCreateStreamComplete(int result); 352 int DoCreateStreamComplete(int result);
350 int DoRestartTunnelAuth(); 353 int DoRestartTunnelAuth();
351 int DoRestartTunnelAuthComplete(int result); 354 int DoRestartTunnelAuthComplete(int result);
352 355
353 // Creates a SpdyHttpStream or a BidirectionalStreamImpl from the given values 356 // Creates a SpdyHttpStream or a BidirectionalStreamImpl from the given values
354 // and sets to |stream_| or |bidirectional_stream_impl_| respectively. Does 357 // and sets to |stream_| or |bidirectional_stream_impl_| respectively. Does
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 const AlternativeService alternative_service_; 453 const AlternativeService alternative_service_;
451 454
452 // AlternativeService for the other Job if this is not an alternative Job. 455 // AlternativeService for the other Job if this is not an alternative Job.
453 AlternativeService other_job_alternative_service_; 456 AlternativeService other_job_alternative_service_;
454 457
455 // Unowned. |this| job is owned by |delegate_|. 458 // Unowned. |this| job is owned by |delegate_|.
456 Delegate* delegate_; 459 Delegate* delegate_;
457 460
458 JobType job_type_; 461 JobType job_type_;
459 462
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 463 // True if handling a HTTPS request, or using SPDY with SSL
472 bool using_ssl_; 464 bool using_ssl_;
473 465
474 // True if this network transaction is using SPDY instead of HTTP. 466 // True if this network transaction is using SPDY instead of HTTP.
475 bool using_spdy_; 467 bool using_spdy_;
476 468
477 // True if this network transaction is using QUIC instead of HTTP. 469 // True if this network transaction is using QUIC instead of HTTP.
478 bool using_quic_; 470 bool using_quic_;
479 QuicStreamRequest quic_request_; 471 QuicStreamRequest quic_request_;
480 472
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 const SSLConfig& server_ssl_config, 552 const SSLConfig& server_ssl_config,
561 const SSLConfig& proxy_ssl_config, 553 const SSLConfig& proxy_ssl_config,
562 HostPortPair destination, 554 HostPortPair destination,
563 GURL origin_url, 555 GURL origin_url,
564 NetLog* net_log) = 0; 556 NetLog* net_log) = 0;
565 }; 557 };
566 558
567 } // namespace net 559 } // namespace net
568 560
569 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ 561 #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