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

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

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

Powered by Google App Engine
This is Rietveld 408576698