From 37ebeead76333cd45227a43f4491be228f606409 Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Thu, 25 Apr 2013 20:53:26 -0400 Subject: [PATCH] Bug 860799 - Part 1: Give frames expecting a system message priority at least BACKGROUND_PERCEIVABLE, so long as either haven't yet handled the system message or are holding the CPU/high-priority wake lock. r=khuey --- dom/ipc/ProcessPriorityManager.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/dom/ipc/ProcessPriorityManager.cpp b/dom/ipc/ProcessPriorityManager.cpp index c6974fb9954..f0d465c96ce 100644 --- a/dom/ipc/ProcessPriorityManager.cpp +++ b/dom/ipc/ProcessPriorityManager.cpp @@ -28,6 +28,7 @@ #include "nsIDOMDocument.h" #include "nsPIDOMWindow.h" #include "StaticPtr.h" +#include "nsIMozBrowserFrame.h" #include "nsIObserver.h" #include "nsITimer.h" #include "nsPrintfCString.h" @@ -228,6 +229,7 @@ public: const nsAutoCString& NameWithComma(); bool HasAppType(const char* aAppType); + bool IsExpectingSystemMessage(); void OnAudioChannelProcessChanged(nsISupports* aSubject); void OnRemoteBrowserFrameShown(nsISupports* aSubject); @@ -702,6 +704,27 @@ ParticularProcessPriorityManager::HasAppType(const char* aAppType) return false; } +bool +ParticularProcessPriorityManager::IsExpectingSystemMessage() +{ + const InfallibleTArray& browsers = + mContentParent->ManagedPBrowserParent(); + for (uint32_t i = 0; i < browsers.Length(); i++) { + TabParent* tp = static_cast(browsers[i]); + nsCOMPtr ownerElement = tp->GetOwnerElement(); + nsCOMPtr bf = do_QueryInterface(ownerElement); + if (!bf) { + continue; + } + + if (bf->GetIsExpectingSystemMessage()) { + return true; + } + } + + return false; +} + ProcessPriority ParticularProcessPriorityManager::ComputePriority() { @@ -724,6 +747,11 @@ ParticularProcessPriorityManager::ComputePriority() return PROCESS_PRIORITY_FOREGROUND; } + if ((mHoldsCPUWakeLock || mHoldsHighPriorityWakeLock) && + IsExpectingSystemMessage()) { + return PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE; + } + AudioChannelService* service = AudioChannelService::GetAudioChannelService(); if (service->ProcessContentOrNormalChannelIsActive(ChildID())) { return PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE;