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 #include "mojo/services/html_viewer/websockethandle_impl.h" | 5 #include "mojo/services/html_viewer/websockethandle_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" |
10 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
11 #include "mojo/services/html_viewer/blink_basic_type_converters.h" | 12 #include "mojo/services/html_viewer/blink_basic_type_converters.h" |
12 #include "mojo/services/public/cpp/network/web_socket_read_queue.h" | 13 #include "mojo/services/public/cpp/network/web_socket_read_queue.h" |
13 #include "mojo/services/public/cpp/network/web_socket_write_queue.h" | 14 #include "mojo/services/public/cpp/network/web_socket_write_queue.h" |
14 #include "mojo/services/public/interfaces/network/network_service.mojom.h" | 15 #include "mojo/services/public/interfaces/network/network_service.mojom.h" |
15 #include "third_party/WebKit/public/platform/WebSerializedOrigin.h" | 16 #include "third_party/WebKit/public/platform/WebSerializedOrigin.h" |
16 #include "third_party/WebKit/public/platform/WebSocketHandleClient.h" | 17 #include "third_party/WebKit/public/platform/WebSocketHandleClient.h" |
17 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
18 #include "third_party/WebKit/public/platform/WebURL.h" | 19 #include "third_party/WebKit/public/platform/WebURL.h" |
19 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 blink::WebSocketHandleClient* client) | 69 blink::WebSocketHandleClient* client) |
69 : handle_(handle), client_(client) {} | 70 : handle_(handle), client_(client) {} |
70 virtual ~WebSocketClientImpl() {} | 71 virtual ~WebSocketClientImpl() {} |
71 | 72 |
72 private: | 73 private: |
73 // WebSocketClient methods: | 74 // WebSocketClient methods: |
74 virtual void DidConnect(bool fail, | 75 virtual void DidConnect(bool fail, |
75 const String& selected_subprotocol, | 76 const String& selected_subprotocol, |
76 const String& extensions, | 77 const String& extensions, |
77 ScopedDataPipeConsumerHandle receive_stream) | 78 ScopedDataPipeConsumerHandle receive_stream) |
78 OVERRIDE { | 79 override { |
79 blink::WebSocketHandleClient* client = client_; | 80 blink::WebSocketHandleClient* client = client_; |
80 WebSocketHandleImpl* handle = handle_; | 81 WebSocketHandleImpl* handle = handle_; |
81 receive_stream_ = receive_stream.Pass(); | 82 receive_stream_ = receive_stream.Pass(); |
82 read_queue_.reset(new WebSocketReadQueue(receive_stream_.get())); | 83 read_queue_.reset(new WebSocketReadQueue(receive_stream_.get())); |
83 if (fail) | 84 if (fail) |
84 handle->Disconnect(); // deletes |this| | 85 handle->Disconnect(); // deletes |this| |
85 client->didConnect(handle, | 86 client->didConnect(handle, |
86 fail, | 87 fail, |
87 selected_subprotocol.To<WebString>(), | 88 selected_subprotocol.To<WebString>(), |
88 extensions.To<WebString>()); | 89 extensions.To<WebString>()); |
89 // |handle| can be deleted here. | 90 // |handle| can be deleted here. |
90 } | 91 } |
91 | 92 |
92 virtual void DidReceiveData(bool fin, | 93 virtual void DidReceiveData(bool fin, |
93 WebSocket::MessageType type, | 94 WebSocket::MessageType type, |
94 uint32_t num_bytes) OVERRIDE { | 95 uint32_t num_bytes) override { |
95 read_queue_->Read(num_bytes, | 96 read_queue_->Read(num_bytes, |
96 base::Bind(&WebSocketClientImpl::DidReadFromReceiveStream, | 97 base::Bind(&WebSocketClientImpl::DidReadFromReceiveStream, |
97 base::Unretained(this), | 98 base::Unretained(this), |
98 fin, type, num_bytes)); | 99 fin, type, num_bytes)); |
99 } | 100 } |
100 | 101 |
101 virtual void DidReceiveFlowControl(int64_t quota) OVERRIDE { | 102 virtual void DidReceiveFlowControl(int64_t quota) override { |
102 client_->didReceiveFlowControl(handle_, quota); | 103 client_->didReceiveFlowControl(handle_, quota); |
103 // |handle| can be deleted here. | 104 // |handle| can be deleted here. |
104 } | 105 } |
105 | 106 |
106 virtual void DidFail(const String& message) OVERRIDE { | 107 virtual void DidFail(const String& message) override { |
107 blink::WebSocketHandleClient* client = client_; | 108 blink::WebSocketHandleClient* client = client_; |
108 WebSocketHandleImpl* handle = handle_; | 109 WebSocketHandleImpl* handle = handle_; |
109 handle->Disconnect(); // deletes |this| | 110 handle->Disconnect(); // deletes |this| |
110 client->didFail(handle, message.To<WebString>()); | 111 client->didFail(handle, message.To<WebString>()); |
111 // |handle| can be deleted here. | 112 // |handle| can be deleted here. |
112 } | 113 } |
113 | 114 |
114 virtual void DidClose(bool was_clean, | 115 virtual void DidClose(bool was_clean, |
115 uint16_t code, | 116 uint16_t code, |
116 const String& reason) OVERRIDE { | 117 const String& reason) override { |
117 blink::WebSocketHandleClient* client = client_; | 118 blink::WebSocketHandleClient* client = client_; |
118 WebSocketHandleImpl* handle = handle_; | 119 WebSocketHandleImpl* handle = handle_; |
119 handle->Disconnect(); // deletes |this| | 120 handle->Disconnect(); // deletes |this| |
120 client->didClose(handle, was_clean, code, reason.To<WebString>()); | 121 client->didClose(handle, was_clean, code, reason.To<WebString>()); |
121 // |handle| can be deleted here. | 122 // |handle| can be deleted here. |
122 } | 123 } |
123 | 124 |
124 void DidReadFromReceiveStream(bool fin, | 125 void DidReadFromReceiveStream(bool fin, |
125 WebSocket::MessageType type, | 126 WebSocket::MessageType type, |
126 uint32_t num_bytes, | 127 uint32_t num_bytes, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 const char* data) { | 209 const char* data) { |
209 web_socket_->Send(fin, ConvertTo<WebSocket::MessageType>(type), num_bytes); | 210 web_socket_->Send(fin, ConvertTo<WebSocket::MessageType>(type), num_bytes); |
210 } | 211 } |
211 | 212 |
212 void WebSocketHandleImpl::Disconnect() { | 213 void WebSocketHandleImpl::Disconnect() { |
213 did_close_ = true; | 214 did_close_ = true; |
214 client_.reset(); | 215 client_.reset(); |
215 } | 216 } |
216 | 217 |
217 } // namespace mojo | 218 } // namespace mojo |
OLD | NEW |