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