summaryrefslogtreecommitdiffstats
path: root/mojo/services/network/web_socket_impl.h
blob: 26a2036537a79ae1dfee58114697d84ca6d5d4a7 (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
// Copyright 2014 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 MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_
#define MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_

#include <stdint.h>

#include "base/memory/scoped_ptr.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/services/network/public/interfaces/web_socket.mojom.h"
#include "mojo/shell/public/cpp/app_lifetime_helper.h"

namespace net {
class WebSocketChannel;
}  // namespace net

namespace mojo {
class NetworkContext;
class WebSocketReadQueue;

// Forms a bridge between the WebSocket mojo interface and the net::WebSocket
// implementation.
class WebSocketImpl : public WebSocket {
 public:
  WebSocketImpl(NetworkContext* context,
                scoped_ptr<mojo::AppRefCount> app_refcount,
                InterfaceRequest<WebSocket> request);
  ~WebSocketImpl() override;

 private:
  // WebSocket methods:
  void Connect(const String& url,
               Array<String> protocols,
               const String& origin,
               ScopedDataPipeConsumerHandle send_stream,
               WebSocketClientPtr client) override;
  void Send(bool fin, WebSocket::MessageType type, uint32_t num_bytes) override;
  void FlowControl(int64_t quota) override;
  void Close(uint16_t code, const String& reason) override;

  // Called with the data to send once it has been read from |send_stream_|.
  void DidReadFromSendStream(bool fin,
                             WebSocket::MessageType type,
                             uint32_t num_bytes,
                             const char* data);

  // The channel we use to send events to the network.
  scoped_ptr<net::WebSocketChannel> channel_;
  ScopedDataPipeConsumerHandle send_stream_;
  scoped_ptr<WebSocketReadQueue> read_queue_;
  NetworkContext* context_;
  scoped_ptr<mojo::AppRefCount> app_refcount_;
  StrongBinding<WebSocket> binding_;
};

}  // namespace mojo

#endif  // MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_