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

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

Issue 2432543002: Refactoring WorkletThreadBackingHolder with template pattern (Closed)
Patch Set: Fixing typos 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
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 70697c37b324dfe7957477603ca4f4fc45e3a761..2370da5dc7958b6e3a26d4293cb5cb647521fafe 100644
--- a/third_party/WebKit/Source/modules/compositorworker/AbstractAnimationWorkletThread.cpp
+++ b/third_party/WebKit/Source/modules/compositorworker/AbstractAnimationWorkletThread.cpp
@@ -5,7 +5,7 @@
#include "modules/compositorworker/AbstractAnimationWorkletThread.h"
#include "core/workers/WorkerBackingThread.h"
-#include "core/workers/WorkletBackingThreadHolder.h"
+#include "core/workers/WorkletThreadHolder.h"
#include "platform/CrossThreadFunctional.h"
#include "platform/WebThreadSupportingGC.h"
#include "public/platform/Platform.h"
@@ -15,74 +15,7 @@
namespace blink {
-namespace {
-
-// This is a singleton class holding the animation worklet thread in this
-// renderer process. WorkletBackingThreadHolder::m_thread is cleared by
-// ModulesInitializer::shutdown.
-//
-// See WorkerThread::terminateAndWaitForAllWorkers for the process shutdown
-// case.
-//
-// TODO(hongchan): consider refactoring static methods in this class into
-// a template class.
-class AnimationWorkletBackingThreadHolder final
- : public WorkletBackingThreadHolder {
- public:
- static AnimationWorkletBackingThreadHolder* instance() {
- MutexLocker locker(holderInstanceMutex());
- return s_instance;
- }
-
- static void ensureInstance() {
- if (!s_instance)
- s_instance = new AnimationWorkletBackingThreadHolder;
- }
-
- static void clear() {
- MutexLocker locker(holderInstanceMutex());
- if (s_instance) {
- s_instance->shutdownAndWait();
- delete s_instance;
- s_instance = nullptr;
- }
- }
-
- static void createForTest() {
- MutexLocker locker(holderInstanceMutex());
- DCHECK_EQ(nullptr, s_instance);
- s_instance = new AnimationWorkletBackingThreadHolder(
- WorkerBackingThread::createForTest(
- Platform::current()->compositorThread()));
- }
-
- private:
- 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() final {
- MutexLocker locker(holderInstanceMutex());
- DCHECK(!m_initialized);
- m_thread->initialize();
- m_initialized = true;
- }
-
- static AnimationWorkletBackingThreadHolder* s_instance;
-};
-
-AnimationWorkletBackingThreadHolder*
- AnimationWorkletBackingThreadHolder::s_instance = nullptr;
-
-} // namespace
+template class WorkletThreadHolder<AbstractAnimationWorkletThread>;
AbstractAnimationWorkletThread::AbstractAnimationWorkletThread(
PassRefPtr<WorkerLoaderProxy> workerLoaderProxy,
@@ -92,7 +25,9 @@ AbstractAnimationWorkletThread::AbstractAnimationWorkletThread(
AbstractAnimationWorkletThread::~AbstractAnimationWorkletThread() {}
WorkerBackingThread& AbstractAnimationWorkletThread::workerBackingThread() {
- return *AnimationWorkletBackingThreadHolder::instance()->thread();
+ return *WorkletThreadHolder<
+ AbstractAnimationWorkletThread>::threadHolderInstance()
+ ->thread();
}
void collectAllGarbageOnThread(WaitableEvent* doneEvent) {
@@ -103,11 +38,12 @@ void collectAllGarbageOnThread(WaitableEvent* doneEvent) {
void AbstractAnimationWorkletThread::collectAllGarbage() {
DCHECK(isMainThread());
WaitableEvent doneEvent;
- AnimationWorkletBackingThreadHolder* instance =
- AnimationWorkletBackingThreadHolder::instance();
- if (!instance)
+ WorkletThreadHolder<AbstractAnimationWorkletThread>* threadHolderInstance =
+ WorkletThreadHolder<
+ AbstractAnimationWorkletThread>::threadHolderInstance();
+ if (!threadHolderInstance)
return;
- instance->thread()->backingThread().postTask(
+ threadHolderInstance->thread()->backingThread().postTask(
BLINK_FROM_HERE, crossThreadBind(&collectAllGarbageOnThread,
crossThreadUnretained(&doneEvent)));
doneEvent.wait();
@@ -115,16 +51,18 @@ void AbstractAnimationWorkletThread::collectAllGarbage() {
void AbstractAnimationWorkletThread::ensureSharedBackingThread() {
DCHECK(isMainThread());
- AnimationWorkletBackingThreadHolder::ensureInstance();
+ WorkletThreadHolder<AbstractAnimationWorkletThread>::ensureInstance(
+ Platform::current()->compositorThread());
}
void AbstractAnimationWorkletThread::clearSharedBackingThread() {
DCHECK(isMainThread());
- AnimationWorkletBackingThreadHolder::clear();
+ WorkletThreadHolder<AbstractAnimationWorkletThread>::clearInstance();
}
void AbstractAnimationWorkletThread::createSharedBackingThreadForTest() {
- AnimationWorkletBackingThreadHolder::createForTest();
+ WorkletThreadHolder<AbstractAnimationWorkletThread>::createForTest(
+ Platform::current()->compositorThread());
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698