Line data Source code
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 "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/Observer.h"
16 : #include "Types.h"
17 : #include "mozilla/StaticPtr.h"
18 : #include "mozilla/dom/WakeLock.h"
19 :
20 : namespace mozilla {
21 : namespace dom {
22 :
23 : class ContentParent;
24 :
25 : namespace power {
26 :
27 : class PowerManagerService
28 : : public nsIPowerManagerService
29 : , public WakeLockObserver
30 : {
31 : public:
32 : NS_DECL_ISUPPORTS
33 : NS_DECL_NSIPOWERMANAGERSERVICE
34 :
35 1 : PowerManagerService()
36 1 : : mWatchdogTimeoutSecs(0)
37 1 : {}
38 :
39 : static already_AddRefed<PowerManagerService> GetInstance();
40 :
41 : void Init();
42 :
43 : // Implement WakeLockObserver
44 : void Notify(const hal::WakeLockInformation& aWakeLockInfo) override;
45 :
46 : /**
47 : * Acquire a wake lock on behalf of a given process (aContentParent).
48 : *
49 : * This method stands in contrast to nsIPowerManagerService::NewWakeLock,
50 : * which acquires a wake lock on behalf of the /current/ process.
51 : *
52 : * NewWakeLockOnBehalfOfProcess is different from NewWakeLock in that
53 : *
54 : * - The wake lock unlocks itself if the /given/ process dies, and
55 : * - The /given/ process shows up in WakeLockInfo::lockingProcesses.
56 : *
57 : */
58 : already_AddRefed<WakeLock>
59 : NewWakeLockOnBehalfOfProcess(const nsAString& aTopic,
60 : ContentParent* aContentParent);
61 :
62 : already_AddRefed<WakeLock>
63 : NewWakeLock(const nsAString& aTopic, nsPIDOMWindowInner* aWindow,
64 : mozilla::ErrorResult& aRv);
65 :
66 : private:
67 :
68 : ~PowerManagerService();
69 :
70 : void ComputeWakeLockState(const hal::WakeLockInformation& aWakeLockInfo,
71 : nsAString &aState);
72 :
73 : void SyncProfile();
74 :
75 : static StaticRefPtr<PowerManagerService> sSingleton;
76 :
77 : nsTArray<nsCOMPtr<nsIDOMMozWakeLockListener>> mWakeLockListeners;
78 :
79 : int32_t mWatchdogTimeoutSecs;
80 : };
81 :
82 : } // namespace power
83 : } // namespace dom
84 : } // namespace mozilla
85 :
86 : #endif // mozilla_dom_power_PowerManagerService_h
|