bug 1249738 - make sNetworkObservers a function static r=dhylands
authorTrevor Saunders <tbsaunde@tbsaunde.org>
Fri, 19 Feb 2016 11:28:00 -0500
changeset 285825 5e27306cd8fb1e7eb0ea859691601b657ceb6727
parent 285824 73c742908f3fa81180be5df7d8b051260af5c5d2
child 285826 4b7370854a0be419daf53e1be636aed4f28ce86f
push id17876
push usercbook@mozilla.com
push dateMon, 29 Feb 2016 10:43:24 +0000
treeherderfx-team@9da51cb4974e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands
bugs1249738
milestone47.0a1
bug 1249738 - make sNetworkObservers a function static r=dhylands
hal/Hal.cpp
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -311,17 +311,23 @@ protected:
     PROXY_IF_SANDBOXED(DisableNetworkNotifications());
   }
 
   void GetCurrentInformationInternal(NetworkInformation* aInfo) {
     PROXY_IF_SANDBOXED(GetCurrentNetworkInformation(aInfo));
   }
 };
 
-static NetworkObserversManager sNetworkObservers;
+static NetworkObserversManager&
+NetworkObservers()
+{
+  static NetworkObserversManager sNetworkObservers;
+  AssertMainThread();
+  return sNetworkObservers;
+}
 
 class WakeLockObserversManager : public ObserversManager<WakeLockInformation>
 {
 protected:
   void EnableNotifications() {
     PROXY_IF_SANDBOXED(EnableWakeLockNotifications());
   }
 
@@ -597,38 +603,38 @@ NotifySensorChange(const SensorData &aSe
 
   observers.Broadcast(aSensorData);
 }
 
 void
 RegisterNetworkObserver(NetworkObserver* aObserver)
 {
   AssertMainThread();
-  sNetworkObservers.AddObserver(aObserver);
+  NetworkObservers().AddObserver(aObserver);
 }
 
 void
 UnregisterNetworkObserver(NetworkObserver* aObserver)
 {
   AssertMainThread();
-  sNetworkObservers.RemoveObserver(aObserver);
+  NetworkObservers().RemoveObserver(aObserver);
 }
 
 void
 GetCurrentNetworkInformation(NetworkInformation* aInfo)
 {
   AssertMainThread();
-  *aInfo = sNetworkObservers.GetCurrentInformation();
+  *aInfo = NetworkObservers().GetCurrentInformation();
 }
 
 void
 NotifyNetworkChange(const NetworkInformation& aInfo)
 {
-  sNetworkObservers.CacheInformation(aInfo);
-  sNetworkObservers.BroadcastCachedInformation();
+  NetworkObservers().CacheInformation(aInfo);
+  NetworkObservers().BroadcastCachedInformation();
 }
 
 void Reboot()
 {
   AssertMainProcess();
   AssertMainThread();
   PROXY_IF_SANDBOXED(Reboot());
 }