Bug 1368666 - Get rid of screen-state-changed observer in ProcessPriorityManager, r=gsvelto
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 30 May 2017 16:27:12 +0200
changeset 409462 bdd60aea3628df3d39dd3b5e9a35676c613ca084
parent 409461 a11d2a3c75a03725c439ccc5de5e857a43cee969
child 409463 0fbbdadea65d7320ed0df17c0d8a4093eb988f0b
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgsvelto
bugs1368666
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 1368666 - Get rid of screen-state-changed observer in ProcessPriorityManager, r=gsvelto
dom/ipc/ProcessPriorityManager.cpp
widget/gonk/nsScreenManagerGonk.cpp
--- a/dom/ipc/ProcessPriorityManager.cpp
+++ b/dom/ipc/ProcessPriorityManager.cpp
@@ -150,55 +150,42 @@ public:
 
   /**
    * Implements WakeLockObserver, used to monitor wake lock changes in the
    * main process.
    */
   virtual void Notify(const WakeLockInformation& aInfo) override;
 
   /**
-   * Prevents processes from changing priority until unfrozen.
-   */
-  void Freeze();
-
-  /**
-   * Allow process' priorities to change again.  This will immediately adjust
-   * processes whose priority change did not happen because of the freeze.
-   */
-  void Unfreeze();
-
-  /**
    * 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 bool sFrozen;
   static StaticRefPtr<ProcessPriorityManagerImpl> sSingleton;
 
   static void PrefChangedCallback(const char* aPref, void* aClosure);
 
   ProcessPriorityManagerImpl();
   ~ProcessPriorityManagerImpl();
   DISALLOW_EVIL_CONSTRUCTORS(ProcessPriorityManagerImpl);
 
   void Init();
 
   already_AddRefed<ParticularProcessPriorityManager>
   GetParticularProcessPriorityManager(ContentParent* aContentParent);
 
   void ObserveContentParentCreated(nsISupports* aContentParent);
   void ObserveContentParentDestroyed(nsISupports* aSubject);
-  void ObserveScreenStateChanged(const char16_t* aData);
 
   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 */
@@ -241,18 +228,17 @@ private:
 class ParticularProcessPriorityManager final
   : public WakeLockObserver
   , public nsIObserver
   , public nsITimerCallback
   , public nsSupportsWeakReference
 {
   ~ParticularProcessPriorityManager();
 public:
-  explicit ParticularProcessPriorityManager(ContentParent* aContentParent,
-                                            bool aFrozen = false);
+  explicit ParticularProcessPriorityManager(ContentParent* aContentParent);
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
   NS_DECL_NSITIMERCALLBACK
 
   virtual void Notify(const WakeLockInformation& aInfo) override;
   static void StaticInit();
   void Init();
@@ -286,18 +272,16 @@ public:
     BACKGROUND_PERCEIVABLE_GRACE_PERIOD,
     BACKGROUND_GRACE_PERIOD,
   };
 
   void ScheduleResetPriority(TimeoutPref aTimeoutPref);
   void ResetPriority();
   void ResetPriorityNow();
   void SetPriorityNow(ProcessPriority aPriority);
-  void Freeze();
-  void Unfreeze();
 
   void ShutDown();
 
 private:
   static uint32_t sBackgroundPerceivableGracePeriodMS;
   static uint32_t sBackgroundGracePeriodMS;
 
   void FireTestOnlyObserverNotification(
@@ -309,32 +293,30 @@ private:
     const char* aData = nullptr);
 
   ContentParent* mContentParent;
   uint64_t mChildID;
   ProcessPriority mPriority;
   bool mHoldsCPUWakeLock;
   bool mHoldsHighPriorityWakeLock;
   bool mIsActivityOpener;
-  bool mFrozen;
 
   /**
    * Used to implement NameWithComma().
    */
   nsAutoCString mNameWithComma;
 
   nsCOMPtr<nsITimer> mResetPriorityTimer;
 };
 
 /* static */ bool ProcessPriorityManagerImpl::sInitialized = false;
 /* static */ bool ProcessPriorityManagerImpl::sPrefsEnabled = false;
 /* static */ bool ProcessPriorityManagerImpl::sRemoteTabsDisabled = true;
 /* static */ bool ProcessPriorityManagerImpl::sTestMode = false;
 /* static */ bool ProcessPriorityManagerImpl::sPrefListenersRegistered = false;
