Bug 1320275 - QuotaManager must be registered as battery observer before calling hal:GetCurrentBatteryInformation, r=janv
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 28 Nov 2016 22:22:51 +0100
changeset 324454 3fa64db7e2ff51f6608364003119469a94b9363d
parent 324453 09f249970fc319f7810d80886d34de54175abf8a
child 324455 fdcc35477bd0d4c6a13875c5cdb7e1a6c8ca98c6
push id84415
push useramarchesini@mozilla.com
push dateMon, 28 Nov 2016 21:24:56 +0000
treeherdermozilla-inbound@3fa64db7e2ff [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv
bugs1320275
milestone53.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 1320275 - QuotaManager must be registered as battery observer before calling hal:GetCurrentBatteryInformation, r=janv
dom/quota/QuotaManagerService.cpp
dom/quota/QuotaManagerService.h
--- a/dom/quota/QuotaManagerService.cpp
+++ b/dom/quota/QuotaManagerService.cpp
@@ -436,17 +436,21 @@ QuotaManagerService::PerformIdleMaintena
   BatteryInformation batteryInfo;
 
 #ifdef MOZ_WIDGET_ANDROID
   // Android XPCShell doesn't load the AndroidBridge that is needed to make
   // GetCurrentBatteryInformation work...
   if (!QuotaManager::kRunningXPCShellTests)
 #endif
   {
+    // In order to give the correct battery level, hal must have registered
+    // battery observers.
+    RegisterBatteryObserver(this);
     GetCurrentBatteryInformation(&batteryInfo);
+    UnregisterBatteryObserver(this);
   }
 
   // If we're running XPCShell because we always want to be able to test this
   // code so pretend that we're always charging.
   if (QuotaManager::kRunningXPCShellTests) {
     batteryInfo.level() = 100;
     batteryInfo.charging() = true;
   }
@@ -702,16 +706,23 @@ QuotaManagerService::Observe(nsISupports
 
     return NS_OK;
   }
 
   MOZ_ASSERT_UNREACHABLE("Should never get here!");
   return NS_OK;
 }
 
+void
+QuotaManagerService::Notify(const hal::BatteryInformation& aBatteryInfo)
+{
+  // This notification is received when battery data changes. We don't need to
+  // deal with this notification.
+}
+
 NS_IMETHODIMP
 AbortOperationsRunnable::Run()
 {
   AssertIsOnBackgroundThread();
 
   if (QuotaManager::IsShuttingDown()) {
     return NS_OK;
   }
--- a/dom/quota/QuotaManagerService.h
+++ b/dom/quota/QuotaManagerService.h
@@ -3,39 +3,46 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_quota_QuotaManagerService_h
 #define mozilla_dom_quota_QuotaManagerService_h
 
 #include "mozilla/dom/ipc/IdType.h"
+#include "mozilla/dom/battery/Types.h"
+#include "mozilla/Observer.h"
 #include "nsAutoPtr.h"
 #include "nsIObserver.h"
 #include "nsIQuotaManagerService.h"
 
 #define QUOTAMANAGER_SERVICE_CONTRACTID \
   "@mozilla.org/dom/quota-manager-service;1"
 
 namespace mozilla {
 namespace ipc {
 
 class PBackgroundChild;
 
 } // namespace ipc
 
+namespace hal {
+class BatteryInformation;
+}
+
 namespace dom {
 namespace quota {
 
 class QuotaChild;
 class QuotaManager;
 
 class QuotaManagerService final
   : public nsIQuotaManagerService
   , public nsIObserver
+  , public BatteryObserver
 {
   typedef mozilla::ipc::PBackgroundChild PBackgroundChild;
 
   class BackgroundCreateCallback;
   class PendingRequestInfo;
   class UsageRequestInfo;
   class RequestInfo;
   class IdleMaintenanceInfo;
@@ -99,15 +106,19 @@ private:
   PerformIdleMaintenance();
 
   void
   RemoveIdleObserver();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIQUOTAMANAGERSERVICE
   NS_DECL_NSIOBSERVER
+
+  // BatteryObserver override
+  void
+  Notify(const hal::BatteryInformation& aBatteryInfo) override;
 };
 
 } // namespace quota
 } // namespace dom
 } // namespace mozilla
 
 #endif /* mozilla_dom_quota_QuotaManagerService_h */