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

Unified Diff: third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp

Issue 2432543002: Refactoring WorkletThreadBackingHolder with template pattern (Closed)
Patch Set: Using Template 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/webaudio/AudioWorkletThread.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp b/third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp
index f59c7373237c228e98fdabb450050777484a7da2..0703cb91ea9a443e24542321a09c0361a5bf9b68 100644
--- a/third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp
@@ -22,63 +22,28 @@ namespace blink {
namespace {
-// TODO(hongchan): consider refactoring static methods in this class into
-// a template class.
-class AudioWorkletThreadHolder final : public WorkletBackingThreadHolder {
- public:
- static AudioWorkletThreadHolder* instance() {
- MutexLocker locker(holderInstanceMutex());
- return s_instance;
- }
-
- static void ensureInstance() {
- if (!s_instance)
- s_instance = new AudioWorkletThreadHolder;
- }
-
- static void clear() {
- MutexLocker locker(holderInstanceMutex());
- if (s_instance) {
- s_instance->shutdownAndWait();
- delete s_instance;
- s_instance = nullptr;
- }
- }
+// AudioWorkletThreadHolder is a singletone container/mananger of a dedicated
+// thread for processing the AudioWorklet.
+class AudioWorkletThreadHolder final
+ : public WorkletThreadHolder<AudioWorkletThreadHolder> {
nhiroki 2016/10/19 01:36:49 I'd prefer to avoid class inheritance as much as p
+ friend class WorkletThreadHolder<AudioWorkletThreadHolder>;
+ public:
static void createForTest() {
- MutexLocker locker(holderInstanceMutex());
- DCHECK_EQ(nullptr, s_instance);
- s_instance =
- new AudioWorkletThreadHolder(WorkerBackingThread::createForTest(
- "AudioWorkletThread", BlinkGC::PerThreadHeapMode));
+ WorkletThreadHolder<AudioWorkletThreadHolder>::createForTest(
+ WorkerBackingThread::createForTest("AudioWorkletThread",
+ BlinkGC::PerThreadHeapMode));
}
private:
AudioWorkletThreadHolder(
std::unique_ptr<WorkerBackingThread> backingThread = nullptr)
- : WorkletBackingThreadHolder(
- backingThread
- ? std::move(backingThread)
- : WorkerBackingThread::create("AudioWorkletThread",
- BlinkGC::PerThreadHeapMode)) {}
-
- static Mutex& holderInstanceMutex() {
- DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, holderMutex, new Mutex);
- return holderMutex;
- }
-
- void initializeOnThread() {
- MutexLocker locker(holderInstanceMutex());
- DCHECK(!m_initialized);
- m_thread->initialize();
- m_initialized = true;
- }
-
- static AudioWorkletThreadHolder* s_instance;
+ : WorkletThreadHolder(backingThread ? std::move(backingThread)
+ : WorkerBackingThread::create(
+ "AudioWorkletThread",
+ BlinkGC::PerThreadHeapMode)) {}
};
-AudioWorkletThreadHolder* AudioWorkletThreadHolder::s_instance = nullptr;
-
} // namespace
std::unique_ptr<AudioWorkletThread> AudioWorkletThread::create(

Powered by Google App Engine
This is Rietveld 408576698