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

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

Issue 2073293002: Revert of JobController 1: Remove cross reference between Request, Job, and Impl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « net/http/http_stream_factory_impl.cc ('k') | net/http/http_stream_factory_impl_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "net/base/completion_callback.h" 14 #include "net/base/completion_callback.h"
15 #include "net/base/net_export.h"
16 #include "net/base/request_priority.h" 15 #include "net/base/request_priority.h"
17 #include "net/http/bidirectional_stream_impl.h"
18 #include "net/http/http_auth.h" 16 #include "net/http/http_auth.h"
19 #include "net/http/http_auth_controller.h" 17 #include "net/http/http_auth_controller.h"
20 #include "net/http/http_request_info.h" 18 #include "net/http/http_request_info.h"
21 #include "net/http/http_stream_factory_impl.h" 19 #include "net/http/http_stream_factory_impl.h"
22 #include "net/log/net_log.h" 20 #include "net/log/net_log.h"
23 #include "net/proxy/proxy_service.h" 21 #include "net/proxy/proxy_service.h"
24 #include "net/quic/quic_stream_factory.h" 22 #include "net/quic/quic_stream_factory.h"
25 #include "net/socket/client_socket_handle.h" 23 #include "net/socket/client_socket_handle.h"
26 #include "net/socket/client_socket_pool_manager.h" 24 #include "net/socket/client_socket_pool_manager.h"
27 #include "net/socket/ssl_client_socket.h" 25 #include "net/socket/ssl_client_socket.h"
28 #include "net/spdy/spdy_session_key.h" 26 #include "net/spdy/spdy_session_key.h"
29 #include "net/ssl/ssl_config_service.h" 27 #include "net/ssl/ssl_config_service.h"
30 28
31 namespace net { 29 namespace net {
32 30
31 class BidirectionalStreamImpl;
33 class ClientSocketHandle; 32 class ClientSocketHandle;
34 class HttpAuthController; 33 class HttpAuthController;
35 class HttpNetworkSession; 34 class HttpNetworkSession;
36 class HttpStream; 35 class HttpStream;
37 class SpdySessionPool; 36 class SpdySessionPool;
38 class QuicHttpStream; 37 class QuicHttpStream;
39 38
40 // An HttpStreamRequestImpl exists for each stream which is in progress of being 39 // An HttpStreamRequestImpl exists for each stream which is in progress of being
41 // created for the StreamFactory. 40 // created for the StreamFactory.
42 class HttpStreamFactoryImpl::Job { 41 class HttpStreamFactoryImpl::Job {
43 public: 42 public:
44 // Delegate to report Job's status to Request and HttpStreamFactory.
45 class NET_EXPORT_PRIVATE Delegate {
46 public:
47 virtual ~Delegate() {}
48
49 // Invoked when |job| has an HttpStream ready.
50 virtual void OnStreamReady(Job* job,
51 const SSLConfig& used_ssl_config,
52 const ProxyInfo& used_proxy_info) = 0;
53
54 // Invoked when |job| has a BidirectionalStream ready.
55 virtual void OnBidirectionalStreamImplReady(
56 Job* job,
57 const SSLConfig& used_ssl_config,
58 const ProxyInfo& used_proxy_info) = 0;
59
60 // Invoked when |job| has a WebSocketHandshakeStream ready.
61 virtual void OnWebSocketHandshakeStreamReady(
62 Job* job,
63 const SSLConfig& used_ssl_config,
64 const ProxyInfo& used_proxy_info,
65 WebSocketHandshakeStreamBase* stream) = 0;
66
67 // Invoked when |job| fails to create a stream.
68 virtual void OnStreamFailed(Job* job,
69 int status,
70 const SSLConfig& used_ssl_config,
71 SSLFailureState ssl_failure_state) = 0;
72
73 // Invoked when |job| has a certificate error for the Request.
74 virtual void OnCertificateError(Job* job,
75 int status,
76 const SSLConfig& used_ssl_config,
77 const SSLInfo& ssl_info) = 0;
78
79 // Invoked when |job| has a failure of the CONNECT request through an HTTPS
80 // proxy.
81 virtual void OnHttpsProxyTunnelResponse(
82 Job* job,
83 const HttpResponseInfo& response_info,
84 const SSLConfig& used_ssl_config,
85 const ProxyInfo& used_proxy_info,
86 HttpStream* stream) = 0;
87
88 // Invoked when |job| raises failure for SSL Client Auth.
89 virtual void OnNeedsClientAuth(Job* job,
90 const SSLConfig& used_ssl_config,
91 SSLCertRequestInfo* cert_info) = 0;
92
93 // Invoked when |job| needs proxy authentication.
94 virtual void OnNeedsProxyAuth(Job* job,
95 const HttpResponseInfo& proxy_response,
96 const SSLConfig& used_ssl_config,
97 const ProxyInfo& used_proxy_info,
98 HttpAuthController* auth_controller) = 0;
99
100 // Invoked to notify the Request and Factory of the readiness of new
101 // SPDY session.
102 virtual void OnNewSpdySessionReady(
103 Job* job,
104 const base::WeakPtr<SpdySession>& spdy_session,
105 bool direct) = 0;
106
107 // Invoked when the orphaned |job| finishes.
108 virtual void OnOrphanedJobComplete(const Job* job) = 0;
109
110 // Invoked when the |job| finishes pre-connecting sockets.
111 virtual void OnPreconnectsComplete(Job* job) = 0;
112
113 // Invoked to record connection attempts made by the socket layer to
114 // Request if |job| is associated with Request.
115 virtual void AddConnectionAttemptsToRequest(
116 Job* job,
117 const ConnectionAttempts& attempts) = 0;
118
119 // Called when |job| determines the appropriate |spdy_session_key| for the
120 // 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
122 // before knowing if SPDY is available.
123 virtual void SetSpdySessionKey(Job* job,
124 const SpdySessionKey& spdy_session_key) = 0;
125
126 // Remove session from the SpdySessionRequestMap.
127 virtual void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) = 0;
128
129 virtual const BoundNetLog* GetNetLog(Job* job) const = 0;
130
131 virtual WebSocketHandshakeStreamBase::CreateHelper*
132 websocket_handshake_stream_create_helper() = 0;
133
134 virtual bool for_websockets() = 0;
135 };
136
137 // Constructor for non-alternative Job. 43 // Constructor for non-alternative Job.
138 // Job is owned by |delegate|, hence |delegate| is valid for the 44 Job(HttpStreamFactoryImpl* stream_factory,
139 // lifetime of the Job.
140 Job(Delegate* delegate,
141 JobType job_type,
142 HttpNetworkSession* session, 45 HttpNetworkSession* session,
143 const HttpRequestInfo& request_info, 46 const HttpRequestInfo& request_info,
144 RequestPriority priority, 47 RequestPriority priority,
145 const SSLConfig& server_ssl_config, 48 const SSLConfig& server_ssl_config,
146 const SSLConfig& proxy_ssl_config, 49 const SSLConfig& proxy_ssl_config,
147 HostPortPair destination, 50 HostPortPair destination,
148 GURL origin_url, 51 GURL origin_url,
149 NetLog* net_log); 52 NetLog* net_log);
150
151 // Constructor for alternative Job. 53 // Constructor for alternative Job.
152 // Job is owned by |delegate|, hence |delegate| is valid for the 54 Job(HttpStreamFactoryImpl* stream_factory,
153 // lifetime of the Job.
154 Job(Delegate* delegate,
155 JobType job_type,
156 HttpNetworkSession* session, 55 HttpNetworkSession* session,
157 const HttpRequestInfo& request_info, 56 const HttpRequestInfo& request_info,
158 RequestPriority priority, 57 RequestPriority priority,
159 const SSLConfig& server_ssl_config, 58 const SSLConfig& server_ssl_config,
160 const SSLConfig& proxy_ssl_config, 59 const SSLConfig& proxy_ssl_config,
161 HostPortPair destination, 60 HostPortPair destination,
162 GURL origin_url, 61 GURL origin_url,
163 AlternativeService alternative_service, 62 AlternativeService alternative_service,
164 NetLog* net_log); 63 NetLog* net_log);
165 virtual ~Job(); 64 ~Job();
166 65
167 // Start initiates the process of creating a new HttpStream. 66 // Start initiates the process of creating a new HttpStream. |request| will be
168 // |delegate_| will be notified upon completion. 67 // notified upon completion if the Job has not been Orphan()'d.
169 virtual void Start(HttpStreamRequest::StreamType stream_type); 68 void Start(Request* request);
170 69
171 // Preconnect will attempt to request |num_streams| sockets from the 70 // Preconnect will attempt to request |num_streams| sockets from the
172 // appropriate ClientSocketPool. 71 // appropriate ClientSocketPool.
173 int Preconnect(int num_streams); 72 int Preconnect(int num_streams);
174 73
175 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); 74 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials);
176 LoadState GetLoadState() const; 75 LoadState GetLoadState() const;
177 76
178 // Tells |this| to wait for |job| to resume it. 77 // Tells |this| to wait for |job| to resume it.
179 void WaitFor(Job* job); 78 void WaitFor(Job* job);
180 79
181 // Tells |this| that |job| has determined it still needs to continue 80 // Tells |this| that |job| has determined it still needs to continue
182 // connecting, so allow |this| to continue after the specified |delay|. If 81 // connecting, so allow |this| to continue after the specified |delay|. If
183 // this is not called, then |request_| is expected to cancel |this| by 82 // this is not called, then |request_| is expected to cancel |this| by
184 // deleting it. 83 // deleting it.
185 void Resume(Job* job, const base::TimeDelta& delay); 84 void Resume(Job* job, const base::TimeDelta& delay);
186 85
187 // Called to detach |this| Job. May resume the other Job, will disconnect 86 // Used to detach the Job from |request|.
188 // the socket for |this| Job, and notify |delegate| upon completion. 87 void Orphan(const Request* request);
189 void Orphan();
190 88
191 void SetPriority(RequestPriority priority); 89 void SetPriority(RequestPriority priority);
192 90
193 RequestPriority priority() const { return priority_; } 91 RequestPriority priority() const { return priority_; }
194 bool was_npn_negotiated() const; 92 bool was_npn_negotiated() const;
195 NextProto protocol_negotiated() const; 93 NextProto protocol_negotiated() const;
196 bool using_spdy() const; 94 bool using_spdy() const;
197 const BoundNetLog& net_log() const { return net_log_; } 95 const BoundNetLog& net_log() const { return net_log_; }
198 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } 96 HttpStreamRequest::StreamType stream_type() const { return stream_type_; }
199 97
200 std::unique_ptr<HttpStream> ReleaseStream() { return std::move(stream_); }
201
202 void SetStream(HttpStream* http_stream) { stream_.reset(http_stream); }
203
204 std::unique_ptr<BidirectionalStreamImpl> ReleaseBidirectionalStream() {
205 return std::move(bidirectional_stream_impl_);
206 }
207
208 const SSLConfig& server_ssl_config() const; 98 const SSLConfig& server_ssl_config() const;
209 const SSLConfig& proxy_ssl_config() const; 99 const SSLConfig& proxy_ssl_config() const;
210 const ProxyInfo& proxy_info() const; 100 const ProxyInfo& proxy_info() const;
211 101
102 // Indicates whether or not this job is performing a preconnect.
103 bool IsPreconnecting() const;
104
105 // Indicates whether or not this Job has been orphaned by a Request.
106 bool IsOrphaned() const;
107
212 // Called to indicate that this job succeeded, and some other jobs 108 // Called to indicate that this job succeeded, and some other jobs
213 // will be orphaned. 109 // will be orphaned.
214 void ReportJobSucceededForRequest(); 110 void ReportJobSucceededForRequest();
215 111
216 // Marks that the other |job| has completed. 112 // Marks that the other |job| has completed.
217 virtual void MarkOtherJobComplete(const Job& job); 113 void MarkOtherJobComplete(const Job& job);
218
219 JobType job_type() const { return job_type_; }
220 114
221 private: 115 private:
222 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); 116 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob);
223 117
224 enum State { 118 enum State {
225 STATE_START, 119 STATE_START,
226 STATE_RESOLVE_PROXY, 120 STATE_RESOLVE_PROXY,
227 STATE_RESOLVE_PROXY_COMPLETE, 121 STATE_RESOLVE_PROXY_COMPLETE,
228 122
229 // Note that when Alternate-Protocol says we can connect to an alternate 123 // Note that when Alternate-Protocol says we can connect to an alternate
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // Invoked by the transport socket pool after host resolution is complete 311 // Invoked by the transport socket pool after host resolution is complete
418 // to allow the connection to be aborted, if a matching SPDY session can 312 // to allow the connection to be aborted, if a matching SPDY session can
419 // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a 313 // be found. Will return ERR_SPDY_SESSION_ALREADY_EXISTS if such a
420 // session is found, and OK otherwise. 314 // session is found, and OK otherwise.
421 static int OnHostResolution(SpdySessionPool* spdy_session_pool, 315 static int OnHostResolution(SpdySessionPool* spdy_session_pool,
422 const SpdySessionKey& spdy_session_key, 316 const SpdySessionKey& spdy_session_key,
423 const GURL& origin_url, 317 const GURL& origin_url,
424 const AddressList& addresses, 318 const AddressList& addresses,
425 const BoundNetLog& net_log); 319 const BoundNetLog& net_log);
426 320
321 Request* request_;
322
427 const HttpRequestInfo request_info_; 323 const HttpRequestInfo request_info_;
428 RequestPriority priority_; 324 RequestPriority priority_;
429 ProxyInfo proxy_info_; 325 ProxyInfo proxy_info_;
430 SSLConfig server_ssl_config_; 326 SSLConfig server_ssl_config_;
431 SSLConfig proxy_ssl_config_; 327 SSLConfig proxy_ssl_config_;
432 const BoundNetLog net_log_; 328 const BoundNetLog net_log_;
433 329
434 CompletionCallback io_callback_; 330 CompletionCallback io_callback_;
435 std::unique_ptr<ClientSocketHandle> connection_; 331 std::unique_ptr<ClientSocketHandle> connection_;
436 HttpNetworkSession* const session_; 332 HttpNetworkSession* const session_;
333 HttpStreamFactoryImpl* const stream_factory_;
437 State next_state_; 334 State next_state_;
438 ProxyService::PacRequest* pac_request_; 335 ProxyService::PacRequest* pac_request_;
439 SSLInfo ssl_info_; 336 SSLInfo ssl_info_;
440 337
441 // The server we are trying to reach, could be that of the origin or of the 338 // The server we are trying to reach, could be that of the origin or of the
442 // alternative service (after applying host mapping rules). 339 // alternative service (after applying host mapping rules).
443 HostPortPair destination_; 340 HostPortPair destination_;
444 341
445 // The origin url we're trying to reach. This url may be different from the 342 // 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. 343 // original request when host mapping rules are set-up.
447 GURL origin_url_; 344 GURL origin_url_;
448 345
449 // AlternativeService for this Job if this is an alternative Job. 346 // AlternativeService for this Job if this is an alternative Job.
450 const AlternativeService alternative_service_; 347 const AlternativeService alternative_service_;
451 348
452 // AlternativeService for the other Job if this is not an alternative Job. 349 // AlternativeService for the other Job if this is not an alternative Job.
453 AlternativeService other_job_alternative_service_; 350 AlternativeService other_job_alternative_service_;
454 351
455 // Unowned. |this| job is owned by |delegate_|.
456 Delegate* delegate_;
457
458 JobType job_type_;
459
460 // This is the Job we're dependent on. It will notify us if/when it's OK to 352 // This is the Job we're dependent on. It will notify us if/when it's OK to
461 // proceed. 353 // proceed.
462 Job* blocking_job_; 354 Job* blocking_job_;
463 355
464 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection. 356 // |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 357 // 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. 358 // proceed and then race the two Jobs.
467 Job* waiting_job_; 359 Job* waiting_job_;
468 360
469 base::TimeDelta wait_time_; 361 base::TimeDelta wait_time_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 base::TimeTicks job_stream_ready_start_time_; 416 base::TimeTicks job_stream_ready_start_time_;
525 417
526 // Type of stream that is requested. 418 // Type of stream that is requested.
527 HttpStreamRequest::StreamType stream_type_; 419 HttpStreamRequest::StreamType stream_type_;
528 420
529 base::WeakPtrFactory<Job> ptr_factory_; 421 base::WeakPtrFactory<Job> ptr_factory_;
530 422
531 DISALLOW_COPY_AND_ASSIGN(Job); 423 DISALLOW_COPY_AND_ASSIGN(Job);
532 }; 424 };
533 425
534 // Factory for creating Jobs.
535 class HttpStreamFactoryImpl::JobFactory {
536 public:
537 virtual ~JobFactory() {}
538
539 // Creates an alternative Job.
540 virtual HttpStreamFactoryImpl::Job* CreateJob(
541 HttpStreamFactoryImpl::Job::Delegate* delegate,
542 HttpStreamFactoryImpl::JobType job_type,
543 HttpNetworkSession* session,
544 const HttpRequestInfo& request_info,
545 RequestPriority priority,
546 const SSLConfig& server_ssl_config,
547 const SSLConfig& proxy_ssl_config,
548 HostPortPair destination,
549 GURL origin_url,
550 AlternativeService alternative_service,
551 NetLog* net_log) = 0;
552
553 // Creates a non-alternative Job.
554 virtual HttpStreamFactoryImpl::Job* CreateJob(
555 HttpStreamFactoryImpl::Job::Delegate* delegate,
556 HttpStreamFactoryImpl::JobType job_type,
557 HttpNetworkSession* session,
558 const HttpRequestInfo& request_info,
559 RequestPriority priority,
560 const SSLConfig& server_ssl_config,
561 const SSLConfig& proxy_ssl_config,
562 HostPortPair destination,
563 GURL origin_url,
564 NetLog* net_log) = 0;
565 };
566
567 } // namespace net 426 } // namespace net
568 427
569 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ 428 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl.cc ('k') | net/http/http_stream_factory_impl_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698