Coverage Report

Created: 2018-09-25 14:53

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