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

Side by Side Diff: net/http/http_stream_factory_impl_job_controller.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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_
6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_
7
8 #include "net/http/http_stream_factory_impl_job.h"
9 #include "net/http/http_stream_factory_impl_request.h"
10
11 namespace net {
12
13 // HttpStreamFactoryImpl::JobController manages Request and Job(s).
14 class HttpStreamFactoryImpl::JobController
15 : public HttpStreamFactoryImpl::Job::Delegate,
16 public HttpStreamFactoryImpl::Request::Helper {
17 public:
18 JobController(HttpStreamFactoryImpl* factory,
19 HttpStreamRequest::Delegate* delegate,
20 HttpNetworkSession* session,
21 JobFactory* job_factory);
22
23 ~JobController() override;
24
25 bool for_websockets() override;
26
27 // Used in tests only for verification purpose.
28 const Job* main_job() const { return main_job_.get(); }
29 const Job* alternative_job() const { return alternative_job_.get(); }
30
31 GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint);
32
33 // Methods below are called by HttpStreamFactoryImpl only.
34 // Creates request and hands out to HttpStreamFactoryImpl, this will also
35 // create Job(s) and start serving the created request.
36 Request* Start(const HttpRequestInfo& request_info,
37 HttpStreamRequest::Delegate* delegate,
38 WebSocketHandshakeStreamBase::CreateHelper*
39 websocket_handshake_stream_create_helper,
40 const BoundNetLog& net_log,
41 HttpStreamRequest::StreamType stream_type,
42 RequestPriority priority,
43 const SSLConfig& server_ssl_config,
44 const SSLConfig& proxy_ssl_config);
45
46 void Preconnect(int num_streams,
47 const HttpRequestInfo& request_info,
48 const SSLConfig& server_ssl_config,
49 const SSLConfig& proxy_ssl_config);
50
51 // From HttpStreamFactoryImpl::Request::Helper.
52 // Returns the LoadState for Request.
53 LoadState GetLoadState() const override;
54
55 // Called when Request is destructed. Job(s) associated with but not bound to
56 // |request_| will be deleted. |request_| and |bound_job_| will be nulled if
57 // ever set.
58 void OnRequestComplete() override;
59
60 // Called to resume the HttpStream creation process when necessary
61 // Proxy authentication credentials are collected.
62 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override;
63
64 // Called when the priority of transaction changes.
65 void SetPriority(RequestPriority priority) override;
66
67 // From HttpStreamFactoryImpl::Job::Delegate.
68 // Invoked when |job| has an HttpStream ready.
69 void OnStreamReady(Job* job,
70 const SSLConfig& used_ssl_config,
71 const ProxyInfo& used_proxy_info) override;
72
73 // Invoked when |job| has a BidirectionalStream ready.
74 void OnBidirectionalStreamImplReady(
75 Job* job,
76 const SSLConfig& used_ssl_config,
77 const ProxyInfo& used_proxy_info) override;
78
79 // Invoked when |job| has a WebSocketHandshakeStream ready.
80 void OnWebSocketHandshakeStreamReady(
81 Job* job,
82 const SSLConfig& used_ssl_config,
83 const ProxyInfo& used_proxy_info,
84 WebSocketHandshakeStreamBase* stream) override;
85
86 // Invoked when |job| fails to create a stream.
87 void OnStreamFailed(Job* job,
88 int status,
89 const SSLConfig& used_ssl_config,
90 SSLFailureState ssl_failure_state) override;
91
92 // Invoked when |job| has a certificate error for the Request.
93 void OnCertificateError(Job* job,
94 int status,
95 const SSLConfig& used_ssl_config,
96 const SSLInfo& ssl_info) override;
97
98 // Invoked when |job| has a failure of the CONNECT request through an HTTPS
99 // proxy.
100 void OnHttpsProxyTunnelResponse(Job* job,
101 const HttpResponseInfo& response_info,
102 const SSLConfig& used_ssl_config,
103 const ProxyInfo& used_proxy_info,
104 HttpStream* stream) override;
105
106 // Invoked when |job| raises failure for SSL Client Auth.
107 void OnNeedsClientAuth(Job* job,
108 const SSLConfig& used_ssl_config,
109 SSLCertRequestInfo* cert_info) override;
110
111 // Invoked when |job| needs proxy authentication.
112 void OnNeedsProxyAuth(Job* job,
113 const HttpResponseInfo& proxy_response,
114 const SSLConfig& used_ssl_config,
115 const ProxyInfo& used_proxy_info,
116 HttpAuthController* auth_controller) override;
117
118 // Invoked to notify the Request and Factory of the readiness of new
119 // SPDY session.
120 void OnNewSpdySessionReady(Job* job,
121 const base::WeakPtr<SpdySession>& spdy_session,
122 bool direct) override;
123
124 // Invoked when the orphaned |job| finishes.
125 void OnOrphanedJobComplete(const Job* job) override;
126
127 // Invoked when the |job| finishes pre-connecting sockets.
128 void OnPreconnectsComplete(Job* job) override;
129
130 // Invoked to record connection attempts made by the socket layer to
131 // Request if |job| is associated with Request.
132 void AddConnectionAttemptsToRequest(
133 Job* job,
134 const ConnectionAttempts& attempts) override;
135
136 // Called when |job| determines the appropriate |spdy_session_key| for the
137 // Request. Note that this does not mean that SPDY is necessarily supported
138 // for this SpdySessionKey, since we may need to wait for NPN to complete
139 // before knowing if SPDY is available.
140 void SetSpdySessionKey(Job* job,
141 const SpdySessionKey& spdy_session_key) override;
142
143 // Remove session from the SpdySessionRequestMap.
144 void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) override;
145 const BoundNetLog* GetNetLog(Job* job) const override;
146 WebSocketHandshakeStreamBase::CreateHelper*
147 websocket_handshake_stream_create_helper() override;
148
149 private:
150 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob);
151
152 // Creates Job(s) for |request_|. Job(s) will be owned by |this|.
153 void CreateJobs(const HttpRequestInfo& request_info,
154 RequestPriority priority,
155 const SSLConfig& server_ssl_config,
156 const SSLConfig& proxy_ssl_config,
157 HttpStreamRequest::Delegate* delegate,
158 HttpStreamRequest::StreamType stream_type,
159 const BoundNetLog& net_log);
160
161 // Attaches |job| to |request_|. Does not mean that |request_| will use |job|.
162 void AttachJob(Job* job);
163
164 // Called to bind |job| to the |request_| and orphan all other jobs that are
165 // still associated with |request_|.
166 void BindJob(Job* job);
167
168 // Called when |request_| is destructed.
169 // Job(s) associated with but not bound to |request_| will be deleted.
170 void CancelJobs();
171
172 // Called after BindJob() to notify the unbound job that its result should be
173 // ignored by JobController. The unbound job can be canceled or continue until
174 // completion.
175 void OrphanUnboundJob();
176
177 // Called when a Job succeeds.
178 void OnJobSucceeded(Job* job);
179
180 // Marks completion of the |request_|.
181 void MarkRequestComplete(bool was_npn_negotiated,
182 NextProto protocol_negotiated,
183 bool using_spdy);
184
185 void MaybeNotifyFactoryOfCompletion();
186
187 // Returns true if QUIC is whitelisted for |host|.
188 bool IsQuicWhitelistedForHost(const std::string& host);
189
190 AlternativeService GetAlternativeServiceFor(
191 const HttpRequestInfo& request_info,
192 HttpStreamRequest::Delegate* delegate,
193 HttpStreamRequest::StreamType stream_type);
194
195 AlternativeService GetAlternativeServiceForInternal(
196 const HttpRequestInfo& request_info,
197 HttpStreamRequest::Delegate* delegate,
198 HttpStreamRequest::StreamType stream_type);
199
200 // Remove session from the SpdySessionRequestMap.
201 void RemoveRequestFromSpdySessionRequestMap();
202
203 HttpStreamFactoryImpl* factory_;
204 HttpNetworkSession* session_;
205 JobFactory* job_factory_;
206
207 // Request will be handed out to factory once created. This just keeps an
208 // reference and is safe as |request_| will notify |this| JobController
209 // when it's destructed by calling OnRequestComplete(), which nulls
210 // |request_|.
211 Request* request_;
212
213 HttpStreamRequest::Delegate* const delegate_;
214
215 // True if this JobController is used to preconnect streams.
216 bool is_preconnect_;
217
218 // |main_job_| is a job waiting to see if |alternative_job_| can reuse a
219 // connection. If |alternative_job_| is unable to do so, |this| will notify
220 // |main_job_| to proceed and then race the two jobs.
221 std::unique_ptr<Job> main_job_;
222 std::unique_ptr<Job> alternative_job_;
223
224 // True if a Job has ever been bound to the |request_|.
225 bool job_bound_;
226
227 // At the point where a Job is irrevocably tied to |request_|, we set this.
228 // It will be nulled when the |request_| is finished.
229 Job* bound_job_;
230 };
231
232 } // namespace net
233
234 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job.cc ('k') | net/http/http_stream_factory_impl_job_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698