Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 class HttpAuthController; | 29 class HttpAuthController; |
| 30 class HttpNetworkSession; | 30 class HttpNetworkSession; |
| 31 class HttpStream; | 31 class HttpStream; |
| 32 class SpdySessionPool; | 32 class SpdySessionPool; |
| 33 class QuicHttpStream; | 33 class QuicHttpStream; |
| 34 | 34 |
| 35 // An HttpStreamRequestImpl exists for each stream which is in progress of being | 35 // An HttpStreamRequestImpl exists for each stream which is in progress of being |
| 36 // created for the StreamFactory. | 36 // created for the StreamFactory. |
| 37 class HttpStreamFactoryImpl::Job { | 37 class HttpStreamFactoryImpl::Job { |
| 38 public: | 38 public: |
| 39 // A Job is considered alternative iff | |
|
Ryan Hamilton
2015/06/02 17:26:56
eschew "iff. This reads just as unambiguiously wh
Bence
2015/06/02 19:32:16
Great idea, thanks.
Done.
| |
| 40 // alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL. | |
| 39 Job(HttpStreamFactoryImpl* stream_factory, | 41 Job(HttpStreamFactoryImpl* stream_factory, |
| 40 HttpNetworkSession* session, | 42 HttpNetworkSession* session, |
| 41 const HttpRequestInfo& request_info, | 43 const HttpRequestInfo& request_info, |
| 42 RequestPriority priority, | 44 RequestPriority priority, |
| 43 const SSLConfig& server_ssl_config, | 45 const SSLConfig& server_ssl_config, |
| 44 const SSLConfig& proxy_ssl_config, | 46 const SSLConfig& proxy_ssl_config, |
| 47 AlternativeService alternative_service, | |
| 45 NetLog* net_log); | 48 NetLog* net_log); |
| 46 ~Job(); | 49 ~Job(); |
| 47 | 50 |
| 48 // Start initiates the process of creating a new HttpStream. |request| will be | 51 // Start initiates the process of creating a new HttpStream. |request| will be |
| 49 // notified upon completion if the Job has not been Orphan()'d. | 52 // notified upon completion if the Job has not been Orphan()'d. |
| 50 void Start(Request* request); | 53 void Start(Request* request); |
| 51 | 54 |
| 52 // Preconnect will attempt to request |num_streams| sockets from the | 55 // Preconnect will attempt to request |num_streams| sockets from the |
| 53 // appropriate ClientSocketPool. | 56 // appropriate ClientSocketPool. |
| 54 int Preconnect(int num_streams); | 57 int Preconnect(int num_streams); |
| 55 | 58 |
| 56 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); | 59 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials); |
| 57 LoadState GetLoadState() const; | 60 LoadState GetLoadState() const; |
| 58 | 61 |
| 59 // Marks this Job as the "alternate" job, from Alternate-Protocol or Alt-Svc | |
| 60 // using the specified alternate service. | |
| 61 void MarkAsAlternate(AlternativeService alternative_service); | |
| 62 | |
| 63 // Tells |this| to wait for |job| to resume it. | 62 // Tells |this| to wait for |job| to resume it. |
| 64 void WaitFor(Job* job); | 63 void WaitFor(Job* job); |
| 65 | 64 |
| 66 // Tells |this| that |job| has determined it still needs to continue | 65 // Tells |this| that |job| has determined it still needs to continue |
| 67 // connecting, so allow |this| to continue. If this is not called, then | 66 // connecting, so allow |this| to continue. If this is not called, then |
| 68 // |request_| is expected to cancel |this| by deleting it. | 67 // |request_| is expected to cancel |this| by deleting it. |
| 69 void Resume(Job* job); | 68 void Resume(Job* job); |
| 70 | 69 |
| 71 // Used to detach the Job from |request|. | 70 // Used to detach the Job from |request|. |
| 72 void Orphan(const Request* request); | 71 void Orphan(const Request* request); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 STATUS_BROKEN, | 138 STATUS_BROKEN, |
| 140 STATUS_SUCCEEDED | 139 STATUS_SUCCEEDED |
| 141 }; | 140 }; |
| 142 | 141 |
| 143 // Wrapper class for SpdySessionPool methods to enforce certificate | 142 // Wrapper class for SpdySessionPool methods to enforce certificate |
| 144 // requirements for SpdySessions. | 143 // requirements for SpdySessions. |
| 145 class ValidSpdySessionPool { | 144 class ValidSpdySessionPool { |
| 146 public: | 145 public: |
| 147 ValidSpdySessionPool(SpdySessionPool* spdy_session_pool, | 146 ValidSpdySessionPool(SpdySessionPool* spdy_session_pool, |
| 148 GURL& origin_url, | 147 GURL& origin_url, |
| 149 bool is_spdy_alternate); | 148 bool is_spdy_alternative); |
| 150 | 149 |
| 151 // Returns OK if a SpdySession was not found (in which case |spdy_session| | 150 // Returns OK if a SpdySession was not found (in which case |spdy_session| |
| 152 // is set to nullptr), or if one was found (in which case |spdy_session| is | 151 // is set to nullptr), or if one was found (in which case |spdy_session| is |
| 153 // set to it) and it has an associated SSL certificate with is valid for | 152 // set to it) and it has an associated SSL certificate with is valid for |
| 154 // |origin_url_|, or if this requirement does not apply because the Job is | 153 // |origin_url_|, or if this requirement does not apply because the Job is |
| 155 // not a SPDY alternate job. Returns the appropriate error code otherwise, | 154 // not a SPDY alternative job. Returns the appropriate error code |
| 155 // otherwise, | |
| 156 // in which case |spdy_session| should not be used. | 156 // in which case |spdy_session| should not be used. |
| 157 int FindAvailableSession(const SpdySessionKey& key, | 157 int FindAvailableSession(const SpdySessionKey& key, |
| 158 const BoundNetLog& net_log, | 158 const BoundNetLog& net_log, |
| 159 base::WeakPtr<SpdySession>* spdy_session); | 159 base::WeakPtr<SpdySession>* spdy_session); |
| 160 | 160 |
| 161 // Creates a SpdySession and sets |spdy_session| to point to it. Returns OK | 161 // Creates a SpdySession and sets |spdy_session| to point to it. Returns OK |
| 162 // if the associated SSL certificate is valid for |origin_url_|, or if this | 162 // if the associated SSL certificate is valid for |origin_url_|, or if this |
| 163 // requirement does not apply because the Job is not a SPDY alternate job. | 163 // requirement does not apply because the Job is not a SPDY alternative job. |
| 164 // Returns the appropriate error code otherwise, in which case | 164 // Returns the appropriate error code otherwise, in which case |
| 165 // |spdy_session| should not be used. | 165 // |spdy_session| should not be used. |
| 166 int CreateAvailableSessionFromSocket( | 166 int CreateAvailableSessionFromSocket( |
| 167 const SpdySessionKey& key, | 167 const SpdySessionKey& key, |
| 168 scoped_ptr<ClientSocketHandle> connection, | 168 scoped_ptr<ClientSocketHandle> connection, |
| 169 const BoundNetLog& net_log, | 169 const BoundNetLog& net_log, |
| 170 int certificate_error_code, | 170 int certificate_error_code, |
| 171 bool is_secure, | 171 bool is_secure, |
| 172 base::WeakPtr<SpdySession>* spdy_session); | 172 base::WeakPtr<SpdySession>* spdy_session); |
| 173 | 173 |
| 174 private: | 174 private: |
| 175 // Returns OK if |spdy_session| has an associated SSL certificate with is | 175 // Returns OK if |spdy_session| has an associated SSL certificate with is |
| 176 // valid for |origin_url_|, or if this requirement does not apply because | 176 // valid for |origin_url_|, or if this requirement does not apply because |
| 177 // the Job is not a SPDY alternate job, or if |spdy_session| is null. | 177 // the Job is not a SPDY alternative job, or if |spdy_session| is null. |
| 178 // Returns appropriate error code otherwise. | 178 // Returns appropriate error code otherwise. |
| 179 int CheckAlternativeServiceValidityForOrigin( | 179 int CheckAlternativeServiceValidityForOrigin( |
| 180 base::WeakPtr<SpdySession> spdy_session); | 180 base::WeakPtr<SpdySession> spdy_session); |
| 181 | 181 |
| 182 SpdySessionPool* const spdy_session_pool_; | 182 SpdySessionPool* const spdy_session_pool_; |
| 183 const GURL origin_url_; | 183 const GURL origin_url_; |
| 184 const bool is_spdy_alternate_; | 184 const bool is_spdy_alternative_; |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 void OnStreamReadyCallback(); | 187 void OnStreamReadyCallback(); |
| 188 void OnWebSocketHandshakeStreamReadyCallback(); | 188 void OnWebSocketHandshakeStreamReadyCallback(); |
| 189 // This callback function is called when a new SPDY session is created. | 189 // This callback function is called when a new SPDY session is created. |
| 190 void OnNewSpdySessionReadyCallback(); | 190 void OnNewSpdySessionReadyCallback(); |
| 191 void OnStreamFailedCallback(int result); | 191 void OnStreamFailedCallback(int result); |
| 192 void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info); | 192 void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info); |
| 193 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info, | 193 void OnNeedsProxyAuthCallback(const HttpResponseInfo& response_info, |
| 194 HttpAuthController* auth_controller); | 194 HttpAuthController* auth_controller); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 224 int SetSpdyHttpStream(base::WeakPtr<SpdySession> session, bool direct); | 224 int SetSpdyHttpStream(base::WeakPtr<SpdySession> session, bool direct); |
| 225 | 225 |
| 226 // Returns to STATE_INIT_CONNECTION and resets some state. | 226 // Returns to STATE_INIT_CONNECTION and resets some state. |
| 227 void ReturnToStateInitConnection(bool close_connection); | 227 void ReturnToStateInitConnection(bool close_connection); |
| 228 | 228 |
| 229 // Set the motivation for this request onto the underlying socket. | 229 // Set the motivation for this request onto the underlying socket. |
| 230 void SetSocketMotivation(); | 230 void SetSocketMotivation(); |
| 231 | 231 |
| 232 bool IsHttpsProxyAndHttpUrl() const; | 232 bool IsHttpsProxyAndHttpUrl() const; |
| 233 | 233 |
| 234 // Returns true iff this Job is an alternate, that is, iff MarkAsAlternate has | |
| 235 // been called. | |
| 236 bool IsAlternate() const; | |
| 237 | |
| 238 // Returns true if this Job is a SPDY alternate job. | |
| 239 bool IsSpdyAlternate() const; | |
| 240 | |
| 241 // Sets several fields of |ssl_config| for |server| based on the proxy info | 234 // Sets several fields of |ssl_config| for |server| based on the proxy info |
| 242 // and other factors. | 235 // and other factors. |
| 243 void InitSSLConfig(const HostPortPair& server, | 236 void InitSSLConfig(const HostPortPair& server, |
| 244 SSLConfig* ssl_config, | 237 SSLConfig* ssl_config, |
| 245 bool is_proxy) const; | 238 bool is_proxy) const; |
| 246 | 239 |
| 247 // Retrieve SSLInfo from our SSL Socket. | 240 // Retrieve SSLInfo from our SSL Socket. |
| 248 // This must only be called when we are using an SSLSocket. | 241 // This must only be called when we are using an SSLSocket. |
| 249 // After calling, the caller can use ssl_info_. | 242 // After calling, the caller can use ssl_info_. |
| 250 void GetSSLInfo(); | 243 void GetSSLInfo(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 SSLInfo ssl_info_; | 305 SSLInfo ssl_info_; |
| 313 | 306 |
| 314 // The server we are trying to reach, could be that of the origin or of the | 307 // The server we are trying to reach, could be that of the origin or of the |
| 315 // alternative service. | 308 // alternative service. |
| 316 HostPortPair server_; | 309 HostPortPair server_; |
| 317 | 310 |
| 318 // The origin url we're trying to reach. This url may be different from the | 311 // The origin url we're trying to reach. This url may be different from the |
| 319 // original request when host mapping rules are set-up. | 312 // original request when host mapping rules are set-up. |
| 320 GURL origin_url_; | 313 GURL origin_url_; |
| 321 | 314 |
| 322 // AlternateProtocol for this job if this is an alternate job. | 315 // AlternativeService for this Job if this is an alternative Job. |
| 323 AlternativeService alternative_service_; | 316 const AlternativeService alternative_service_; |
| 324 | 317 |
| 325 // AlternateProtocol for the other job if this is not an alternate job. | 318 // Is this a SPDY or QUIC alternative Job? |
| 319 const bool is_spdy_alternative_; | |
| 320 const bool is_quic_alternative_; | |
|
Ryan Hamilton
2015/06/02 17:26:57
It's not obvious to me that this is a win, but per
Bence
2015/06/02 19:32:16
I agree: it doesn't seem to matter much. I revert
| |
| 321 | |
| 322 // AlternativeService for the other Job if this is not an alternative Job. | |
| 326 AlternativeService other_job_alternative_service_; | 323 AlternativeService other_job_alternative_service_; |
| 327 | 324 |
| 328 // This is the Job we're dependent on. It will notify us if/when it's OK to | 325 // This is the Job we're dependent on. It will notify us if/when it's OK to |
| 329 // proceed. | 326 // proceed. |
| 330 Job* blocking_job_; | 327 Job* blocking_job_; |
| 331 | 328 |
| 332 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection. | 329 // |waiting_job_| is a Job waiting to see if |this| can reuse a connection. |
| 333 // If |this| is unable to do so, we'll notify |waiting_job_| that it's ok to | 330 // If |this| is unable to do so, we'll notify |waiting_job_| that it's ok to |
| 334 // proceed and then race the two Jobs. | 331 // proceed and then race the two Jobs. |
| 335 Job* waiting_job_; | 332 Job* waiting_job_; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 JobStatus other_job_status_; | 385 JobStatus other_job_status_; |
| 389 | 386 |
| 390 base::WeakPtrFactory<Job> ptr_factory_; | 387 base::WeakPtrFactory<Job> ptr_factory_; |
| 391 | 388 |
| 392 DISALLOW_COPY_AND_ASSIGN(Job); | 389 DISALLOW_COPY_AND_ASSIGN(Job); |
| 393 }; | 390 }; |
| 394 | 391 |
| 395 } // namespace net | 392 } // namespace net |
| 396 | 393 |
| 397 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ | 394 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_JOB_H_ |
| OLD | NEW |