From 1aa1fb33527522c5a80b8edd2feeb351c6869969 Mon Sep 17 00:00:00 2001 From: Eitan Isaacson Date: Tue, 14 Oct 2014 14:42:51 -0700 Subject: [PATCH] Bug 1080863 - Make nsPicoService an observer and initialize on profile-after-change. r=smaug --- .../webspeech/synth/pico/nsPicoService.cpp | 33 +++++++++---------- .../webspeech/synth/pico/nsPicoService.h | 20 ++++++++--- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/content/media/webspeech/synth/pico/nsPicoService.cpp b/content/media/webspeech/synth/pico/nsPicoService.cpp index 5d436dcdb06..f94b87a019c 100644 --- a/content/media/webspeech/synth/pico/nsPicoService.cpp +++ b/content/media/webspeech/synth/pico/nsPicoService.cpp @@ -411,28 +411,13 @@ PicoCallbackRunnable::OnCancel() NS_INTERFACE_MAP_BEGIN(nsPicoService) NS_INTERFACE_MAP_ENTRY(nsISpeechService) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISpeechService) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver) NS_INTERFACE_MAP_END NS_IMPL_ADDREF(nsPicoService) NS_IMPL_RELEASE(nsPicoService) -nsPicoService::nsPicoService() - : mInitialized(false) - , mVoicesMonitor("nsPicoService::mVoices") - , mCurrentTask(nullptr) - , mPicoSystem(nullptr) - , mPicoEngine(nullptr) - , mSgResource(nullptr) - , mTaResource(nullptr) - , mPicoMemArea(nullptr) -{ - DebugOnly rv = NS_NewNamedThread("Pico Worker", getter_AddRefs(mThread)); - MOZ_ASSERT(NS_SUCCEEDED(rv)); - rv = mThread->Dispatch(NS_NewRunnableMethod(this, &nsPicoService::Init), NS_DISPATCH_NORMAL); - MOZ_ASSERT(NS_SUCCEEDED(rv)); -} - nsPicoService::~nsPicoService() { // We don't worry about removing the voices because this gets @@ -447,6 +432,20 @@ nsPicoService::~nsPicoService() UnloadEngine(); } +// nsIObserver + +NS_IMETHODIMP +nsPicoService::Observe(nsISupports* aSubject, const char* aTopic, + const char16_t* aData) +{ + MOZ_ASSERT(NS_IsMainThread()); + NS_ENSURE_TRUE(!strcmp(aTopic, "profile-after-change"), NS_ERROR_UNEXPECTED); + + DebugOnly rv = NS_NewNamedThread("Pico Worker", getter_AddRefs(mThread)); + MOZ_ASSERT(NS_SUCCEEDED(rv)); + return mThread->Dispatch( + NS_NewRunnableMethod(this, &nsPicoService::Init), NS_DISPATCH_NORMAL); +} // nsISpeechService NS_IMETHODIMP diff --git a/content/media/webspeech/synth/pico/nsPicoService.h b/content/media/webspeech/synth/pico/nsPicoService.h index bebadbe3ec4..320b178bc99 100644 --- a/content/media/webspeech/synth/pico/nsPicoService.h +++ b/content/media/webspeech/synth/pico/nsPicoService.h @@ -10,6 +10,7 @@ #include "mozilla/Mutex.h" #include "nsAutoPtr.h" #include "nsTArray.h" +#include "nsIObserver.h" #include "nsIThread.h" #include "nsISpeechService.h" #include "nsRefPtrHashtable.h" @@ -26,7 +27,8 @@ typedef void* pico_System; typedef void* pico_Resource; typedef void* pico_Engine; -class nsPicoService : public nsISpeechService +class nsPicoService : public nsIObserver, + public nsISpeechService { friend class PicoCallbackRunnable; friend class PicoInitRunnable; @@ -34,8 +36,7 @@ class nsPicoService : public nsISpeechService public: NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSISPEECHSERVICE - - nsPicoService(); + NS_DECL_NSIOBSERVER static nsPicoService* GetInstance(); @@ -82,8 +83,19 @@ private: nsAutoPtr mPicoMemArea; static StaticRefPtr sSingleton; -}; +protected: + nsPicoService() : mInitialized(false) + , mVoicesMonitor("nsPicoService::mVoices") + , mCurrentTask(nullptr) + , mPicoSystem(nullptr) + , mPicoEngine(nullptr) + , mSgResource(nullptr) + , mTaResource(nullptr) + , mPicoMemArea(nullptr) + { + } +}; } // namespace dom } // namespace mozilla