summaryrefslogtreecommitdiffstats
path: root/net/websockets/websocket_handshake_stream_create_helper.h
blob: ef4baeb53e41cce0dde2f67d0e2dbabcd263bb3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_CREATE_HELPER_H_
#define NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_CREATE_HELPER_H_

#include <string>
#include <vector>

#include "net/base/net_export.h"
#include "net/websockets/websocket_handshake_stream_base.h"
#include "net/websockets/websocket_stream.h"

namespace net {

// Implementation of WebSocketHandshakeStreamBase::CreateHelper. This class is
// used in the implementation of WebSocketStream::CreateAndConnectStream() and
// is not intended to be used by itself.
//
// Holds the information needed to construct a
// WebSocketBasicHandshakeStreamBase.
class NET_EXPORT_PRIVATE WebSocketHandshakeStreamCreateHelper
    : public WebSocketHandshakeStreamBase::CreateHelper {
 public:
  explicit WebSocketHandshakeStreamCreateHelper(
      WebSocketStream::ConnectDelegate* connect_delegate,
      const std::vector<std::string>& requested_subprotocols);

  virtual ~WebSocketHandshakeStreamCreateHelper();

  // WebSocketHandshakeStreamBase::CreateHelper methods

  // Create a WebSocketBasicHandshakeStream.
  virtual WebSocketHandshakeStreamBase* CreateBasicStream(
      scoped_ptr<ClientSocketHandle> connection,
      bool using_proxy) OVERRIDE;

  // Unimplemented as of November 2013.
  virtual WebSocketHandshakeStreamBase* CreateSpdyStream(
      const base::WeakPtr<SpdySession>& session,
      bool use_relative_url) OVERRIDE;

  // Return the WebSocketHandshakeStreamBase object that we created. In the case
  // where CreateBasicStream() was called more than once, returns the most
  // recent stream, which will be the one on which the handshake succeeded.
  WebSocketHandshakeStreamBase* stream() { return stream_; }

 private:
  const std::vector<std::string> requested_subprotocols_;

  // This is owned by the caller of CreateBaseStream() or
  // CreateSpdyStream(). Both the stream and this object will be destroyed
  // during the destruction of the URLRequest object associated with the
  // handshake.
  WebSocketHandshakeStreamBase* stream_;

  WebSocketStream::ConnectDelegate* connect_delegate_;

  DISALLOW_COPY_AND_ASSIGN(WebSocketHandshakeStreamCreateHelper);
};

}  // namespace net

#endif  // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_CREATE_HELPER_H_