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.
5 #ifndef MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_
6 #define MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "mojo/application/public/cpp/app_lifetime_helper.h"
10 #include "mojo/services/network/public/interfaces/web_socket.mojom.h"
11 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
14 class WebSocketChannel
;
19 class WebSocketReadQueue
;
21 // Forms a bridge between the WebSocket mojo interface and the net::WebSocket
23 class WebSocketImpl
: public WebSocket
{
25 WebSocketImpl(NetworkContext
* context
,
26 scoped_ptr
<mojo::AppRefCount
> app_refcount
,
27 InterfaceRequest
<WebSocket
> request
);
28 ~WebSocketImpl() override
;
32 void Connect(const String
& url
,
33 Array
<String
> protocols
,
35 ScopedDataPipeConsumerHandle send_stream
,
36 WebSocketClientPtr client
) override
;
37 void Send(bool fin
, WebSocket::MessageType type
, uint32_t num_bytes
) override
;
38 void FlowControl(int64_t quota
) override
;
39 void Close(uint16_t code
, const String
& reason
) override
;
41 // Called with the data to send once it has been read from |send_stream_|.
42 void DidReadFromSendStream(bool fin
,
43 WebSocket::MessageType type
,
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 scoped_ptr
<mojo::AppRefCount
> app_refcount_
;
53 StrongBinding
<WebSocket
> binding_
;
58 #endif // MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_