- add sources.
[platform/framework/web/crosswalk.git] / src / net / http / http_stream_factory_impl_request.h
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.
4
5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
7
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"
15
16 namespace net {
17
18 class ClientSocketHandle;
19 class SpdySession;
20
21 class HttpStreamFactoryImpl::Request : public HttpStreamRequest {
22  public:
23   Request(
24       const GURL& url,
25       HttpStreamFactoryImpl* factory,
26       HttpStreamRequest::Delegate* delegate,
27       WebSocketHandshakeStreamBase::Factory* websocket_handshake_stream_factory,
28       const BoundNetLog& net_log);
29   virtual ~Request();
30
31   // The GURL from the HttpRequestInfo the started the Request.
32   const GURL& url() const { return url_; }
33
34   // Called when the Job determines the appropriate |spdy_session_key| for the
35   // Request. Note that this does not mean that SPDY is necessarily supported
36   // for this SpdySessionKey, since we may need to wait for NPN to complete
37   // before knowing if SPDY is available.
38   void SetSpdySessionKey(const SpdySessionKey& spdy_session_key);
39
40   // Called when the Job determines the appropriate |http_pipelining_key| for
41   // the Request. Registers this Request with the factory, so that if an
42   // existing pipeline becomes available, this Request can be late bound to it.
43   // Returns true if this is this key was new to the factory.
44   bool SetHttpPipeliningKey(const HttpPipelinedHost::Key& http_pipelining_key);
45
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);
49
50   // Marks completion of the request. Must be called before OnStreamReady().
51   // |job_net_log| is the BoundNetLog of the Job that fulfilled this request.
52   void Complete(bool was_npn_negotiated,
53                 NextProto protocol_negotiated,
54                 bool using_spdy,
55                 const BoundNetLog& job_net_log);
56
57   // If this Request has a |spdy_session_key_|, remove this session from the
58   // SpdySessionRequestMap.
59   void RemoveRequestFromSpdySessionRequestMap();
60
61   // If this Request has a |http_pipelining_key_|, remove this session from the
62   // HttpPipeliningRequestMap.
63   void RemoveRequestFromHttpPipeliningRequestMap();
64
65   // Called by an attached Job if it sets up a SpdySession.
66   void OnNewSpdySessionReady(Job* job,
67                              const base::WeakPtr<SpdySession>& spdy_session,
68                              bool direct);
69
70   WebSocketHandshakeStreamBase::Factory* websocket_handshake_stream_factory() {
71     return websocket_handshake_stream_factory_;
72   }
73
74   // HttpStreamRequest::Delegate methods which we implement. Note we don't
75   // actually subclass HttpStreamRequest::Delegate.
76
77   void OnStreamReady(Job* job,
78                      const SSLConfig& used_ssl_config,
79                      const ProxyInfo& used_proxy_info,
80                      HttpStreamBase* 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, int status, const SSLConfig& used_ssl_config);
86   void OnCertificateError(Job* job,
87                           int status,
88                           const SSLConfig& used_ssl_config,
89                           const SSLInfo& ssl_info);
90   void OnNeedsProxyAuth(Job* job,
91                         const HttpResponseInfo& proxy_response,
92                         const SSLConfig& used_ssl_config,
93                         const ProxyInfo& used_proxy_info,
94                         HttpAuthController* auth_controller);
95   void OnNeedsClientAuth(Job* job,
96                          const SSLConfig& used_ssl_config,
97                          SSLCertRequestInfo* cert_info);
98   void OnHttpsProxyTunnelResponse(
99       Job *job,
100       const HttpResponseInfo& response_info,
101       const SSLConfig& used_ssl_config,
102       const ProxyInfo& used_proxy_info,
103       HttpStreamBase* stream);
104
105   // HttpStreamRequest methods.
106
107   virtual int RestartTunnelWithProxyAuth(
108       const AuthCredentials& credentials) OVERRIDE;
109   virtual void SetPriority(RequestPriority priority) OVERRIDE;
110   virtual LoadState GetLoadState() const OVERRIDE;
111   virtual bool was_npn_negotiated() const OVERRIDE;
112   virtual NextProto protocol_negotiated() const OVERRIDE;
113   virtual bool using_spdy() const OVERRIDE;
114
115  private:
116   // Used to orphan all jobs in |jobs_| other than |job| which becomes "bound"
117   // to the request.
118   void OrphanJobsExcept(Job* job);
119
120   // Used to orphan all jobs in |jobs_|.
121   void OrphanJobs();
122
123   // Called when a Job succeeds.
124   void OnJobSucceeded(Job* job);
125
126   const GURL url_;
127   HttpStreamFactoryImpl* const factory_;
128   WebSocketHandshakeStreamBase::Factory* const
129       websocket_handshake_stream_factory_;
130   HttpStreamRequest::Delegate* const delegate_;
131   const BoundNetLog net_log_;
132
133   // At the point where Job is irrevocably tied to the Request, we set this.
134   scoped_ptr<Job> bound_job_;
135   std::set<HttpStreamFactoryImpl::Job*> jobs_;
136   scoped_ptr<const SpdySessionKey> spdy_session_key_;
137   scoped_ptr<const HttpPipelinedHost::Key> http_pipelining_key_;
138
139   bool completed_;
140   bool was_npn_negotiated_;
141   // Protocol negotiated with the server.
142   NextProto protocol_negotiated_;
143   bool using_spdy_;
144
145   DISALLOW_COPY_AND_ASSIGN(Request);
146 };
147
148 }  // namespace net
149
150 #endif  // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_