Chromium Code Reviews| 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" | |
| 32 #include "core/dom/MessagePort.h" | |
| 33 #include "core/inspector/ConsoleTypes.h" | 9 #include "core/inspector/ConsoleTypes.h" |
| 34 #include "core/workers/WorkerLoaderProxy.h" | 10 #include "core/workers/WorkerLoaderProxy.h" |
| 35 #include "platform/heap/Handle.h" | |
| 36 #include "wtf/Forward.h" | 11 #include "wtf/Forward.h" |
| 37 #include "wtf/Noncopyable.h" | |
| 38 #include "wtf/PassRefPtr.h" | |
| 39 #include "wtf/RefPtr.h" | |
| 40 #include "wtf/Vector.h" | |
| 41 #include <memory> | |
| 42 | 12 |
| 43 namespace blink { | 13 namespace blink { |
| 44 | 14 |
| 45 class ExecutionContext; | 15 class ExecutionContext; |
| 46 class InProcessWorkerBase; | |
| 47 class InProcessWorkerObjectProxy; | |
| 48 class ParentFrameTaskRunners; | 16 class ParentFrameTaskRunners; |
| 49 class WorkerClients; | |
| 50 class WorkerInspectorProxy; | 17 class WorkerInspectorProxy; |
| 18 class WorkerLoaderProxy; | |
| 51 class WorkerThread; | 19 class WorkerThread; |
| 20 class WorkerThreadStartupData; | |
| 52 | 21 |
| 53 // TODO(nhiroki): "MessagingProxy" is not well-defined term among worker | 22 class CORE_EXPORT ThreadedMessagingProxyBase : private WorkerLoaderProxyProvider { |
| 54 // components. Probably we should rename this to something more suitable. | |
| 55 // (http://crbug.com/603785) | |
| 56 class CORE_EXPORT InProcessWorkerMessagingProxy : private WorkerLoaderProxyProvi der { | |
| 57 WTF_MAKE_NONCOPYABLE(InProcessWorkerMessagingProxy); | |
| 58 public: | 23 public: |
| 59 // These methods should only be used on the parent context thread. | 24 void terminateGlobalScope(); |
| 60 void startWorkerGlobalScope(const KURL& scriptURL, const String& userAgent, const String& sourceCode); | |
| 61 void terminateWorkerGlobalScope(); | |
| 62 void postMessageToWorkerGlobalScope(PassRefPtr<SerializedScriptValue>, std:: unique_ptr<MessagePortChannelArray>); | |
| 63 bool hasPendingActivity() const; | |
| 64 void workerObjectDestroyed(); | |
| 65 | 25 |
| 66 // These methods come from worker context thread via | 26 virtual void workerThreadCreated(); |
| 67 // InProcessWorkerObjectProxy and are called on the parent context thread. | 27 virtual void parentObjectDestroyed(); |
|
yhirano
2016/09/07 04:46:37
Is "parent object" defined? Can you write some com
ikilpatrick
2016/09/07 17:53:57
Added comments in this file.
| |
| 68 void postMessageToWorkerObject(PassRefPtr<SerializedScriptValue>, std::uniqu e_ptr<MessagePortChannelArray>); | 28 |
| 69 void dispatchErrorEvent(const String& errorMessage, std::unique_ptr<SourceLo cation>, int exceptionId); | |
| 70 void reportConsoleMessage(MessageSource, MessageLevel, const String& message , std::unique_ptr<SourceLocation>); | 29 void reportConsoleMessage(MessageSource, MessageLevel, const String& message , std::unique_ptr<SourceLocation>); |
| 71 void postMessageToPageInspector(const String&); | 30 void postMessageToPageInspector(const String&); |
| 72 | 31 |
| 73 // 'virtual' for testing. | 32 // 'virtual' for testing. |
| 74 virtual void confirmMessageFromWorkerObject(); | |
| 75 virtual void pendingActivityFinished(); | |
| 76 virtual void workerThreadTerminated(); | 33 virtual void workerThreadTerminated(); |
| 77 | 34 |
| 78 void workerThreadCreated(); | |
| 79 | |
| 80 ExecutionContext* getExecutionContext() const { return m_executionContext.ge t(); } | 35 ExecutionContext* getExecutionContext() const { return m_executionContext.ge t(); } |
| 81 | 36 |
| 82 ParentFrameTaskRunners* getParentFrameTaskRunners() { return m_parentFrameTa skRunners.get(); } | 37 ParentFrameTaskRunners* getParentFrameTaskRunners() { return m_parentFrameTa skRunners.get(); } |
| 83 | 38 |
| 84 // Number of live messaging proxies, used by leak detection. | 39 // Number of live messaging proxies, used by leak detection. |
| 85 static int proxyCount(); | 40 static int proxyCount(); |
| 86 | 41 |
| 87 protected: | 42 protected: |
| 88 InProcessWorkerMessagingProxy(InProcessWorkerBase*, WorkerClients*); | 43 ThreadedMessagingProxyBase(ExecutionContext*); |
| 89 ~InProcessWorkerMessagingProxy() override; | 44 ~ThreadedMessagingProxyBase() override; |
| 90 | 45 |
| 46 void initializeWorkerThread(std::unique_ptr<WorkerThreadStartupData>); | |
| 91 virtual std::unique_ptr<WorkerThread> createWorkerThread(double originTime) = 0; | 47 virtual std::unique_ptr<WorkerThread> createWorkerThread(double originTime) = 0; |
| 92 | 48 |
| 49 WorkerThread* workerThread() const { return m_workerThread.get(); } | |
| 50 | |
| 51 bool askedToTerminate() const { return m_askedToTerminate; } | |
| 52 | |
| 93 PassRefPtr<WorkerLoaderProxy> loaderProxy() { return m_loaderProxy; } | 53 PassRefPtr<WorkerLoaderProxy> loaderProxy() { return m_loaderProxy; } |
| 94 InProcessWorkerObjectProxy& workerObjectProxy() { return *m_workerObjectProx y.get(); } | 54 WorkerInspectorProxy* workerInspectorProxy() { return m_workerInspectorProxy .get(); } |
| 95 | 55 |
| 96 private: | 56 // Returns true if this is called on the parent context thread. |
| 97 friend class InProcessWorkerMessagingProxyForTest; | 57 bool isParentContextThread() const; |
| 98 InProcessWorkerMessagingProxy(ExecutionContext*, InProcessWorkerBase*, Worke rClients*); | |
| 99 | |
| 100 void workerObjectDestroyedInternal(); | |
| 101 | 58 |
| 102 // WorkerLoaderProxyProvider | 59 // WorkerLoaderProxyProvider |
| 103 // These methods are called on different threads to schedule loading | 60 // These methods are called on different threads to schedule loading |
| 104 // requests and to send callbacks back to WorkerGlobalScope. | 61 // requests and to send callbacks back to WorkerGlobalScope. |
| 105 void postTaskToLoader(const WebTraceLocation&, std::unique_ptr<ExecutionCont extTask>) override; | 62 void postTaskToLoader(const WebTraceLocation&, std::unique_ptr<ExecutionCont extTask>) override; |
| 106 void postTaskToWorkerGlobalScope(const WebTraceLocation&, std::unique_ptr<Ex ecutionContextTask>) override; | 63 void postTaskToWorkerGlobalScope(const WebTraceLocation&, std::unique_ptr<Ex ecutionContextTask>) override; |
| 107 | 64 private: |
| 108 // Returns true if this is called on the parent context thread. | 65 friend class InProcessWorkerMessagingProxyForTest; |
| 109 bool isParentContextThread() const; | 66 void parentObjectDestroyedInternal(); |
| 110 | 67 |
| 111 Persistent<ExecutionContext> m_executionContext; | 68 Persistent<ExecutionContext> m_executionContext; |
| 112 std::unique_ptr<InProcessWorkerObjectProxy> m_workerObjectProxy; | 69 Persistent<WorkerInspectorProxy> m_workerInspectorProxy; |
| 113 WeakPersistent<InProcessWorkerBase> m_workerObject; | 70 Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; |
| 114 bool m_mayBeDestroyed; | 71 |
| 115 std::unique_ptr<WorkerThread> m_workerThread; | 72 std::unique_ptr<WorkerThread> m_workerThread; |
| 116 | 73 |
| 117 // Unconfirmed messages from the parent context thread to the worker thread. | 74 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
| 118 unsigned m_unconfirmedMessageCount; | |
| 119 | 75 |
| 120 bool m_workerGlobalScopeMayHavePendingActivity; | 76 bool m_mayBeDestroyed; |
| 121 bool m_askedToTerminate; | 77 bool m_askedToTerminate; |
| 122 | |
| 123 // Tasks are queued here until there's a thread object created. | |
| 124 Vector<std::unique_ptr<ExecutionContextTask>> m_queuedEarlyTasks; | |
| 125 | |
| 126 Persistent<WorkerInspectorProxy> m_workerInspectorProxy; | |
| 127 | |
| 128 Persistent<WorkerClients> m_workerClients; | |
| 129 | |
| 130 Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; | |
| 131 | |
| 132 RefPtr<WorkerLoaderProxy> m_loaderProxy; | |
| 133 }; | 78 }; |
| 134 | 79 |
| 135 } // namespace blink | 80 } // namespace blink |
| 136 | 81 |
| 137 #endif // InProcessWorkerMessagingProxy_h | 82 #endif // ThreadedMessagingProxyBase_h |
| OLD | NEW |