Bug 792443 - hal::RegisterSystemTimeChangeObserver should register the observer through sandbox, r=jlebar
authorSteven Lee <slee@mozilla.com>
Sun, 23 Sep 2012 13:00:32 -0400
changeset 107852 4a8ade9e7af866d1a289cf506e44822ffeb1fb6c
parent 107851 a21e1c1d2ba82b36293bbc7e70ab7bd2ea2f7b5d
child 107853 78c1ecf6bf13ebaca0c67bb046ffb9461c060e74
push idunknown
push userunknown
push dateunknown
reviewersjlebar
bugs792443
milestone18.0a1
Bug 792443 - hal::RegisterSystemTimeChangeObserver should register the observer through sandbox, r=jlebar
hal/Hal.cpp
hal/HalInternal.h
hal/fallback/FallbackTime.cpp
hal/gonk/GonkHal.cpp
hal/sandbox/PHal.ipdl
hal/sandbox/SandboxHal.cpp
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -401,47 +401,48 @@ bool SetLight(LightType light, const hal
 }
 
 bool GetLight(LightType light, hal::LightConfiguration* aConfig)
 {
   AssertMainThread();
   RETURN_PROXY_IF_SANDBOXED(GetLight(light, aConfig));
 }
 
-static StaticAutoPtr<ObserverList<SystemTimeChange> > sSystemTimeObservers;
-
-static void
-InitializeSystemTimeChangeObserver()
+class SystemTimeObserversManager : public ObserversManager<SystemTimeChange>
 {
-  if (!sSystemTimeObservers) {
-    sSystemTimeObservers = new ObserverList<SystemTimeChange>;
-    ClearOnShutdown(&sSystemTimeObservers);
+protected:
+  void EnableNotifications() {
+    PROXY_IF_SANDBOXED(EnableSystemTimeChangeNotifications());
   }
-}
+
+  void DisableNotifications() {
+    PROXY_IF_SANDBOXED(DisableSystemTimeChangeNotifications());
+  }
+};
+
+static SystemTimeObserversManager sSystemTimeObservers;
 
 void
 RegisterSystemTimeChangeObserver(SystemTimeObserver *aObserver)
 {
   AssertMainThread();
-  InitializeSystemTimeChangeObserver();
-  sSystemTimeObservers->AddObserver(aObserver);
+  sSystemTimeObservers.AddObserver(aObserver);
 }
 
 void
 UnregisterSystemTimeChangeObserver(SystemTimeObserver *aObserver)
 {
   AssertMainThread();
-  sSystemTimeObservers->RemoveObserver(aObserver);
+  sSystemTimeObservers.RemoveObserver(aObserver);
 }
 
 void
 NotifySystemTimeChange(const hal::SystemTimeChange& aReason)
 {
-  InitializeSystemTimeChangeObserver();
-  sSystemTimeObservers->Broadcast(aReason);
+  sSystemTimeObservers.BroadcastInformation(aReason);
 }
  
 void 
 AdjustSystemClock(int32_t aDeltaMilliseconds)
 {
   AssertMainThread();
   PROXY_IF_SANDBOXED(AdjustSystemClock(aDeltaMilliseconds));
 }
--- a/hal/HalInternal.h
+++ b/hal/HalInternal.h
@@ -69,12 +69,22 @@ void DisableSwitchNotifications(hal::Swi
  */
 bool EnableAlarm();
 
 /**
  * Disable alarm notifications from the backend.
  */
 void DisableAlarm();
 
+/**
+ * Enable system time change notifications from the backend.
+ */
+void EnableSystemTimeChangeNotifications();
+
+/**
+ * Disable system time change notifications from the backend.
+ */
+void DisableSystemTimeChangeNotifications();
+
 } // namespace MOZ_HAL_NAMESPACE
 } // namespace mozilla
 
 #endif  // mozilla_HalInternal_h
