1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_dom_power_PowerManagerService_h
6 #define mozilla_dom_power_PowerManagerService_h
9 #include "nsDataHashtable.h"
10 #include "nsHashKeys.h"
12 #include "nsIPowerManagerService.h"
13 #include "mozilla/Observer.h"
15 #include "mozilla/StaticPtr.h"
16 #include "mozilla/dom/WakeLock.h"
25 class PowerManagerService
26 : public nsIPowerManagerService
27 , public WakeLockObserver
31 NS_DECL_NSIPOWERMANAGERSERVICE
33 static already_AddRefed
<PowerManagerService
> GetInstance();
37 // Implement WakeLockObserver
38 void Notify(const hal::WakeLockInformation
& aWakeLockInfo
) MOZ_OVERRIDE
;
41 * Acquire a wake lock on behalf of a given process (aContentParent).
43 * This method stands in contrast to nsIPowerManagerService::NewWakeLock,
44 * which acquires a wake lock on behalf of the /current/ process.
46 * NewWakeLockOnBehalfOfProcess is different from NewWakeLock in that
48 * - The wake lock unlocks itself if the /given/ process dies, and
49 * - The /given/ process shows up in WakeLockInfo::lockingProcesses.
52 already_AddRefed
<WakeLock
>
53 NewWakeLockOnBehalfOfProcess(const nsAString
& aTopic
,
54 ContentParent
* aContentParent
);
56 already_AddRefed
<WakeLock
>
57 NewWakeLock(const nsAString
& aTopic
, nsIDOMWindow
* aWindow
,
58 mozilla::ErrorResult
& aRv
);
62 ~PowerManagerService();
64 void ComputeWakeLockState(const hal::WakeLockInformation
& aWakeLockInfo
,
69 static StaticRefPtr
<PowerManagerService
> sSingleton
;
71 nsTArray
<nsCOMPtr
<nsIDOMMozWakeLockListener
> > mWakeLockListeners
;
73 int32_t mWatchdogTimeoutSecs
;
78 } // namespace mozilla
80 #endif // mozilla_dom_power_PowerManagerService_h