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 14 matching lines...) Expand all Loading... | |
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 WorkerWebSocketChannel_h | 31 #ifndef WorkerWebSocketChannel_h |
32 #define WorkerWebSocketChannel_h | 32 #define WorkerWebSocketChannel_h |
33 | 33 |
34 #include "bindings/core/v8/SourceLocation.h" | 34 #include "bindings/core/v8/SourceLocation.h" |
35 #include "core/workers/WorkerThreadLifecycleObserver.h" | |
35 #include "modules/websockets/WebSocketChannel.h" | 36 #include "modules/websockets/WebSocketChannel.h" |
36 #include "modules/websockets/WebSocketChannelClient.h" | 37 #include "modules/websockets/WebSocketChannelClient.h" |
37 #include "platform/heap/Handle.h" | 38 #include "platform/heap/Handle.h" |
38 #include "platform/v8_inspector/public/ConsoleTypes.h" | 39 #include "platform/v8_inspector/public/ConsoleTypes.h" |
39 #include "wtf/Assertions.h" | 40 #include "wtf/Assertions.h" |
40 #include "wtf/Forward.h" | 41 #include "wtf/Forward.h" |
41 #include "wtf/OwnPtr.h" | 42 #include "wtf/OwnPtr.h" |
42 #include "wtf/RefPtr.h" | 43 #include "wtf/RefPtr.h" |
43 #include "wtf/Vector.h" | 44 #include "wtf/Vector.h" |
44 #include "wtf/text/WTFString.h" | 45 #include "wtf/text/WTFString.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 { | 77 { |
77 ASSERT_NOT_REACHED(); | 78 ASSERT_NOT_REACHED(); |
78 } | 79 } |
79 void close(int code, const String& reason) override; | 80 void close(int code, const String& reason) override; |
80 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation>) ov erride; | 81 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation>) ov erride; |
81 void disconnect() override; // Will suppress didClose(). | 82 void disconnect() override; // Will suppress didClose(). |
82 | 83 |
83 DECLARE_VIRTUAL_TRACE(); | 84 DECLARE_VIRTUAL_TRACE(); |
84 | 85 |
85 class Bridge; | 86 class Bridge; |
86 // Allocated in the worker thread, but used in the main thread. | 87 // Allocated and used in the main thread, but destructed in the worker |
yhirano
2016/06/09 04:55:13
|Peer| is an on-heap class so it will be destructe
nhiroki
2016/06/09 07:37:07
Done.
| |
87 class Peer final : public GarbageCollectedFinalized<Peer>, public WebSocketC hannelClient { | 88 // thread. |
89 class Peer final : public GarbageCollectedFinalized<Peer>, public WebSocketC hannelClient, public WorkerThreadLifecycleObserver { | |
88 USING_GARBAGE_COLLECTED_MIXIN(Peer); | 90 USING_GARBAGE_COLLECTED_MIXIN(Peer); |
89 WTF_MAKE_NONCOPYABLE(Peer); | 91 WTF_MAKE_NONCOPYABLE(Peer); |
90 public: | 92 public: |
91 Peer(Bridge*, PassRefPtr<WorkerLoaderProxy>, WebSocketChannelSyncHelper* ); | 93 Peer(Bridge*, PassRefPtr<WorkerLoaderProxy>, WebSocketChannelSyncHelper* , WorkerThreadContext*); |
92 ~Peer() override; | 94 ~Peer() override; |
93 | 95 |
94 // SourceLocation parameter may be shown when the connection fails. | 96 // SourceLocation parameter may be shown when the connection fails. |
95 void initialize(PassOwnPtr<SourceLocation>, ExecutionContext*); | 97 void initialize(PassOwnPtr<SourceLocation>, ExecutionContext*); |
96 | 98 |
97 void connect(const KURL&, const String& protocol); | 99 void connect(const KURL&, const String& protocol); |
98 void sendTextAsCharVector(PassOwnPtr<Vector<char>>); | 100 void sendTextAsCharVector(PassOwnPtr<Vector<char>>); |
99 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>>); | 101 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>>); |
100 void sendBlob(PassRefPtr<BlobDataHandle>); | 102 void sendBlob(PassRefPtr<BlobDataHandle>); |
101 void close(int code, const String& reason); | 103 void close(int code, const String& reason); |
102 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation> ); | 104 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation> ); |
103 void disconnect(); | 105 void disconnect(); |
104 | 106 |
105 DECLARE_VIRTUAL_TRACE(); | 107 DECLARE_VIRTUAL_TRACE(); |
106 | 108 |
107 // WebSocketChannelClient functions. | 109 // WebSocketChannelClient functions. |
108 void didConnect(const String& subprotocol, const String& extensions) ove rride; | 110 void didConnect(const String& subprotocol, const String& extensions) ove rride; |
109 void didReceiveTextMessage(const String& payload) override; | 111 void didReceiveTextMessage(const String& payload) override; |
110 void didReceiveBinaryMessage(PassOwnPtr<Vector<char>>) override; | 112 void didReceiveBinaryMessage(PassOwnPtr<Vector<char>>) override; |
111 void didConsumeBufferedAmount(uint64_t) override; | 113 void didConsumeBufferedAmount(uint64_t) override; |
112 void didStartClosingHandshake() override; | 114 void didStartClosingHandshake() override; |
113 void didClose(ClosingHandshakeCompletionStatus, unsigned short code, con st String& reason) override; | 115 void didClose(ClosingHandshakeCompletionStatus, unsigned short code, con st String& reason) override; |
114 void didError() override; | 116 void didError() override; |
115 | 117 |
118 // WorkerThreadLifecycleObserver function. | |
119 void contextDestroyed() override; | |
120 | |
116 private: | 121 private: |
117 Member<Bridge> m_bridge; | 122 Member<Bridge> m_bridge; |
yhirano
2016/06/09 04:55:13
If you use CrossThreadPersistent in Member, this s
nhiroki
2016/06/09 07:37:07
Done.
| |
118 RefPtr<WorkerLoaderProxy> m_loaderProxy; | 123 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
119 Member<WebSocketChannel> m_mainWebSocketChannel; | 124 Member<WebSocketChannel> m_mainWebSocketChannel; |
120 Member<WebSocketChannelSyncHelper> m_syncHelper; | 125 Member<WebSocketChannelSyncHelper> m_syncHelper; |
121 }; | 126 }; |
122 | 127 |
123 // Bridge for Peer. Running on the worker thread. | 128 // Bridge for Peer. Running on the worker thread. |
124 class Bridge final : public GarbageCollectedFinalized<Bridge> { | 129 class Bridge final : public GarbageCollectedFinalized<Bridge> { |
125 WTF_MAKE_NONCOPYABLE(Bridge); | 130 WTF_MAKE_NONCOPYABLE(Bridge); |
126 public: | 131 public: |
127 Bridge(WebSocketChannelClient*, WorkerGlobalScope&); | 132 Bridge(WebSocketChannelClient*, WorkerGlobalScope&); |
128 ~Bridge(); | 133 ~Bridge(); |
129 // SourceLocation parameter may be shown when the connection fails. | 134 // SourceLocation parameter may be shown when the connection fails. |
130 void initialize(PassOwnPtr<SourceLocation>); | 135 void initialize(PassOwnPtr<SourceLocation>); |
131 bool connect(const KURL&, const String& protocol); | 136 bool connect(const KURL&, const String& protocol); |
132 void send(const CString& message); | 137 void send(const CString& message); |
133 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLengt h); | 138 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLengt h); |
134 void send(PassRefPtr<BlobDataHandle>); | 139 void send(PassRefPtr<BlobDataHandle>); |
135 void close(int code, const String& reason); | 140 void close(int code, const String& reason); |
136 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation> ); | 141 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation> ); |
137 void disconnect(); | 142 void disconnect(); |
138 | 143 |
144 void createPeerOnMainThread(PassOwnPtr<SourceLocation>, WorkerThreadCont ext*, ExecutionContext*); | |
145 | |
139 // Returns null when |disconnect| has already been called. | 146 // Returns null when |disconnect| has already been called. |
140 WebSocketChannelClient* client() { return m_client; } | 147 WebSocketChannelClient* client() { return m_client; } |
141 | 148 |
142 DECLARE_TRACE(); | 149 DECLARE_TRACE(); |
143 | 150 |
144 private: | 151 private: |
145 // Returns false if shutdown event is received before method completion. | 152 // Returns false if shutdown event is received before method completion. |
146 bool waitForMethodCompletion(std::unique_ptr<ExecutionContextTask>); | 153 bool waitForMethodCompletion(std::unique_ptr<ExecutionContextTask>); |
147 | 154 |
148 Member<WebSocketChannelClient> m_client; | 155 Member<WebSocketChannelClient> m_client; |
149 Member<WorkerGlobalScope> m_workerGlobalScope; | 156 Member<WorkerGlobalScope> m_workerGlobalScope; |
150 RefPtr<WorkerLoaderProxy> m_loaderProxy; | 157 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
151 Member<WebSocketChannelSyncHelper> m_syncHelper; | 158 Member<WebSocketChannelSyncHelper> m_syncHelper; |
152 Member<Peer> m_peer; | 159 CrossThreadPersistent<Peer> m_peer; |
153 }; | 160 }; |
154 | 161 |
155 private: | 162 private: |
156 WorkerWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*, PassOwnP tr<SourceLocation>); | 163 WorkerWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*, PassOwnP tr<SourceLocation>); |
157 | 164 |
158 Member<Bridge> m_bridge; | 165 Member<Bridge> m_bridge; |
159 OwnPtr<SourceLocation> m_locationAtConnection; | 166 OwnPtr<SourceLocation> m_locationAtConnection; |
160 }; | 167 }; |
161 | 168 |
162 } // namespace blink | 169 } // namespace blink |
163 | 170 |
164 #endif // WorkerWebSocketChannel_h | 171 #endif // WorkerWebSocketChannel_h |
OLD | NEW |