Add a function to create a bookmark app from a WebApplicationInfo.
[chromium-blink-merge.git] / net / http / http_stream_factory_impl_request.h
blob22c8ff2d485bedabb520b86e176e866229660de0
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/base/net_log.h"
11 #include "net/http/http_stream_factory_impl.h"
12 #include "net/socket/ssl_client_socket.h"
13 #include "net/spdy/spdy_session_key.h"
14 #include "url/gurl.h"
16 namespace net {
18 class ClientSocketHandle;
19 class HttpStream;
20 class SpdySession;
22 class HttpStreamFactoryImpl::Request : public HttpStreamRequest {
23 public:
24 Request(const GURL& url,
25 HttpStreamFactoryImpl* factory,
26 HttpStreamRequest::Delegate* delegate,
27 WebSocketHandshakeStreamBase::CreateHelper*
28 websocket_handshake_stream_create_helper,
29 const BoundNetLog& net_log);
30 virtual ~Request();
32 // The GURL from the HttpRequestInfo the started the Request.
33 const GURL& url() const { return url_; }
35 // Called when the Job determines the appropriate |spdy_session_key| for the
36 // Request. Note that this does not mean that SPDY is necessarily supported
37 // for this SpdySessionKey, since we may need to wait for NPN to complete
38 // before knowing if SPDY is available.
39 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key);
41 // Called when the Job determines the appropriate |http_pipelining_key| for
42 // the Request. Registers this Request with the factory, so that if an
43 // existing pipeline becomes available, this Request can be late bound to it.
44 // Returns true if this is this key was new to the factory.
45 bool SetHttpPipeliningKey(const HttpPipelinedHost::Key& http_pipelining_key);
47 // Attaches |job| to this request. Does not mean that Request will use |job|,
48 // but Request will own |job|.
49 void AttachJob(HttpStreamFactoryImpl::Job* job);
51 // Marks completion of the request. Must be called before OnStreamReady().
52 // |job_net_log| is the BoundNetLog of the Job that fulfilled this request.
53 void Complete(bool was_npn_negotiated,
54 NextProto protocol_negotiated,
55 bool using_spdy,
56 const BoundNetLog& job_net_log);
58 // If this Request has a |spdy_session_key_|, remove this session from the
59 // SpdySessionRequestMap.
60 void RemoveRequestFromSpdySessionRequestMap();
62 // If this Request has a |http_pipelining_key_|, remove this session from the
63 // HttpPipeliningRequestMap.
64 void RemoveRequestFromHttpPipeliningRequestMap();
66 // Called by an attached Job if it sets up a SpdySession.
67 void OnNewSpdySessionReady(Job* job,
68 scoped_ptr<HttpStream> stream,
69 const base::WeakPtr<SpdySession>& spdy_session,
70 bool direct);
72 WebSocketHandshakeStreamBase::CreateHelper*
73 websocket_handshake_stream_create_helper() {
74 return websocket_handshake_stream_create_helper_;
77 // HttpStreamRequest::Delegate methods which we implement. Note we don't
78 // actually subclass HttpStreamRequest::Delegate.
80 void OnStreamReady(Job* job,
81 const SSLConfig& used_ssl_config,
82 const ProxyInfo& used_proxy_info,
83 HttpStreamBase* stream);
84 void OnWebSocketHandshakeStreamReady(Job* job,
85 const SSLConfig& used_ssl_config,
86 const ProxyInfo& used_proxy_info,
87 WebSocketHandshakeStreamBase* stream);
88 void OnStreamFailed(Job* job, int status, const SSLConfig& used_ssl_config);
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 HttpStreamBase* stream);
108 // HttpStreamRequest methods.
110 virtual int RestartTunnelWithProxyAuth(
111 const AuthCredentials& credentials) OVERRIDE;
112 virtual void SetPriority(RequestPriority priority) OVERRIDE;
113 virtual LoadState GetLoadState() const OVERRIDE;
114 virtual bool was_npn_negotiated() const OVERRIDE;
115 virtual NextProto protocol_negotiated() const OVERRIDE;
116 virtual bool using_spdy() const OVERRIDE;
118 private:
119 // Used to orphan all jobs in |jobs_| other than |job| which becomes "bound"
120 // to the request.
121 void OrphanJobsExcept(Job* job);
123 // Used to orphan all jobs in |jobs_|.
124 void OrphanJobs();
126 // Called when a Job succeeds.
127 void OnJobSucceeded(Job* job);
129 const GURL url_;
130 HttpStreamFactoryImpl* const factory_;
131 WebSocketHandshakeStreamBase::CreateHelper* const
132 websocket_handshake_stream_create_helper_;
133 HttpStreamRequest::Delegate* const delegate_;
134 const BoundNetLog net_log_;
136 // At the point where Job is irrevocably tied to the Request, we set this.
137 scoped_ptr<Job> bound_job_;
138 std::set<HttpStreamFactoryImpl::Job*> jobs_;
139 scoped_ptr<const SpdySessionKey> spdy_session_key_;
140 scoped_ptr<const HttpPipelinedHost::Key> http_pipelining_key_;
142 bool completed_;
143 bool was_npn_negotiated_;
144 // Protocol negotiated with the server.
145 NextProto protocol_negotiated_;
146 bool using_spdy_;
148 DISALLOW_COPY_AND_ASSIGN(Request);
151 } // namespace net
153 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_