зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1054219 - [B2G][SpeakerManager] Avoid to create unnecessary speakerManager instance on child process. r=baku
This commit is contained in:
Родитель
881a16d231
Коммит
dc0928b9d6
|
@ -944,6 +944,7 @@ bool
|
|||
ContentChild::RecvSpeakerManagerNotify()
|
||||
{
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
// Only notify the process which has the SpeakerManager instance.
|
||||
nsRefPtr<SpeakerManagerService> service =
|
||||
SpeakerManagerService::GetSpeakerManagerService();
|
||||
if (service) {
|
||||
|
|
|
@ -3219,10 +3219,10 @@ ContentParent::RecvSpeakerManagerGetSpeakerStatus(bool* aValue)
|
|||
#ifdef MOZ_WIDGET_GONK
|
||||
*aValue = false;
|
||||
nsRefPtr<SpeakerManagerService> service =
|
||||
SpeakerManagerService::GetSpeakerManagerService();
|
||||
if (service) {
|
||||
*aValue = service->GetSpeakerStatus();
|
||||
}
|
||||
SpeakerManagerService::GetOrCreateSpeakerManagerService();
|
||||
MOZ_ASSERT(service);
|
||||
|
||||
*aValue = service->GetSpeakerStatus();
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
|
@ -3233,10 +3233,10 @@ ContentParent::RecvSpeakerManagerForceSpeaker(const bool& aEnable)
|
|||
{
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
nsRefPtr<SpeakerManagerService> service =
|
||||
SpeakerManagerService::GetSpeakerManagerService();
|
||||
if (service) {
|
||||
service->ForceSpeaker(aEnable, mChildID);
|
||||
}
|
||||
SpeakerManagerService::GetOrCreateSpeakerManagerService();
|
||||
MOZ_ASSERT(service);
|
||||
service->ForceSpeaker(aEnable, mChildID);
|
||||
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
|
|
|
@ -27,18 +27,17 @@ SpeakerManager::SpeakerManager()
|
|||
{
|
||||
SetIsDOMBinding();
|
||||
SpeakerManagerService *service =
|
||||
SpeakerManagerService::GetSpeakerManagerService();
|
||||
if (service) {
|
||||
service->RegisterSpeakerManager(this);
|
||||
}
|
||||
SpeakerManagerService::GetOrCreateSpeakerManagerService();
|
||||
MOZ_ASSERT(service);
|
||||
service->RegisterSpeakerManager(this);
|
||||
}
|
||||
|
||||
SpeakerManager::~SpeakerManager()
|
||||
{
|
||||
SpeakerManagerService *service = SpeakerManagerService::GetSpeakerManagerService();
|
||||
if (service) {
|
||||
service->UnRegisterSpeakerManager(this);
|
||||
}
|
||||
SpeakerManagerService *service = SpeakerManagerService::GetOrCreateSpeakerManagerService();
|
||||
MOZ_ASSERT(service);
|
||||
|
||||
service->UnRegisterSpeakerManager(this);
|
||||
nsCOMPtr<EventTarget> target = do_QueryInterface(GetOwner());
|
||||
NS_ENSURE_TRUE_VOID(target);
|
||||
|
||||
|
@ -55,11 +54,10 @@ SpeakerManager::Speakerforced()
|
|||
if (mForcespeaker && !mVisible) {
|
||||
return false;
|
||||
}
|
||||
SpeakerManagerService *service = SpeakerManagerService::GetSpeakerManagerService();
|
||||
if (service) {
|
||||
return service->GetSpeakerStatus();
|
||||
}
|
||||
return false;
|
||||
SpeakerManagerService *service = SpeakerManagerService::GetOrCreateSpeakerManagerService();
|
||||
MOZ_ASSERT(service);
|
||||
return service->GetSpeakerStatus();
|
||||
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -71,10 +69,10 @@ SpeakerManager::Forcespeaker()
|
|||
void
|
||||
SpeakerManager::SetForcespeaker(bool aEnable)
|
||||
{
|
||||
SpeakerManagerService *service = SpeakerManagerService::GetSpeakerManagerService();
|
||||
if (service) {
|
||||
service->ForceSpeaker(aEnable, mVisible);
|
||||
}
|
||||
SpeakerManagerService *service = SpeakerManagerService::GetOrCreateSpeakerManagerService();
|
||||
MOZ_ASSERT(service);
|
||||
|
||||
service->ForceSpeaker(aEnable, mVisible);
|
||||
mForcespeaker = aEnable;
|
||||
}
|
||||
|
||||
|
@ -192,8 +190,10 @@ SpeakerManager::HandleEvent(nsIDOMEvent* aEvent)
|
|||
// switches to true in all apps. I.e. the app doesn't have to
|
||||
// call forcespeaker=true again when it comes into foreground.
|
||||
SpeakerManagerService *service =
|
||||
SpeakerManagerService::GetSpeakerManagerService();
|
||||
if (service && mVisible && mForcespeaker) {
|
||||
SpeakerManagerService::GetOrCreateSpeakerManagerService();
|
||||
MOZ_ASSERT(service);
|
||||
|
||||
if (mVisible && mForcespeaker) {
|
||||
service->ForceSpeaker(mForcespeaker, mVisible);
|
||||
}
|
||||
// If an application that has called forcespeaker=true, but no audio is
|
||||
|
@ -214,10 +214,10 @@ SpeakerManager::SetAudioChannelActive(bool isActive)
|
|||
{
|
||||
if (!isActive && !mVisible) {
|
||||
SpeakerManagerService *service =
|
||||
SpeakerManagerService::GetSpeakerManagerService();
|
||||
if (service) {
|
||||
service->ForceSpeaker(false, mVisible);
|
||||
}
|
||||
SpeakerManagerService::GetOrCreateSpeakerManagerService();
|
||||
MOZ_ASSERT(service);
|
||||
|
||||
service->ForceSpeaker(false, mVisible);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,12 @@ StaticRefPtr<SpeakerManagerService> gSpeakerManagerService;
|
|||
|
||||
// static
|
||||
SpeakerManagerService*
|
||||
SpeakerManagerService::GetSpeakerManagerService()
|
||||
SpeakerManagerService::GetOrCreateSpeakerManagerService()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
||||
return SpeakerManagerServiceChild::GetSpeakerManagerService();
|
||||
return SpeakerManagerServiceChild::GetOrCreateSpeakerManagerService();
|
||||
}
|
||||
|
||||
// If we already exist, exit early
|
||||
|
@ -41,9 +41,21 @@ SpeakerManagerService::GetSpeakerManagerService()
|
|||
|
||||
// Create new instance, register, return
|
||||
nsRefPtr<SpeakerManagerService> service = new SpeakerManagerService();
|
||||
NS_ENSURE_TRUE(service, nullptr);
|
||||
|
||||
gSpeakerManagerService = service;
|
||||
|
||||
return gSpeakerManagerService;
|
||||
}
|
||||
|
||||
SpeakerManagerService*
|
||||
SpeakerManagerService::GetSpeakerManagerService()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
||||
return SpeakerManagerServiceChild::GetSpeakerManagerService();
|
||||
}
|
||||
|
||||
return gSpeakerManagerService;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,15 @@ class SpeakerManagerService : public nsIObserver
|
|||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
/*
|
||||
* Return null or instance which has been created.
|
||||
*/
|
||||
static SpeakerManagerService* GetSpeakerManagerService();
|
||||
/*
|
||||
* Return SpeakerManagerService instance.
|
||||
* If SpeakerManagerService is not exist, create and return new one.
|
||||
*/
|
||||
static SpeakerManagerService* GetOrCreateSpeakerManagerService();
|
||||
virtual void ForceSpeaker(bool aEnable, bool aVisible);
|
||||
virtual bool GetSpeakerStatus();
|
||||
virtual void SetAudioChannelActive(bool aIsActive);
|
||||
|
|
|
@ -22,7 +22,7 @@ StaticRefPtr<SpeakerManagerServiceChild> gSpeakerManagerServiceChild;
|
|||
|
||||
// static
|
||||
SpeakerManagerService*
|
||||
SpeakerManagerServiceChild::GetSpeakerManagerService()
|
||||
SpeakerManagerServiceChild::GetOrCreateSpeakerManagerService()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
|
@ -33,9 +33,18 @@ SpeakerManagerServiceChild::GetSpeakerManagerService()
|
|||
|
||||
// Create new instance, register, return
|
||||
nsRefPtr<SpeakerManagerServiceChild> service = new SpeakerManagerServiceChild();
|
||||
NS_ENSURE_TRUE(service, nullptr);
|
||||
|
||||
gSpeakerManagerServiceChild = service;
|
||||
|
||||
return gSpeakerManagerServiceChild;
|
||||
}
|
||||
|
||||
// static
|
||||
SpeakerManagerService*
|
||||
SpeakerManagerServiceChild::GetSpeakerManagerService()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
return gSpeakerManagerServiceChild;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,15 @@ namespace dom {
|
|||
class SpeakerManagerServiceChild : public SpeakerManagerService
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Return null or instance which has been created.
|
||||
*/
|
||||
static SpeakerManagerService* GetSpeakerManagerService();
|
||||
/*
|
||||
* Return SpeakerManagerServiceChild instance.
|
||||
* If SpeakerManagerServiceChild is not exist, create and return new one.
|
||||
*/
|
||||
static SpeakerManagerService* GetOrCreateSpeakerManagerService();
|
||||
static void Shutdown();
|
||||
virtual void ForceSpeaker(bool aEnable, bool aVisible) MOZ_OVERRIDE;
|
||||
virtual bool GetSpeakerStatus() MOZ_OVERRIDE;
|
||||
|
|
Загрузка…
Ссылка в новой задаче