OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 InProcessWorkerObjectProxy_h | 31 #ifndef ThreadedWorkletObjectProxy_h |
32 #define InProcessWorkerObjectProxy_h | 32 #define ThreadedWorkletObjectProxy_h |
33 | 33 |
34 #include "core/CoreExport.h" | 34 #include "core/CoreExport.h" |
35 #include "core/dom/MessagePort.h" | 35 #include "core/dom/MessagePort.h" |
36 #include "core/workers/WorkerReportingProxy.h" | 36 #include "core/workers/WorkerReportingProxy.h" |
37 #include "platform/Timer.h" | |
38 #include "platform/heap/Handle.h" | 37 #include "platform/heap/Handle.h" |
39 #include "wtf/PassRefPtr.h" | 38 #include "wtf/PassRefPtr.h" |
40 #include <memory> | 39 #include <memory> |
41 | 40 |
42 namespace blink { | 41 namespace blink { |
43 | 42 |
44 class ConsoleMessage; | 43 class ConsoleMessage; |
45 class ExecutionContext; | 44 class ExecutionContext; |
46 class ExecutionContextTask; | 45 class ExecutionContextTask; |
47 class InProcessWorkerMessagingProxy; | 46 class ThreadedWorkletMessagingProxy; |
48 class ParentFrameTaskRunners; | |
49 class WorkerGlobalScope; | |
50 class WorkerOrWorkletGlobalScope; | 47 class WorkerOrWorkletGlobalScope; |
51 | 48 |
52 // A proxy to talk to the worker object. This object is created on the | 49 // A proxy to talk to the worker object. This object is created on the |
53 // parent context thread (i.e. usually the main thread), passed on to | 50 // parent context thread (i.e. usually the main thread), passed on to |
54 // the worker thread, and used to proxy messages to the | 51 // the worker thread, and used just to proxy messages to the |
55 // InProcessWorkerMessagingProxy on the parent context thread. | 52 // ThreadedWorkletMessagingProxy on the parent context thread. |
56 // | |
57 // This also checks pending activities on WorkerGlobalScope and reports a result | |
58 // to the message proxy when an exponential backoff timer is fired. | |
59 // | 53 // |
60 // Used only by in-process workers (DedicatedWorker and CompositorWorker.) | 54 // Used only by in-process workers (DedicatedWorker and CompositorWorker.) |
61 class CORE_EXPORT InProcessWorkerObjectProxy : public WorkerReportingProxy { | 55 class CORE_EXPORT ThreadedWorkletObjectProxy : public WorkerReportingProxy { |
62 USING_FAST_MALLOC(InProcessWorkerObjectProxy); | 56 USING_FAST_MALLOC(ThreadedWorkletObjectProxy); |
63 WTF_MAKE_NONCOPYABLE(InProcessWorkerObjectProxy); | 57 WTF_MAKE_NONCOPYABLE(ThreadedWorkletObjectProxy); |
| 58 |
64 public: | 59 public: |
65 static std::unique_ptr<InProcessWorkerObjectProxy> create(InProcessWorkerMes
sagingProxy*); | 60 static std::unique_ptr<ThreadedWorkletObjectProxy> create(ThreadedWorkletMes
sagingProxy*); |
66 ~InProcessWorkerObjectProxy() override; | 61 ~ThreadedWorkletObjectProxy() override {} |
67 | 62 |
68 void postMessageToWorkerObject(PassRefPtr<SerializedScriptValue>, std::uniqu
e_ptr<MessagePortChannelArray>); | |
69 void postTaskToMainExecutionContext(std::unique_ptr<ExecutionContextTask>); | 63 void postTaskToMainExecutionContext(std::unique_ptr<ExecutionContextTask>); |
70 void confirmMessageFromWorkerObject(); | 64 // void confirmMessageFromWorkerObject(bool hasPendingActivity); |
71 void startPendingActivityTimer(); | 65 void reportPendingActivity(bool hasPendingActivity); |
72 | 66 |
73 // WorkerReportingProxy overrides. | 67 // WorkerReportingProxy overrides. |
74 void reportException(const String& errorMessage, std::unique_ptr<SourceLocat
ion>, int exceptionId) override; | 68 void reportException(const String& errorMessage, std::unique_ptr<SourceLocat
ion>, int exceptionId) override {} |
75 void reportConsoleMessage(MessageSource, MessageLevel, const String& message
, SourceLocation*) override; | 69 void reportConsoleMessage(MessageSource, MessageLevel, const String& message
, SourceLocation*) override; |
76 void postMessageToPageInspector(const String&) override; | 70 void postMessageToPageInspector(const String&) override; |
77 void didEvaluateWorkerScript(bool success) override; | 71 void didEvaluateWorkerScript(bool success) override {} |
78 void workerGlobalScopeStarted(WorkerOrWorkletGlobalScope*) override; | 72 void workerGlobalScopeStarted(WorkerOrWorkletGlobalScope*) override {} |
79 void workerGlobalScopeClosed() override; | 73 void workerGlobalScopeClosed() override; |
80 void workerThreadTerminated() override; | 74 void workerThreadTerminated() override; |
81 void willDestroyWorkerGlobalScope() override; | 75 void willDestroyWorkerGlobalScope() override {} |
82 | 76 |
83 protected: | 77 protected: |
84 InProcessWorkerObjectProxy(InProcessWorkerMessagingProxy*); | 78 ThreadedWorkletObjectProxy(ThreadedWorkletMessagingProxy*); |
85 virtual ExecutionContext* getExecutionContext(); | |
86 | 79 |
87 private: | 80 private: |
88 friend class InProcessWorkerMessagingProxyForTest; | 81 ExecutionContext* getExecutionContext() const; |
89 | |
90 void checkPendingActivity(TimerBase*); | |
91 | |
92 // Returns the parent frame's task runners. | |
93 ParentFrameTaskRunners* getParentFrameTaskRunners(); | |
94 | 82 |
95 // This object always outlives this proxy. | 83 // This object always outlives this proxy. |
96 InProcessWorkerMessagingProxy* m_messagingProxy; | 84 ThreadedWorkletMessagingProxy* m_messagingProxy; |
97 | |
98 // Used for checking pending activities on the worker global scope. This is | |
99 // cancelled when the worker global scope is destroyed. | |
100 std::unique_ptr<Timer<InProcessWorkerObjectProxy>> m_timer; | |
101 | |
102 // The next interval duration of the timer. This is initially set to | |
103 // kDefaultIntervalInSec and exponentially increased up to | |
104 // |m_maxIntervalInSec|. | |
105 double m_nextIntervalInSec; | |
106 | |
107 // The max interval duration of the timer. This is usually kMaxIntervalInSec | |
108 // but made as a member variable for testing. | |
109 double m_maxIntervalInSec; | |
110 | |
111 Persistent<WorkerGlobalScope> m_workerGlobalScope; | |
112 }; | 85 }; |
113 | 86 |
114 } // namespace blink | 87 } // namespace blink |
115 | 88 |
116 #endif // InProcessWorkerObjectProxy_h | 89 #endif // ThreadedWorkletObjectProxy_h |
OLD | NEW |