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_; } | |
| 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, | |
| 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 RemoveRequestFromSpdySessionRequestMap(Job* job); | |
|
Randy Smith (Not in Mondays)
2016/05/16 20:46:39
The style guide discourages using overloading, i.e
Zhongyi Shi
2016/05/16 23:08:53
Done.
| |
| 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 // Used to orphan jobs. | |
| 146 // Job(s) associated with not bounded to the |request_| will be disassociated | |
| 147 // from the |request_| so that it will not be canceled when |request_| is | |
| 148 // destructed. Nor will it report completion to |request_|. | |
| 149 void OrphanJobs(); | |
| 150 | |
| 151 // Called when a Job succeeds. | |
| 152 void OnJobSucceeded(Job* job); | |
| 153 | |
| 154 // Marks completion of the |request_|. | |
| 155 void MarkRequestComplete(bool was_npn_negotiated, | |
| 156 NextProto protocol_negotiated, | |
| 157 bool using_spdy); | |
| 158 | |
| 159 void MaybeNotifyFactoryOfCompletion(); | |
| 160 | |
| 161 GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint); | |
| 162 | |
| 163 // Returns true if QUIC is whitelisted for |host|. | |
| 164 bool IsQuicWhitelistedForHost(const std::string& host); | |
| 165 | |
| 166 AlternativeService GetAlternativeServiceFor( | |
| 167 const HttpRequestInfo& request_info, | |
| 168 HttpStreamRequest::Delegate* delegate, | |
| 169 HttpStreamRequest::StreamType stream_type); | |
| 170 | |
| 171 // Remove session from the SpdySessionRequestMap. | |
| 172 void RemoveRequestFromSpdySessionRequestMap(); | |
| 173 | |
| 174 HttpStreamFactoryImpl* factory_; | |
| 175 HttpNetworkSession* session_; | |
| 176 | |
| 177 // Request will be handed out to factory once created. This just keeps an | |
| 178 // reference and is safe as |request_| will notify |this| JobController | |
| 179 // when it's destructed by calling OnRequestComplete(), which nulls | |
| 180 // |request_|. | |
| 181 Request* request_; | |
| 182 | |
| 183 HttpStreamRequest::Delegate* const delegate_; | |
| 184 | |
| 185 // True if this JobController is used to preconnect streams. | |
| 186 bool is_preconnect_; | |
| 187 | |
| 188 // |main_job_| is a job waiting to see if |alternative_job_| can reuse a | |
| 189 // connection. If |alternative_job_| is unable to do so, |this| will notify | |
| 190 // |main_job_| to proceed and then race the two jobs. | |
| 191 std::unique_ptr<Job> main_job_; | |
| 192 std::unique_ptr<Job> alternative_job_; | |
| 193 | |
| 194 // True if a Job has ever been bound to the |request_|. | |
| 195 bool job_bound_; | |
| 196 | |
| 197 // At the point where a Job is irrevocably tied to |request_|, we set this. | |
| 198 // It will be nulled when the |request_| is finished. | |
| 199 Job* bound_job_; | |
| 200 }; | |
| 201 | |
| 202 } // namespace net | |
| 203 | |
| 204 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_CONTROLLER_H_ | |
| OLD | NEW |