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

Side by Side Diff: Source/modules/websockets/WorkerThreadableWebSocketChannel.h

Issue 17648006: Rename WorkerContext to WorkerGlobalScope (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef WorkerThreadableWebSocketChannel_h 31 #ifndef WorkerThreadableWebSocketChannel_h
32 #define WorkerThreadableWebSocketChannel_h 32 #define WorkerThreadableWebSocketChannel_h
33 33
34 #include "core/page/ConsoleTypes.h" 34 #include "core/page/ConsoleTypes.h"
35 #include "core/workers/WorkerContext.h" 35 #include "core/workers/WorkerGlobalScope.h"
36 #include "modules/websockets/WebSocketChannel.h" 36 #include "modules/websockets/WebSocketChannel.h"
37 #include "modules/websockets/WebSocketChannelClient.h" 37 #include "modules/websockets/WebSocketChannelClient.h"
38 38
39 #include "wtf/PassOwnPtr.h" 39 #include "wtf/PassOwnPtr.h"
40 #include "wtf/PassRefPtr.h" 40 #include "wtf/PassRefPtr.h"
41 #include "wtf/RefCounted.h" 41 #include "wtf/RefCounted.h"
42 #include "wtf/RefPtr.h" 42 #include "wtf/RefPtr.h"
43 #include "wtf/Threading.h" 43 #include "wtf/Threading.h"
44 #include "wtf/Vector.h" 44 #include "wtf/Vector.h"
45 #include "wtf/text/WTFString.h" 45 #include "wtf/text/WTFString.h"
46 46
47 namespace WebCore { 47 namespace WebCore {
48 48
49 class KURL; 49 class KURL;
50 class ScriptExecutionContext; 50 class ScriptExecutionContext;
51 class ThreadableWebSocketChannelClientWrapper; 51 class ThreadableWebSocketChannelClientWrapper;
52 class WorkerContext; 52 class WorkerGlobalScope;
53 class WorkerLoaderProxy; 53 class WorkerLoaderProxy;
54 class WorkerRunLoop; 54 class WorkerRunLoop;
55 55
56 class WorkerThreadableWebSocketChannel : public RefCounted<WorkerThreadableWebSo cketChannel>, public WebSocketChannel { 56 class WorkerThreadableWebSocketChannel : public RefCounted<WorkerThreadableWebSo cketChannel>, public WebSocketChannel {
57 WTF_MAKE_FAST_ALLOCATED; 57 WTF_MAKE_FAST_ALLOCATED;
58 public: 58 public:
59 static PassRefPtr<WebSocketChannel> create(WorkerContext* workerContext, Web SocketChannelClient* client, const String& taskMode) 59 static PassRefPtr<WebSocketChannel> create(WorkerGlobalScope* workerGlobalSc ope, WebSocketChannelClient* client, const String& taskMode)
60 { 60 {
61 return adoptRef(new WorkerThreadableWebSocketChannel(workerContext, clie nt, taskMode)); 61 return adoptRef(new WorkerThreadableWebSocketChannel(workerGlobalScope, client, taskMode));
62 } 62 }
63 virtual ~WorkerThreadableWebSocketChannel(); 63 virtual ~WorkerThreadableWebSocketChannel();
64 64
65 // WebSocketChannel functions. 65 // WebSocketChannel functions.
66 virtual void connect(const KURL&, const String& protocol) OVERRIDE; 66 virtual void connect(const KURL&, const String& protocol) OVERRIDE;
67 virtual String subprotocol() OVERRIDE; 67 virtual String subprotocol() OVERRIDE;
68 virtual String extensions() OVERRIDE; 68 virtual String extensions() OVERRIDE;
69 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; 69 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE;
70 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO ffset, unsigned byteLength) OVERRIDE; 70 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO ffset, unsigned byteLength) OVERRIDE;
71 virtual WebSocketChannel::SendResult send(const Blob&) OVERRIDE; 71 virtual WebSocketChannel::SendResult send(const Blob&) OVERRIDE;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 123
124 protected: 124 protected:
125 // WebSocketChannel functions. 125 // WebSocketChannel functions.
126 virtual void refWebSocketChannel() OVERRIDE { ref(); } 126 virtual void refWebSocketChannel() OVERRIDE { ref(); }
127 virtual void derefWebSocketChannel() OVERRIDE { deref(); } 127 virtual void derefWebSocketChannel() OVERRIDE { deref(); }
128 128
129 private: 129 private:
130 // Bridge for Peer. Running on the worker thread. 130 // Bridge for Peer. Running on the worker thread.
131 class Bridge : public RefCounted<Bridge> { 131 class Bridge : public RefCounted<Bridge> {
132 public: 132 public:
133 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl ientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const String& taskMode) 133 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl ientWrapper> workerClientWrapper, PassRefPtr<WorkerGlobalScope> workerGlobalScop e, const String& taskMode)
134 { 134 {
135 return adoptRef(new Bridge(workerClientWrapper, workerContext, taskM ode)); 135 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope, t askMode));
136 } 136 }
137 ~Bridge(); 137 ~Bridge();
138 // sourceURLAtConnection and lineNumberAtConnection parameters may 138 // sourceURLAtConnection and lineNumberAtConnection parameters may
139 // be shown when the connection fails. 139 // be shown when the connection fails.
140 void initialize(const String& sourceURLAtConnection, unsigned lineNumber AtConnection); 140 void initialize(const String& sourceURLAtConnection, unsigned lineNumber AtConnection);
141 void connect(const KURL&, const String& protocol); 141 void connect(const KURL&, const String& protocol);
142 WebSocketChannel::SendResult send(const String& message); 142 WebSocketChannel::SendResult send(const String& message);
143 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse t, unsigned byteLength); 143 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse t, unsigned byteLength);
144 WebSocketChannel::SendResult send(const Blob&); 144 WebSocketChannel::SendResult send(const Blob&);
145 unsigned long bufferedAmount(); 145 unsigned long bufferedAmount();
146 void close(int code, const String& reason); 146 void close(int code, const String& reason);
147 void fail(const String& reason, MessageLevel, const String& sourceURL, u nsigned lineNumber); 147 void fail(const String& reason, MessageLevel, const String& sourceURL, u nsigned lineNumber);
148 void disconnect(); 148 void disconnect();
149 void suspend(); 149 void suspend();
150 void resume(); 150 void resume();
151 151
152 using RefCounted<Bridge>::ref; 152 using RefCounted<Bridge>::ref;
153 using RefCounted<Bridge>::deref; 153 using RefCounted<Bridge>::deref;
154 154
155 private: 155 private:
156 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<W orkerContext>, const String& taskMode); 156 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<W orkerGlobalScope>, const String& taskMode);
157 157
158 static void setWebSocketChannel(ScriptExecutionContext*, Bridge* thisPtr , Peer*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>); 158 static void setWebSocketChannel(ScriptExecutionContext*, Bridge* thisPtr , Peer*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>);
159 159
160 // Executed on the main thread to create a Peer for this bridge. 160 // Executed on the main thread to create a Peer for this bridge.
161 // sourceURL and lineNumber provides the source filename and 161 // sourceURL and lineNumber provides the source filename and
162 // the line number information at the connection initiation 162 // the line number information at the connection initiation
163 // respectively. They may be shown when the connection fails. 163 // respectively. They may be shown when the connection fails.
164 static void mainThreadInitialize(ScriptExecutionContext*, WorkerLoaderPr oxy*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, const String& taskMod e, const String& sourceURL, unsigned lineNumber); 164 static void mainThreadInitialize(ScriptExecutionContext*, WorkerLoaderPr oxy*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, const String& taskMod e, const String& sourceURL, unsigned lineNumber);
165 165
166 // Executed on the worker context's thread. 166 // Executed on the worker context's thread.
167 void clearClientWrapper(); 167 void clearClientWrapper();
168 168
169 void setMethodNotCompleted(); 169 void setMethodNotCompleted();
170 void waitForMethodCompletion(); 170 void waitForMethodCompletion();
171 171
172 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; 172 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper;
173 RefPtr<WorkerContext> m_workerContext; 173 RefPtr<WorkerGlobalScope> m_workerGlobalScope;
174 WorkerLoaderProxy& m_loaderProxy; 174 WorkerLoaderProxy& m_loaderProxy;
175 String m_taskMode; 175 String m_taskMode;
176 Peer* m_peer; 176 Peer* m_peer;
177 }; 177 };
178 178
179 WorkerThreadableWebSocketChannel(WorkerContext*, WebSocketChannelClient*, co nst String& taskMode); 179 WorkerThreadableWebSocketChannel(WorkerGlobalScope*, WebSocketChannelClient* , const String& taskMode);
180 180
181 static void mainThreadConnect(ScriptExecutionContext*, Peer*, const KURL&, c onst String& protocol); 181 static void mainThreadConnect(ScriptExecutionContext*, Peer*, const KURL&, c onst String& protocol);
182 static void mainThreadSend(ScriptExecutionContext*, Peer*, const String& mes sage); 182 static void mainThreadSend(ScriptExecutionContext*, Peer*, const String& mes sage);
183 static void mainThreadSendArrayBuffer(ScriptExecutionContext*, Peer*, PassOw nPtr<Vector<char> >); 183 static void mainThreadSendArrayBuffer(ScriptExecutionContext*, Peer*, PassOw nPtr<Vector<char> >);
184 static void mainThreadSendBlob(ScriptExecutionContext*, Peer*, const KURL&, const String& type, long long size); 184 static void mainThreadSendBlob(ScriptExecutionContext*, Peer*, const KURL&, const String& type, long long size);
185 static void mainThreadBufferedAmount(ScriptExecutionContext*, Peer*); 185 static void mainThreadBufferedAmount(ScriptExecutionContext*, Peer*);
186 static void mainThreadClose(ScriptExecutionContext*, Peer*, int code, const String& reason); 186 static void mainThreadClose(ScriptExecutionContext*, Peer*, int code, const String& reason);
187 static void mainThreadFail(ScriptExecutionContext*, Peer*, const String& rea son, MessageLevel, const String& sourceURL, unsigned lineNumber); 187 static void mainThreadFail(ScriptExecutionContext*, Peer*, const String& rea son, MessageLevel, const String& sourceURL, unsigned lineNumber);
188 static void mainThreadDestroy(ScriptExecutionContext*, PassOwnPtr<Peer>); 188 static void mainThreadDestroy(ScriptExecutionContext*, PassOwnPtr<Peer>);
189 static void mainThreadSuspend(ScriptExecutionContext*, Peer*); 189 static void mainThreadSuspend(ScriptExecutionContext*, Peer*);
190 static void mainThreadResume(ScriptExecutionContext*, Peer*); 190 static void mainThreadResume(ScriptExecutionContext*, Peer*);
191 191
192 class WorkerContextDidInitializeTask; 192 class WorkerGlobalScopeDidInitializeTask;
193 193
194 RefPtr<WorkerContext> m_workerContext; 194 RefPtr<WorkerGlobalScope> m_workerGlobalScope;
195 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; 195 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper;
196 RefPtr<Bridge> m_bridge; 196 RefPtr<Bridge> m_bridge;
197 String m_sourceURLAtConnection; 197 String m_sourceURLAtConnection;
198 unsigned m_lineNumberAtConnection; 198 unsigned m_lineNumberAtConnection;
199 }; 199 };
200 200
201 } // namespace WebCore 201 } // namespace WebCore
202 202
203 #endif // WorkerThreadableWebSocketChannel_h 203 #endif // WorkerThreadableWebSocketChannel_h
OLDNEW
« no previous file with comments | « Source/modules/websockets/WorkerContextWebSocket.idl ('k') | Source/modules/websockets/WorkerThreadableWebSocketChannel.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698