OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "webkit/tools/test_shell/simple_socket_stream_bridge.h" | 7 #include "webkit/tools/test_shell/simple_socket_stream_bridge.h" |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 #include "net/socket_stream/socket_stream.h" | 12 #include "net/socket_stream/socket_stream_job.h" |
| 13 #include "net/websockets/websocket_job.h" |
13 #include "net/url_request/url_request_context.h" | 14 #include "net/url_request/url_request_context.h" |
14 #include "third_party/WebKit/WebKit/chromium/public/WebSocketStreamHandle.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebSocketStreamHandle.h" |
15 #include "webkit/glue/websocketstreamhandle_bridge.h" | 16 #include "webkit/glue/websocketstreamhandle_bridge.h" |
16 #include "webkit/glue/websocketstreamhandle_delegate.h" | 17 #include "webkit/glue/websocketstreamhandle_delegate.h" |
17 | 18 |
18 using webkit_glue::WebSocketStreamHandleBridge; | 19 using webkit_glue::WebSocketStreamHandleBridge; |
19 | 20 |
20 static const int kNoSocketId = 0; | 21 static const int kNoSocketId = 0; |
21 | 22 |
22 namespace { | 23 namespace { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 void DoOnConnected(int max_amount_send_allowed); | 59 void DoOnConnected(int max_amount_send_allowed); |
59 void DoOnSentData(int amount_sent); | 60 void DoOnSentData(int amount_sent); |
60 void DoOnReceivedData(std::vector<char>* data); | 61 void DoOnReceivedData(std::vector<char>* data); |
61 void DoOnClose(); | 62 void DoOnClose(); |
62 | 63 |
63 int socket_id_; | 64 int socket_id_; |
64 MessageLoop* message_loop_; | 65 MessageLoop* message_loop_; |
65 WebKit::WebSocketStreamHandle* handle_; | 66 WebKit::WebSocketStreamHandle* handle_; |
66 webkit_glue::WebSocketStreamHandleDelegate* delegate_; | 67 webkit_glue::WebSocketStreamHandleDelegate* delegate_; |
67 | 68 |
68 scoped_refptr<net::SocketStream> socket_; | 69 scoped_refptr<net::SocketStreamJob> socket_; |
69 // Number of pending tasks to handle net::SocketStream::Delegate methods. | 70 // Number of pending tasks to handle net::SocketStream::Delegate methods. |
70 int num_pending_tasks_; | 71 int num_pending_tasks_; |
71 | 72 |
72 DISALLOW_COPY_AND_ASSIGN(WebSocketStreamHandleBridgeImpl); | 73 DISALLOW_COPY_AND_ASSIGN(WebSocketStreamHandleBridgeImpl); |
73 }; | 74 }; |
74 | 75 |
75 WebSocketStreamHandleBridgeImpl::WebSocketStreamHandleBridgeImpl( | 76 WebSocketStreamHandleBridgeImpl::WebSocketStreamHandleBridgeImpl( |
76 WebKit::WebSocketStreamHandle* handle, | 77 WebKit::WebSocketStreamHandle* handle, |
77 webkit_glue::WebSocketStreamHandleDelegate* delegate) | 78 webkit_glue::WebSocketStreamHandleDelegate* delegate) |
78 : socket_id_(kNoSocketId), | 79 : socket_id_(kNoSocketId), |
79 message_loop_(MessageLoop::current()), | 80 message_loop_(MessageLoop::current()), |
80 handle_(handle), | 81 handle_(handle), |
81 delegate_(delegate), | 82 delegate_(delegate), |
82 num_pending_tasks_(0) { | 83 num_pending_tasks_(0) { |
| 84 net::WebSocketJob::EnsureInit(); |
83 } | 85 } |
84 | 86 |
85 WebSocketStreamHandleBridgeImpl::~WebSocketStreamHandleBridgeImpl() { | 87 WebSocketStreamHandleBridgeImpl::~WebSocketStreamHandleBridgeImpl() { |
86 DCHECK_EQ(socket_id_, kNoSocketId); | 88 DCHECK_EQ(socket_id_, kNoSocketId); |
87 } | 89 } |
88 | 90 |
89 void WebSocketStreamHandleBridgeImpl::Connect(const GURL& url) { | 91 void WebSocketStreamHandleBridgeImpl::Connect(const GURL& url) { |
90 DCHECK(g_io_thread); | 92 DCHECK(g_io_thread); |
91 AddRef(); // Released in DoOnClose(). | 93 AddRef(); // Released in DoOnClose(). |
92 g_io_thread->PostTask( | 94 g_io_thread->PostTask( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // Release socket_ on IO thread. | 149 // Release socket_ on IO thread. |
148 socket_ = NULL; | 150 socket_ = NULL; |
149 socket_id_ = kNoSocketId; | 151 socket_id_ = kNoSocketId; |
150 message_loop_->PostTask( | 152 message_loop_->PostTask( |
151 FROM_HERE, | 153 FROM_HERE, |
152 NewRunnableMethod(this, &WebSocketStreamHandleBridgeImpl::DoOnClose)); | 154 NewRunnableMethod(this, &WebSocketStreamHandleBridgeImpl::DoOnClose)); |
153 } | 155 } |
154 | 156 |
155 void WebSocketStreamHandleBridgeImpl::DoConnect(const GURL& url) { | 157 void WebSocketStreamHandleBridgeImpl::DoConnect(const GURL& url) { |
156 DCHECK(MessageLoop::current() == g_io_thread); | 158 DCHECK(MessageLoop::current() == g_io_thread); |
157 socket_ = new net::SocketStream(url, this); | 159 socket_ = net::SocketStreamJob::CreateSocketStreamJob(url, this); |
158 socket_->set_context(g_request_context); | 160 socket_->set_context(g_request_context); |
159 socket_->Connect(); | 161 socket_->Connect(); |
160 } | 162 } |
161 | 163 |
162 void WebSocketStreamHandleBridgeImpl::DoSend(std::vector<char>* data) { | 164 void WebSocketStreamHandleBridgeImpl::DoSend(std::vector<char>* data) { |
163 DCHECK(MessageLoop::current() == g_io_thread); | 165 DCHECK(MessageLoop::current() == g_io_thread); |
164 scoped_ptr<std::vector<char> > scoped_data(data); | 166 scoped_ptr<std::vector<char> > scoped_data(data); |
165 if (!socket_) | 167 if (!socket_) |
166 return; | 168 return; |
167 if (!socket_->SendData(&(data->at(0)), data->size())) | 169 if (!socket_->SendData(&(data->at(0)), data->size())) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 namespace webkit_glue { | 232 namespace webkit_glue { |
231 | 233 |
232 /* static */ | 234 /* static */ |
233 WebSocketStreamHandleBridge* WebSocketStreamHandleBridge::Create( | 235 WebSocketStreamHandleBridge* WebSocketStreamHandleBridge::Create( |
234 WebKit::WebSocketStreamHandle* handle, | 236 WebKit::WebSocketStreamHandle* handle, |
235 WebSocketStreamHandleDelegate* delegate) { | 237 WebSocketStreamHandleDelegate* delegate) { |
236 return new WebSocketStreamHandleBridgeImpl(handle, delegate); | 238 return new WebSocketStreamHandleBridgeImpl(handle, delegate); |
237 } | 239 } |
238 | 240 |
239 } // namespace webkit_glue | 241 } // namespace webkit_glue |
OLD | NEW |