X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fthird_party%2FWebKit%2FSource%2Fmodules%2Fwebsockets%2FWorkerThreadableWebSocketChannel.h;h=ccef389409adb3b7655b2571573780b49fab1467;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=bce1650884e01e71569c10b00b5ec13b65260b4e;hpb=7338fba38ba696536d1cc9d389afd716a6ab2fe6;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/third_party/WebKit/Source/modules/websockets/WorkerThreadableWebSocketChannel.h b/src/third_party/WebKit/Source/modules/websockets/WorkerThreadableWebSocketChannel.h index bce1650..ccef389 100644 --- a/src/third_party/WebKit/Source/modules/websockets/WorkerThreadableWebSocketChannel.h +++ b/src/third_party/WebKit/Source/modules/websockets/WorkerThreadableWebSocketChannel.h @@ -42,14 +42,20 @@ #include "wtf/RefPtr.h" #include "wtf/Threading.h" #include "wtf/Vector.h" +#include "wtf/WeakPtr.h" #include "wtf/text/WTFString.h" +namespace blink { +class WebWaitableEvent; +} + namespace WebCore { class BlobDataHandle; class KURL; class ExecutionContext; class ThreadableWebSocketChannelClientWrapper; +class ThreadableWebSocketChannelSyncHelper; class WorkerGlobalScope; class WorkerLoaderProxy; class WorkerRunLoop; @@ -57,9 +63,9 @@ class WorkerRunLoop; class WorkerThreadableWebSocketChannel FINAL : public RefCounted, public WebSocketChannel { WTF_MAKE_FAST_ALLOCATED; public: - static PassRefPtr create(WorkerGlobalScope* workerGlobalScope, WebSocketChannelClient* client, const String& taskMode, const String& sourceURL, unsigned lineNumber) + static PassRefPtr create(WorkerGlobalScope* workerGlobalScope, WebSocketChannelClient* client, const String& sourceURL, unsigned lineNumber) { - return adoptRef(new WorkerThreadableWebSocketChannel(workerGlobalScope, client, taskMode, sourceURL, lineNumber)); + return adoptRef(new WorkerThreadableWebSocketChannel(workerGlobalScope, client, sourceURL, lineNumber)); } virtual ~WorkerThreadableWebSocketChannel(); @@ -77,23 +83,23 @@ public: virtual void suspend() OVERRIDE; virtual void resume() OVERRIDE; - // Generated by the bridge. The Peer and its bridge should have identical - // lifetimes. + // Generated by the bridge. The Peer is destructed by an async call from + // Bridge, and may outlive the bridge. All methods of this class must + // be called on the main thread. class Peer FINAL : public WebSocketChannelClient { WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; public: + virtual ~Peer(); + // sourceURLAtConnection and lineNumberAtConnection parameters may // be shown when the connection fails. - static Peer* create(PassRefPtr clientWrapper, WorkerLoaderProxy& loaderProxy, ExecutionContext* context, const String& taskMode, const String& sourceURLAtConnection, unsigned lineNumberAtConnection) - { - return new Peer(clientWrapper, loaderProxy, context, taskMode, sourceURLAtConnection, lineNumberAtConnection); - } - virtual ~Peer(); + static void initialize(ExecutionContext*, PassRefPtr >, WorkerLoaderProxy*, PassRefPtr, const String& sourceURLAtConnection, unsigned lineNumberAtConnection, PassOwnPtr); + void destroy(); void connect(const KURL&, const String& protocol); void send(const String& message); - void send(const ArrayBuffer&); - void send(PassRefPtr); + void sendArrayBuffer(PassOwnPtr >); + void sendBlob(PassRefPtr); void bufferedAmount(); void close(int code, const String& reason); void fail(const String& reason, MessageLevel, const String& sourceURL, unsigned lineNumber); @@ -111,12 +117,13 @@ public: virtual void didReceiveMessageError() OVERRIDE; private: - Peer(PassRefPtr, WorkerLoaderProxy&, ExecutionContext*, const String& taskMode, const String& sourceURL, unsigned lineNumber); + Peer(PassRefPtr >, PassRefPtr, WorkerLoaderProxy&, ExecutionContext*, const String& sourceURL, unsigned lineNumber, PassOwnPtr); RefPtr m_workerClientWrapper; WorkerLoaderProxy& m_loaderProxy; RefPtr m_mainWebSocketChannel; - String m_taskMode; + OwnPtr m_syncHelper; + WeakPtrFactory m_weakFactory; }; using RefCounted::ref; @@ -131,9 +138,9 @@ private: // Bridge for Peer. Running on the worker thread. class Bridge : public RefCounted { public: - static PassRefPtr create(PassRefPtr workerClientWrapper, PassRefPtr workerGlobalScope, const String& taskMode) + static PassRefPtr create(PassRefPtr workerClientWrapper, PassRefPtr workerGlobalScope) { - return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope, taskMode)); + return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope)); } ~Bridge(); // sourceURLAtConnection and lineNumberAtConnection parameters may @@ -154,43 +161,26 @@ private: using RefCounted::deref; private: - Bridge(PassRefPtr, PassRefPtr, const String& taskMode); + Bridge(PassRefPtr, PassRefPtr); static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer*, PassRefPtr); - // Executed on the main thread to create a Peer for this bridge. - // sourceURL and lineNumber provides the source filename and - // the line number information at the connection initiation - // respectively. They may be shown when the connection fails. - static void mainThreadInitialize(ExecutionContext*, WorkerLoaderProxy*, PassRefPtr, const String& taskMode, const String& sourceURL, unsigned lineNumber); - // Executed on the worker context's thread. void clearClientWrapper(); - void setMethodNotCompleted(); - void waitForMethodCompletion(); + // Returns false if shutdown event is received before method completion. + bool waitForMethodCompletion(); + + void terminatePeer(); RefPtr m_workerClientWrapper; RefPtr m_workerGlobalScope; WorkerLoaderProxy& m_loaderProxy; - String m_taskMode; - Peer* m_peer; + ThreadableWebSocketChannelSyncHelper* m_syncHelper; + WeakPtr m_peer; }; - WorkerThreadableWebSocketChannel(WorkerGlobalScope*, WebSocketChannelClient*, const String& taskMode, const String& sourceURL, unsigned lineNumber); - - static void mainThreadConnect(ExecutionContext*, Peer*, const KURL&, const String& protocol); - static void mainThreadSend(ExecutionContext*, Peer*, const String& message); - static void mainThreadSendArrayBuffer(ExecutionContext*, Peer*, PassOwnPtr >); - static void mainThreadSendBlob(ExecutionContext*, Peer*, PassRefPtr); - static void mainThreadBufferedAmount(ExecutionContext*, Peer*); - static void mainThreadClose(ExecutionContext*, Peer*, int code, const String& reason); - static void mainThreadFail(ExecutionContext*, Peer*, const String& reason, MessageLevel, const String& sourceURL, unsigned lineNumber); - static void mainThreadDestroy(ExecutionContext*, PassOwnPtr); - static void mainThreadSuspend(ExecutionContext*, Peer*); - static void mainThreadResume(ExecutionContext*, Peer*); - - class WorkerGlobalScopeDidInitializeTask; + WorkerThreadableWebSocketChannel(WorkerGlobalScope*, WebSocketChannelClient*, const String& sourceURL, unsigned lineNumber); RefPtr m_workerGlobalScope; RefPtr m_workerClientWrapper;