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