| 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 JobFactory { |
| 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(); } |
| 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 LoadState GetLoadState() const override; |
| 83 |
| 84 // Job(s) associated with but not bound to |request_| will be deleted. |
| 85 // |request_| and |bound_job_| will be nulled if ever set. |
| 86 void OnRequestComplete() override; |
| 87 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override; |
| 88 void SetPriority(RequestPriority priority) override; |
| 89 |
| 90 // From HttpStreamFactoryImpl::Job::Delegate. |
| 91 void OnStreamReady(Job* job, |
| 92 const SSLConfig& used_ssl_config, |
| 93 const ProxyInfo& used_proxy_info) override; |
| 94 void OnBidirectionalStreamImplReady( |
| 95 Job* job, |
| 96 const SSLConfig& used_ssl_config, |
| 97 const ProxyInfo& used_proxy_info) override; |
| 98 void OnWebSocketHandshakeStreamReady( |
| 99 Job* job, |
| 100 const SSLConfig& used_ssl_config, |
| 101 const ProxyInfo& used_proxy_info, |
| 102 WebSocketHandshakeStreamBase* stream) override; |
| 103 void OnStreamFailed(Job* job, |
| 104 int status, |
| 105 const SSLConfig& used_ssl_config, |
| 106 SSLFailureState ssl_failure_state) override; |
| 107 void OnCertificateError(Job* job, |
| 108 int status, |
| 109 const SSLConfig& used_ssl_config, |
| 110 const SSLInfo& ssl_info) override; |
| 111 void OnHttpsProxyTunnelResponse(Job* job, |
| 112 const HttpResponseInfo& response_info, |
| 113 const SSLConfig& used_ssl_config, |
| 114 const ProxyInfo& used_proxy_info, |
| 115 HttpStream* stream) override; |
| 116 void OnNeedsClientAuth(Job* job, |
| 117 const SSLConfig& used_ssl_config, |
| 118 SSLCertRequestInfo* cert_info) override; |
| 119 void OnNeedsProxyAuth(Job* job, |
| 120 const HttpResponseInfo& proxy_response, |
| 121 const SSLConfig& used_ssl_config, |
| 122 const ProxyInfo& used_proxy_info, |
| 123 HttpAuthController* auth_controller) override; |
| 124 void OnNewSpdySessionReady(Job* job, |
| 125 const base::WeakPtr<SpdySession>& spdy_session, |
| 126 bool direct) override; |
| 127 void OnOrphanedJobComplete(const Job* job) override; |
| 128 void OnPreconnectsComplete(Job* job) override; |
| 129 void AddConnectionAttemptsToRequest( |
| 130 Job* job, |
| 131 const ConnectionAttempts& attempts) override; |
| 132 void SetSpdySessionKey(Job* job, |
| 133 const SpdySessionKey& spdy_session_key) override; |
| 134 void RemoveRequestFromSpdySessionRequestMapForJob(Job* job) override; |
| 135 const BoundNetLog* GetNetLog(Job* job) const override; |
| 136 WebSocketHandshakeStreamBase::CreateHelper* |
| 137 websocket_handshake_stream_create_helper() override; |
| 138 |
| 139 private: |
| 140 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, SetPriority); |
| 141 FRIEND_TEST_ALL_PREFIXES(HttpStreamFactoryImplRequestTest, DelayMainJob); |
| 142 |
| 143 // Creates Job(s) for |request_|. Job(s) will be owned by |this|. |
| 144 void CreateJobs(const HttpRequestInfo& request_info, |
| 145 RequestPriority priority, |
| 146 const SSLConfig& server_ssl_config, |
| 147 const SSLConfig& proxy_ssl_config, |
| 148 HttpStreamRequest::Delegate* delegate, |
| 149 HttpStreamRequest::StreamType stream_type, |
| 150 const BoundNetLog& net_log); |
| 151 |
| 152 // Attaches |job| to |request_|. Does not mean that |request_| will use |job|. |
| 153 void AttachJob(Job* job); |
| 154 |
| 155 // Called to bind |job| to the |request_| and orphan all other jobs that are |
| 156 // still associated with |request_|. |
| 157 void BindJob(Job* job); |
| 158 |
| 159 // Called when |request_| is destructed. |
| 160 // Job(s) associated with but not bound to |request_| will be deleted. |
| 161 void CancelJobs(); |
| 162 |
| 163 // Called after BindJob() to notify the unbound job that its result should be |
| 164 // ignored by JobController. The unbound job can be canceled or continue until |
| 165 // completion. |
| 166 void OrphanUnboundJob(); |
| 167 |
| 168 // Called when a Job succeeds. |
| 169 void OnJobSucceeded(Job* job); |
| 170 |
| 171 // Marks completion of the |request_|. |
| 172 void MarkRequestComplete(bool was_npn_negotiated, |
| 173 NextProto protocol_negotiated, |
| 174 bool using_spdy); |
| 175 |
| 176 void MaybeNotifyFactoryOfCompletion(); |
| 177 |
| 178 // Returns true if QUIC is whitelisted for |host|. |
| 179 bool IsQuicWhitelistedForHost(const std::string& host); |
| 180 |
| 181 AlternativeService GetAlternativeServiceFor( |
| 182 const HttpRequestInfo& request_info, |
| 183 HttpStreamRequest::Delegate* delegate, |
| 184 HttpStreamRequest::StreamType stream_type); |
| 185 |
| 186 // Remove session from the SpdySessionRequestMap. |
| 187 void RemoveRequestFromSpdySessionRequestMap(); |
| 188 |
| 189 HttpStreamFactoryImpl* factory_; |
| 190 HttpNetworkSession* session_; |
| 191 JobFactory* job_factory_; |
| 192 |
| 193 // Request will be handed out to factory once created. This just keeps an |
| 194 // reference and is safe as |request_| will notify |this| JobController |
| 195 // when it's destructed by calling OnRequestComplete(), which nulls |
| 196 // |request_|. |
| 197 Request* request_; |
| 198 |
| 199 HttpStreamRequest::Delegate* const delegate_; |
| 200 |
| 201 // True if this JobController is used to preconnect streams. |
| 202 bool is_preconnect_; |
| 203 |
| 204 // |main_job_| is a job waiting to see if |alternative_job_| can reuse a |
| 205 // connection. If |alternative_job_| is unable to do so, |this| will notify |
| 206 // |main_job_| to proceed and then race the two jobs. |
| 207 std::unique_ptr<Job> main_job_; |
| 208 std::unique_ptr<Job> alternative_job_; |
| 209 |
| 210 // True if a Job has ever been bound to the |request_|. |
| 211 bool job_bound_; |
| 212 |
| 213 // At the point where a Job is irrevocably tied to |request_|, we set this. |
| 214 // It will be nulled when the |request_| is finished. |
| 215 Job* bound_job_; |
| 216 }; |
| 217 |
| 218 } // namespace net |
| 219 |
| 220 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ |
| OLD | NEW |