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.foregroundOomScoreAdjust", 67);
|
||||
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.backgroundHomescreenKillUnderMB", 5);
|
||||
pref("hal.processPriorityManager.gonk.backgroundOomScoreAdjust", 400);
|
||||
|
@ -239,6 +239,12 @@ AudioChannelService::GetMuted(AudioChannelType aType, bool aElementHidden)
|
||||
return muted;
|
||||
}
|
||||
|
||||
bool
|
||||
AudioChannelService::ContentChannelIsActive()
|
||||
{
|
||||
return mChannelCounters[AUDIO_CHANNEL_CONTENT].Length() > 0;
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
NotifyEnumerator(AudioChannelAgent* aAgent,
|
||||
AudioChannelType aType, void* aData)
|
||||
|
@ -53,6 +53,12 @@ public:
|
||||
*/
|
||||
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:
|
||||
void Notify();
|
||||
|
||||
|
@ -12,11 +12,8 @@
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "mozilla/unused.h"
|
||||
#include "mozilla/Util.h"
|
||||
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
|
||||
#include "base/basictypes.h"
|
||||
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
@ -82,6 +79,11 @@ AudioChannelServiceChild::RegisterAudioChannelAgent(AudioChannelAgent* aAgent,
|
||||
if (cc) {
|
||||
cc->SendAudioChannelRegisterType(aType);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->NotifyObservers(nullptr, "audio-channel-agent-changed", nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -98,5 +100,9 @@ AudioChannelServiceChild::UnregisterAudioChannelAgent(AudioChannelAgent* aAgent)
|
||||
if (cc) {
|
||||
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/HalTypes.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "AudioChannelService.h"
|
||||
#include "prlog.h"
|
||||
#include "nsWeakPtr.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
@ -80,6 +81,11 @@ GetPPMLog()
|
||||
ProcessPriority
|
||||
GetBackgroundPriority()
|
||||
{
|
||||
AudioChannelService* service = AudioChannelService::GetAudioChannelService();
|
||||
if (service->ContentChannelIsActive()) {
|
||||
return PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE;
|
||||
}
|
||||
|
||||
bool isHomescreen = false;
|
||||
|
||||
ContentChild* contentChild = ContentChild::GetSingleton();
|
||||
@ -101,6 +107,17 @@ GetBackgroundPriority()
|
||||
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
|
||||
* informs the hal back-end when this process transitions between having no
|
||||
@ -135,6 +152,7 @@ public:
|
||||
|
||||
private:
|
||||
void SetPriority(ProcessPriority aPriority);
|
||||
void OnAudioChannelAgentChanged();
|
||||
void OnContentDocumentGlobalCreated(nsISupports* aOuterWindow);
|
||||
void OnInnerWindowDestroyed();
|
||||
void OnGracePeriodTimerFired();
|
||||
@ -170,6 +188,7 @@ ProcessPriorityManager::Init()
|
||||
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
||||
os->AddObserver(this, "content-document-global-created", /* ownsWeak = */ false);
|
||||
os->AddObserver(this, "inner-window-destroyed", /* ownsWeak = */ false);
|
||||
os->AddObserver(this, "audio-channel-agent-changed", /* ownsWeak = */ false);
|
||||
|
||||
SetPriority(PROCESS_PRIORITY_FOREGROUND);
|
||||
}
|
||||
@ -186,6 +205,8 @@ ProcessPriorityManager::Observe(
|
||||
OnInnerWindowDestroyed();
|
||||
} else if (!strcmp(aTopic, "timer-callback")) {
|
||||
OnGracePeriodTimerFired();
|
||||
} else if (!strcmp(aTopic, "audio-channel-agent-changed")) {
|
||||
OnAudioChannelAgentChanged();
|
||||
} else {
|
||||
MOZ_ASSERT(false);
|
||||
}
|
||||
@ -201,6 +222,14 @@ ProcessPriorityManager::HandleEvent(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
ProcessPriorityManager::OnAudioChannelAgentChanged()
|
||||
{
|
||||
if (IsBackgroundPriority(mProcessPriority)) {
|
||||
SetPriority(GetBackgroundPriority());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ProcessPriorityManager::OnContentDocumentGlobalCreated(
|
||||
nsISupports* aOuterWindow)
|
||||
@ -297,8 +326,7 @@ ProcessPriorityManager::SetPriority(ProcessPriority aPriority)
|
||||
return;
|
||||
}
|
||||
|
||||
if (aPriority == PROCESS_PRIORITY_BACKGROUND ||
|
||||
aPriority == PROCESS_PRIORITY_BACKGROUND_HOMESCREEN) {
|
||||
if (IsBackgroundPriority(aPriority)) {
|
||||
// If this is a foreground --> background transition, give ourselves a
|
||||
// grace period before informing hal.
|
||||
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
|
||||
// in SetPriority(BACKGROUND), and we canceled this timer if there was an
|
||||
// intervening SetPriority(FOREGROUND) call.
|
||||
MOZ_ASSERT(mProcessPriority == PROCESS_PRIORITY_BACKGROUND ||
|
||||
mProcessPriority == PROCESS_PRIORITY_BACKGROUND_HOMESCREEN);
|
||||
MOZ_ASSERT(IsBackgroundPriority(mProcessPriority));
|
||||
|
||||
mGracePeriodTimer = nullptr;
|
||||
hal::SetProcessPriority(getpid(), mProcessPriority);
|
||||
|
@ -70,6 +70,7 @@ typedef Observer<SwitchEvent> SwitchObserver;
|
||||
enum ProcessPriority {
|
||||
PROCESS_PRIORITY_BACKGROUND,
|
||||
PROCESS_PRIORITY_BACKGROUND_HOMESCREEN,
|
||||
PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE,
|
||||
// Any priority greater than or equal to FOREGROUND is considered
|
||||
// "foreground" for the purposes of priority testing, for example
|
||||
// CurrentProcessIsForeground().
|
||||
|
@ -1046,8 +1046,13 @@ EnsureKernelLowMemKillerParamsSet()
|
||||
nsAutoCString adjParams;
|
||||
nsAutoCString minfreeParams;
|
||||
|
||||
const char* priorityClasses[] =
|
||||
{"master", "foreground", "background", "backgroundHomescreen"};
|
||||
const char* priorityClasses[] = {
|
||||
"master",
|
||||
"foreground",
|
||||
"background",
|
||||
"backgroundHomescreen",
|
||||
"backgroundPerceivable"
|
||||
};
|
||||
for (size_t i = 0; i < NS_ARRAY_LENGTH(priorityClasses); i++) {
|
||||
int32_t oomScoreAdj;
|
||||
if (!NS_SUCCEEDED(Preferences::GetInt(nsPrintfCString(
|
||||
@ -1112,6 +1117,9 @@ SetProcessPriority(int aPid, ProcessPriority aPriority)
|
||||
case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN:
|
||||
priorityStr = "backgroundHomescreen";
|
||||
break;
|
||||
case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE:
|
||||
priorityStr = "backgroundPerceivable";
|
||||
break;
|
||||
case PROCESS_PRIORITY_FOREGROUND:
|
||||
priorityStr = "foreground";
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user