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. |
87 class Peer final : public GarbageCollectedFinalized<Peer>, public WebSocketC hannelClient { | 88 class Peer final : public GarbageCollectedFinalized<Peer>, public WebSocketC hannelClient, public WorkerThreadLifecycleObserver { |
88 USING_GARBAGE_COLLECTED_MIXIN(Peer); | 89 USING_GARBAGE_COLLECTED_MIXIN(Peer); |
89 WTF_MAKE_NONCOPYABLE(Peer); | 90 WTF_MAKE_NONCOPYABLE(Peer); |
90 public: | 91 public: |
91 Peer(Bridge*, PassRefPtr<WorkerLoaderProxy>, WebSocketChannelSyncHelper* ); | 92 Peer(Bridge*, PassRefPtr<WorkerLoaderProxy>, WebSocketChannelSyncHelper* , WorkerThreadContext*); |
92 ~Peer() override; | 93 ~Peer() override; |
93 | 94 |
94 // SourceLocation parameter may be shown when the connection fails. | 95 // SourceLocation parameter may be shown when the connection fails. |
95 void initialize(PassOwnPtr<SourceLocation>, ExecutionContext*); | 96 bool initialize(PassOwnPtr<SourceLocation>, ExecutionContext*); |
96 | 97 |
97 void connect(const KURL&, const String& protocol); | 98 void connect(const KURL&, const String& protocol); |
98 void sendTextAsCharVector(PassOwnPtr<Vector<char>>); | 99 void sendTextAsCharVector(PassOwnPtr<Vector<char>>); |
99 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>>); | 100 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>>); |
100 void sendBlob(PassRefPtr<BlobDataHandle>); | 101 void sendBlob(PassRefPtr<BlobDataHandle>); |
101 void close(int code, const String& reason); | 102 void close(int code, const String& reason); |
102 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation> ); | 103 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation> ); |
103 void disconnect(); | 104 void disconnect(); |
104 | 105 |
105 DECLARE_VIRTUAL_TRACE(); | 106 DECLARE_VIRTUAL_TRACE(); |
106 | 107 |
107 // WebSocketChannelClient functions. | 108 // WebSocketChannelClient functions. |
108 void didConnect(const String& subprotocol, const String& extensions) ove rride; | 109 void didConnect(const String& subprotocol, const String& extensions) ove rride; |
109 void didReceiveTextMessage(const String& payload) override; | 110 void didReceiveTextMessage(const String& payload) override; |
110 void didReceiveBinaryMessage(PassOwnPtr<Vector<char>>) override; | 111 void didReceiveBinaryMessage(PassOwnPtr<Vector<char>>) override; |
111 void didConsumeBufferedAmount(uint64_t) override; | 112 void didConsumeBufferedAmount(uint64_t) override; |
112 void didStartClosingHandshake() override; | 113 void didStartClosingHandshake() override; |
113 void didClose(ClosingHandshakeCompletionStatus, unsigned short code, con st String& reason) override; | 114 void didClose(ClosingHandshakeCompletionStatus, unsigned short code, con st String& reason) override; |
114 void didError() override; | 115 void didError() override; |
115 | 116 |
117 // WorkerThreadLifecycleObserver function. | |
118 void contextDestroyed() override; | |
119 | |
116 private: | 120 private: |
117 Member<Bridge> m_bridge; | 121 CrossThreadWeakPersistent<Bridge> m_bridge; |
haraken
2016/06/10 00:45:36
This changes the lifetime semantics. Before, it wa
yhirano
2016/06/10 01:54:05
It's intended. Previously Bridge and Peer referenc
| |
118 RefPtr<WorkerLoaderProxy> m_loaderProxy; | 122 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
119 Member<WebSocketChannel> m_mainWebSocketChannel; | 123 Member<WebSocketChannel> m_mainWebSocketChannel; |
120 Member<WebSocketChannelSyncHelper> m_syncHelper; | 124 Member<WebSocketChannelSyncHelper> m_syncHelper; |
121 }; | 125 }; |
122 | 126 |
123 // Bridge for Peer. Running on the worker thread. | 127 // Bridge for Peer. Running on the worker thread. |
124 class Bridge final : public GarbageCollectedFinalized<Bridge> { | 128 class Bridge final : public GarbageCollectedFinalized<Bridge> { |
125 WTF_MAKE_NONCOPYABLE(Bridge); | 129 WTF_MAKE_NONCOPYABLE(Bridge); |
126 public: | 130 public: |
127 Bridge(WebSocketChannelClient*, WorkerGlobalScope&); | 131 Bridge(WebSocketChannelClient*, WorkerGlobalScope&); |
128 ~Bridge(); | 132 ~Bridge(); |
129 // SourceLocation parameter may be shown when the connection fails. | 133 // SourceLocation parameter may be shown when the connection fails. |
130 void initialize(PassOwnPtr<SourceLocation>); | 134 void initialize(PassOwnPtr<SourceLocation>); |
131 bool connect(const KURL&, const String& protocol); | 135 bool connect(const KURL&, const String& protocol); |
132 void send(const CString& message); | 136 void send(const CString& message); |
133 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLengt h); | 137 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLengt h); |
134 void send(PassRefPtr<BlobDataHandle>); | 138 void send(PassRefPtr<BlobDataHandle>); |
135 void close(int code, const String& reason); | 139 void close(int code, const String& reason); |
136 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation> ); | 140 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation> ); |
137 void disconnect(); | 141 void disconnect(); |
138 | 142 |
143 void createPeerOnMainThread(PassOwnPtr<SourceLocation>, WorkerThreadCont ext*, ExecutionContext*); | |
144 | |
139 // Returns null when |disconnect| has already been called. | 145 // Returns null when |disconnect| has already been called. |
140 WebSocketChannelClient* client() { return m_client; } | 146 WebSocketChannelClient* client() { return m_client; } |
141 | 147 |
142 DECLARE_TRACE(); | 148 DECLARE_TRACE(); |
143 | 149 |
144 private: | 150 private: |
145 // Returns false if shutdown event is received before method completion. | 151 // Returns false if shutdown event is received before method completion. |
146 bool waitForMethodCompletion(std::unique_ptr<ExecutionContextTask>); | 152 bool waitForMethodCompletion(std::unique_ptr<ExecutionContextTask>); |
147 | 153 |
148 Member<WebSocketChannelClient> m_client; | 154 Member<WebSocketChannelClient> m_client; |
149 Member<WorkerGlobalScope> m_workerGlobalScope; | 155 Member<WorkerGlobalScope> m_workerGlobalScope; |
150 RefPtr<WorkerLoaderProxy> m_loaderProxy; | 156 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
151 Member<WebSocketChannelSyncHelper> m_syncHelper; | 157 Member<WebSocketChannelSyncHelper> m_syncHelper; |
152 Member<Peer> m_peer; | 158 CrossThreadPersistent<Peer> m_peer; |
153 }; | 159 }; |
154 | 160 |
155 private: | 161 private: |
156 WorkerWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*, PassOwnP tr<SourceLocation>); | 162 WorkerWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*, PassOwnP tr<SourceLocation>); |
157 | 163 |
158 Member<Bridge> m_bridge; | 164 Member<Bridge> m_bridge; |
159 OwnPtr<SourceLocation> m_locationAtConnection; | 165 OwnPtr<SourceLocation> m_locationAtConnection; |
160 }; | 166 }; |
161 | 167 |
162 } // namespace blink | 168 } // namespace blink |
163 | 169 |
164 #endif // WorkerWebSocketChannel_h | 170 #endif // WorkerWebSocketChannel_h |
OLD | NEW |