Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: third_party/WebKit/Source/core/workers/ThreadedMessagingProxyBase.h

Issue 2702243003: Disallow cross-thread Persistent<> read access. (Closed)
Patch Set: rebase fixup Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/WorkerLoaderProxy.h" 12 #include "core/workers/WorkerLoaderProxy.h"
12 #include "wtf/Forward.h" 13 #include "wtf/Forward.h"
13 14
14 namespace blink { 15 namespace blink {
15 16
16 class ExecutionContext; 17 class ExecutionContext;
17 class ParentFrameTaskRunners;
18 class SourceLocation; 18 class SourceLocation;
19 class WorkerInspectorProxy; 19 class WorkerInspectorProxy;
20 class WorkerLoaderProxy; 20 class WorkerLoaderProxy;
21 class WorkerThread; 21 class WorkerThread;
22 class WorkerThreadStartupData; 22 class WorkerThreadStartupData;
23 23
24 class CORE_EXPORT ThreadedMessagingProxyBase 24 class CORE_EXPORT ThreadedMessagingProxyBase
25 : private WorkerLoaderProxyProvider { 25 : private WorkerLoaderProxyProvider {
26 public: 26 public:
27 void terminateGlobalScope(); 27 void terminateGlobalScope();
28 28
29 virtual void workerThreadCreated(); 29 virtual void workerThreadCreated();
30 30
31 // This method should be called in the destructor of the object which 31 // 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. 32 // initially created it. This object could either be a Worker or a Worklet.
33 virtual void parentObjectDestroyed(); 33 virtual void parentObjectDestroyed();
34 34
35 void countFeature(UseCounter::Feature); 35 void countFeature(UseCounter::Feature);
36 void countDeprecation(UseCounter::Feature); 36 void countDeprecation(UseCounter::Feature);
37 37
38 void reportConsoleMessage(MessageSource, 38 void reportConsoleMessage(MessageSource,
39 MessageLevel, 39 MessageLevel,
40 const String& message, 40 const String& message,
41 std::unique_ptr<SourceLocation>); 41 std::unique_ptr<SourceLocation>);
42 void postMessageToPageInspector(const String&); 42 void postMessageToPageInspector(const String&);
43 43
44 // 'virtual' for testing. 44 // 'virtual' for testing.
45 virtual void workerThreadTerminated(); 45 virtual void workerThreadTerminated();
46 46
47 // Accessed from both the parent thread and the worker.
47 ExecutionContext* getExecutionContext() const { 48 ExecutionContext* getExecutionContext() const {
48 return m_executionContext.get(); 49 return m_executionContext.get();
49 } 50 }
50 51
52 // Accessed from both the parent thread and the worker.
51 ParentFrameTaskRunners* getParentFrameTaskRunners() { 53 ParentFrameTaskRunners* getParentFrameTaskRunners() {
52 return m_parentFrameTaskRunners.get(); 54 return m_parentFrameTaskRunners.get();
53 } 55 }
54 56
55 // Number of live messaging proxies, used by leak detection. 57 // Number of live messaging proxies, used by leak detection.
56 static int proxyCount(); 58 static int proxyCount();
57 59
58 protected: 60 protected:
59 ThreadedMessagingProxyBase(ExecutionContext*); 61 ThreadedMessagingProxyBase(ExecutionContext*);
60 ~ThreadedMessagingProxyBase() override; 62 ~ThreadedMessagingProxyBase() override;
61 63
62 void initializeWorkerThread(std::unique_ptr<WorkerThreadStartupData>); 64 void initializeWorkerThread(std::unique_ptr<WorkerThreadStartupData>);
63 virtual std::unique_ptr<WorkerThread> createWorkerThread( 65 virtual std::unique_ptr<WorkerThread> createWorkerThread(
64 double originTime) = 0; 66 double originTime) = 0;
65 67
66 WorkerThread* workerThread() const { return m_workerThread.get(); } 68 WorkerThread* workerThread() const { return m_workerThread.get(); }
67 69
68 bool askedToTerminate() const { return m_askedToTerminate; } 70 bool askedToTerminate() const { return m_askedToTerminate; }
69 71
70 PassRefPtr<WorkerLoaderProxy> loaderProxy() { return m_loaderProxy; } 72 PassRefPtr<WorkerLoaderProxy> loaderProxy() { return m_loaderProxy; }
71 WorkerInspectorProxy* workerInspectorProxy() { 73 WorkerInspectorProxy* workerInspectorProxy() const {
72 return m_workerInspectorProxy.get(); 74 return m_workerInspectorProxy.get();
73 } 75 }
74 76
75 // Returns true if this is called on the parent context thread. 77 // Returns true if this is called on the parent context thread.
76 bool isParentContextThread() const; 78 bool isParentContextThread() const;
77 79
78 // WorkerLoaderProxyProvider 80 // WorkerLoaderProxyProvider
79 // These methods are called on different threads to schedule loading 81 // These methods are called on different threads to schedule loading
80 // requests and to send callbacks back to WorkerGlobalScope. 82 // requests and to send callbacks back to WorkerGlobalScope.
81 void postTaskToLoader(const WebTraceLocation&, 83 void postTaskToLoader(const WebTraceLocation&,
82 std::unique_ptr<ExecutionContextTask>) override; 84 std::unique_ptr<ExecutionContextTask>) override;
83 void postTaskToWorkerGlobalScope( 85 void postTaskToWorkerGlobalScope(
84 const WebTraceLocation&, 86 const WebTraceLocation&,
85 std::unique_ptr<WTF::CrossThreadClosure>) override; 87 std::unique_ptr<WTF::CrossThreadClosure>) override;
86 88
87 private: 89 private:
88 friend class InProcessWorkerMessagingProxyForTest; 90 friend class InProcessWorkerMessagingProxyForTest;
89 friend class ThreadedWorkletMessagingProxyForTest; 91 friend class ThreadedWorkletMessagingProxyForTest;
90 92
91 void parentObjectDestroyedInternal(); 93 void parentObjectDestroyedInternal();
92 94
93 Persistent<ExecutionContext> m_executionContext; 95 // Accessed cross-thread when worker thread posts tasks to the parent.
96 CrossThreadPersistent<ExecutionContext> m_executionContext;
haraken 2017/02/20 23:57:18 Ditto.
94 Persistent<WorkerInspectorProxy> m_workerInspectorProxy; 97 Persistent<WorkerInspectorProxy> m_workerInspectorProxy;
95 Persistent<ParentFrameTaskRunners> m_parentFrameTaskRunners; 98 // Accessed cross-thread when worker thread posts tasks to the parent.
99 CrossThreadPersistent<ParentFrameTaskRunners> m_parentFrameTaskRunners;
96 100
97 std::unique_ptr<WorkerThread> m_workerThread; 101 std::unique_ptr<WorkerThread> m_workerThread;
98 102
99 RefPtr<WorkerLoaderProxy> m_loaderProxy; 103 RefPtr<WorkerLoaderProxy> m_loaderProxy;
100 104
101 bool m_mayBeDestroyed; 105 bool m_mayBeDestroyed;
102 bool m_askedToTerminate; 106 bool m_askedToTerminate;
103 }; 107 };
104 108
105 } // namespace blink 109 } // namespace blink
106 110
107 #endif // ThreadedMessagingProxyBase_h 111 #endif // ThreadedMessagingProxyBase_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698