Home | History | Annotate | Download | only in websockets
      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 
     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 
     26 WebSocketHandshakeStreamCreateHelper::~WebSocketHandshakeStreamCreateHelper() {}
     27 
     28 WebSocketHandshakeStreamBase*
     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   return stream_ = new WebSocketBasicHandshakeStream(connection.Pass(),
     39                                                      connect_delegate_,
     40                                                      using_proxy,
     41                                                      requested_subprotocols_,
     42                                                      extensions,
     43                                                      failure_message_);
     44 }
     45 
     46 // TODO(ricea): Create a WebSocketSpdyHandshakeStream. crbug.com/323852
     47 WebSocketHandshakeStreamBase*
     48 WebSocketHandshakeStreamCreateHelper::CreateSpdyStream(
     49     const base::WeakPtr<SpdySession>& session,
     50     bool use_relative_url) {
     51   NOTREACHED() << "Not implemented";
     52   return NULL;
     53 }
     54 
     55 }  // namespace net
     56