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