Bug 1080863 - Make nsPicoService an observer and initialize on profile-after-change. r=smaug

This commit is contained in:
Eitan Isaacson 2014-10-15 14:44:10 -07:00
Родитель 8c488b9625
Коммит 0c3af88521
2 изменённых файлов: 20 добавлений и 6 удалений

Просмотреть файл

@ -411,7 +411,8 @@ 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)
@ -427,10 +428,6 @@ nsPicoService::nsPicoService()
, mTaResource(nullptr)
, mPicoMemArea(nullptr)
{
DebugOnly<nsresult> 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()
@ -447,6 +444,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<nsresult> 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

Просмотреть файл

@ -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,6 +36,7 @@ class nsPicoService : public nsISpeechService
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSISPEECHSERVICE
NS_DECL_NSIOBSERVER
nsPicoService();