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_HTML_VIEWER_WEBSOCKETHANDLE_IMPL_H_
6 #define MOJO_SERVICES_HTML_VIEWER_WEBSOCKETHANDLE_IMPL_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "mojo/common/handle_watcher.h"
11 #include "mojo/services/public/interfaces/network/web_socket.mojom.h"
12 #include "third_party/WebKit/public/platform/WebSocketHandle.h"
16 class WebSocketClientImpl
;
17 class WebSocketWriteQueue
;
19 // Implements WebSocketHandle by talking to the mojo WebSocket interface.
20 class WebSocketHandleImpl
: public blink::WebSocketHandle
{
22 explicit WebSocketHandleImpl(NetworkService
* network_service
);
25 friend class WebSocketClientImpl
;
27 virtual ~WebSocketHandleImpl();
29 // blink::WebSocketHandle methods:
30 virtual void connect(const blink::WebURL
& url
,
31 const blink::WebVector
<blink::WebString
>& protocols
,
32 const blink::WebSerializedOrigin
& origin
,
33 blink::WebSocketHandleClient
*) override
;
34 virtual void send(bool fin
,
37 size_t size
) override
;
38 virtual void flowControl(int64_t quota
) override
;
39 virtual void close(unsigned short code
,
40 const blink::WebString
& reason
) override
;
42 // Called when we finished writing to |send_stream_|.
43 void DidWriteToSendStream(bool fin
,
44 WebSocketHandle::MessageType type
,
48 // Called when the socket is closed.
51 WebSocketPtr web_socket_
;
52 scoped_ptr
<WebSocketClientImpl
> client_
;
53 ScopedDataPipeProducerHandle send_stream_
;
54 scoped_ptr
<WebSocketWriteQueue
> write_queue_
;
55 // True if close() was called.
58 DISALLOW_COPY_AND_ASSIGN(WebSocketHandleImpl
);
63 #endif // MOJO_SERVICES_HTML_VIEWER_WEBSOCKETHANDLE_IMPL_H_