dom/power/PowerManagerService.h
author L10n Bumper Bot <release+l10nbumper@mozilla.com>
Fri, 20 Sep 2019 07:00:34 +0000
changeset 551953 46ed6978d8c8c11843d07212a9438a0b6a5acd94
parent 505383 6f3709b3878117466168c40affa7bca0b60cf75b
permissions -rw-r--r--
no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD es-AR -> a5e8e43b0b67 gn -> 486db3ffe5cd he -> c354d895d06c hsb -> d2065587a234 ia -> 9981119edcd2 it -> dd6d411bac87 kab -> 4ba315e825cf nb-NO -> 08b6bb1dc03f pt-BR -> eb00874e16c3 sl -> da1ca4a1672c sv-SE -> 2ae445c60be6 uk -> d8c3eda02cd6 zh-CN -> 5c7f0cd04558

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_power_PowerManagerService_h
#define mozilla_dom_power_PowerManagerService_h

#include "nsCOMPtr.h"
#include "nsDataHashtable.h"
#include "nsHashKeys.h"
#include "nsTArray.h"
#include "nsIDOMWakeLockListener.h"
#include "nsIPowerManagerService.h"
#include "mozilla/HalWakeLockInformation.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/dom/WakeLock.h"

namespace mozilla {
namespace dom {

class ContentParent;

namespace power {

class PowerManagerService : public nsIPowerManagerService,
                            public hal::WakeLockObserver {
 public:
  NS_DECL_ISUPPORTS
  NS_DECL_NSIPOWERMANAGERSERVICE

  PowerManagerService() {}

  static already_AddRefed<PowerManagerService> GetInstance();

  void Init();

  // Implement WakeLockObserver
  void Notify(const hal::WakeLockInformation& aWakeLockInfo) override;

  /**
   * Acquire a wake lock on behalf of a given process (aContentParent).
   *
   * This method stands in contrast to nsIPowerManagerService::NewWakeLock,
   * which acquires a wake lock on behalf of the /current/ process.
   *
   * NewWakeLockOnBehalfOfProcess is different from NewWakeLock in that
   *
   *  - The wake lock unlocks itself if the /given/ process dies, and
   *  - The /given/ process shows up in WakeLockInfo::lockingProcesses.
   *
   */
  already_AddRefed<WakeLock> NewWakeLockOnBehalfOfProcess(
      const nsAString& aTopic, ContentParent* aContentParent);

  already_AddRefed<WakeLock> NewWakeLock(const nsAString& aTopic,
                                         nsPIDOMWindowInner* aWindow,
                                         mozilla::ErrorResult& aRv);

 private:
  ~PowerManagerService();

  void ComputeWakeLockState(const hal::WakeLockInformation& aWakeLockInfo,
                            nsAString& aState);

  static StaticRefPtr<PowerManagerService> sSingleton;

  nsTArray<nsCOMPtr<nsIDOMMozWakeLockListener>> mWakeLockListeners;
};

}  // namespace power
}  // namespace dom
}  // namespace mozilla

#endif  // mozilla_dom_power_PowerManagerService_h