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