dom/power/PowerManagerService.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/power/PowerManagerService.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +#ifndef mozilla_dom_power_PowerManagerService_h
     1.9 +#define mozilla_dom_power_PowerManagerService_h
    1.10 +
    1.11 +#include "nsCOMPtr.h"
    1.12 +#include "nsDataHashtable.h"
    1.13 +#include "nsHashKeys.h"
    1.14 +#include "nsTArray.h"
    1.15 +#include "nsIPowerManagerService.h"
    1.16 +#include "mozilla/Observer.h"
    1.17 +#include "Types.h"
    1.18 +#include "mozilla/StaticPtr.h"
    1.19 +#include "mozilla/dom/WakeLock.h"
    1.20 +
    1.21 +namespace mozilla {
    1.22 +namespace dom {
    1.23 +
    1.24 +class ContentParent;
    1.25 +
    1.26 +namespace power {
    1.27 +
    1.28 +class PowerManagerService
    1.29 +  : public nsIPowerManagerService
    1.30 +  , public WakeLockObserver
    1.31 +{
    1.32 +public:
    1.33 +  NS_DECL_ISUPPORTS
    1.34 +  NS_DECL_NSIPOWERMANAGERSERVICE
    1.35 +
    1.36 +  static already_AddRefed<PowerManagerService> GetInstance();
    1.37 +
    1.38 +  void Init();
    1.39 +
    1.40 +  // Implement WakeLockObserver
    1.41 +  void Notify(const hal::WakeLockInformation& aWakeLockInfo);
    1.42 +
    1.43 +  /**
    1.44 +   * Acquire a wake lock on behalf of a given process (aContentParent).
    1.45 +   *
    1.46 +   * This method stands in contrast to nsIPowerManagerService::NewWakeLock,
    1.47 +   * which acquires a wake lock on behalf of the /current/ process.
    1.48 +   *
    1.49 +   * NewWakeLockOnBehalfOfProcess is different from NewWakeLock in that
    1.50 +   *
    1.51 +   *  - The wake lock unlocks itself if the /given/ process dies, and
    1.52 +   *  - The /given/ process shows up in WakeLockInfo::lockingProcesses.
    1.53 +   *
    1.54 +   */
    1.55 +  already_AddRefed<WakeLock>
    1.56 +  NewWakeLockOnBehalfOfProcess(const nsAString& aTopic,
    1.57 +                               ContentParent* aContentParent);
    1.58 +
    1.59 +  already_AddRefed<WakeLock>
    1.60 +  NewWakeLock(const nsAString& aTopic, nsIDOMWindow* aWindow,
    1.61 +              mozilla::ErrorResult& aRv);
    1.62 +
    1.63 +private:
    1.64 +
    1.65 +  ~PowerManagerService();
    1.66 +
    1.67 +  void ComputeWakeLockState(const hal::WakeLockInformation& aWakeLockInfo,
    1.68 +                            nsAString &aState);
    1.69 +
    1.70 +  void SyncProfile();
    1.71 +
    1.72 +  static StaticRefPtr<PowerManagerService> sSingleton;
    1.73 +
    1.74 +  nsTArray<nsCOMPtr<nsIDOMMozWakeLockListener> > mWakeLockListeners;
    1.75 +  
    1.76 +  int32_t mWatchdogTimeoutSecs;
    1.77 +};
    1.78 +
    1.79 +} // namespace power
    1.80 +} // namespace dom
    1.81 +} // namespace mozilla
    1.82 +
    1.83 +#endif // mozilla_dom_power_PowerManagerService_h

mercurial