| 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 16 matching lines...) Expand all Loading... |
| 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 <stdint.h> | 34 #include <stdint.h> |
| 35 #include <memory> | 35 #include <memory> |
| 36 #include "bindings/core/v8/SourceLocation.h" | 36 #include "bindings/core/v8/SourceLocation.h" |
| 37 #include "core/workers/ParentFrameTaskRunners.h" |
| 37 #include "core/workers/WorkerThreadLifecycleObserver.h" | 38 #include "core/workers/WorkerThreadLifecycleObserver.h" |
| 38 #include "modules/websockets/WebSocketChannel.h" | 39 #include "modules/websockets/WebSocketChannel.h" |
| 39 #include "modules/websockets/WebSocketChannelClient.h" | 40 #include "modules/websockets/WebSocketChannelClient.h" |
| 40 #include "platform/heap/Handle.h" | 41 #include "platform/heap/Handle.h" |
| 41 #include "platform/wtf/Assertions.h" | 42 #include "platform/wtf/Assertions.h" |
| 42 #include "platform/wtf/Forward.h" | 43 #include "platform/wtf/Forward.h" |
| 43 #include "platform/wtf/RefPtr.h" | 44 #include "platform/wtf/RefPtr.h" |
| 44 #include "platform/wtf/Vector.h" | 45 #include "platform/wtf/Vector.h" |
| 45 #include "platform/wtf/text/WTFString.h" | 46 #include "platform/wtf/text/WTFString.h" |
| 46 #include "public/platform/WebTraceLocation.h" | 47 #include "public/platform/WebTraceLocation.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 90 |
| 90 class Bridge; | 91 class Bridge; |
| 91 // Allocated and used in the main thread. | 92 // Allocated and used in the main thread. |
| 92 class Peer final : public GarbageCollectedFinalized<Peer>, | 93 class Peer final : public GarbageCollectedFinalized<Peer>, |
| 93 public WebSocketChannelClient, | 94 public WebSocketChannelClient, |
| 94 public WorkerThreadLifecycleObserver { | 95 public WorkerThreadLifecycleObserver { |
| 95 USING_GARBAGE_COLLECTED_MIXIN(Peer); | 96 USING_GARBAGE_COLLECTED_MIXIN(Peer); |
| 96 WTF_MAKE_NONCOPYABLE(Peer); | 97 WTF_MAKE_NONCOPYABLE(Peer); |
| 97 | 98 |
| 98 public: | 99 public: |
| 99 Peer(Bridge*, PassRefPtr<WorkerLoaderProxy>, WorkerThreadLifecycleContext*); | 100 Peer(Bridge*, |
| 101 PassRefPtr<WorkerLoaderProxy>, |
| 102 RefPtr<WebTaskRunner>, |
| 103 WorkerThreadLifecycleContext*); |
| 100 ~Peer() override; | 104 ~Peer() override; |
| 101 | 105 |
| 102 // SourceLocation parameter may be shown when the connection fails. | 106 // SourceLocation parameter may be shown when the connection fails. |
| 103 bool Initialize(std::unique_ptr<SourceLocation>, ThreadableLoadingContext*); | 107 bool Initialize(std::unique_ptr<SourceLocation>, ThreadableLoadingContext*); |
| 104 | 108 |
| 105 bool Connect(const KURL&, const String& protocol); | 109 bool Connect(const KURL&, const String& protocol); |
| 106 void SendTextAsCharVector(std::unique_ptr<Vector<char>>); | 110 void SendTextAsCharVector(std::unique_ptr<Vector<char>>); |
| 107 void SendBinaryAsCharVector(std::unique_ptr<Vector<char>>); | 111 void SendBinaryAsCharVector(std::unique_ptr<Vector<char>>); |
| 108 void SendBlob(PassRefPtr<BlobDataHandle>); | 112 void SendBlob(PassRefPtr<BlobDataHandle>); |
| 109 void Close(int code, const String& reason); | 113 void Close(int code, const String& reason); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 127 unsigned short code, | 131 unsigned short code, |
| 128 const String& reason) override; | 132 const String& reason) override; |
| 129 void DidError() override; | 133 void DidError() override; |
| 130 | 134 |
| 131 // WorkerThreadLifecycleObserver function. | 135 // WorkerThreadLifecycleObserver function. |
| 132 void ContextDestroyed(WorkerThreadLifecycleContext*) override; | 136 void ContextDestroyed(WorkerThreadLifecycleContext*) override; |
| 133 | 137 |
| 134 private: | 138 private: |
| 135 CrossThreadWeakPersistent<Bridge> bridge_; | 139 CrossThreadWeakPersistent<Bridge> bridge_; |
| 136 RefPtr<WorkerLoaderProxy> loader_proxy_; | 140 RefPtr<WorkerLoaderProxy> loader_proxy_; |
| 141 RefPtr<WebTaskRunner> worker_networking_task_runner_; |
| 137 Member<WebSocketChannel> main_web_socket_channel_; | 142 Member<WebSocketChannel> main_web_socket_channel_; |
| 138 }; | 143 }; |
| 139 | 144 |
| 140 // Bridge for Peer. Running on the worker thread. | 145 // Bridge for Peer. Running on the worker thread. |
| 141 class Bridge final : public GarbageCollectedFinalized<Bridge> { | 146 class Bridge final : public GarbageCollectedFinalized<Bridge> { |
| 142 WTF_MAKE_NONCOPYABLE(Bridge); | 147 WTF_MAKE_NONCOPYABLE(Bridge); |
| 143 | 148 |
| 144 public: | 149 public: |
| 145 Bridge(WebSocketChannelClient*, WorkerGlobalScope&); | 150 Bridge(WebSocketChannelClient*, WorkerGlobalScope&); |
| 146 ~Bridge(); | 151 ~Bridge(); |
| 147 | 152 |
| 148 // SourceLocation parameter may be shown when the connection fails. | 153 // SourceLocation parameter may be shown when the connection fails. |
| 149 bool Connect(std::unique_ptr<SourceLocation>, | 154 bool Connect(std::unique_ptr<SourceLocation>, |
| 150 const KURL&, | 155 const KURL&, |
| 151 const String& protocol); | 156 const String& protocol); |
| 152 | 157 |
| 153 void Send(const CString& message); | 158 void Send(const CString& message); |
| 154 void Send(const DOMArrayBuffer&, | 159 void Send(const DOMArrayBuffer&, |
| 155 unsigned byte_offset, | 160 unsigned byte_offset, |
| 156 unsigned byte_length); | 161 unsigned byte_length); |
| 157 void Send(PassRefPtr<BlobDataHandle>); | 162 void Send(PassRefPtr<BlobDataHandle>); |
| 158 void Close(int code, const String& reason); | 163 void Close(int code, const String& reason); |
| 159 void Fail(const String& reason, | 164 void Fail(const String& reason, |
| 160 MessageLevel, | 165 MessageLevel, |
| 161 std::unique_ptr<SourceLocation>); | 166 std::unique_ptr<SourceLocation>); |
| 162 void Disconnect(); | 167 void Disconnect(); |
| 163 | 168 |
| 164 void ConnectOnMainThread(std::unique_ptr<SourceLocation>, | 169 void ConnectOnMainThread(std::unique_ptr<SourceLocation>, |
| 165 RefPtr<WorkerLoaderProxy>, | 170 RefPtr<WorkerLoaderProxy>, |
| 171 RefPtr<WebTaskRunner>, |
| 166 WorkerThreadLifecycleContext*, | 172 WorkerThreadLifecycleContext*, |
| 167 const KURL&, | 173 const KURL&, |
| 168 const String& protocol, | 174 const String& protocol, |
| 169 WebSocketChannelSyncHelper*); | 175 WebSocketChannelSyncHelper*); |
| 170 | 176 |
| 171 // Returns null when |disconnect| has already been called. | 177 // Returns null when |disconnect| has already been called. |
| 172 WebSocketChannelClient* Client() { return client_; } | 178 WebSocketChannelClient* Client() { return client_; } |
| 173 | 179 |
| 174 DECLARE_TRACE(); | 180 DECLARE_TRACE(); |
| 175 // Promptly clear connection to peer + loader proxy. | 181 // Promptly clear connection to peer + loader proxy. |
| 176 EAGERLY_FINALIZE(); | 182 EAGERLY_FINALIZE(); |
| 177 | 183 |
| 178 private: | 184 private: |
| 179 Member<WebSocketChannelClient> client_; | 185 Member<WebSocketChannelClient> client_; |
| 180 Member<WorkerGlobalScope> worker_global_scope_; | 186 Member<WorkerGlobalScope> worker_global_scope_; |
| 181 RefPtr<WorkerLoaderProxy> loader_proxy_; | 187 RefPtr<WorkerLoaderProxy> loader_proxy_; |
| 188 CrossThreadPersistent<ParentFrameTaskRunners> parent_frame_task_runners_; |
| 182 CrossThreadPersistent<Peer> peer_; | 189 CrossThreadPersistent<Peer> peer_; |
| 183 }; | 190 }; |
| 184 | 191 |
| 185 private: | 192 private: |
| 186 WorkerWebSocketChannel(WorkerGlobalScope&, | 193 WorkerWebSocketChannel(WorkerGlobalScope&, |
| 187 WebSocketChannelClient*, | 194 WebSocketChannelClient*, |
| 188 std::unique_ptr<SourceLocation>); | 195 std::unique_ptr<SourceLocation>); |
| 189 | 196 |
| 190 Member<Bridge> bridge_; | 197 Member<Bridge> bridge_; |
| 191 std::unique_ptr<SourceLocation> location_at_connection_; | 198 std::unique_ptr<SourceLocation> location_at_connection_; |
| 192 }; | 199 }; |
| 193 | 200 |
| 194 } // namespace blink | 201 } // namespace blink |
| 195 | 202 |
| 196 #endif // WorkerWebSocketChannel_h | 203 #endif // WorkerWebSocketChannel_h |
| OLD | NEW |