Bug 1368941 - Remove gonk specific code from ProcessPriorityManager, r=gsvelto
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 31 May 2017 21:23:52 +0200
changeset 361598 b0ebe9dd56aeae5db543e72156886bf2404d90c1
parent 361597 7d9c81795eeda760c11c4c8eb217cfecb7699d01
child 361599 fc6012cad03e870b46ce4ddc2077762c31f8f9b7
push id90898
push useramarchesini@mozilla.com
push dateWed, 31 May 2017 19:24:12 +0000
treeherdermozilla-inbound@b0ebe9dd56ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgsvelto
bugs1368941
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1368941 - Remove gonk specific code from ProcessPriorityManager, r=gsvelto
dom/ipc/ProcessPriorityManager.cpp
dom/ipc/ProcessPriorityManager.h
widget/gonk/GonkMemoryPressureMonitoring.cpp
--- a/dom/ipc/ProcessPriorityManager.cpp
+++ b/dom/ipc/ProcessPriorityManager.cpp
@@ -131,21 +131,16 @@ public:
   /**
    * If a magic testing-only pref is set, notify the observer service on the
    * given topic with the given data.  This is used for testing
    */
   void FireTestOnlyObserverNotification(const char* aTopic,
                                         const nsACString& aData = EmptyCString());
 
   /**
-   * Does one of the child processes have priority FOREGROUND_HIGH?
-   */
-  bool ChildProcessHasHighPriority();
-
-  /**
    * This must be called by a ParticularProcessPriorityManager when it changes
    * its priority.
    */
   void NotifyProcessPriorityChanged(
     ParticularProcessPriorityManager* aParticularManager,
     hal::ProcessPriority aOldPriority);
 
   /**
@@ -202,17 +197,16 @@ class ProcessPriorityManagerChild final
 public:
   static void StaticInit();
   static ProcessPriorityManagerChild* Singleton();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
 
   bool CurrentProcessIsForeground();
-  bool CurrentProcessIsHighPriority();
 
 private:
   static StaticRefPtr<ProcessPriorityManagerChild> sSingleton;
 
   ProcessPriorityManagerChild();
   ~ProcessPriorityManagerChild() {}
   DISALLOW_EVIL_CONSTRUCTORS(ProcessPriorityManagerChild);
 
@@ -252,18 +246,16 @@ public:
    * returns an empty string.
    *
    * The reference returned here is guaranteed to be live until the next call
    * to NameWithComma() or until the ParticularProcessPriorityManager is
    * destroyed, whichever comes first.
    */
   const nsAutoCString& NameWithComma();
 
-  bool IsExpectingSystemMessage();
-
   void OnRemoteBrowserFrameShown(nsISupports* aSubject);
   void OnTabParentDestroyed(nsISupports* aSubject);
   void OnActivityOpened(const char16_t* aData);
   void OnActivityClosed(const char16_t* aData);
 
   ProcessPriority CurrentPriority();
   ProcessPriority ComputePriority();
 
@@ -510,22 +502,16 @@ ProcessPriorityManagerImpl::ObserveConte
     pppm->ShutDown();
 
     mParticularManagers.Remove(childID);
 
     mHighPriorityChildIDs.RemoveEntry(childID);
   }
 }
 
