зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1055920 - [B2G][AudioChannel] Avoid to create unnecessary AudioChannel instance on child process. r=baku
This commit is contained in:
Родитель
bcbd8dd34b
Коммит
4b227d8d5a
|
@ -114,7 +114,7 @@ AudioChannelAgent::InitInternal(nsIDOMWindow* aWindow, int32_t aChannelType,
|
|||
/* boolean startPlaying (); */
|
||||
NS_IMETHODIMP AudioChannelAgent::StartPlaying(int32_t *_retval)
|
||||
{
|
||||
AudioChannelService *service = AudioChannelService::GetAudioChannelService();
|
||||
AudioChannelService *service = AudioChannelService::GetOrCreateAudioChannelService();
|
||||
if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR ||
|
||||
service == nullptr || mIsRegToService) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -135,7 +135,7 @@ NS_IMETHODIMP AudioChannelAgent::StopPlaying(void)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
AudioChannelService *service = AudioChannelService::GetAudioChannelService();
|
||||
AudioChannelService *service = AudioChannelService::GetOrCreateAudioChannelService();
|
||||
service->UnregisterAudioChannelAgent(this);
|
||||
mIsRegToService = false;
|
||||
return NS_OK;
|
||||
|
@ -150,7 +150,7 @@ NS_IMETHODIMP AudioChannelAgent::SetVisibilityState(bool visible)
|
|||
|
||||
mVisible = visible;
|
||||
if (mIsRegToService && oldVisibility != mVisible && callback) {
|
||||
AudioChannelService *service = AudioChannelService::GetAudioChannelService();
|
||||
AudioChannelService *service = AudioChannelService::GetOrCreateAudioChannelService();
|
||||
callback->CanPlayChanged(service->GetState(this, !mVisible));
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -160,7 +160,7 @@ void AudioChannelAgent::NotifyAudioChannelStateChanged()
|
|||
{
|
||||
nsCOMPtr<nsIAudioChannelAgentCallback> callback = GetCallback();
|
||||
if (callback) {
|
||||
AudioChannelService *service = AudioChannelService::GetAudioChannelService();
|
||||
AudioChannelService *service = AudioChannelService::GetOrCreateAudioChannelService();
|
||||
callback->CanPlayChanged(service->GetState(this, !mVisible));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,20 @@ AudioChannelService::GetAudioChannelService()
|
|||
return AudioChannelServiceChild::GetAudioChannelService();
|
||||
}
|
||||
|
||||
return gAudioChannelService;
|
||||
|
||||
}
|
||||
|
||||
// static
|
||||
AudioChannelService*
|
||||
AudioChannelService::GetOrCreateAudioChannelService()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
||||
return AudioChannelServiceChild::GetOrCreateAudioChannelService();
|
||||
}
|
||||
|
||||
// If we already exist, exit early
|
||||
if (gAudioChannelService) {
|
||||
return gAudioChannelService;
|
||||
|
@ -65,7 +79,7 @@ AudioChannelService::GetAudioChannelService()
|
|||
|
||||
// Create new instance, register, return
|
||||
nsRefPtr<AudioChannelService> service = new AudioChannelService();
|
||||
NS_ENSURE_TRUE(service, nullptr);
|
||||
MOZ_ASSERT(service);
|
||||
|
||||
gAudioChannelService = service;
|
||||
return gAudioChannelService;
|
||||
|
|
|
@ -36,13 +36,18 @@ public:
|
|||
NS_DECL_NSITIMERCALLBACK
|
||||
|
||||
/**
|
||||
* Returns the AudioChannelServce singleton. Only to be called from main
|
||||
* thread.
|
||||
*
|
||||
* @return NS_OK on proper assignment, NS_ERROR_FAILURE otherwise.
|
||||
* Returns the AudioChannelServce singleton or null if the process havn't create it before.
|
||||
* Only to be called from main thread.
|
||||
*/
|
||||
static AudioChannelService* GetAudioChannelService();
|
||||
|
||||
/**
|
||||
* Returns the AudioChannelServce singleton.
|
||||
* If AudioChannelServce is not exist, create and return new one.
|
||||
* Only to be called from main thread.
|
||||
*/
|
||||
static AudioChannelService* GetOrCreateAudioChannelService();
|
||||
|
||||
/**
|
||||
* Shutdown the singleton.
|
||||
*/
|
||||
|
|
|
@ -32,6 +32,16 @@ AudioChannelServiceChild::GetAudioChannelService()
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
return gAudioChannelServiceChild;
|
||||
|
||||
}
|
||||
|
||||
// static
|
||||
AudioChannelService*
|
||||
AudioChannelServiceChild::GetOrCreateAudioChannelService()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// If we already exist, exit early
|
||||
if (gAudioChannelServiceChild) {
|
||||
return gAudioChannelServiceChild;
|
||||
|
@ -39,7 +49,7 @@ AudioChannelServiceChild::GetAudioChannelService()
|
|||
|
||||
// Create new instance, register, return
|
||||
nsRefPtr<AudioChannelServiceChild> service = new AudioChannelServiceChild();
|
||||
NS_ENSURE_TRUE(service, nullptr);
|
||||
MOZ_ASSERT(service);
|
||||
|
||||
gAudioChannelServiceChild = service;
|
||||
return gAudioChannelServiceChild;
|
||||
|
|
|
@ -21,13 +21,18 @@ class AudioChannelServiceChild : public AudioChannelService
|
|||
public:
|
||||
|
||||
/**
|
||||
* Returns the AudioChannelServce singleton. Only to be called from main
|
||||
* thread.
|
||||
*
|
||||
* @return NS_OK on proper assignment, NS_ERROR_FAILURE otherwise.
|
||||
* Returns the AudioChannelServce singleton or null if the process havn't create it before.
|
||||
* Only to be called from main thread.
|
||||
*/
|
||||
static AudioChannelService* GetAudioChannelService();
|
||||
|
||||
/**
|
||||
* Returns the AudioChannelServce singleton.
|
||||
* If AudioChannelServce is not exist, create and return new one.
|
||||
* Only to be called from main thread.
|
||||
*/
|
||||
static AudioChannelService* GetOrCreateAudioChannelService();
|
||||
|
||||
static void Shutdown();
|
||||
|
||||
virtual void RegisterAudioChannelAgent(AudioChannelAgent* aAgent,
|
||||
|
|
|
@ -3797,11 +3797,9 @@ void
|
|||
nsPIDOMWindow::RefreshMediaElements()
|
||||
{
|
||||
nsRefPtr<AudioChannelService> service =
|
||||
AudioChannelService::GetAudioChannelService();
|
||||
if (service) {
|
||||
AudioChannelService::GetOrCreateAudioChannelService();
|
||||
service->RefreshAgentsVolume(this);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsPIDOMWindow::SendAfterRemotePaintIfRequested()
|
||||
|
|
|
@ -2352,12 +2352,12 @@ ContentParent::RecvAudioChannelGetState(const AudioChannel& aChannel,
|
|||
AudioChannelState* aState)
|
||||
{
|
||||
nsRefPtr<AudioChannelService> service =
|
||||
AudioChannelService::GetAudioChannelService();
|
||||
AudioChannelService::GetOrCreateAudioChannelService();
|
||||
*aState = AUDIO_CHANNEL_STATE_NORMAL;
|
||||
if (service) {
|
||||
MOZ_ASSERT(service);
|
||||
*aState = service->GetStateInternal(aChannel, mChildID,
|
||||
aElementHidden, aElementWasHidden);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2366,10 +2366,10 @@ ContentParent::RecvAudioChannelRegisterType(const AudioChannel& aChannel,
|
|||
const bool& aWithVideo)
|
||||
{
|
||||
nsRefPtr<AudioChannelService> service =
|
||||
AudioChannelService::GetAudioChannelService();
|
||||
if (service) {
|
||||
AudioChannelService::GetOrCreateAudioChannelService();
|
||||
MOZ_ASSERT(service);
|
||||
service->RegisterType(aChannel, mChildID, aWithVideo);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2379,10 +2379,10 @@ ContentParent::RecvAudioChannelUnregisterType(const AudioChannel& aChannel,
|
|||
const bool& aWithVideo)
|
||||
{
|
||||
nsRefPtr<AudioChannelService> service =
|
||||
AudioChannelService::GetAudioChannelService();
|
||||
if (service) {
|
||||
AudioChannelService::GetOrCreateAudioChannelService();
|
||||
MOZ_ASSERT(service);
|
||||
service->UnregisterType(aChannel, aElementHidden, mChildID, aWithVideo);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2390,10 +2390,10 @@ bool
|
|||
ContentParent::RecvAudioChannelChangedNotification()
|
||||
{
|
||||
nsRefPtr<AudioChannelService> service =
|
||||
AudioChannelService::GetAudioChannelService();
|
||||
if (service) {
|
||||
AudioChannelService::GetOrCreateAudioChannelService();
|
||||
MOZ_ASSERT(service);
|
||||
service->SendAudioChannelChangedNotification(ChildID());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2402,11 +2402,10 @@ ContentParent::RecvAudioChannelChangeDefVolChannel(const int32_t& aChannel,
|
|||
const bool& aHidden)
|
||||
{
|
||||
nsRefPtr<AudioChannelService> service =
|
||||
AudioChannelService::GetAudioChannelService();
|
||||
if (service) {
|
||||
AudioChannelService::GetOrCreateAudioChannelService();
|
||||
MOZ_ASSERT(service);
|
||||
service->SetDefaultVolumeControlChannelInternal(aChannel,
|
||||
aHidden, mChildID);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -995,7 +995,7 @@ ParticularProcessPriorityManager::ComputePriority()
|
|||
return PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE;
|
||||
}
|
||||
|
||||
AudioChannelService* service = AudioChannelService::GetAudioChannelService();
|
||||
AudioChannelService* service = AudioChannelService::GetOrCreateAudioChannelService();
|
||||
if (service->ProcessContentOrNormalChannelIsActive(ChildID())) {
|
||||
return PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE;
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ SpeakerManager::HandleEvent(nsIDOMEvent* aEvent)
|
|||
// the background, we switch 'speakerforced' to false.
|
||||
if (!mVisible && mForcespeaker) {
|
||||
AudioChannelService* audioChannelService =
|
||||
AudioChannelService::GetAudioChannelService();
|
||||
AudioChannelService::GetOrCreateAudioChannelService();
|
||||
if (audioChannelService && !audioChannelService->AnyAudioChannelIsActive()) {
|
||||
service->ForceSpeaker(false, mVisible);
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ SpeakerManagerService::SpeakerManagerService()
|
|||
}
|
||||
}
|
||||
AudioChannelService* audioChannelService =
|
||||
AudioChannelService::GetAudioChannelService();
|
||||
AudioChannelService::GetOrCreateAudioChannelService();
|
||||
if (audioChannelService) {
|
||||
audioChannelService->RegisterSpeakerManager(this);
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ SpeakerManagerService::~SpeakerManagerService()
|
|||
{
|
||||
MOZ_COUNT_DTOR(SpeakerManagerService);
|
||||
AudioChannelService* audioChannelService =
|
||||
AudioChannelService::GetAudioChannelService();
|
||||
AudioChannelService::GetOrCreateAudioChannelService();
|
||||
if (audioChannelService)
|
||||
audioChannelService->UnregisterSpeakerManager(this);
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ SpeakerManagerServiceChild::SetAudioChannelActive(bool aIsActive)
|
|||
SpeakerManagerServiceChild::SpeakerManagerServiceChild()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
AudioChannelService* audioChannelService = AudioChannelService::GetAudioChannelService();
|
||||
AudioChannelService* audioChannelService = AudioChannelService::GetOrCreateAudioChannelService();
|
||||
if (audioChannelService) {
|
||||
audioChannelService->RegisterSpeakerManager(this);
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ SpeakerManagerServiceChild::SpeakerManagerServiceChild()
|
|||
|
||||
SpeakerManagerServiceChild::~SpeakerManagerServiceChild()
|
||||
{
|
||||
AudioChannelService* audioChannelService = AudioChannelService::GetAudioChannelService();
|
||||
AudioChannelService* audioChannelService = AudioChannelService::GetOrCreateAudioChannelService();
|
||||
if (audioChannelService) {
|
||||
audioChannelService->UnregisterSpeakerManager(this);
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ AudioChannelManager::NotifyVolumeControlChannelChanged()
|
|||
bool isActive = false;
|
||||
docshell->GetIsActive(&isActive);
|
||||
|
||||
AudioChannelService* service = AudioChannelService::GetAudioChannelService();
|
||||
AudioChannelService* service = AudioChannelService::GetOrCreateAudioChannelService();
|
||||
if (isActive) {
|
||||
service->SetDefaultVolumeControlChannel(mVolumeChannel, isActive);
|
||||
} else {
|
||||
|
|
|
@ -316,8 +316,8 @@ AudioManager::HandleAudioChannelProcessChanged()
|
|||
return;
|
||||
}
|
||||
|
||||
AudioChannelService *service = AudioChannelService::GetAudioChannelService();
|
||||
NS_ENSURE_TRUE_VOID(service);
|
||||
AudioChannelService *service = AudioChannelService::GetOrCreateAudioChannelService();
|
||||
MOZ_ASSERT(service);
|
||||
|
||||
bool telephonyChannelIsActive = service->TelephonyChannelIsActive();
|
||||
telephonyChannelIsActive ? SetPhoneState(PHONE_STATE_IN_COMMUNICATION) :
|
||||
|
|
|
@ -590,7 +590,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(Geolocation, Init)
|
|||
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsGeolocationService, nsGeolocationService::GetGeolocationService)
|
||||
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(AudioChannelService, AudioChannelService::GetAudioChannelService)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(AudioChannelService, AudioChannelService::GetOrCreateAudioChannelService)
|
||||
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(DataStoreService, DataStoreService::GetOrCreate)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче