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

Unified Diff: third_party/WebKit/Source/modules/compositorworker/AbstractAnimationWorkletThread.cpp

Issue 2389193003: Refactor BackingThreadHolder to WorkletBackingThreadHolder (Closed)
Patch Set: Fixing compilation error for try bots Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/workers/WorkletBackingThreadHolder.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/compositorworker/AbstractAnimationWorkletThread.cpp
diff --git a/third_party/WebKit/Source/modules/compositorworker/AbstractAnimationWorkletThread.cpp b/third_party/WebKit/Source/modules/compositorworker/AbstractAnimationWorkletThread.cpp
index 7101897393374eb47004643bea5572c0a81c34e3..70697c37b324dfe7957477603ca4f4fc45e3a761 100644
--- a/third_party/WebKit/Source/modules/compositorworker/AbstractAnimationWorkletThread.cpp
+++ b/third_party/WebKit/Source/modules/compositorworker/AbstractAnimationWorkletThread.cpp
@@ -5,8 +5,8 @@
#include "modules/compositorworker/AbstractAnimationWorkletThread.h"
#include "core/workers/WorkerBackingThread.h"
+#include "core/workers/WorkletBackingThreadHolder.h"
#include "platform/CrossThreadFunctional.h"
-#include "platform/WaitableEvent.h"
#include "platform/WebThreadSupportingGC.h"
#include "public/platform/Platform.h"
#include "wtf/Assertions.h"
@@ -18,20 +18,25 @@ namespace blink {
namespace {
// This is a singleton class holding the animation worklet thread in this
-// renderer process. BackingThreadHolder::m_thread is cleared by
+// renderer process. WorkletBackingThreadHolder::m_thread is cleared by
// ModulesInitializer::shutdown.
+//
// See WorkerThread::terminateAndWaitForAllWorkers for the process shutdown
// case.
-class BackingThreadHolder {
+//
+// TODO(hongchan): consider refactoring static methods in this class into
+// a template class.
+class AnimationWorkletBackingThreadHolder final
+ : public WorkletBackingThreadHolder {
public:
- static BackingThreadHolder* instance() {
+ static AnimationWorkletBackingThreadHolder* instance() {
MutexLocker locker(holderInstanceMutex());
return s_instance;
}
static void ensureInstance() {
if (!s_instance)
- s_instance = new BackingThreadHolder;
+ s_instance = new AnimationWorkletBackingThreadHolder;
}
static void clear() {
@@ -46,60 +51,36 @@ class BackingThreadHolder {
static void createForTest() {
MutexLocker locker(holderInstanceMutex());
DCHECK_EQ(nullptr, s_instance);
- s_instance = new BackingThreadHolder(WorkerBackingThread::createForTest(
- Platform::current()->compositorThread()));
+ s_instance = new AnimationWorkletBackingThreadHolder(
+ WorkerBackingThread::createForTest(
+ Platform::current()->compositorThread()));
}
- WorkerBackingThread* thread() { return m_thread.get(); }
-
private:
- BackingThreadHolder(
- std::unique_ptr<WorkerBackingThread> useBackingThread = nullptr)
- : m_thread(useBackingThread
- ? std::move(useBackingThread)
- : WorkerBackingThread::create(
- Platform::current()->compositorThread())) {
- DCHECK(isMainThread());
- m_thread->backingThread().postTask(
- BLINK_FROM_HERE,
- crossThreadBind(&BackingThreadHolder::initializeOnThread,
- crossThreadUnretained(this)));
- }
+ AnimationWorkletBackingThreadHolder(
+ std::unique_ptr<WorkerBackingThread> backingThread = nullptr)
+ : WorkletBackingThreadHolder(
+ backingThread ? std::move(backingThread)
+ : WorkerBackingThread::create(
+ Platform::current()->compositorThread())) {}
static Mutex& holderInstanceMutex() {
DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, holderMutex, new Mutex);
return holderMutex;
}
- void initializeOnThread() {
+ void initializeOnThread() final {
MutexLocker locker(holderInstanceMutex());
DCHECK(!m_initialized);
m_thread->initialize();
m_initialized = true;
}
- void shutdownAndWait() {
- DCHECK(isMainThread());
- WaitableEvent doneEvent;
- m_thread->backingThread().postTask(
- BLINK_FROM_HERE, crossThreadBind(&BackingThreadHolder::shutdownOnThread,
- crossThreadUnretained(this),
- crossThreadUnretained(&doneEvent)));
- doneEvent.wait();
- }
-
- void shutdownOnThread(WaitableEvent* doneEvent) {
- m_thread->shutdown();
- doneEvent->signal();
- }
-
- std::unique_ptr<WorkerBackingThread> m_thread;
- bool m_initialized = false;
-
- static BackingThreadHolder* s_instance;
+ static AnimationWorkletBackingThreadHolder* s_instance;
};
-BackingThreadHolder* BackingThreadHolder::s_instance = nullptr;
+AnimationWorkletBackingThreadHolder*
+ AnimationWorkletBackingThreadHolder::s_instance = nullptr;
} // namespace
@@ -111,7 +92,7 @@ AbstractAnimationWorkletThread::AbstractAnimationWorkletThread(
AbstractAnimationWorkletThread::~AbstractAnimationWorkletThread() {}
WorkerBackingThread& AbstractAnimationWorkletThread::workerBackingThread() {
- return *BackingThreadHolder::instance()->thread();
+ return *AnimationWorkletBackingThreadHolder::instance()->thread();
}
void collectAllGarbageOnThread(WaitableEvent* doneEvent) {
@@ -122,7 +103,8 @@ void collectAllGarbageOnThread(WaitableEvent* doneEvent) {
void AbstractAnimationWorkletThread::collectAllGarbage() {
DCHECK(isMainThread());
WaitableEvent doneEvent;
- BackingThreadHolder* instance = BackingThreadHolder::instance();
+ AnimationWorkletBackingThreadHolder* instance =
+ AnimationWorkletBackingThreadHolder::instance();
if (!instance)
return;
instance->thread()->backingThread().postTask(
@@ -133,16 +115,16 @@ void AbstractAnimationWorkletThread::collectAllGarbage() {
void AbstractAnimationWorkletThread::ensureSharedBackingThread() {
DCHECK(isMainThread());
- BackingThreadHolder::ensureInstance();
+ AnimationWorkletBackingThreadHolder::ensureInstance();
}
void AbstractAnimationWorkletThread::clearSharedBackingThread() {
DCHECK(isMainThread());
- BackingThreadHolder::clear();
+ AnimationWorkletBackingThreadHolder::clear();
}
void AbstractAnimationWorkletThread::createSharedBackingThreadForTest() {
- BackingThreadHolder::createForTest();
+ AnimationWorkletBackingThreadHolder::createForTest();
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/workers/WorkletBackingThreadHolder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698