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

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

Issue 265713004: Cleanup WorkerThreadableWebSocketChannel's logic to wait for the main thread (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 protected: 133 protected:
134 // WebSocketChannel functions. 134 // WebSocketChannel functions.
135 virtual void refWebSocketChannel() OVERRIDE { ref(); } 135 virtual void refWebSocketChannel() OVERRIDE { ref(); }
136 virtual void derefWebSocketChannel() OVERRIDE { deref(); } 136 virtual void derefWebSocketChannel() OVERRIDE { deref(); }
137 137
138 private: 138 private:
139 // Bridge for Peer. Running on the worker thread. 139 // Bridge for Peer. Running on the worker thread.
140 class Bridge : public RefCounted<Bridge> { 140 class Bridge : public RefCounted<Bridge> {
141 public: 141 public:
142 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl ientWrapper> workerClientWrapper, PassRefPtrWillBeRawPtr<WorkerGlobalScope> work erGlobalScope) 142 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl ientWrapper> workerClientWrapper, WorkerGlobalScope& workerGlobalScope)
143 { 143 {
144 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope)); 144 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope));
145 } 145 }
146 ~Bridge(); 146 ~Bridge();
147 // sourceURLAtConnection and lineNumberAtConnection parameters may 147 // sourceURLAtConnection and lineNumberAtConnection parameters may
148 // be shown when the connection fails. 148 // be shown when the connection fails.
149 void initialize(const String& sourceURLAtConnection, unsigned lineNumber AtConnection); 149 void initialize(const String& sourceURLAtConnection, unsigned lineNumber AtConnection);
150 bool connect(const KURL&, const String& protocol); 150 bool connect(const KURL&, const String& protocol);
151 WebSocketChannel::SendResult send(const String& message); 151 WebSocketChannel::SendResult send(const String& message);
152 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse t, unsigned byteLength); 152 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse t, unsigned byteLength);
153 WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>); 153 WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>);
154 unsigned long bufferedAmount(); 154 unsigned long bufferedAmount();
155 void close(int code, const String& reason); 155 void close(int code, const String& reason);
156 void fail(const String& reason, MessageLevel, const String& sourceURL, u nsigned lineNumber); 156 void fail(const String& reason, MessageLevel, const String& sourceURL, u nsigned lineNumber);
157 void disconnect(); 157 void disconnect();
158 void suspend(); 158 void suspend();
159 void resume(); 159 void resume();
160 160
161 using RefCounted<Bridge>::ref; 161 using RefCounted<Bridge>::ref;
162 using RefCounted<Bridge>::deref; 162 using RefCounted<Bridge>::deref;
163 163
164 private: 164 private:
165 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtrWi llBeRawPtr<WorkerGlobalScope>); 165 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerGlobal Scope&);
166 166
167 static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer *, PassRefPtr<ThreadableWebSocketChannelClientWrapper>); 167 static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer *, PassRefPtr<ThreadableWebSocketChannelClientWrapper>);
168 168
169 // Executed on the worker context's thread. 169 // Executed on the worker context's thread.
170 void clearClientWrapper(); 170 void clearClientWrapper();
171 171
172 // Returns false if shutdown event is received before method completion. 172 // Returns false if shutdown event is received before method completion.
173 bool waitForMethodCompletion(); 173 bool waitForMethodCompletion();
174 174
175 void terminatePeer(); 175 void terminatePeer();
176 176
177 bool hasTerminatedPeer() { return !m_syncHelper; }
178
177 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrap per; 179 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrap per;
178 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; 180 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope;
179 WorkerLoaderProxy& m_loaderProxy; 181 WorkerLoaderProxy& m_loaderProxy;
180 ThreadableWebSocketChannelSyncHelper* m_syncHelper; 182 ThreadableWebSocketChannelSyncHelper* m_syncHelper;
181 WeakPtr<Peer> m_peer; 183 WeakPtr<Peer> m_peer;
182 }; 184 };
183 185
184 WorkerThreadableWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient* , const String& sourceURL, unsigned lineNumber); 186 WorkerThreadableWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient* , const String& sourceURL, unsigned lineNumber);
185 187
186 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope;
187 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; 188 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper;
188 RefPtr<Bridge> m_bridge; 189 RefPtr<Bridge> m_bridge;
189 String m_sourceURLAtConnection; 190 String m_sourceURLAtConnection;
190 unsigned m_lineNumberAtConnection; 191 unsigned m_lineNumberAtConnection;
191 }; 192 };
192 193
193 } // namespace WebCore 194 } // namespace WebCore
194 195
195 #endif // WorkerThreadableWebSocketChannel_h 196 #endif // WorkerThreadableWebSocketChannel_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698