-bool
-ProcessPriorityManagerImpl::ChildProcessHasHighPriority( void )
-{
-  return mHighPriorityChildIDs.Count() > 0;
-}
-
 void
 ProcessPriorityManagerImpl::NotifyProcessPriorityChanged(
   ParticularProcessPriorityManager* aParticularManager,
   ProcessPriority aOldPriority)
 {
   ProcessPriority newPriority = aParticularManager->CurrentPriority();
 
   if (newPriority >= PROCESS_PRIORITY_FOREGROUND_HIGH &&
@@ -833,46 +819,29 @@ NS_IMETHODIMP
 ParticularProcessPriorityManager::Notify(nsITimer* aTimer)
 {
   LOGP("Reset priority timer callback; about to ResetPriorityNow.");
   ResetPriorityNow();
   mResetPriorityTimer = nullptr;
   return NS_OK;
 }
 
-bool
-ParticularProcessPriorityManager::IsExpectingSystemMessage()
-{
-  const ManagedContainer<PBrowserParent>& browsers =
-    mContentParent->ManagedPBrowserParent();
-  for (auto iter = browsers.ConstIter(); !iter.Done(); iter.Next()) {
-    TabParent* tp = TabParent::GetFrom(iter.Get()->GetKey());
-    nsCOMPtr<nsIMozBrowserFrame> bf = do_QueryInterface(tp->GetOwnerElement());
-    if (!bf) {
-      continue;
-    }
-  }
-
-  return false;
-}
-
 ProcessPriority
 ParticularProcessPriorityManager::CurrentPriority()
 {
   return mPriority;
 }
 
 ProcessPriority
 ParticularProcessPriorityManager::ComputePriority()
 {
   // TODO...
   return PROCESS_PRIORITY_FOREGROUND;
 
-  if ((mHoldsCPUWakeLock || mHoldsHighPriorityWakeLock) &&
-      IsExpectingSystemMessage()) {
+  if (mHoldsCPUWakeLock || mHoldsHighPriorityWakeLock) {
     return PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE;
   }
 
   return mIsActivityOpener ? PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE
                            : PROCESS_PRIORITY_BACKGROUND;
 }
 
 void
@@ -1003,18 +972,17 @@ ProcessPriorityManagerChild::StaticInit(
 
 /* static */ ProcessPriorityManagerChild*
 ProcessPriorityManagerChild::Singleton()
 {
   StaticInit();
   return sSingleton;
 }
 
-NS_IMPL_ISUPPORTS(ProcessPriorityManagerChild,
-                  nsIObserver)
+NS_IMPL_ISUPPORTS(ProcessPriorityManagerChild, nsIObserver)
 
 ProcessPriorityManagerChild::ProcessPriorityManagerChild()
 {
   if (XRE_IsParentProcess()) {
     mCachedPriority = PROCESS_PRIORITY_MASTER;
   } else {
     mCachedPriority = PROCESS_PRIORITY_UNKNOWN;
   }
@@ -1028,20 +996,19 @@ ProcessPriorityManagerChild::Init()
   if (!XRE_IsParentProcess()) {
     nsCOMPtr<nsIObserverService> os = services::GetObserverService();
     NS_ENSURE_TRUE_VOID(os);
     os->AddObserver(this, "ipc:process-priority-changed", /* weak = */ false);
   }
 }
 
 NS_IMETHODIMP
-ProcessPriorityManagerChild::Observe(
-  nsISupports* aSubject,
-  const char* aTopic,
-  const char16_t* aData)
+ProcessPriorityManagerChild::Observe(nsISupports* aSubject,
+                                     const char* aTopic,
+                                     const char16_t* aData)
 {
   MOZ_ASSERT(!strcmp(aTopic, "ipc:process-priority-changed"));
 
   nsCOMPtr<nsIPropertyBag2> props = do_QueryInterface(aSubject);
   NS_ENSURE_TRUE(props, NS_OK);
 
   int32_t priority = static_cast<int32_t>(PROCESS_PRIORITY_UNKNOWN);
   props->GetPropertyAsInt32(NS_LITERAL_STRING("priority"), &priority);
@@ -1054,23 +1021,16 @@ ProcessPriorityManagerChild::Observe(
 
 bool
 ProcessPriorityManagerChild::CurrentProcessIsForeground()
 {
   return mCachedPriority == PROCESS_PRIORITY_UNKNOWN ||
          mCachedPriority >= PROCESS_PRIORITY_FOREGROUND;
 }
 
-bool
-ProcessPriorityManagerChild::CurrentProcessIsHighPriority()
-{
-  return mCachedPriority == PROCESS_PRIORITY_UNKNOWN ||
-         mCachedPriority >= PROCESS_PRIORITY_FOREGROUND_HIGH;
-}
-
 } // namespace
 
 namespace mozilla {
 
 /* static */ void
 ProcessPriorityManager::Init()
 {
   ProcessPriorityManagerImpl::StaticInit();
@@ -1093,23 +1053,9 @@ ProcessPriorityManager::SetProcessPriori
 
 /* static */ bool
 ProcessPriorityManager::CurrentProcessIsForeground()
 {
   return ProcessPriorityManagerChild::Singleton()->
     CurrentProcessIsForeground();
 }
 
-/* static */ bool
-ProcessPriorityManager::AnyProcessHasHighPriority()
-{
-  ProcessPriorityManagerImpl* singleton =
-    ProcessPriorityManagerImpl::GetSingleton();
-
-  if (singleton) {
-    return singleton->ChildProcessHasHighPriority();
-  } else {
-    return ProcessPriorityManagerChild::Singleton()->
-      CurrentProcessIsHighPriority();
-  }
-}
-
 } // namespace mozilla
--- a/dom/ipc/ProcessPriorityManager.h
+++ b/dom/ipc/ProcessPriorityManager.h
@@ -63,22 +63,16 @@ public:
    * Returns true iff this process's priority is FOREGROUND*.
    *
    * Note that because process priorities are set in the main process, it's
    * possible for this method to return a stale value.  So be careful about
    * what you use this for.
    */
   static bool CurrentProcessIsForeground();
 
-  /**
-   * Returns true if one or more processes with FOREGROUND_HIGH priority are
-   * present, false otherwise.
-   */
-  static bool AnyProcessHasHighPriority();
-
 private:
   ProcessPriorityManager();
   DISALLOW_EVIL_CONSTRUCTORS(ProcessPriorityManager);
 };
 
 } // namespace mozilla
 
 #endif
--- a/widget/gonk/GonkMemoryPressureMonitoring.cpp
+++ b/widget/gonk/GonkMemoryPressureMonitoring.cpp
@@ -305,27 +305,23 @@ private:
       return -1; // Trigger adjusted, wait indefinitely.
     }
 
     // Wait again but double the duration, max once per day.
     return std::min(86400000, timeout * 2);
   }
 
   /**
-   * Dispatch the specified memory pressure event unless a high-priority
-   * process is present. If a high-priority process is present then it's likely
-   * responding to an urgent event (an incoming call or message for example) so
-   * avoid wasting CPU time responding to low-memory events.
+   * Dispatch the specified memory pressure event. If a high-priority process is
+   * present then it's likely responding to an urgent event (an incoming call or
+   * message for example) so avoid wasting CPU time responding to low-memory
+   * events.
    */
   nsresult DispatchMemoryPressure(MemoryPressureState state)
   {
-    if (ProcessPriorityManager::AnyProcessHasHighPriority()) {
-      return NS_OK;
-    }
-
     return NS_DispatchMemoryPressure(state);
   }
 
   Monitor mMonitor;
   uint32_t mPollMS; // Ongoing pressure poll delay
   uint32_t mSoftLowMemTriggerKB; // Soft memory pressure level
   uint32_t mHardLowMemTriggerKB; // Hard memory pressure level
   uint32_t mLowMemTriggerKB; // Current value of the trigger