OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ThreadedMessagingProxyBase_h | 5 #ifndef ThreadedMessagingProxyBase_h |
6 #define ThreadedMessagingProxyBase_h | 6 #define ThreadedMessagingProxyBase_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "core/frame/UseCounter.h" | 9 #include "core/frame/UseCounter.h" |
10 #include "core/inspector/ConsoleTypes.h" | 10 #include "core/inspector/ConsoleTypes.h" |
11 #include "core/workers/ParentFrameTaskRunners.h" | 11 #include "core/workers/ParentFrameTaskRunners.h" |
12 #include "core/workers/WorkerLoaderProxy.h" | |
13 #include "platform/wtf/Forward.h" | 12 #include "platform/wtf/Forward.h" |
14 | 13 |
15 namespace blink { | 14 namespace blink { |
16 | 15 |
17 class ExecutionContext; | 16 class ExecutionContext; |
18 class SourceLocation; | 17 class SourceLocation; |
| 18 class ThreadableLoadingContext; |
19 class WorkerInspectorProxy; | 19 class WorkerInspectorProxy; |
20 class WorkerLoaderProxy; | |
21 class WorkerThread; | 20 class WorkerThread; |
22 class WorkerThreadStartupData; | 21 class WorkerThreadStartupData; |
23 | 22 |
24 class CORE_EXPORT ThreadedMessagingProxyBase | 23 class CORE_EXPORT ThreadedMessagingProxyBase { |
25 : private WorkerLoaderProxyProvider { | |
26 public: | 24 public: |
27 void TerminateGlobalScope(); | 25 void TerminateGlobalScope(); |
28 | 26 |
29 virtual void WorkerThreadCreated(); | 27 virtual void WorkerThreadCreated(); |
30 | 28 |
31 // This method should be called in the destructor of the object which | 29 // This method should be called in the destructor of the object which |
32 // initially created it. This object could either be a Worker or a Worklet. | 30 // initially created it. This object could either be a Worker or a Worklet. |
33 virtual void ParentObjectDestroyed(); | 31 virtual void ParentObjectDestroyed(); |
34 | 32 |
35 void CountFeature(UseCounter::Feature); | 33 void CountFeature(UseCounter::Feature); |
(...skipping 18 matching lines...) Expand all Loading... |
54 return parent_frame_task_runners_.Get(); | 52 return parent_frame_task_runners_.Get(); |
55 } | 53 } |
56 | 54 |
57 // Number of live messaging proxies, used by leak detection. | 55 // Number of live messaging proxies, used by leak detection. |
58 static int ProxyCount(); | 56 static int ProxyCount(); |
59 | 57 |
60 void SetWorkerThreadForTest(std::unique_ptr<WorkerThread>); | 58 void SetWorkerThreadForTest(std::unique_ptr<WorkerThread>); |
61 | 59 |
62 protected: | 60 protected: |
63 ThreadedMessagingProxyBase(ExecutionContext*); | 61 ThreadedMessagingProxyBase(ExecutionContext*); |
64 ~ThreadedMessagingProxyBase() override; | 62 virtual ~ThreadedMessagingProxyBase(); |
65 | 63 |
66 void InitializeWorkerThread(std::unique_ptr<WorkerThreadStartupData>); | 64 void InitializeWorkerThread(std::unique_ptr<WorkerThreadStartupData>); |
67 virtual std::unique_ptr<WorkerThread> CreateWorkerThread( | 65 virtual std::unique_ptr<WorkerThread> CreateWorkerThread( |
68 double origin_time) = 0; | 66 double origin_time) = 0; |
69 | 67 |
70 WorkerThread* GetWorkerThread() const { return worker_thread_.get(); } | 68 WorkerThread* GetWorkerThread() const { return worker_thread_.get(); } |
71 | 69 |
72 bool AskedToTerminate() const { return asked_to_terminate_; } | 70 bool AskedToTerminate() const { return asked_to_terminate_; } |
73 | 71 |
74 PassRefPtr<WorkerLoaderProxy> LoaderProxy() { return loader_proxy_; } | |
75 WorkerInspectorProxy* GetWorkerInspectorProxy() const { | 72 WorkerInspectorProxy* GetWorkerInspectorProxy() const { |
76 return worker_inspector_proxy_.Get(); | 73 return worker_inspector_proxy_.Get(); |
77 } | 74 } |
78 | 75 |
79 // Returns true if this is called on the parent context thread. | 76 // Returns true if this is called on the parent context thread. |
80 bool IsParentContextThread() const; | 77 bool IsParentContextThread() const; |
81 | 78 |
82 // WorkerLoaderProxyProvider | 79 ThreadableLoadingContext* GetThreadableLoadingContext(); |
83 ThreadableLoadingContext* GetThreadableLoadingContext() override; | |
84 | 80 |
85 private: | 81 private: |
86 friend class InProcessWorkerMessagingProxyForTest; | 82 friend class InProcessWorkerMessagingProxyForTest; |
87 friend class ThreadedWorkletMessagingProxyForTest; | 83 friend class ThreadedWorkletMessagingProxyForTest; |
88 | 84 |
89 void ParentObjectDestroyedInternal(); | 85 void ParentObjectDestroyedInternal(); |
90 | 86 |
91 Persistent<ExecutionContext> execution_context_; | 87 Persistent<ExecutionContext> execution_context_; |
92 Persistent<ThreadableLoadingContext> loading_context_; | |
93 Persistent<WorkerInspectorProxy> worker_inspector_proxy_; | 88 Persistent<WorkerInspectorProxy> worker_inspector_proxy_; |
94 // Accessed cross-thread when worker thread posts tasks to the parent. | 89 // Accessed cross-thread when worker thread posts tasks to the parent. |
95 CrossThreadPersistent<ParentFrameTaskRunners> parent_frame_task_runners_; | 90 CrossThreadPersistent<ParentFrameTaskRunners> parent_frame_task_runners_; |
96 | 91 |
97 std::unique_ptr<WorkerThread> worker_thread_; | 92 std::unique_ptr<WorkerThread> worker_thread_; |
98 | 93 |
99 RefPtr<WorkerLoaderProxy> loader_proxy_; | |
100 | |
101 bool may_be_destroyed_; | 94 bool may_be_destroyed_; |
102 bool asked_to_terminate_; | 95 bool asked_to_terminate_; |
103 }; | 96 }; |
104 | 97 |
105 } // namespace blink | 98 } // namespace blink |
106 | 99 |
107 #endif // ThreadedMessagingProxyBase_h | 100 #endif // ThreadedMessagingProxyBase_h |
OLD | NEW |