Bug 1503002 - Don't register WakeLockObserver for ProcessPriorityManagerImpl. r=gsvelto
authorMike Conley <mconley@mozilla.com>
Tue, 08 Jan 2019 22:46:16 +0000
changeset 510069 ec0c3354ab22096f0a80bf3075fa15209fecd6ae
parent 510068 5ecacfcd6e65fe5a1dee88b40ef00ca20c0282e8
child 510070 f4b4aaf49c1980c74cf76dfd0ae853f3c4c510c3
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgsvelto
bugs1503002
milestone66.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 1503002 - Don't register WakeLockObserver for ProcessPriorityManagerImpl. r=gsvelto The WakeLockObserver is being used to set a boolean that's never being read. This also makes it so that dom.ipc.processPriorityManager.enabled can be set to true by default. Without this patch, setting that pref to true by default means that the WakeLockObserver attempts to be registered before Hal has had a chance to initialize which causes an assertion failure. Differential Revision: https://phabricator.services.mozilla.com/D15964
dom/ipc/ProcessPriorityManager.cpp
--- a/dom/ipc/ProcessPriorityManager.cpp
+++ b/dom/ipc/ProcessPriorityManager.cpp
@@ -97,17 +97,16 @@ class ParticularProcessPriorityManager;
  * return null.)
  *
  * ProcessPriorityManager::CurrentProcessIsForeground() and
  * ProcessPriorityManager::AnyProcessHasHighPriority() which can be called in
  * any process, are handled separately, by the ProcessPriorityManagerChild
  * class.
  */
 class ProcessPriorityManagerImpl final : public nsIObserver,
-                                         public WakeLockObserver,
                                          public nsSupportsWeakReference {
  public:
   /**
    * If we're in the main process, get the ProcessPriorityManagerImpl
    * singleton.  If we're in a child process, return null.
    */
   static ProcessPriorityManagerImpl* GetSingleton();
 
@@ -134,30 +133,18 @@ class ProcessPriorityManagerImpl final :
   /**
    * This must be called by a ParticularProcessPriorityManager when it changes
    * its priority.
    */
   void NotifyProcessPriorityChanged(
       ParticularProcessPriorityManager* aParticularManager,
       hal::ProcessPriority aOldPriority);
 
-  /**
-   * Implements WakeLockObserver, used to monitor wake lock changes in the
-   * main process.
-   */
-  virtual void Notify(const WakeLockInformation& aInfo) override;
-
   void TabActivityChanged(TabParent* aTabParent, bool aIsActive);
 
-  /**
-   * Call ShutDown before destroying the ProcessPriorityManager because
-   * WakeLockObserver hols a strong reference to it.
-   */
-  void ShutDown();
-
  private:
   static bool sPrefsEnabled;
   static bool sRemoteTabsDisabled;
   static bool sTestMode;
   static bool sPrefListenersRegistered;
   static bool sInitialized;
   static StaticRefPtr<ProcessPriorityManagerImpl> sSingleton;
 
@@ -173,19 +160,16 @@ class ProcessPriorityManagerImpl final :
   GetParticularProcessPriorityManager(ContentParent* aContentParent);
 
   void ObserveContentParentCreated(nsISupports* aContentParent);
   void ObserveContentParentDestroyed(nsISupports* aSubject);
 
   nsDataHashtable<nsUint64HashKey, RefPtr<ParticularProcessPriorityManager> >
       mParticularManagers;
 
-  /** True if the main process is holding a high-priority wakelock */
-  bool mHighPriority;
-
   /** Contains the PIDs of child processes holding high-priority wakelocks */
   nsTHashtable<nsUint64HashKey> mHighPriorityChildIDs;
 };
 
 /**
  * This singleton class implements the parts of the process priority manager
  * that are available from all processes.
  */
@@ -313,17 +297,16 @@ class ParticularProcessPriorityManager f
 
 NS_IMPL_ISUPPORTS(ProcessPriorityManagerImpl, nsIObserver,
                   nsISupportsWeakReference);
 
 /* static */ void ProcessPriorityManagerImpl::PrefChangedCallback(
     const char* aPref, void* aClosure) {
   StaticInit();
   if (!PrefsEnabled() && sSingleton) {
-    sSingleton->ShutDown();
     sSingleton = nullptr;
     sInitialized = false;
   }
 }
 
 /* static */ bool ProcessPriorityManagerImpl::PrefsEnabled() {
   return sPrefsEnabled && hal::SetProcessPrioritySupported() &&
          !sRemoteTabsDisabled;
@@ -377,27 +360,21 @@ NS_IMPL_ISUPPORTS(ProcessPriorityManager
 ProcessPriorityManagerImpl::GetSingleton() {
   if (!sSingleton) {
     StaticInit();
   }
 
   return sSingleton;
 }
 
-ProcessPriorityManagerImpl::ProcessPriorityManagerImpl()
-    : mHighPriority(false) {
+ProcessPriorityManagerImpl::ProcessPriorityManagerImpl() {
   MOZ_ASSERT(XRE_IsParentProcess());
-  RegisterWakeLockObserver(this);
 }
 
-ProcessPriorityManagerImpl::~ProcessPriorityManagerImpl() { ShutDown(); }
-
-void ProcessPriorityManagerImpl::ShutDown() {
-  UnregisterWakeLockObserver(this);
-}
+ProcessPriorityManagerImpl::~ProcessPriorityManagerImpl() = default;
 
 void ProcessPriorityManagerImpl::Init() {
   LOG("Starting up.  This is the master process.");
 
   // The master process's priority never changes; set it here and then forget
   // about it.  We'll manage only subprocesses' priorities using the process
   // priority manager.
   hal::SetProcessPriority(getpid(), PROCESS_PRIORITY_MASTER);
@@ -488,34 +465,16 @@ void ProcessPriorityManagerImpl::NotifyP
       aOldPriority < PROCESS_PRIORITY_FOREGROUND_HIGH) {
     mHighPriorityChildIDs.PutEntry(aParticularManager->ChildID());
   } else if (newPriority < PROCESS_PRIORITY_FOREGROUND_HIGH &&
              aOldPriority >= PROCESS_PRIORITY_FOREGROUND_HIGH) {
     mHighPriorityChildIDs.RemoveEntry(aParticularManager->ChildID());
   }
 }
 
-/* virtual */ void ProcessPriorityManagerImpl::Notify(
-    const WakeLockInformation& aInfo) {
-  /* The main process always has an ID of 0, if it is present in the wake-lock
-   * information then we explicitly requested a high-priority wake-lock for the
-   * main process. */
-  if (aInfo.topic().EqualsLiteral("high-priority")) {
-    if (aInfo.lockingProcesses().Contains((uint64_t)0)) {
-      mHighPriority = true;
-    } else {
-      mHighPriority = false;
-    }
-
-    LOG("Got wake lock changed event. "
-        "Now mHighPriorityParent = %d\n",
-        mHighPriority);
-  }
-}
-
 void ProcessPriorityManagerImpl::TabActivityChanged(TabParent* aTabParent,
                                                     bool aIsActive) {
   ContentParent* cp = aTabParent->Manager()->AsContentParent();
   RefPtr<ParticularProcessPriorityManager> pppm =
       GetParticularProcessPriorityManager(cp);
   if (!pppm) {
     return;
   }