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 "nsDataHashtable.h"
11 #include "nsHashKeys.h"
13 #include "nsIDOMWakeLockListener.h"
14 #include "nsIPowerManagerService.h"
15 #include "mozilla/HalWakeLockInformation.h"
16 #include "mozilla/StaticPtr.h"
17 #include "mozilla/dom/WakeLock.h"
26 class PowerManagerService
: public nsIPowerManagerService
,
27 public hal::WakeLockObserver
{
30 NS_DECL_NSIPOWERMANAGERSERVICE
32 PowerManagerService() {}
34 static already_AddRefed
<PowerManagerService
> GetInstance();
38 // Implement WakeLockObserver
39 void Notify(const hal::WakeLockInformation
& aWakeLockInfo
) override
;
42 * Acquire a wake lock on behalf of a given process (aContentParent).
44 * This method stands in contrast to nsIPowerManagerService::NewWakeLock,
45 * which acquires a wake lock on behalf of the /current/ process.
47 * NewWakeLockOnBehalfOfProcess is different from NewWakeLock in that
49 * - The wake lock unlocks itself if the /given/ process dies, and
50 * - The /given/ process shows up in WakeLockInfo::lockingProcesses.
53 already_AddRefed
<WakeLock
> NewWakeLockOnBehalfOfProcess(
54 const nsAString
& aTopic
, ContentParent
* aContentParent
);
56 already_AddRefed
<WakeLock
> NewWakeLock(const nsAString
& aTopic
,
57 nsPIDOMWindowInner
* aWindow
,
58 mozilla::ErrorResult
& aRv
);
61 ~PowerManagerService();
63 void ComputeWakeLockState(const hal::WakeLockInformation
& aWakeLockInfo
,
66 static StaticRefPtr
<PowerManagerService
> sSingleton
;
68 nsTArray
<nsCOMPtr
<nsIDOMMozWakeLockListener
>> mWakeLockListeners
;
73 } // namespace mozilla
75 #endif // mozilla_dom_power_PowerManagerService_h