Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / websockets / websocket_handshake_stream_base.h
bloba858febe0bcfb9740a2ab53a3e8654febe0f5fda
1 // Copyright 2013 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_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_BASE_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_BASE_H_
8 // This file is included from net/http files.
9 // Since net/http can be built without linking net/websockets code,
10 // this file must not introduce any link-time dependencies on websockets.
12 #include <string>
14 #include "base/basictypes.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/supports_user_data.h"
18 #include "net/http/http_stream.h"
19 #include "net/url_request/websocket_handshake_userdata_key.h"
20 #include "net/websockets/websocket_stream.h"
22 namespace net {
24 class ClientSocketHandle;
25 class SpdySession;
27 // WebSocketHandshakeStreamBase is the base class of
28 // WebSocketBasicHandshakeStream. net/http code uses this interface to handle
29 // WebSocketBasicHandshakeStream when it needs to be treated differently from
30 // HttpStreamBase.
31 class NET_EXPORT WebSocketHandshakeStreamBase : public HttpStream {
32 public:
33 // An object that stores data needed for the creation of a
34 // WebSocketBasicHandshakeStream object. A new CreateHelper is used for each
35 // WebSocket connection.
36 class NET_EXPORT_PRIVATE CreateHelper : public base::SupportsUserData::Data {
37 public:
38 // Returns a key to use to lookup this object in a URLRequest object. It is
39 // different from any other key that is supplied to
40 // URLRequest::SetUserData().
41 static const void* DataKey() { return kWebSocketHandshakeUserDataKey; }
43 ~CreateHelper() override {}
45 // Create a WebSocketBasicHandshakeStream. This is called after the
46 // underlying connection has been established but before any handshake data
47 // has been transferred. This can be called more than once in the case that
48 // HTTP authentication is needed.
49 virtual WebSocketHandshakeStreamBase* CreateBasicStream(
50 scoped_ptr<ClientSocketHandle> connection,
51 bool using_proxy) = 0;
53 // Create a WebSocketSpdyHandshakeStream (unimplemented as of October 2013)
54 virtual WebSocketHandshakeStreamBase* CreateSpdyStream(
55 const base::WeakPtr<SpdySession>& session,
56 bool use_relative_url) = 0;
59 // This has to have an inline implementation so that the net/url_request/
60 // tests do not fail on iOS.
61 ~WebSocketHandshakeStreamBase() override {}
63 // After the handshake has completed, this method creates a WebSocketStream
64 // (of the appropriate type) from the WebSocketHandshakeStreamBase object.
65 // The WebSocketHandshakeStreamBase object is unusable after Upgrade() has
66 // been called.
67 virtual scoped_ptr<WebSocketStream> Upgrade() = 0;
69 protected:
70 // As with the destructor, this must be inline.
71 WebSocketHandshakeStreamBase() {}
73 private:
74 DISALLOW_COPY_AND_ASSIGN(WebSocketHandshakeStreamBase);
77 } // namespace net
79 #endif // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_BASE_H_