-/* static */ bool ProcessPriorityManagerImpl::sFrozen = false;
 /* static */ StaticRefPtr<ProcessPriorityManagerImpl>
   ProcessPriorityManagerImpl::sSingleton;
 /* static */ uint32_t ParticularProcessPriorityManager::sBackgroundPerceivableGracePeriodMS = 0;
 /* static */ uint32_t ParticularProcessPriorityManager::sBackgroundGracePeriodMS = 0;
 
 NS_IMPL_ISUPPORTS(ProcessPriorityManagerImpl,
                   nsIObserver,
                   nsISupportsWeakReference);
@@ -445,49 +427,46 @@ ProcessPriorityManagerImpl::Init()
   // about it.  We'll manage only subprocesses' priorities using the process
   // priority manager.
   hal::SetProcessPriority(getpid(), PROCESS_PRIORITY_MASTER);
 
   nsCOMPtr<nsIObserverService> os = services::GetObserverService();
   if (os) {
     os->AddObserver(this, "ipc:content-created", /* ownsWeak */ true);
     os->AddObserver(this, "ipc:content-shutdown", /* ownsWeak */ true);
-    os->AddObserver(this, "screen-state-changed", /* ownsWeak */ true);
   }
 }
 
 NS_IMETHODIMP
 ProcessPriorityManagerImpl::Observe(
   nsISupports* aSubject,
   const char* aTopic,
   const char16_t* aData)
 {
   nsDependentCString topic(aTopic);
   if (topic.EqualsLiteral("ipc:content-created")) {
     ObserveContentParentCreated(aSubject);
   } else if (topic.EqualsLiteral("ipc:content-shutdown")) {
     ObserveContentParentDestroyed(aSubject);
-  } else if (topic.EqualsLiteral("screen-state-changed")) {
-    ObserveScreenStateChanged(aData);
   } else {
     MOZ_ASSERT(false);
   }
 
   return NS_OK;
 }
 
 already_AddRefed<ParticularProcessPriorityManager>
 ProcessPriorityManagerImpl::GetParticularProcessPriorityManager(
   ContentParent* aContentParent)
 {
   RefPtr<ParticularProcessPriorityManager> pppm;
   uint64_t cpId = aContentParent->ChildID();
   mParticularManagers.Get(cpId, &pppm);
   if (!pppm) {
-    pppm = new ParticularProcessPriorityManager(aContentParent, sFrozen);
+    pppm = new ParticularProcessPriorityManager(aContentParent);
     pppm->Init();
     mParticularManagers.Put(cpId, pppm);
 
     FireTestOnlyObserverNotification("process-created",
       nsPrintfCString("%" PRIu64, cpId));
   }
 
   return pppm.forget();
@@ -532,32 +511,16 @@ ProcessPriorityManagerImpl::ObserveConte
     pppm->ShutDown();
 
     mParticularManagers.Remove(childID);
 
     mHighPriorityChildIDs.RemoveEntry(childID);
   }
 }
 
-void
-ProcessPriorityManagerImpl::ObserveScreenStateChanged(const char16_t* aData)
-{
-  if (NS_LITERAL_STRING("on").Equals(aData)) {
-    sFrozen = false;
-    for (auto iter = mParticularManagers.Iter(); !iter.Done(); iter.Next()) {
-      iter.UserData()->Unfreeze();
-    }
-  } else {
-    sFrozen = true;
-    for (auto iter = mParticularManagers.Iter(); !iter.Done(); iter.Next()) {
-      iter.UserData()->Freeze();
-    }
-  }
-}
-
 bool
 ProcessPriorityManagerImpl::ChildProcessHasHighPriority( void )
 {
   return mHighPriorityChildIDs.Count() > 0;
 }
 
 void
 ProcessPriorityManagerImpl::NotifyProcessPriorityChanged(
@@ -594,24 +557,23 @@ ProcessPriorityManagerImpl::Notify(const
 }
 
 NS_IMPL_ISUPPORTS(ParticularProcessPriorityManager,
                   nsIObserver,
                   nsITimerCallback,
                   nsISupportsWeakReference);
 
 ParticularProcessPriorityManager::ParticularProcessPriorityManager(
-  ContentParent* aContentParent, bool aFrozen)
+  ContentParent* aContentParent)
   : mContentParent(aContentParent)
   , mChildID(aContentParent->ChildID())
   , mPriority(PROCESS_PRIORITY_UNKNOWN)
   , mHoldsCPUWakeLock(false)
   , mHoldsHighPriorityWakeLock(false)
   , mIsActivityOpener(false)
