• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "net/websockets/websocket_handshake_stream_create_helper.h"
6 
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "net/socket/client_socket_handle.h"
11 #include "net/spdy/spdy_session.h"
12 #include "net/websockets/websocket_basic_handshake_stream.h"
13 
14 namespace net {
15 
WebSocketHandshakeStreamCreateHelper(WebSocketStream::ConnectDelegate * connect_delegate,const std::vector<std::string> & requested_subprotocols)16 WebSocketHandshakeStreamCreateHelper::WebSocketHandshakeStreamCreateHelper(
17     WebSocketStream::ConnectDelegate* connect_delegate,
18     const std::vector<std::string>& requested_subprotocols)
19     : requested_subprotocols_(requested_subprotocols),
20       stream_(NULL),
21       connect_delegate_(connect_delegate),
22       failure_message_(NULL) {
23   DCHECK(connect_delegate_);
24 }
25 
~WebSocketHandshakeStreamCreateHelper()26 WebSocketHandshakeStreamCreateHelper::~WebSocketHandshakeStreamCreateHelper() {}
27 
28 WebSocketHandshakeStreamBase*
CreateBasicStream(scoped_ptr<ClientSocketHandle> connection,bool using_proxy)29 WebSocketHandshakeStreamCreateHelper::CreateBasicStream(
30     scoped_ptr<ClientSocketHandle> connection,
31     bool using_proxy) {
32   DCHECK(failure_message_) << "set_failure_message() must be called";
33   // The list of supported extensions and parameters is hard-coded.
34   // TODO(ricea): If more extensions are added, consider a more flexible
35   // method.
36   std::vector<std::string> extensions(
37       1, "permessage-deflate; client_max_window_bits");
38   WebSocketBasicHandshakeStream* stream =
39       new WebSocketBasicHandshakeStream(connection.Pass(),
40                                         connect_delegate_,
41                                         using_proxy,
42                                         requested_subprotocols_,
43                                         extensions,
44                                         failure_message_);
45   OnStreamCreated(stream);
46   stream_ = stream;
47   return stream;
48 }
49 
50 // TODO(ricea): Create a WebSocketSpdyHandshakeStream. crbug.com/323852
51 WebSocketHandshakeStreamBase*
CreateSpdyStream(const base::WeakPtr<SpdySession> & session,bool use_relative_url)52 WebSocketHandshakeStreamCreateHelper::CreateSpdyStream(
53     const base::WeakPtr<SpdySession>& session,
54     bool use_relative_url) {
55   NOTREACHED() << "Not implemented";
56   return NULL;
57 }
58 
Upgrade()59 scoped_ptr<WebSocketStream> WebSocketHandshakeStreamCreateHelper::Upgrade() {
60   DCHECK(stream_);
61   WebSocketHandshakeStreamBase* stream = stream_;
62   stream_ = NULL;
63   return stream->Upgrade();
64 }
65 
OnStreamCreated(WebSocketBasicHandshakeStream * stream)66 void WebSocketHandshakeStreamCreateHelper::OnStreamCreated(
67     WebSocketBasicHandshakeStream* stream) {
68 }
69 
70 }  // namespace net
71