Bug 1614879 [wpt PR 21750] - Set request mode for beacon request with non-cors-safeli...
[gecko.git] / dom / power / PowerManagerService.h
blobb1ba7fff8f7600e9b62741515b68026dbb476c87
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
9 #include "nsCOMPtr.h"
10 #include "nsDataHashtable.h"
11 #include "nsHashKeys.h"
12 #include "nsTArray.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"
19 namespace mozilla {
20 namespace dom {
22 class ContentParent;
24 namespace power {
26 class PowerManagerService : public nsIPowerManagerService,
27 public hal::WakeLockObserver {
28 public:
29 NS_DECL_ISUPPORTS
30 NS_DECL_NSIPOWERMANAGERSERVICE
32 PowerManagerService() {}
34 static already_AddRefed<PowerManagerService> GetInstance();
36 void Init();
38 // Implement WakeLockObserver
39 void Notify(const hal::WakeLockInformation& aWakeLockInfo) override;
41 /**
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);
60 private:
61 ~PowerManagerService();
63 void ComputeWakeLockState(const hal::WakeLockInformation& aWakeLockInfo,
64 nsAString& aState);
66 static StaticRefPtr<PowerManagerService> sSingleton;
68 nsTArray<nsCOMPtr<nsIDOMMozWakeLockListener>> mWakeLockListeners;
71 } // namespace power
72 } // namespace dom
73 } // namespace mozilla
75 #endif // mozilla_dom_power_PowerManagerService_h