Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Side by Side Diff: webkit/tools/test_shell/simple_socket_stream_bridge.cc

Issue 10458057: Websocket should fire 'error' event if no server available (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/atomicops.h" 9 #include "base/atomicops.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 30 matching lines...) Expand all
41 virtual void Close(); 41 virtual void Close();
42 42
43 // net::SocketStream::Delegate methods. 43 // net::SocketStream::Delegate methods.
44 virtual void OnConnected(net::SocketStream* req, 44 virtual void OnConnected(net::SocketStream* req,
45 int max_pending_send_allowed); 45 int max_pending_send_allowed);
46 virtual void OnSentData(net::SocketStream* req, 46 virtual void OnSentData(net::SocketStream* req,
47 int amount_sent); 47 int amount_sent);
48 virtual void OnReceivedData(net::SocketStream* req, 48 virtual void OnReceivedData(net::SocketStream* req,
49 const char* data, int len); 49 const char* data, int len);
50 virtual void OnClose(net::SocketStream* req); 50 virtual void OnClose(net::SocketStream* req);
51 virtual void OnError(const net::SocketStream* req, int error_code);
51 52
52 private: 53 private:
53 virtual ~WebSocketStreamHandleBridgeImpl(); 54 virtual ~WebSocketStreamHandleBridgeImpl();
54 55
55 // Runs on |g_io_thread|; 56 // Runs on |g_io_thread|;
56 void DoConnect(const GURL& url); 57 void DoConnect(const GURL& url);
57 void DoSend(std::vector<char>* data); 58 void DoSend(std::vector<char>* data);
58 void DoClose(); 59 void DoClose();
59 60
60 // Runs on |message_loop_|; 61 // Runs on |message_loop_|;
61 void DoOnConnected(int max_amount_send_allowed); 62 void DoOnConnected(int max_amount_send_allowed);
62 void DoOnSentData(int amount_sent); 63 void DoOnSentData(int amount_sent);
63 void DoOnReceivedData(std::vector<char>* data); 64 void DoOnReceivedData(std::vector<char>* data);
64 void DoOnClose(); 65 void DoOnClose();
66 void DoOnError(int error_code);
65 67
66 int socket_id_; 68 int socket_id_;
67 MessageLoop* message_loop_; 69 MessageLoop* message_loop_;
68 WebKit::WebSocketStreamHandle* handle_; 70 WebKit::WebSocketStreamHandle* handle_;
69 webkit_glue::WebSocketStreamHandleDelegate* delegate_; 71 webkit_glue::WebSocketStreamHandleDelegate* delegate_;
70 72
71 scoped_refptr<net::SocketStreamJob> socket_; 73 scoped_refptr<net::SocketStreamJob> socket_;
72 // Number of pending tasks to handle net::SocketStream::Delegate methods. 74 // Number of pending tasks to handle net::SocketStream::Delegate methods.
73 base::subtle::Atomic32 num_pending_tasks_; 75 base::subtle::Atomic32 num_pending_tasks_;
74 76
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 void WebSocketStreamHandleBridgeImpl::OnClose(net::SocketStream* socket) { 149 void WebSocketStreamHandleBridgeImpl::OnClose(net::SocketStream* socket) {
148 base::subtle::NoBarrier_AtomicIncrement(&num_pending_tasks_, 1); 150 base::subtle::NoBarrier_AtomicIncrement(&num_pending_tasks_, 1);
149 // Release socket_ on IO thread. 151 // Release socket_ on IO thread.
150 socket_ = NULL; 152 socket_ = NULL;
151 socket_id_ = kNoSocketId; 153 socket_id_ = kNoSocketId;
152 message_loop_->PostTask( 154 message_loop_->PostTask(
153 FROM_HERE, 155 FROM_HERE,
154 base::Bind(&WebSocketStreamHandleBridgeImpl::DoOnClose, this)); 156 base::Bind(&WebSocketStreamHandleBridgeImpl::DoOnClose, this));
155 } 157 }
156 158
159 void WebSocketStreamHandleBridgeImpl::OnError(
160 const net::SocketStream* socket, int error_code) {
161 base::subtle::NoBarrier_AtomicIncrement(&num_pending_tasks_, 1);
162 message_loop_->PostTask(
163 FROM_HERE,
164 base::Bind(&WebSocketStreamHandleBridgeImpl::DoOnError, this,
165 error_code));
166 }
167
157 void WebSocketStreamHandleBridgeImpl::DoConnect(const GURL& url) { 168 void WebSocketStreamHandleBridgeImpl::DoConnect(const GURL& url) {
158 DCHECK(MessageLoop::current() == g_io_thread); 169 DCHECK(MessageLoop::current() == g_io_thread);
159 socket_ = net::SocketStreamJob::CreateSocketStreamJob( 170 socket_ = net::SocketStreamJob::CreateSocketStreamJob(
160 url, this, g_request_context->transport_security_state(), 171 url, this, g_request_context->transport_security_state(),
161 g_request_context->ssl_config_service()); 172 g_request_context->ssl_config_service());
162 socket_->set_context(g_request_context); 173 socket_->set_context(g_request_context);
163 socket_->Connect(); 174 socket_->Connect();
164 } 175 }
165 176
166 void WebSocketStreamHandleBridgeImpl::DoSend(std::vector<char>* data) { 177 void WebSocketStreamHandleBridgeImpl::DoSend(std::vector<char>* data) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 DCHECK_EQ(num_pending_tasks_, 0); 221 DCHECK_EQ(num_pending_tasks_, 0);
211 DCHECK(!socket_); 222 DCHECK(!socket_);
212 DCHECK_EQ(socket_id_, kNoSocketId); 223 DCHECK_EQ(socket_id_, kNoSocketId);
213 webkit_glue::WebSocketStreamHandleDelegate* delegate = delegate_; 224 webkit_glue::WebSocketStreamHandleDelegate* delegate = delegate_;
214 delegate_ = NULL; 225 delegate_ = NULL;
215 if (delegate) 226 if (delegate)
216 delegate->DidClose(handle_); 227 delegate->DidClose(handle_);
217 Release(); 228 Release();
218 } 229 }
219 230
231 void WebSocketStreamHandleBridgeImpl::DoOnError(int error_code) {
232 DCHECK(MessageLoop::current() == message_loop_);
233 base::subtle::NoBarrier_AtomicIncrement(&num_pending_tasks_, -1);
234 if (delegate_)
235 delegate_->DidFail(handle_, error_code);
236 }
237
220 } // namespace 238 } // namespace
221 239
222 /* static */ 240 /* static */
223 void SimpleSocketStreamBridge::InitializeOnIOThread( 241 void SimpleSocketStreamBridge::InitializeOnIOThread(
224 net::URLRequestContext* request_context) { 242 net::URLRequestContext* request_context) {
225 g_io_thread = MessageLoop::current(); 243 g_io_thread = MessageLoop::current();
226 g_request_context = request_context; 244 g_request_context = request_context;
227 } 245 }
228 246
229 void SimpleSocketStreamBridge::Cleanup() { 247 void SimpleSocketStreamBridge::Cleanup() {
230 g_io_thread = NULL; 248 g_io_thread = NULL;
231 g_request_context = NULL; 249 g_request_context = NULL;
232 } 250 }
233 251
234 /* static */ 252 /* static */
235 webkit_glue::WebSocketStreamHandleBridge* SimpleSocketStreamBridge::Create( 253 webkit_glue::WebSocketStreamHandleBridge* SimpleSocketStreamBridge::Create(
236 WebKit::WebSocketStreamHandle* handle, 254 WebKit::WebSocketStreamHandle* handle,
237 webkit_glue::WebSocketStreamHandleDelegate* delegate) { 255 webkit_glue::WebSocketStreamHandleDelegate* delegate) {
238 return new WebSocketStreamHandleBridgeImpl(handle, delegate); 256 return new WebSocketStreamHandleBridgeImpl(handle, delegate);
239 } 257 }
OLDNEW
« webkit/glue/websocketstreamhandle_impl.cc ('K') | « webkit/glue/websocketstreamhandle_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698