OLD | NEW |
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 ASSERT_NOT_REACHED(); | 83 ASSERT_NOT_REACHED(); |
84 return WebSocketChannel::SendFail; | 84 return WebSocketChannel::SendFail; |
85 } | 85 } |
86 virtual unsigned long bufferedAmount() const OVERRIDE; | 86 virtual unsigned long bufferedAmount() const OVERRIDE; |
87 virtual void close(int code, const String& reason) OVERRIDE; | 87 virtual void close(int code, const String& reason) OVERRIDE; |
88 virtual void fail(const String& reason, MessageLevel, const String&, unsigne
d) OVERRIDE; | 88 virtual void fail(const String& reason, MessageLevel, const String&, unsigne
d) OVERRIDE; |
89 virtual void disconnect() OVERRIDE; // Will suppress didClose(). | 89 virtual void disconnect() OVERRIDE; // Will suppress didClose(). |
90 virtual void suspend() OVERRIDE; | 90 virtual void suspend() OVERRIDE; |
91 virtual void resume() OVERRIDE; | 91 virtual void resume() OVERRIDE; |
92 | 92 |
93 virtual void trace(Visitor*) OVERRIDE; | |
94 | |
95 // Generated by the bridge. The Peer is destructed by an async call from | 93 // Generated by the bridge. The Peer is destructed by an async call from |
96 // Bridge, and may outlive the bridge. All methods of this class must | 94 // Bridge, and may outlive the bridge. All methods of this class must |
97 // be called on the main thread. | 95 // be called on the main thread. |
98 class Peer FINAL : public WebSocketChannelClient { | 96 class Peer FINAL : public WebSocketChannelClient { |
99 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; | 97 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; |
100 public: | 98 public: |
101 virtual ~Peer(); | 99 virtual ~Peer(); |
102 | 100 |
103 // sourceURLAtConnection and lineNumberAtConnection parameters may | 101 // sourceURLAtConnection and lineNumberAtConnection parameters may |
104 // be shown when the connection fails. | 102 // be shown when the connection fails. |
105 static void initialize(ExecutionContext*, PassRefPtr<WeakReference<Peer>
>, WorkerLoaderProxy*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientW
rapper>, const String& sourceURLAtConnection, unsigned lineNumberAtConnection, P
assOwnPtr<ThreadableWebSocketChannelSyncHelper>); | 103 static void initialize(ExecutionContext*, PassRefPtr<WeakReference<Peer>
>, WorkerLoaderProxy*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, con
st String& sourceURLAtConnection, unsigned lineNumberAtConnection, PassOwnPtr<Th
readableWebSocketChannelSyncHelper>); |
106 void destroy(); | 104 void destroy(); |
107 | 105 |
108 void connect(const KURL&, const String& protocol); | 106 void connect(const KURL&, const String& protocol); |
109 void send(const String& message); | 107 void send(const String& message); |
110 void sendArrayBuffer(PassOwnPtr<Vector<char> >); | 108 void sendArrayBuffer(PassOwnPtr<Vector<char> >); |
111 void sendBlob(PassRefPtr<BlobDataHandle>); | 109 void sendBlob(PassRefPtr<BlobDataHandle>); |
112 void bufferedAmount(); | 110 void bufferedAmount(); |
113 void close(int code, const String& reason); | 111 void close(int code, const String& reason); |
114 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); | 112 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); |
115 void disconnect(); | 113 void disconnect(); |
116 void suspend(); | 114 void suspend(); |
117 void resume(); | 115 void resume(); |
118 | 116 |
119 // WebSocketChannelClient functions. | 117 // WebSocketChannelClient functions. |
120 virtual void didConnect() OVERRIDE; | 118 virtual void didConnect() OVERRIDE; |
121 virtual void didReceiveMessage(const String& message) OVERRIDE; | 119 virtual void didReceiveMessage(const String& message) OVERRIDE; |
122 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE; | 120 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE; |
123 virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERR
IDE; | 121 virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERR
IDE; |
124 virtual void didStartClosingHandshake() OVERRIDE; | 122 virtual void didStartClosingHandshake() OVERRIDE; |
125 virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHand
shakeCompletionStatus, unsigned short code, const String& reason) OVERRIDE; | 123 virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHand
shakeCompletionStatus, unsigned short code, const String& reason) OVERRIDE; |
126 virtual void didReceiveMessageError() OVERRIDE; | 124 virtual void didReceiveMessageError() OVERRIDE; |
127 | 125 |
128 private: | 126 private: |
129 Peer(PassRefPtr<WeakReference<Peer> >, PassRefPtrWillBeRawPtr<Threadable
WebSocketChannelClientWrapper>, WorkerLoaderProxy&, ExecutionContext*, const Str
ing& sourceURL, unsigned lineNumber, PassOwnPtr<ThreadableWebSocketChannelSyncHe
lper>); | 127 Peer(PassRefPtr<WeakReference<Peer> >, PassRefPtr<ThreadableWebSocketCha
nnelClientWrapper>, WorkerLoaderProxy&, ExecutionContext*, const String& sourceU
RL, unsigned lineNumber, PassOwnPtr<ThreadableWebSocketChannelSyncHelper>); |
130 | 128 |
131 const RefPtrWillBePersistent<ThreadableWebSocketChannelClientWrapper> m_
workerClientWrapper; | 129 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrap
per; |
132 WorkerLoaderProxy& m_loaderProxy; | 130 WorkerLoaderProxy& m_loaderProxy; |
133 RefPtrWillBePersistent<WebSocketChannel> m_mainWebSocketChannel; | 131 RefPtrWillBePersistent<WebSocketChannel> m_mainWebSocketChannel; |
134 OwnPtr<ThreadableWebSocketChannelSyncHelper> m_syncHelper; | 132 OwnPtr<ThreadableWebSocketChannelSyncHelper> m_syncHelper; |
135 WeakPtrFactory<Peer> m_weakFactory; | 133 WeakPtrFactory<Peer> m_weakFactory; |
136 }; | 134 }; |
137 | 135 |
138 private: | 136 private: |
139 // Bridge for Peer. Running on the worker thread. | 137 // Bridge for Peer. Running on the worker thread. |
140 class Bridge : public RefCounted<Bridge> { | 138 class Bridge : public RefCounted<Bridge> { |
141 public: | 139 public: |
142 static PassRefPtr<Bridge> create(PassRefPtrWillBeRawPtr<ThreadableWebSoc
ketChannelClientWrapper> workerClientWrapper, WorkerGlobalScope& workerGlobalSco
pe) | 140 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl
ientWrapper> workerClientWrapper, WorkerGlobalScope& workerGlobalScope) |
143 { | 141 { |
144 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope)); | 142 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope)); |
145 } | 143 } |
146 ~Bridge(); | 144 ~Bridge(); |
147 // sourceURLAtConnection and lineNumberAtConnection parameters may | 145 // sourceURLAtConnection and lineNumberAtConnection parameters may |
148 // be shown when the connection fails. | 146 // be shown when the connection fails. |
149 void initialize(const String& sourceURLAtConnection, unsigned lineNumber
AtConnection); | 147 void initialize(const String& sourceURLAtConnection, unsigned lineNumber
AtConnection); |
150 bool connect(const KURL&, const String& protocol); | 148 bool connect(const KURL&, const String& protocol); |
151 WebSocketChannel::SendResult send(const String& message); | 149 WebSocketChannel::SendResult send(const String& message); |
152 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse
t, unsigned byteLength); | 150 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse
t, unsigned byteLength); |
153 WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>); | 151 WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>); |
154 unsigned long bufferedAmount(); | 152 unsigned long bufferedAmount(); |
155 void close(int code, const String& reason); | 153 void close(int code, const String& reason); |
156 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); | 154 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); |
157 void disconnect(); | 155 void disconnect(); |
158 void suspend(); | 156 void suspend(); |
159 void resume(); | 157 void resume(); |
160 | 158 |
161 private: | 159 private: |
162 Bridge(PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>,
WorkerGlobalScope&); | 160 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerGlobal
Scope&); |
163 | 161 |
164 static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer
*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>); | 162 static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer
*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>); |
165 | 163 |
166 // Executed on the worker context's thread. | 164 // Executed on the worker context's thread. |
167 void clearClientWrapper(); | 165 void clearClientWrapper(); |
168 | 166 |
169 // Returns false if shutdown event is received before method completion. | 167 // Returns false if shutdown event is received before method completion. |
170 bool waitForMethodCompletion(PassOwnPtr<ExecutionContextTask>); | 168 bool waitForMethodCompletion(PassOwnPtr<ExecutionContextTask>); |
171 | 169 |
172 void terminatePeer(); | 170 void terminatePeer(); |
173 | 171 |
174 bool hasTerminatedPeer() { return !m_syncHelper; } | 172 bool hasTerminatedPeer() { return !m_syncHelper; } |
175 | 173 |
176 const RefPtrWillBePersistent<ThreadableWebSocketChannelClientWrapper> m_
workerClientWrapper; | 174 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrap
per; |
177 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 175 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
178 WorkerLoaderProxy& m_loaderProxy; | 176 WorkerLoaderProxy& m_loaderProxy; |
179 ThreadableWebSocketChannelSyncHelper* m_syncHelper; | 177 ThreadableWebSocketChannelSyncHelper* m_syncHelper; |
180 WeakPtr<Peer> m_peer; | 178 WeakPtr<Peer> m_peer; |
181 }; | 179 }; |
182 | 180 |
183 WorkerThreadableWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*
, const String& sourceURL, unsigned lineNumber); | 181 WorkerThreadableWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*
, const String& sourceURL, unsigned lineNumber); |
184 | 182 |
185 const RefPtrWillBeMember<ThreadableWebSocketChannelClientWrapper> m_workerCl
ientWrapper; | 183 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; |
186 RefPtr<Bridge> m_bridge; | 184 RefPtr<Bridge> m_bridge; |
187 String m_sourceURLAtConnection; | 185 String m_sourceURLAtConnection; |
188 unsigned m_lineNumberAtConnection; | 186 unsigned m_lineNumberAtConnection; |
189 }; | 187 }; |
190 | 188 |
191 } // namespace WebCore | 189 } // namespace WebCore |
192 | 190 |
193 #endif // WorkerThreadableWebSocketChannel_h | 191 #endif // WorkerThreadableWebSocketChannel_h |
OLD | NEW |