PowerManagerService.h (1738B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 #ifndef mozilla_dom_power_PowerManagerService_h 7 #define mozilla_dom_power_PowerManagerService_h 8 9 #include "mozilla/HalWakeLockInformation.h" 10 #include "mozilla/StaticPtr.h" 11 #include "mozilla/dom/WakeLock.h" 12 #include "nsCOMPtr.h" 13 #include "nsHashKeys.h" 14 #include "nsIDOMWakeLockListener.h" 15 #include "nsIPowerManagerService.h" 16 #include "nsTArray.h" 17 18 namespace mozilla::dom { 19 20 class ContentParent; 21 22 namespace power { 23 24 class PowerManagerService : public nsIPowerManagerService, 25 public hal::WakeLockObserver { 26 public: 27 NS_DECL_ISUPPORTS 28 NS_DECL_NSIPOWERMANAGERSERVICE 29 30 PowerManagerService() = default; 31 32 static already_AddRefed<PowerManagerService> GetInstance(); 33 34 void Init(); 35 36 // Implement WakeLockObserver 37 void Notify(const hal::WakeLockInformation& aWakeLockInfo) override; 38 39 already_AddRefed<WakeLock> NewWakeLock(const nsAString& aTopic, 40 nsPIDOMWindowInner* aWindow, 41 mozilla::ErrorResult& aRv); 42 43 private: 44 ~PowerManagerService(); 45 46 void ComputeWakeLockState(const hal::WakeLockInformation& aWakeLockInfo, 47 nsAString& aState); 48 49 static StaticRefPtr<PowerManagerService> sSingleton; 50 51 nsTArray<nsCOMPtr<nsIDOMMozWakeLockListener>> mWakeLockListeners; 52 }; 53 54 } // namespace power 55 } // namespace mozilla::dom 56 57 #endif // mozilla_dom_power_PowerManagerService_h