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

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

Issue 316008: Make WebSocketStreamHandleBridge RefCountedThreadSafe. (Closed)
Patch Set: Created 11 years, 2 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
« no previous file with comments | « webkit/glue/websocketstreamhandle_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h"
13 #include "net/url_request/url_request_context.h" 13 #include "net/url_request/url_request_context.h"
14 #include "webkit/api/public/WebSocketStreamHandle.h" 14 #include "webkit/api/public/WebSocketStreamHandle.h"
15 #include "webkit/glue/websocketstreamhandle_bridge.h" 15 #include "webkit/glue/websocketstreamhandle_bridge.h"
16 #include "webkit/glue/websocketstreamhandle_delegate.h" 16 #include "webkit/glue/websocketstreamhandle_delegate.h"
17 17
18 using webkit_glue::WebSocketStreamHandleBridge; 18 using webkit_glue::WebSocketStreamHandleBridge;
19 19
20 static const int kNoSocketId = 0; 20 static const int kNoSocketId = 0;
21 21
22 namespace { 22 namespace {
23 23
24 MessageLoop* g_io_thread; 24 MessageLoop* g_io_thread;
25 scoped_refptr<URLRequestContext> g_request_context; 25 scoped_refptr<URLRequestContext> g_request_context;
26 26
27 class WebSocketStreamHandleBridgeImpl 27 class WebSocketStreamHandleBridgeImpl
28 : public base::RefCountedThreadSafe<WebSocketStreamHandleBridgeImpl>, 28 : public WebSocketStreamHandleBridge,
29 public WebSocketStreamHandleBridge,
30 public net::SocketStream::Delegate { 29 public net::SocketStream::Delegate {
31 public: 30 public:
32 WebSocketStreamHandleBridgeImpl( 31 WebSocketStreamHandleBridgeImpl(
33 WebKit::WebSocketStreamHandle* handle, 32 WebKit::WebSocketStreamHandle* handle,
34 webkit_glue::WebSocketStreamHandleDelegate* delegate); 33 webkit_glue::WebSocketStreamHandleDelegate* delegate);
35 virtual ~WebSocketStreamHandleBridgeImpl();
36 34
37 // WebSocketStreamHandleBridge methods. 35 // WebSocketStreamHandleBridge methods.
38 virtual void Connect(const GURL& url); 36 virtual void Connect(const GURL& url);
39 virtual bool Send(const std::vector<char>& data); 37 virtual bool Send(const std::vector<char>& data);
40 virtual void Close(); 38 virtual void Close();
41 39
42 // net::SocketStream::Delegate methods. 40 // net::SocketStream::Delegate methods.
43 virtual void OnConnected(net::SocketStream* req, 41 virtual void OnConnected(net::SocketStream* req,
44 int max_pending_send_allowed); 42 int max_pending_send_allowed);
45 virtual void OnSentData(net::SocketStream* req, 43 virtual void OnSentData(net::SocketStream* req,
46 int amount_sent); 44 int amount_sent);
47 virtual void OnReceivedData(net::SocketStream* req, 45 virtual void OnReceivedData(net::SocketStream* req,
48 const char* data, int len); 46 const char* data, int len);
49 virtual void OnClose(net::SocketStream* req); 47 virtual void OnClose(net::SocketStream* req);
50 48
49 private:
50 virtual ~WebSocketStreamHandleBridgeImpl();
51 51
52 private:
53 // Runs on |g_io_thread|; 52 // Runs on |g_io_thread|;
54 void DoConnect(const GURL& url); 53 void DoConnect(const GURL& url);
55 void DoSend(std::vector<char>* data); 54 void DoSend(std::vector<char>* data);
56 void DoClose(); 55 void DoClose();
57 56
58 // Runs on |message_loop_|; 57 // Runs on |message_loop_|;
59 void DoOnConnected(int max_amount_send_allowed); 58 void DoOnConnected(int max_amount_send_allowed);
60 void DoOnSentData(int amount_sent); 59 void DoOnSentData(int amount_sent);
61 void DoOnReceivedData(std::vector<char>* data); 60 void DoOnReceivedData(std::vector<char>* data);
62 void DoOnClose(webkit_glue::WebSocketStreamHandleDelegate* delegate); 61 void DoOnClose(webkit_glue::WebSocketStreamHandleDelegate* delegate);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 namespace webkit_glue { 217 namespace webkit_glue {
219 218
220 /* static */ 219 /* static */
221 WebSocketStreamHandleBridge* WebSocketStreamHandleBridge::Create( 220 WebSocketStreamHandleBridge* WebSocketStreamHandleBridge::Create(
222 WebKit::WebSocketStreamHandle* handle, 221 WebKit::WebSocketStreamHandle* handle,
223 WebSocketStreamHandleDelegate* delegate) { 222 WebSocketStreamHandleDelegate* delegate) {
224 return new WebSocketStreamHandleBridgeImpl(handle, delegate); 223 return new WebSocketStreamHandleBridgeImpl(handle, delegate);
225 } 224 }
226 225
227 } // namespace webkit_glue 226 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/websocketstreamhandle_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698