Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / net / http / http_stream_factory_impl_request.h
blobe65dac88e45600f7e1bf1d529079276284f296e8
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
3 // found in the LICENSE file.
5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
8 #include <set>
9 #include "base/memory/scoped_ptr.h"
10 #include "net/http/http_stream_factory_impl.h"
11 #include "net/log/net_log.h"
12 #include "net/socket/connection_attempts.h"
13 #include "net/socket/ssl_client_socket.h"
14 #include "net/spdy/spdy_session_key.h"
15 #include "net/ssl/ssl_failure_state.h"
16 #include "url/gurl.h"
18 namespace net {
20 class ClientSocketHandle;
21 class HttpStream;
22 class SpdySession;
24 class HttpStreamFactoryImpl::Request : public HttpStreamRequest {
25 public:
26 Request(const GURL& url,
27 HttpStreamFactoryImpl* factory,
28 HttpStreamRequest::Delegate* delegate,
29 WebSocketHandshakeStreamBase::CreateHelper*
30 websocket_handshake_stream_create_helper,
31 const BoundNetLog& net_log);
32 ~Request() override;
34 // The GURL from the HttpRequestInfo the started the Request.
35 const GURL& url() const { return url_; }
37 const BoundNetLog& net_log() const { return net_log_; }
39 // Called when the Job determines the appropriate |spdy_session_key| for the
40 // Request. Note that this does not mean that SPDY is necessarily supported
41 // for this SpdySessionKey, since we may need to wait for NPN to complete
42 // before knowing if SPDY is available.
43 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key);
44 bool HasSpdySessionKey() const;
46 // Attaches |job| to this request. Does not mean that Request will use |job|,
47 // but Request will own |job|.
48 void AttachJob(HttpStreamFactoryImpl::Job* job);
50 // Marks completion of the request. Must be called before OnStreamReady().
51 void Complete(bool was_npn_negotiated,
52 NextProto protocol_negotiated,
53 bool using_spdy);
55 // If this Request has a |spdy_session_key_|, remove this session from the
56 // SpdySessionRequestMap.
57 void RemoveRequestFromSpdySessionRequestMap();
59 // Called by an attached Job if it sets up a SpdySession.
60 void OnNewSpdySessionReady(Job* job,
61 scoped_ptr<HttpStream> stream,
62 const base::WeakPtr<SpdySession>& spdy_session,
63 bool direct);
65 // Called by an attached Job to record connection attempts made by the socket
66 // layer for this stream request.
67 void AddConnectionAttempts(const ConnectionAttempts& attempts);
69 WebSocketHandshakeStreamBase::CreateHelper*
70 websocket_handshake_stream_create_helper() {
71 return websocket_handshake_stream_create_helper_;
74 // HttpStreamRequest::Delegate methods which we implement. Note we don't
75 // actually subclass HttpStreamRequest::Delegate.
77 void OnStreamReady(Job* job,
78 const SSLConfig& used_ssl_config,
79 const ProxyInfo& used_proxy_info,
80 HttpStream* stream);
81 void OnWebSocketHandshakeStreamReady(Job* job,
82 const SSLConfig& used_ssl_config,
83 const ProxyInfo& used_proxy_info,
84 WebSocketHandshakeStreamBase* stream);
85 void OnStreamFailed(Job* job,
86 int status,
87 const SSLConfig& used_ssl_config,
88 SSLFailureState ssl_failure_state);
89 void OnCertificateError(Job* job,
90 int status,
91 const SSLConfig& used_ssl_config,
92 const SSLInfo& ssl_info);
93 void OnNeedsProxyAuth(Job* job,
94 const HttpResponseInfo& proxy_response,
95 const SSLConfig& used_ssl_config,
96 const ProxyInfo& used_proxy_info,
97 HttpAuthController* auth_controller);
98 void OnNeedsClientAuth(Job* job,
99 const SSLConfig& used_ssl_config,
100 SSLCertRequestInfo* cert_info);
101 void OnHttpsProxyTunnelResponse(
102 Job *job,
103 const HttpResponseInfo& response_info,
104 const SSLConfig& used_ssl_config,
105 const ProxyInfo& used_proxy_info,
106 HttpStream* stream);
108 // HttpStreamRequest methods.
110 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override;
111 void SetPriority(RequestPriority priority) override;
112 LoadState GetLoadState() const override;
113 bool was_npn_negotiated() const override;
114 NextProto protocol_negotiated() const override;
115 bool using_spdy() const override;
116 const ConnectionAttempts& connection_attempts() const override;
118 private:
119 // Used to bind |job| to the request and orphan all other jobs in |jobs_|.
120 void BindJob(Job* job);
122 // Used to orphan all jobs in |jobs_|.
123 void OrphanJobs();
125 // Used to cancel all jobs in |jobs_|.
126 void CancelJobs();
128 // Called when a Job succeeds.
129 void OnJobSucceeded(Job* job);
131 const GURL url_;
132 HttpStreamFactoryImpl* const factory_;
133 WebSocketHandshakeStreamBase::CreateHelper* const
134 websocket_handshake_stream_create_helper_;
135 HttpStreamRequest::Delegate* const delegate_;
136 const BoundNetLog net_log_;
138 // At the point where Job is irrevocably tied to the Request, we set this.
139 scoped_ptr<Job> bound_job_;
140 std::set<HttpStreamFactoryImpl::Job*> jobs_;
141 scoped_ptr<const SpdySessionKey> spdy_session_key_;
143 bool completed_;
144 bool was_npn_negotiated_;
145 // Protocol negotiated with the server.
146 NextProto protocol_negotiated_;
147 bool using_spdy_;
148 ConnectionAttempts connection_attempts_;
150 DISALLOW_COPY_AND_ASSIGN(Request);
153 } // namespace net
155 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_