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
10 #include "nsHashKeys.h"
12 #include "nsIDOMWakeLockListener.h"
13 #include "nsIPowerManagerService.h"
14 #include "mozilla/HalWakeLockInformation.h"
15 #include "mozilla/StaticPtr.h"
16 #include "mozilla/dom/WakeLock.h"
18 namespace mozilla::dom
{
24 class PowerManagerService
: public nsIPowerManagerService
,
25 public hal::WakeLockObserver
{
28 NS_DECL_NSIPOWERMANAGERSERVICE
30 PowerManagerService() = default;
32 static already_AddRefed
<PowerManagerService
> GetInstance();
36 // Implement WakeLockObserver
37 void Notify(const hal::WakeLockInformation
& aWakeLockInfo
) override
;
39 already_AddRefed
<WakeLock
> NewWakeLock(const nsAString
& aTopic
,
40 nsPIDOMWindowInner
* aWindow
,
41 mozilla::ErrorResult
& aRv
);
44 ~PowerManagerService();
46 void ComputeWakeLockState(const hal::WakeLockInformation
& aWakeLockInfo
,
49 static StaticRefPtr
<PowerManagerService
> sSingleton
;
51 nsTArray
<nsCOMPtr
<nsIDOMMozWakeLockListener
>> mWakeLockListeners
;
55 } // namespace mozilla::dom
57 #endif // mozilla_dom_power_PowerManagerService_h