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

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

Issue 350763007: [WebSocket] Create Peer on the worker thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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 | « no previous file | Source/modules/websockets/WorkerThreadableWebSocketChannel.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 virtual void trace(Visitor*) OVERRIDE; 87 virtual void trace(Visitor*) OVERRIDE;
88 88
89 // Generated by the bridge. The Peer is destructed by an async call from 89 // Generated by the bridge. The Peer is destructed by an async call from
90 // Bridge, and may outlive the bridge. All methods of this class must 90 // Bridge, and may outlive the bridge. All methods of this class must
91 // be called on the main thread. 91 // be called on the main thread.
92 class Peer FINAL : public NoBaseWillBeGarbageCollectedFinalized<Peer>, publi c WebSocketChannelClient { 92 class Peer FINAL : public NoBaseWillBeGarbageCollectedFinalized<Peer>, publi c WebSocketChannelClient {
93 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Peer); 93 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(Peer);
94 WTF_MAKE_NONCOPYABLE(Peer); 94 WTF_MAKE_NONCOPYABLE(Peer);
95 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; 95 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
96 public: 96 public:
97 static PassOwnPtrWillBeRawPtr<Peer> create(PassRefPtrWillBeRawPtr<Thread ableWebSocketChannelClientWrapper>, WorkerLoaderProxy&, PassRefPtrWillBeRawPtr<T hreadableWebSocketChannelSyncHelper>);
97 virtual ~Peer(); 98 virtual ~Peer();
98 99
99 // sourceURLAtConnection and lineNumberAtConnection parameters may 100 // sourceURLAtConnection and lineNumberAtConnection parameters may
100 // be shown when the connection fails. 101 // be shown when the connection fails.
101 #if ENABLE(OILPAN) 102 static void initialize(ExecutionContext* executionContext, Peer* peer, c onst String& sourceURLAtConnection, unsigned lineNumberAtConnection)
102 static void initialize(ExecutionContext*, WeakMember<Peer>*, WorkerLoade rProxy*, RawPtr<ThreadableWebSocketChannelClientWrapper>, const String& sourceUR LAtConnection, unsigned lineNumberAtConnection, RawPtr<ThreadableWebSocketChanne lSyncHelper>); 103 {
103 #else 104 peer->initializeInternal(executionContext, sourceURLAtConnection, li neNumberAtConnection);
104 static void initialize(ExecutionContext*, PassRefPtr<WeakReference<Peer> >, WorkerLoaderProxy*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, con st String& sourceURLAtConnection, unsigned lineNumberAtConnection, PassRefPtr<Th readableWebSocketChannelSyncHelper>); 105 }
105 #endif
106 106
107 void destroy();
108 void connect(const KURL&, const String& protocol); 107 void connect(const KURL&, const String& protocol);
109 void send(const String& message); 108 void send(const String& message);
110 void sendArrayBuffer(PassOwnPtr<Vector<char> >); 109 void sendArrayBuffer(PassOwnPtr<Vector<char> >);
111 void sendBlob(PassRefPtr<BlobDataHandle>); 110 void sendBlob(PassRefPtr<BlobDataHandle>);
112 void bufferedAmount(); 111 void bufferedAmount();
113 void close(int code, const String& reason); 112 void close(int code, const String& reason);
114 void fail(const String& reason, MessageLevel, const String& sourceURL, u nsigned lineNumber); 113 void fail(const String& reason, MessageLevel, const String& sourceURL, u nsigned lineNumber);
115 void disconnect(); 114 void disconnect();
116 115
117 virtual void trace(Visitor*) OVERRIDE; 116 virtual void trace(Visitor*) OVERRIDE;
118 117
119 // WebSocketChannelClient functions. 118 // WebSocketChannelClient functions.
120 virtual void didConnect(const String& subprotocol, const String& extensi ons) OVERRIDE; 119 virtual void didConnect(const String& subprotocol, const String& extensi ons) OVERRIDE;
121 virtual void didReceiveMessage(const String& message) OVERRIDE; 120 virtual void didReceiveMessage(const String& message) OVERRIDE;
122 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE; 121 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE;
123 virtual void didConsumeBufferedAmount(unsigned long) OVERRIDE; 122 virtual void didConsumeBufferedAmount(unsigned long) OVERRIDE;
124 virtual void didStartClosingHandshake() OVERRIDE; 123 virtual void didStartClosingHandshake() OVERRIDE;
125 virtual void didClose(ClosingHandshakeCompletionStatus, unsigned short c ode, const String& reason) OVERRIDE; 124 virtual void didClose(ClosingHandshakeCompletionStatus, unsigned short c ode, const String& reason) OVERRIDE;
126 virtual void didReceiveMessageError() OVERRIDE; 125 virtual void didReceiveMessageError() OVERRIDE;
127 126
128 private: 127 private:
129 #if ENABLE(OILPAN) 128 Peer(PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>, Wo rkerLoaderProxy&, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelSyncHelper>);
130 Peer(RawPtr<ThreadableWebSocketChannelClientWrapper>, WorkerLoaderProxy& , ExecutionContext*, const String& sourceURL, unsigned lineNumber, RawPtr<Thread ableWebSocketChannelSyncHelper>); 129
131 #else 130 void initializeInternal(ExecutionContext*, const String& sourceURLAtConn ection, unsigned lineNumberAtConnection);
132 Peer(PassRefPtr<WeakReference<Peer> >, PassRefPtr<ThreadableWebSocketCha nnelClientWrapper>, WorkerLoaderProxy&, ExecutionContext*, const String& sourceU RL, unsigned lineNumber, PassRefPtr<ThreadableWebSocketChannelSyncHelper>);
133 #endif
134 131
135 const RefPtrWillBeMember<ThreadableWebSocketChannelClientWrapper> m_work erClientWrapper; 132 const RefPtrWillBeMember<ThreadableWebSocketChannelClientWrapper> m_work erClientWrapper;
136 WorkerLoaderProxy& m_loaderProxy; 133 WorkerLoaderProxy& m_loaderProxy;
137 RefPtrWillBeMember<WebSocketChannel> m_mainWebSocketChannel; 134 RefPtrWillBeMember<WebSocketChannel> m_mainWebSocketChannel;
138 RefPtrWillBeMember<ThreadableWebSocketChannelSyncHelper> m_syncHelper; 135 RefPtrWillBeMember<ThreadableWebSocketChannelSyncHelper> m_syncHelper;
139 #if ENABLE(OILPAN)
140 // The lifetime of the Peer object is explicitly managed by the Bridge o bject.
141 // When the Bridge object calls Peer::initialize, the persistent handle is created.
142 // When the Bridge object calls Peer::destroy, the persistent handle is destroyed.
143 // This is because we cannot dispatch a disconnect chain from Peer's des tructor since
144 // the disconnect chain touches on-heap objets.
145 GC_PLUGIN_IGNORE("")
146 Persistent<Peer> m_keepAlive;
147 #else
148 WeakPtrFactory<Peer> m_weakFactory;
149 #endif
150 }; 136 };
151 137
152 // Bridge for Peer. Running on the worker thread. 138 // Bridge for Peer. Running on the worker thread.
153 class Bridge FINAL : public RefCountedWillBeGarbageCollectedFinalized<Bridge > { 139 class Bridge FINAL : public RefCountedWillBeGarbageCollectedFinalized<Bridge > {
154 public: 140 public:
155 static PassRefPtrWillBeRawPtr<Bridge> create(PassRefPtrWillBeRawPtr<Thre adableWebSocketChannelClientWrapper> workerClientWrapper, WorkerGlobalScope& wor kerGlobalScope) 141 static PassRefPtrWillBeRawPtr<Bridge> create(PassRefPtrWillBeRawPtr<Thre adableWebSocketChannelClientWrapper> workerClientWrapper, WorkerGlobalScope& wor kerGlobalScope)
156 { 142 {
157 return adoptRefWillBeNoop(new Bridge(workerClientWrapper, workerGlob alScope)); 143 return adoptRefWillBeNoop(new Bridge(workerClientWrapper, workerGlob alScope));
158 } 144 }
159 ~Bridge(); 145 ~Bridge();
(...skipping 15 matching lines...) Expand all
175 Bridge(PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>, WorkerGlobalScope&); 161 Bridge(PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>, WorkerGlobalScope&);
176 162
177 static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer *, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>); 163 static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer *, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>);
178 164
179 // Executed on the worker context's thread. 165 // Executed on the worker context's thread.
180 void clearClientWrapper(); 166 void clearClientWrapper();
181 167
182 // Returns false if shutdown event is received before method completion. 168 // Returns false if shutdown event is received before method completion.
183 bool waitForMethodCompletion(PassOwnPtr<ExecutionContextTask>); 169 bool waitForMethodCompletion(PassOwnPtr<ExecutionContextTask>);
184 170
185 void terminatePeer(); 171 RefPtrWillBeMember<ThreadableWebSocketChannelClientWrapper> m_workerClie ntWrapper;
186
187 bool hasTerminatedPeer() { return !m_syncHelper; }
188
189 const RefPtrWillBeMember<ThreadableWebSocketChannelClientWrapper> m_work erClientWrapper;
190 RefPtrWillBeMember<WorkerGlobalScope> m_workerGlobalScope; 172 RefPtrWillBeMember<WorkerGlobalScope> m_workerGlobalScope;
191 WorkerLoaderProxy& m_loaderProxy; 173 WorkerLoaderProxy& m_loaderProxy;
192 RawPtrWillBeMember<ThreadableWebSocketChannelSyncHelper> m_syncHelper; 174 RefPtrWillBeMember<ThreadableWebSocketChannelSyncHelper> m_syncHelper;
193 // The value of this pointer is set when a Peer object is created in Pee r::initilize() 175 OwnPtrWillBeMember<Peer> m_peer;
194 // in the main thread.
195 WeakPtrWillBeWeakMember<Peer> m_peer;
196 }; 176 };
197 177
198 private: 178 private:
199 WorkerThreadableWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient* , const String& sourceURL, unsigned lineNumber); 179 WorkerThreadableWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient* , const String& sourceURL, unsigned lineNumber);
200 180
201 const RefPtrWillBeMember<ThreadableWebSocketChannelClientWrapper> m_workerCl ientWrapper; 181 const RefPtrWillBeMember<ThreadableWebSocketChannelClientWrapper> m_workerCl ientWrapper;
202 RefPtrWillBeMember<Bridge> m_bridge; 182 RefPtrWillBeMember<Bridge> m_bridge;
203 String m_sourceURLAtConnection; 183 String m_sourceURLAtConnection;
204 unsigned m_lineNumberAtConnection; 184 unsigned m_lineNumberAtConnection;
205 }; 185 };
206 186
207 } // namespace blink 187 } // namespace blink
208 188
209 #endif // WorkerThreadableWebSocketChannel_h 189 #endif // WorkerThreadableWebSocketChannel_h
OLDNEW
« no previous file with comments | « no previous file | Source/modules/websockets/WorkerThreadableWebSocketChannel.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698