| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 void disconnect() override; // Will suppress didClose(). | 82 void disconnect() override; // Will suppress didClose(). |
| 83 | 83 |
| 84 DECLARE_VIRTUAL_TRACE(); | 84 DECLARE_VIRTUAL_TRACE(); |
| 85 | 85 |
| 86 class Bridge; | 86 class Bridge; |
| 87 // Allocated and used in the main thread. | 87 // Allocated and used in the main thread. |
| 88 class Peer final : public GarbageCollectedFinalized<Peer>, public WebSocketC
hannelClient, public WorkerThreadLifecycleObserver { | 88 class Peer final : public GarbageCollectedFinalized<Peer>, public WebSocketC
hannelClient, public WorkerThreadLifecycleObserver { |
| 89 USING_GARBAGE_COLLECTED_MIXIN(Peer); | 89 USING_GARBAGE_COLLECTED_MIXIN(Peer); |
| 90 WTF_MAKE_NONCOPYABLE(Peer); | 90 WTF_MAKE_NONCOPYABLE(Peer); |
| 91 public: | 91 public: |
| 92 Peer(Bridge*, PassRefPtr<WorkerLoaderProxy>, WebSocketChannelSyncHelper*
, WorkerThreadLifecycleContext*); | 92 Peer(Bridge*, PassRefPtr<WorkerLoaderProxy>, WorkerThreadLifecycleContex
t*); |
| 93 ~Peer() override; | 93 ~Peer() override; |
| 94 | 94 |
| 95 // SourceLocation parameter may be shown when the connection fails. | 95 // SourceLocation parameter may be shown when the connection fails. |
| 96 bool initialize(std::unique_ptr<SourceLocation>, ExecutionContext*); | 96 bool initialize(std::unique_ptr<SourceLocation>, ExecutionContext*); |
| 97 | 97 |
| 98 bool connect(const KURL&, const String& protocol); | 98 bool connect(const KURL&, const String& protocol); |
| 99 void sendTextAsCharVector(std::unique_ptr<Vector<char>>); | 99 void sendTextAsCharVector(std::unique_ptr<Vector<char>>); |
| 100 void sendBinaryAsCharVector(std::unique_ptr<Vector<char>>); | 100 void sendBinaryAsCharVector(std::unique_ptr<Vector<char>>); |
| 101 void sendBlob(PassRefPtr<BlobDataHandle>); | 101 void sendBlob(PassRefPtr<BlobDataHandle>); |
| 102 void close(int code, const String& reason); | 102 void close(int code, const String& reason); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 116 void didClose(ClosingHandshakeCompletionStatus, unsigned short code, con
st String& reason) override; | 116 void didClose(ClosingHandshakeCompletionStatus, unsigned short code, con
st String& reason) override; |
| 117 void didError() override; | 117 void didError() override; |
| 118 | 118 |
| 119 // WorkerThreadLifecycleObserver function. | 119 // WorkerThreadLifecycleObserver function. |
| 120 void contextDestroyed() override; | 120 void contextDestroyed() override; |
| 121 | 121 |
| 122 private: | 122 private: |
| 123 CrossThreadWeakPersistent<Bridge> m_bridge; | 123 CrossThreadWeakPersistent<Bridge> m_bridge; |
| 124 RefPtr<WorkerLoaderProxy> m_loaderProxy; | 124 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
| 125 Member<WebSocketChannel> m_mainWebSocketChannel; | 125 Member<WebSocketChannel> m_mainWebSocketChannel; |
| 126 Member<WebSocketChannelSyncHelper> m_syncHelper; | |
| 127 }; | 126 }; |
| 128 | 127 |
| 129 // Bridge for Peer. Running on the worker thread. | 128 // Bridge for Peer. Running on the worker thread. |
| 130 class Bridge final : public GarbageCollectedFinalized<Bridge> { | 129 class Bridge final : public GarbageCollectedFinalized<Bridge> { |
| 131 WTF_MAKE_NONCOPYABLE(Bridge); | 130 WTF_MAKE_NONCOPYABLE(Bridge); |
| 132 public: | 131 public: |
| 133 Bridge(WebSocketChannelClient*, WorkerGlobalScope&); | 132 Bridge(WebSocketChannelClient*, WorkerGlobalScope&); |
| 134 ~Bridge(); | 133 ~Bridge(); |
| 135 | 134 |
| 136 // SourceLocation parameter may be shown when the connection fails. | 135 // SourceLocation parameter may be shown when the connection fails. |
| 137 bool connect(std::unique_ptr<SourceLocation>, const KURL&, const String&
protocol); | 136 bool connect(std::unique_ptr<SourceLocation>, const KURL&, const String&
protocol); |
| 138 | 137 |
| 139 void send(const CString& message); | 138 void send(const CString& message); |
| 140 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLengt
h); | 139 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLengt
h); |
| 141 void send(PassRefPtr<BlobDataHandle>); | 140 void send(PassRefPtr<BlobDataHandle>); |
| 142 void close(int code, const String& reason); | 141 void close(int code, const String& reason); |
| 143 void fail(const String& reason, MessageLevel, std::unique_ptr<SourceLoca
tion>); | 142 void fail(const String& reason, MessageLevel, std::unique_ptr<SourceLoca
tion>); |
| 144 void disconnect(); | 143 void disconnect(); |
| 145 | 144 |
| 146 void connectOnMainThread(std::unique_ptr<SourceLocation>, WorkerThreadLi
fecycleContext*, const KURL&, const String& protocol, ExecutionContext*); | 145 void connectOnMainThread(std::unique_ptr<SourceLocation>, WorkerThreadLi
fecycleContext*, const KURL&, const String& protocol, WebSocketChannelSyncHelper
*, ExecutionContext*); |
| 147 | 146 |
| 148 // Returns null when |disconnect| has already been called. | 147 // Returns null when |disconnect| has already been called. |
| 149 WebSocketChannelClient* client() { return m_client; } | 148 WebSocketChannelClient* client() { return m_client; } |
| 150 | 149 |
| 151 DECLARE_TRACE(); | 150 DECLARE_TRACE(); |
| 152 // Promptly clear connection to peer + loader proxy. | 151 // Promptly clear connection to peer + loader proxy. |
| 153 EAGERLY_FINALIZE(); | 152 EAGERLY_FINALIZE(); |
| 154 | 153 |
| 155 private: | 154 private: |
| 156 // Returns false if shutdown event is received before method completion. | |
| 157 bool waitForMethodCompletion(const WebTraceLocation&, std::unique_ptr<Ex
ecutionContextTask>); | |
| 158 | |
| 159 Member<WebSocketChannelClient> m_client; | 155 Member<WebSocketChannelClient> m_client; |
| 160 Member<WorkerGlobalScope> m_workerGlobalScope; | 156 Member<WorkerGlobalScope> m_workerGlobalScope; |
| 161 RefPtr<WorkerLoaderProxy> m_loaderProxy; | 157 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
| 162 Member<WebSocketChannelSyncHelper> m_syncHelper; | |
| 163 CrossThreadPersistent<Peer> m_peer; | 158 CrossThreadPersistent<Peer> m_peer; |
| 164 }; | 159 }; |
| 165 | 160 |
| 166 private: | 161 private: |
| 167 WorkerWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*, std::uni
que_ptr<SourceLocation>); | 162 WorkerWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*, std::uni
que_ptr<SourceLocation>); |
| 168 | 163 |
| 169 Member<Bridge> m_bridge; | 164 Member<Bridge> m_bridge; |
| 170 std::unique_ptr<SourceLocation> m_locationAtConnection; | 165 std::unique_ptr<SourceLocation> m_locationAtConnection; |
| 171 }; | 166 }; |
| 172 | 167 |
| 173 } // namespace blink | 168 } // namespace blink |
| 174 | 169 |
| 175 #endif // WorkerWebSocketChannel_h | 170 #endif // WorkerWebSocketChannel_h |
| OLD | NEW |