Port Android relocation packer to chromium build
[chromium-blink-merge.git] / mojo / services / html_viewer / websockethandle_impl.h
blobeef6a96a7f61eb82539bbbbe05e10e50e16533d8
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/network/public/interfaces/web_socket.mojom.h"
12 #include "third_party/WebKit/public/platform/WebSocketHandle.h"
14 namespace mojo {
15 class NetworkService;
16 class WebSocketWriteQueue;
19 namespace html_viewer {
21 class WebSocketClientImpl;
23 // Implements WebSocketHandle by talking to the mojo WebSocket interface.
24 class WebSocketHandleImpl : public blink::WebSocketHandle {
25 public:
26 explicit WebSocketHandleImpl(mojo::NetworkService* network_service);
28 private:
29 friend class WebSocketClientImpl;
31 virtual ~WebSocketHandleImpl();
33 // blink::WebSocketHandle methods:
34 virtual void connect(const blink::WebURL& url,
35 const blink::WebVector<blink::WebString>& protocols,
36 const blink::WebSerializedOrigin& origin,
37 blink::WebSocketHandleClient*) override;
38 virtual void send(bool fin,
39 MessageType,
40 const char* data,
41 size_t size) override;
42 virtual void flowControl(int64_t quota) override;
43 virtual void close(unsigned short code,
44 const blink::WebString& reason) override;
46 // Called when we finished writing to |send_stream_|.
47 void DidWriteToSendStream(bool fin,
48 WebSocketHandle::MessageType type,
49 uint32_t num_bytes,
50 const char* data);
52 // Called when the socket is closed.
53 void Disconnect();
55 mojo::WebSocketPtr web_socket_;
56 scoped_ptr<WebSocketClientImpl> client_;
57 mojo::ScopedDataPipeProducerHandle send_stream_;
58 scoped_ptr<mojo::WebSocketWriteQueue> write_queue_;
59 // True if close() was called.
60 bool did_close_;
62 DISALLOW_COPY_AND_ASSIGN(WebSocketHandleImpl);
65 } // namespace html_viewer
67 #endif // MOJO_SERVICES_HTML_VIEWER_WEBSOCKETHANDLE_IMPL_H_