| OLD | NEW |
| 1 /* | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 * | 3 // found in the LICENSE file. |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 * | |
| 25 */ | |
| 26 | 4 |
| 27 #ifndef InProcessWorkerMessagingProxy_h | 5 #ifndef ThreadedMessagingProxyBase_h |
| 28 #define InProcessWorkerMessagingProxy_h | 6 #define ThreadedMessagingProxyBase_h |
| 29 | 7 |
| 30 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 31 #include "core/dom/ExecutionContext.h" | 9 #include "core/inspector/ConsoleTypes.h" |
| 32 #include "core/workers/InProcessWorkerGlobalScopeProxy.h" | 10 #include "core/workers/ThreadedGlobalScopeProxy.h" |
| 33 #include "core/workers/WorkerLoaderProxy.h" | 11 #include "core/workers/WorkerLoaderProxy.h" |
| 34 #include "platform/heap/Handle.h" | |
| 35 #include "wtf/Forward.h" | 12 #include "wtf/Forward.h" |
| 36 #include "wtf/Noncopyable.h" | |
| 37 #include "wtf/PassRefPtr.h" | |
| 38 #include "wtf/RefPtr.h" | |
| 39 #include "wtf/Vector.h" | |
| 40 #include <memory> | |
| 41 | 13 |
| 42 namespace blink { | 14 namespace blink { |
| 43 | 15 |
| 44 class ExecutionContext; | 16 class ExecutionContext; |
| 45 class InProcessWorkerBase; | |
| 46 class InProcessWorkerObjectProxy; | |
| 47 class ParentFrameTaskRunners; | 17 class ParentFrameTaskRunners; |
| 48 class WorkerClients; | |
| 49 class WorkerInspectorProxy; | 18 class WorkerInspectorProxy; |
| 19 class WorkerLoaderProxy; |
| 50 class WorkerThread; | 20 class WorkerThread; |
| 21 class WorkerThreadStartupData; |
| 51 | 22 |
| 52 // TODO(nhiroki): "MessagingProxy" is not well-defined term among worker | 23 class CORE_EXPORT ThreadedMessagingProxyBase |
| 53 // components. Probably we should rename this to something more suitable. | 24 : public ThreadedGlobalScopeProxy |
| 54 // (http://crbug.com/603785) | |
| 55 class CORE_EXPORT InProcessWorkerMessagingProxy | |
| 56 : public InProcessWorkerGlobalScopeProxy | |
| 57 , private WorkerLoaderProxyProvider { | 25 , private WorkerLoaderProxyProvider { |
| 58 WTF_MAKE_NONCOPYABLE(InProcessWorkerMessagingProxy); | |
| 59 public: | 26 public: |
| 60 // Implementations of InProcessWorkerGlobalScopeProxy. | 27 void terminateGlobalScope() override; |
| 61 // (Only use these methods in the parent context thread.) | |
| 62 void startWorkerGlobalScope(const KURL& scriptURL, const String& userAgent,
const String& sourceCode) override; | |
| 63 void terminateWorkerGlobalScope() override; | |
| 64 void postMessageToWorkerGlobalScope(PassRefPtr<SerializedScriptValue>, std::
unique_ptr<MessagePortChannelArray>) override; | |
| 65 bool hasPendingActivity() const final; | 28 bool hasPendingActivity() const final; |
| 66 void workerObjectDestroyed() override; | 29 void parentObjectDestroyed() override; |
| 67 | 30 |
| 68 // These methods come from worker context thread via | |
| 69 // InProcessWorkerObjectProxy and are called on the parent context thread. | |
| 70 void postMessageToWorkerObject(PassRefPtr<SerializedScriptValue>, std::uniqu
e_ptr<MessagePortChannelArray>); | |
| 71 void dispatchErrorEvent(const String& errorMessage, std::unique_ptr<SourceLo
cation>, int exceptionId); | |
| 72 void reportConsoleMessage(MessageSource, MessageLevel, const String& message
, std::unique_ptr<SourceLocation>); | 31 void reportConsoleMessage(MessageSource, MessageLevel, const String& message
, std::unique_ptr<SourceLocation>); |
| 73 void postMessageToPageInspector(const String&); | 32 void postMessageToPageInspector(const String&); |
| 74 | 33 |
| 75 // 'virtual' for testing. | 34 // 'virtual' for testing. |
| 76 virtual void confirmMessageFromWorkerObject(); | 35 virtual void confirmMessageFromWorkerObject(); |
| 77 virtual void pendingActivityFinished(); | 36 virtual void pendingActivityFinished(); |
| 78 virtual void workerThreadTerminated(); | 37 virtual void workerThreadTerminated(); |
| 79 | 38 |
| 80 void workerThreadCreated(); | 39 void workerThreadCreated(); |
| 81 | 40 |
| 82 ExecutionContext* getExecutionContext() const { return m_executionContext.ge
t(); } | 41 ExecutionContext* getExecutionContext() const { return m_executionContext.ge
t(); } |
| 83 | 42 |
| 84 ParentFrameTaskRunners* getParentFrameTaskRunners() { return m_parentFrameTa
skRunners.get(); } | 43 ParentFrameTaskRunners* getParentFrameTaskRunners() { return m_parentFrameTa
skRunners.get(); } |
| 85 | 44 |
| 86 // Number of live messaging proxies, used by leak detection. | 45 // Number of live messaging proxies, used by leak detection. |
| 87 static int proxyCount(); | 46 static int proxyCount(); |
| 88 | 47 |
| 89 protected: | 48 protected: |
| 90 InProcessWorkerMessagingProxy(InProcessWorkerBase*, WorkerClients*); | 49 ThreadedMessagingProxyBase(ExecutionContext*); |
| 91 ~InProcessWorkerMessagingProxy() override; | 50 ~ThreadedMessagingProxyBase() override; |
| 92 | 51 |
| 52 void initializeWorkerThread(std::unique_ptr<WorkerThreadStartupData>); |
| 93 virtual std::unique_ptr<WorkerThread> createWorkerThread(double originTime)
= 0; | 53 virtual std::unique_ptr<WorkerThread> createWorkerThread(double originTime)
= 0; |
| 94 | 54 |
| 55 WorkerThread* workerThread() const { return m_workerThread.get(); } |
| 56 |
| 57 void postOrQueueTaskToWorkerGlobalScope(std::unique_ptr<ExecutionContextTask
>); |
| 58 bool askedToTerminate() const { return m_askedToTerminate; } |
| 59 |
| 95 PassRefPtr<WorkerLoaderProxy> loaderProxy() { return m_loaderProxy; } | 60 PassRefPtr<WorkerLoaderProxy> loaderProxy() { return m_loaderProxy; } |
| 96 InProcessWorkerObjectProxy& workerObjectProxy() { return *m_workerObjectProx
y.get(); } | 61 WorkerInspectorProxy* workerInspectorProxy() { return m_workerInspectorProxy
.get(); } |
| 97 | 62 |
| 98 private: | 63 // Returns true if this is called on the parent context thread. |
| 99 friend class InProcessWorkerMessagingProxyForTest; | 64 bool isParentContextThread() const; |
| 100 InProcessWorkerMessagingProxy(ExecutionContext*, InProcessWorkerBase*, Worke
rClients*); | |
| 101 | |
| 102 void workerObjectDestroyedInternal(); | |
| 103 | 65 |
| 104 // WorkerLoaderProxyProvider | 66 // WorkerLoaderProxyProvider |
| 105 // These methods are called on different threads to schedule loading | 67 // These methods are called on different threads to schedule loading |
| 106 // requests and to send callbacks back to WorkerGlobalScope. | 68 // requests and to send callbacks back to WorkerGlobalScope. |
| 107 void postTaskToLoader(const WebTraceLocation&, std::unique_ptr<ExecutionCont
extTask>) override; | 69 void postTaskToLoader(const WebTraceLocation&, std::unique_ptr<ExecutionCont
extTask>) override; |
| 108 void postTaskToWorkerGlobalScope(const WebTraceLocation&, std::unique_ptr<Ex
ecutionContextTask>) override; | 70 void postTaskToWorkerGlobalScope(const WebTraceLocation&, std::unique_ptr<Ex
ecutionContextTask>) override; |
| 109 | 71 private: |
| 110 // Returns true if this is called on the parent context thread. | 72 friend class InProcessWorkerMessagingProxyForTest; |
| 111 bool isParentContextThread() const; | 73 void parentObjectDestroyedInternal(); |
| 112 | 74 |
| 113 Persistent<ExecutionContext> m_executionContext; | 75 Persistent<ExecutionContext> m_executionContext; |
| 114 std::unique_ptr<InProcessWorkerObjectProxy> m_workerObjectProxy; | |
| 115 WeakPersistent<InProcessWorkerBase> m_workerObject; | |
| 116 bool m_mayBeDestroyed; | 76 bool m_mayBeDestroyed; |
| 117 std::unique_ptr<WorkerThread> m_workerThread; | 77 std::unique_ptr<WorkerThread> m_workerThread; |
| 118 | 78 |
| 119 // Unconfirmed messages from the parent context thread to the worker thread. | 79 // Unconfirmed messages from the parent context thread to the worker thread. |
| 120 unsigned m_unconfirmedMessageCount; | 80 unsigned m_unconfirmedMessageCount; |
| 121 | 81 |
| 122 bool m_workerGlobalScopeMayHavePendingActivity; | 82 bool m_workerGlobalScopeMayHavePendingActivity; |
| 123 bool m_askedToTerminate; | 83 bool m_askedToTerminate; |
| 124 | 84 |
| 125 // Tasks are queued here until there's a thread object created. | 85 // Tasks are queued here until there's a thread object created. |
| 126 Vector<std::unique_ptr<ExecutionContextTask>> m_queuedEarlyTasks; | 86 Vector<std::unique_ptr<ExecutionContextTask>> m_queuedEarlyTasks; |
| 127 | 87 |
| 128 Persistent<WorkerInspectorProxy> m_workerInspectorProxy; | 88 Persistent<WorkerInspectorProxy> m_workerInspectorProxy; |
| 129 | 89 |
| 130 Persistent<WorkerClients> m_workerClients; | |
| 131 | |
| 132 Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; | 90 Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; |
| 133 | 91 |
| 134 RefPtr<WorkerLoaderProxy> m_loaderProxy; | 92 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
| 135 }; | 93 }; |
| 136 | 94 |
| 137 } // namespace blink | 95 } // namespace blink |
| 138 | 96 |
| 139 #endif // InProcessWorkerMessagingProxy_h | 97 #endif // ThreadedMessagingProxyBase_h |
| OLD | NEW |