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