--- a/hal/fallback/FallbackTime.cpp
+++ b/hal/fallback/FallbackTime.cpp
@@ -19,10 +19,19 @@ SetTimezone(const nsCString& aTimezoneSp
 {}
 
 nsCString
 GetTimezone()
 {
   return EmptyCString();
 }
 
+void
+EnableSystemTimeChangeNotifications()
+{
+}
+
+void
+DisableSystemTimeChangeNotifications()
+{
+}
 } // namespace hal_impl
 } // namespace mozilla
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -665,16 +665,26 @@ SetTimezone(const nsCString& aTimezoneSp
 nsCString
 GetTimezone()
 {
   char timezone[32];
   property_get("persist.sys.timezone", timezone, "");
   return nsCString(timezone);
 }
 
+void
+EnableSystemTimeChangeNotifications()
+{
+}
+
+void
+DisableSystemTimeChangeNotifications()
+{
+}
+
 // Nothing to do here.  Gonk widgetry always listens for screen
 // orientation changes.
 void
 EnableScreenConfigurationNotifications()
 {
 }
 
 void
--- a/hal/sandbox/PHal.ipdl
+++ b/hal/sandbox/PHal.ipdl
@@ -130,16 +130,18 @@ parent:
 
     sync GetScreenBrightness() returns (double brightness);
     SetScreenBrightness(double brightness);
 
     AdjustSystemClock(int32_t aDeltaMilliseconds);
     SetTimezone(nsCString aTimezoneSpec);
     sync GetTimezone()
       returns (nsCString aTimezoneSpec);
+    EnableSystemTimeChangeNotifications();
+    DisableSystemTimeChangeNotifications();
 
     sync SetLight(LightType light, LightConfiguration aConfig)
       returns (bool status);
     sync GetLight(LightType light)
       returns (LightConfiguration aConfig, bool status);
 
     Reboot();
     PowerOff();
--- a/hal/sandbox/SandboxHal.cpp
+++ b/hal/sandbox/SandboxHal.cpp
@@ -199,16 +199,28 @@ nsCString
 GetTimezone()
 {
   nsCString timezone;
   Hal()->SendGetTimezone(&timezone);
   return timezone;
 }
 
 void
+EnableSystemTimeChangeNotifications()
+{
+  Hal()->SendEnableSystemTimeChangeNotifications();
+}
+
+void
+DisableSystemTimeChangeNotifications()
+{
+  Hal()->SendDisableSystemTimeChangeNotifications();
+}
+
+void
 Reboot()
 {
   Hal()->SendReboot();
 }
 
 void
 PowerOff()
 {
@@ -357,16 +369,17 @@ CancelFMRadioSeek()
 
 class HalParent : public PHalParent
                 , public BatteryObserver
                 , public NetworkObserver
                 , public ISensorObserver
                 , public WakeLockObserver
                 , public ScreenConfigurationObserver
                 , public SwitchObserver
+                , public SystemTimeObserver
 {
 public:
   virtual void
   ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE
   {
     // NB: you *must* unconditionally unregister your observer here,
     // if it *may* be registered below.
     hal::UnregisterBatteryObserver(this);
@@ -604,16 +617,30 @@ public:
     if (!AppProcessHasPermission(this, "time")) {
       return false;
     }
     *aTimezoneSpec = hal::GetTimezone();
     return true;
   }
 
   virtual bool
+  RecvEnableSystemTimeChangeNotifications() MOZ_OVERRIDE
+  {
+    hal::RegisterSystemTimeChangeObserver(this);
+    return true;
+  }
+
+  virtual bool
+  RecvDisableSystemTimeChangeNotifications() MOZ_OVERRIDE
+  {
+    hal::UnregisterSystemTimeChangeObserver(this);
+    return true;
+  }
+
+  virtual bool
   RecvReboot() MOZ_OVERRIDE
   {
     if (!AppProcessHasPermission(this, "power")) {
       return false;
     }
     hal::Reboot();
     return true;
   }