OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_ | 5 #ifndef MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_ |
6 #define MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_ | 6 #define MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "mojo/public/cpp/bindings/strong_binding.h" | 11 #include "mojo/public/cpp/bindings/strong_binding.h" |
12 #include "mojo/services/network/public/interfaces/web_socket.mojom.h" | 12 #include "mojo/services/network/public/interfaces/web_socket.mojom.h" |
13 #include "mojo/shell/public/cpp/shell.h" | 13 #include "mojo/shell/public/cpp/message_loop_ref.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 class WebSocketChannel; | 16 class WebSocketChannel; |
17 } // namespace net | 17 } // namespace net |
18 | 18 |
19 namespace mojo { | 19 namespace mojo { |
20 class NetworkContext; | 20 class NetworkContext; |
21 class WebSocketReadQueue; | 21 class WebSocketReadQueue; |
22 | 22 |
23 // Forms a bridge between the WebSocket mojo interface and the net::WebSocket | 23 // Forms a bridge between the WebSocket mojo interface and the net::WebSocket |
24 // implementation. | 24 // implementation. |
25 class WebSocketImpl : public WebSocket { | 25 class WebSocketImpl : public WebSocket { |
26 public: | 26 public: |
27 WebSocketImpl(NetworkContext* context, | 27 WebSocketImpl(NetworkContext* context, |
28 scoped_ptr<mojo::AppRefCount> app_refcount, | 28 scoped_ptr<mojo::MessageLoopRef> app_refcount, |
29 InterfaceRequest<WebSocket> request); | 29 InterfaceRequest<WebSocket> request); |
30 ~WebSocketImpl() override; | 30 ~WebSocketImpl() override; |
31 | 31 |
32 private: | 32 private: |
33 // WebSocket methods: | 33 // WebSocket methods: |
34 void Connect(const String& url, | 34 void Connect(const String& url, |
35 Array<String> protocols, | 35 Array<String> protocols, |
36 const String& origin, | 36 const String& origin, |
37 ScopedDataPipeConsumerHandle send_stream, | 37 ScopedDataPipeConsumerHandle send_stream, |
38 WebSocketClientPtr client) override; | 38 WebSocketClientPtr client) override; |
39 void Send(bool fin, WebSocket::MessageType type, uint32_t num_bytes) override; | 39 void Send(bool fin, WebSocket::MessageType type, uint32_t num_bytes) override; |
40 void FlowControl(int64_t quota) override; | 40 void FlowControl(int64_t quota) override; |
41 void Close(uint16_t code, const String& reason) override; | 41 void Close(uint16_t code, const String& reason) override; |
42 | 42 |
43 // Called with the data to send once it has been read from |send_stream_|. | 43 // Called with the data to send once it has been read from |send_stream_|. |
44 void DidReadFromSendStream(bool fin, | 44 void DidReadFromSendStream(bool fin, |
45 WebSocket::MessageType type, | 45 WebSocket::MessageType type, |
46 uint32_t num_bytes, | 46 uint32_t num_bytes, |
47 const char* data); | 47 const char* data); |
48 | 48 |
49 // The channel we use to send events to the network. | 49 // The channel we use to send events to the network. |
50 scoped_ptr<net::WebSocketChannel> channel_; | 50 scoped_ptr<net::WebSocketChannel> channel_; |
51 ScopedDataPipeConsumerHandle send_stream_; | 51 ScopedDataPipeConsumerHandle send_stream_; |
52 scoped_ptr<WebSocketReadQueue> read_queue_; | 52 scoped_ptr<WebSocketReadQueue> read_queue_; |
53 NetworkContext* context_; | 53 NetworkContext* context_; |
54 scoped_ptr<mojo::AppRefCount> app_refcount_; | 54 scoped_ptr<mojo::MessageLoopRef> app_refcount_; |
55 StrongBinding<WebSocket> binding_; | 55 StrongBinding<WebSocket> binding_; |
56 }; | 56 }; |
57 | 57 |
58 } // namespace mojo | 58 } // namespace mojo |
59 | 59 |
60 #endif // MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_ | 60 #endif // MOJO_SERVICES_NETWORK_WEB_SOCKET_IMPL_H_ |
OLD | NEW |