mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 793105 - Add a "backgroundPerceivable" class for audio-channel-content. r=jlebar,roc
This commit is contained in:
parent
2ad944e28e
commit
f34bb3f29c
@ -544,6 +544,8 @@ pref("hal.processPriorityManager.gonk.masterOomScoreAdjust", 0);
|
|||||||
pref("hal.processPriorityManager.gonk.masterKillUnderMB", 1);
|
pref("hal.processPriorityManager.gonk.masterKillUnderMB", 1);
|
||||||
pref("hal.processPriorityManager.gonk.foregroundOomScoreAdjust", 67);
|
pref("hal.processPriorityManager.gonk.foregroundOomScoreAdjust", 67);
|
||||||
pref("hal.processPriorityManager.gonk.foregroundKillUnderMB", 4);
|
pref("hal.processPriorityManager.gonk.foregroundKillUnderMB", 4);
|
||||||
|
pref("hal.processPriorityManager.gonk.backgroundPerceivableOomScoreAdjust", 134);
|
||||||
|
pref("hal.processPriorityManager.gonk.backgroundPerceivebleKillUnderMB", 5);
|
||||||
pref("hal.processPriorityManager.gonk.backgroundHomescreenOomScoreAdjust", 200);
|
pref("hal.processPriorityManager.gonk.backgroundHomescreenOomScoreAdjust", 200);
|
||||||
pref("hal.processPriorityManager.gonk.backgroundHomescreenKillUnderMB", 5);
|
pref("hal.processPriorityManager.gonk.backgroundHomescreenKillUnderMB", 5);
|
||||||
pref("hal.processPriorityManager.gonk.backgroundOomScoreAdjust", 400);
|
pref("hal.processPriorityManager.gonk.backgroundOomScoreAdjust", 400);
|
||||||
|
@ -239,6 +239,12 @@ AudioChannelService::GetMuted(AudioChannelType aType, bool aElementHidden)
|
|||||||
return muted;
|
return muted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
AudioChannelService::ContentChannelIsActive()
|
||||||
|
{
|
||||||
|
return mChannelCounters[AUDIO_CHANNEL_CONTENT].Length() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
static PLDHashOperator
|
static PLDHashOperator
|
||||||
NotifyEnumerator(AudioChannelAgent* aAgent,
|
NotifyEnumerator(AudioChannelAgent* aAgent,
|
||||||
AudioChannelType aType, void* aData)
|
AudioChannelType aType, void* aData)
|
||||||
|
@ -53,6 +53,12 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual bool GetMuted(AudioChannelType aType, bool aElementHidden);
|
virtual bool GetMuted(AudioChannelType aType, bool aElementHidden);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if there is a content channel active in this process
|
||||||
|
* or one of its subprocesses.
|
||||||
|
*/
|
||||||
|
virtual bool ContentChannelIsActive();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Notify();
|
void Notify();
|
||||||
|
|
||||||
|
@ -12,11 +12,8 @@
|
|||||||
#include "mozilla/StaticPtr.h"
|
#include "mozilla/StaticPtr.h"
|
||||||
#include "mozilla/unused.h"
|
#include "mozilla/unused.h"
|
||||||
#include "mozilla/Util.h"
|
#include "mozilla/Util.h"
|
||||||
|
|
||||||
#include "mozilla/dom/ContentChild.h"
|
#include "mozilla/dom/ContentChild.h"
|
||||||
|
#include "nsIObserverService.h"
|
||||||
#include "base/basictypes.h"
|
|
||||||
|
|
||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
@ -82,6 +79,11 @@ AudioChannelServiceChild::RegisterAudioChannelAgent(AudioChannelAgent* aAgent,
|
|||||||
if (cc) {
|
if (cc) {
|
||||||
cc->SendAudioChannelRegisterType(aType);
|
cc->SendAudioChannelRegisterType(aType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||||
|
if (obs) {
|
||||||
|
obs->NotifyObservers(nullptr, "audio-channel-agent-changed", nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -98,5 +100,9 @@ AudioChannelServiceChild::UnregisterAudioChannelAgent(AudioChannelAgent* aAgent)
|
|||||||
if (cc) {
|
if (cc) {
|
||||||
cc->SendAudioChannelUnregisterType(type);
|
cc->SendAudioChannelUnregisterType(type);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||||
|
if (obs) {
|
||||||
|
obs->NotifyObservers(nullptr, "audio-channel-agent-changed", nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "mozilla/Services.h"
|
#include "mozilla/Services.h"
|
||||||
#include "mozilla/HalTypes.h"
|
#include "mozilla/HalTypes.h"
|
||||||
#include "mozilla/TimeStamp.h"
|
#include "mozilla/TimeStamp.h"
|
||||||
|
#include "AudioChannelService.h"
|
||||||
#include "prlog.h"
|
#include "prlog.h"
|
||||||
#include "nsWeakPtr.h"
|
#include "nsWeakPtr.h"
|
||||||
#include "nsXULAppAPI.h"
|
#include "nsXULAppAPI.h"
|
||||||
@ -80,6 +81,11 @@ GetPPMLog()
|
|||||||
ProcessPriority
|
ProcessPriority
|
||||||
GetBackgroundPriority()
|
GetBackgroundPriority()
|
||||||
{
|
{
|
||||||
|
AudioChannelService* service = AudioChannelService::GetAudioChannelService();
|
||||||
|
if (service->ContentChannelIsActive()) {
|
||||||
|
return PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE;
|
||||||
|
}
|
||||||
|
|
||||||
bool isHomescreen = false;
|
bool isHomescreen = false;
|
||||||
|
|
||||||
ContentChild* contentChild = ContentChild::GetSingleton();
|
ContentChild* contentChild = ContentChild::GetSingleton();
|
||||||
@ -101,6 +107,17 @@ GetBackgroundPriority()
|
|||||||
PROCESS_PRIORITY_BACKGROUND;
|
PROCESS_PRIORITY_BACKGROUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the priority is a backround priority.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
IsBackgroundPriority(ProcessPriority aPriority)
|
||||||
|
{
|
||||||
|
return (aPriority == PROCESS_PRIORITY_BACKGROUND ||
|
||||||
|
aPriority == PROCESS_PRIORITY_BACKGROUND_HOMESCREEN ||
|
||||||
|
aPriority == PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class listens to window creation and visibilitychange events and
|
* This class listens to window creation and visibilitychange events and
|
||||||
* informs the hal back-end when this process transitions between having no
|
* informs the hal back-end when this process transitions between having no
|
||||||
@ -135,6 +152,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void SetPriority(ProcessPriority aPriority);
|
void SetPriority(ProcessPriority aPriority);
|
||||||
|
void OnAudioChannelAgentChanged();
|
||||||
void OnContentDocumentGlobalCreated(nsISupports* aOuterWindow);
|
void OnContentDocumentGlobalCreated(nsISupports* aOuterWindow);
|
||||||
void OnInnerWindowDestroyed();
|
void OnInnerWindowDestroyed();
|
||||||
void OnGracePeriodTimerFired();
|
void OnGracePeriodTimerFired();
|
||||||
@ -170,6 +188,7 @@ ProcessPriorityManager::Init()
|
|||||||
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
||||||
os->AddObserver(this, "content-document-global-created", /* ownsWeak = */ false);
|
os->AddObserver(this, "content-document-global-created", /* ownsWeak = */ false);
|
||||||
os->AddObserver(this, "inner-window-destroyed", /* ownsWeak = */ false);
|
os->AddObserver(this, "inner-window-destroyed", /* ownsWeak = */ false);
|
||||||
|
os->AddObserver(this, "audio-channel-agent-changed", /* ownsWeak = */ false);
|
||||||
|
|
||||||
SetPriority(PROCESS_PRIORITY_FOREGROUND);
|
SetPriority(PROCESS_PRIORITY_FOREGROUND);
|
||||||
}
|
}
|
||||||
@ -186,6 +205,8 @@ ProcessPriorityManager::Observe(
|
|||||||
OnInnerWindowDestroyed();
|
OnInnerWindowDestroyed();
|
||||||
} else if (!strcmp(aTopic, "timer-callback")) {
|
} else if (!strcmp(aTopic, "timer-callback")) {
|
||||||
OnGracePeriodTimerFired();
|
OnGracePeriodTimerFired();
|
||||||
|
} else if (!strcmp(aTopic, "audio-channel-agent-changed")) {
|
||||||
|
OnAudioChannelAgentChanged();
|
||||||
} else {
|
} else {
|
||||||
MOZ_ASSERT(false);
|
MOZ_ASSERT(false);
|
||||||
}
|
}
|
||||||
@ -201,6 +222,14 @@ ProcessPriorityManager::HandleEvent(
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ProcessPriorityManager::OnAudioChannelAgentChanged()
|
||||||
|
{
|
||||||
|
if (IsBackgroundPriority(mProcessPriority)) {
|
||||||
|
SetPriority(GetBackgroundPriority());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ProcessPriorityManager::OnContentDocumentGlobalCreated(
|
ProcessPriorityManager::OnContentDocumentGlobalCreated(
|
||||||
nsISupports* aOuterWindow)
|
nsISupports* aOuterWindow)
|
||||||
@ -297,8 +326,7 @@ ProcessPriorityManager::SetPriority(ProcessPriority aPriority)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aPriority == PROCESS_PRIORITY_BACKGROUND ||
|
if (IsBackgroundPriority(aPriority)) {
|
||||||
aPriority == PROCESS_PRIORITY_BACKGROUND_HOMESCREEN) {
|
|
||||||
// If this is a foreground --> background transition, give ourselves a
|
// If this is a foreground --> background transition, give ourselves a
|
||||||
// grace period before informing hal.
|
// grace period before informing hal.
|
||||||
uint32_t gracePeriodMS = Preferences::GetUint("dom.ipc.processPriorityManager.gracePeriodMS", 1000);
|
uint32_t gracePeriodMS = Preferences::GetUint("dom.ipc.processPriorityManager.gracePeriodMS", 1000);
|
||||||
@ -345,8 +373,7 @@ ProcessPriorityManager::OnGracePeriodTimerFired()
|
|||||||
// mProcessPriority should already be one of the BACKGROUND values: We set it
|
// mProcessPriority should already be one of the BACKGROUND values: We set it
|
||||||
// in SetPriority(BACKGROUND), and we canceled this timer if there was an
|
// in SetPriority(BACKGROUND), and we canceled this timer if there was an
|
||||||
// intervening SetPriority(FOREGROUND) call.
|
// intervening SetPriority(FOREGROUND) call.
|
||||||
MOZ_ASSERT(mProcessPriority == PROCESS_PRIORITY_BACKGROUND ||
|
MOZ_ASSERT(IsBackgroundPriority(mProcessPriority));
|
||||||
mProcessPriority == PROCESS_PRIORITY_BACKGROUND_HOMESCREEN);
|
|
||||||
|
|
||||||
mGracePeriodTimer = nullptr;
|
mGracePeriodTimer = nullptr;
|
||||||
hal::SetProcessPriority(getpid(), mProcessPriority);
|
hal::SetProcessPriority(getpid(), mProcessPriority);
|
||||||
|
@ -70,6 +70,7 @@ typedef Observer<SwitchEvent> SwitchObserver;
|
|||||||
enum ProcessPriority {
|
enum ProcessPriority {
|
||||||
PROCESS_PRIORITY_BACKGROUND,
|
PROCESS_PRIORITY_BACKGROUND,
|
||||||
PROCESS_PRIORITY_BACKGROUND_HOMESCREEN,
|
PROCESS_PRIORITY_BACKGROUND_HOMESCREEN,
|
||||||
|
PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE,
|
||||||
// Any priority greater than or equal to FOREGROUND is considered
|
// Any priority greater than or equal to FOREGROUND is considered
|
||||||
// "foreground" for the purposes of priority testing, for example
|
// "foreground" for the purposes of priority testing, for example
|
||||||
// CurrentProcessIsForeground().
|
// CurrentProcessIsForeground().
|
||||||
|
@ -1046,8 +1046,13 @@ EnsureKernelLowMemKillerParamsSet()
|
|||||||
nsAutoCString adjParams;
|
nsAutoCString adjParams;
|
||||||
nsAutoCString minfreeParams;
|
nsAutoCString minfreeParams;
|
||||||
|
|
||||||
const char* priorityClasses[] =
|
const char* priorityClasses[] = {
|
||||||
{"master", "foreground", "background", "backgroundHomescreen"};
|
"master",
|
||||||
|
"foreground",
|
||||||
|
"background",
|
||||||
|
"backgroundHomescreen",
|
||||||
|
"backgroundPerceivable"
|
||||||
|
};
|
||||||
for (size_t i = 0; i < NS_ARRAY_LENGTH(priorityClasses); i++) {
|
for (size_t i = 0; i < NS_ARRAY_LENGTH(priorityClasses); i++) {
|
||||||
int32_t oomScoreAdj;
|
int32_t oomScoreAdj;
|
||||||
if (!NS_SUCCEEDED(Preferences::GetInt(nsPrintfCString(
|
if (!NS_SUCCEEDED(Preferences::GetInt(nsPrintfCString(
|
||||||
@ -1112,6 +1117,9 @@ SetProcessPriority(int aPid, ProcessPriority aPriority)
|
|||||||
case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN:
|
case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN:
|
||||||
priorityStr = "backgroundHomescreen";
|
priorityStr = "backgroundHomescreen";
|
||||||
break;
|
break;
|
||||||
|
case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE:
|
||||||
|
priorityStr = "backgroundPerceivable";
|
||||||
|
break;
|
||||||
case PROCESS_PRIORITY_FOREGROUND:
|
case PROCESS_PRIORITY_FOREGROUND:
|
||||||
priorityStr = "foreground";
|
priorityStr = "foreground";
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user