• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_
6 #define MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_
7 
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "mojo/public/cpp/bindings/interface_impl.h"
11 #include "mojo/services/public/interfaces/network/web_socket.mojom.h"
12 
13 namespace net {
14 class WebSocketChannel;
15 }  // namespace net
16 
17 namespace mojo {
18 class NetworkContext;
19 class WebSocketReadQueue;
20 
21 // Forms a bridge between the WebSocket mojo interface and the net::WebSocket
22 // implementation.
23 class WebSocketImpl : public InterfaceImpl<WebSocket> {
24  public:
25   explicit WebSocketImpl(NetworkContext* context);
26   virtual ~WebSocketImpl();
27 
28  private:
29   // WebSocket methods:
30   virtual void Connect(const String& url,
31                        Array<String> protocols,
32                        const String& origin,
33                        ScopedDataPipeConsumerHandle send_stream,
34                        WebSocketClientPtr client) OVERRIDE;
35   virtual void Send(bool fin,
36                     WebSocket::MessageType type,
37                     uint32_t num_bytes) OVERRIDE;
38   virtual void FlowControl(int64_t quota) OVERRIDE;
39   virtual void Close(uint16_t code, const String& reason) OVERRIDE;
40 
41   // Called with the data to send once it has been read from |send_stream_|.
42   void DidReadFromSendStream(bool fin,
43                              WebSocket::MessageType type,
44                              uint32_t num_bytes,
45                              const char* data);
46 
47   // The channel we use to send events to the network.
48   scoped_ptr<net::WebSocketChannel> channel_;
49   ScopedDataPipeConsumerHandle send_stream_;
50   scoped_ptr<WebSocketReadQueue> read_queue_;
51   NetworkContext* context_;
52 };
53 
54 }  // namespace mojo
55 
56 #endif  // MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_
57