-  , mFrozen(aFrozen)
 {
   MOZ_ASSERT(XRE_IsParentProcess());
   LOGP("Creating ParticularProcessPriorityManager.");
 }
 
 void
 ParticularProcessPriorityManager::StaticInit()
 {
@@ -794,20 +756,16 @@ ParticularProcessPriorityManager::OnTabP
 }
 
 void
 ParticularProcessPriorityManager::OnFrameloaderVisibleChanged(nsISupports* aSubject)
 {
   nsCOMPtr<nsIFrameLoader> fl = do_QueryInterface(aSubject);
   NS_ENSURE_TRUE_VOID(fl);
 
-  if (mFrozen) {
-    return; // Ignore visibility changes when the screen is off
-  }
-
   TabParent* tp = TabParent::GetFrom(fl);
   if (!tp) {
     return;
   }
 
   MOZ_ASSERT(XRE_IsParentProcess());
   if (tp->Manager() != mContentParent) {
     return;
@@ -969,17 +927,16 @@ ParticularProcessPriorityManager::SetPri
 {
   if (aPriority == PROCESS_PRIORITY_UNKNOWN) {
     MOZ_ASSERT(false);
     return;
   }
 
   if (!ProcessPriorityManagerImpl::PrefsEnabled() ||
       !mContentParent ||
-      mFrozen ||
       mPriority == aPriority) {
     return;
   }
 
   if (mPriority == aPriority) {
     hal::SetProcessPriority(Pid(), mPriority);
     return;
   }
@@ -1000,28 +957,16 @@ ParticularProcessPriorityManager::SetPri
     Unused << mContentParent->SendNotifyProcessPriorityChanged(mPriority);
   }
 
   FireTestOnlyObserverNotification("process-priority-set",
     ProcessPriorityToString(mPriority));
 }
 
 void
-ParticularProcessPriorityManager::Freeze()
-{
-  mFrozen = true;
-}
-
-void
-ParticularProcessPriorityManager::Unfreeze()
-{
-  mFrozen = false;
-}
-
-void
 ParticularProcessPriorityManager::ShutDown()
 {
   MOZ_ASSERT(mContentParent);
 
   UnregisterWakeLockObserver(this);
 
   if (mResetPriorityTimer) {
     mResetPriorityTimer->Cancel();
--- a/widget/gonk/nsScreenManagerGonk.cpp
+++ b/widget/gonk/nsScreenManagerGonk.cpp
@@ -60,25 +60,16 @@ namespace {
 
 class ScreenOnOffEvent : public mozilla::Runnable {
 public:
     ScreenOnOffEvent(bool on)
         : mIsOn(on)
     {}
 
     NS_IMETHOD Run() override {
-        // Notify observers that the screen state has just changed.
-        nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
-        if (observerService) {
-          observerService->NotifyObservers(
-            nullptr, "screen-state-changed",
-            mIsOn ? u"on" : u"off"
-          );
-        }
-
         RefPtr<nsScreenGonk> screen = nsScreenManagerGonk::GetPrimaryScreen();
         const nsTArray<nsWindow*>& windows = screen->GetTopWindows();
 
         for (uint32_t i = 0; i < windows.Length(); i++) {
             nsWindow *win = windows[i];
 
             if (nsIWidgetListener* listener = win->GetWidgetListener()) {
                 listener->SizeModeChanged(mIsOn ? nsSizeMode_Fullscreen : nsSizeMode_Minimized);