michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef mozilla_dom_power_PowerManagerService_h michael@0: #define mozilla_dom_power_PowerManagerService_h michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsDataHashtable.h" michael@0: #include "nsHashKeys.h" michael@0: #include "nsTArray.h" michael@0: #include "nsIPowerManagerService.h" michael@0: #include "mozilla/Observer.h" michael@0: #include "Types.h" michael@0: #include "mozilla/StaticPtr.h" michael@0: #include "mozilla/dom/WakeLock.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class ContentParent; michael@0: michael@0: namespace power { michael@0: michael@0: class PowerManagerService michael@0: : public nsIPowerManagerService michael@0: , public WakeLockObserver michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIPOWERMANAGERSERVICE michael@0: michael@0: static already_AddRefed GetInstance(); michael@0: michael@0: void Init(); michael@0: michael@0: // Implement WakeLockObserver michael@0: void Notify(const hal::WakeLockInformation& aWakeLockInfo); michael@0: michael@0: /** michael@0: * Acquire a wake lock on behalf of a given process (aContentParent). michael@0: * michael@0: * This method stands in contrast to nsIPowerManagerService::NewWakeLock, michael@0: * which acquires a wake lock on behalf of the /current/ process. michael@0: * michael@0: * NewWakeLockOnBehalfOfProcess is different from NewWakeLock in that michael@0: * michael@0: * - The wake lock unlocks itself if the /given/ process dies, and michael@0: * - The /given/ process shows up in WakeLockInfo::lockingProcesses. michael@0: * michael@0: */ michael@0: already_AddRefed michael@0: NewWakeLockOnBehalfOfProcess(const nsAString& aTopic, michael@0: ContentParent* aContentParent); michael@0: michael@0: already_AddRefed michael@0: NewWakeLock(const nsAString& aTopic, nsIDOMWindow* aWindow, michael@0: mozilla::ErrorResult& aRv); michael@0: michael@0: private: michael@0: michael@0: ~PowerManagerService(); michael@0: michael@0: void ComputeWakeLockState(const hal::WakeLockInformation& aWakeLockInfo, michael@0: nsAString &aState); michael@0: michael@0: void SyncProfile(); michael@0: michael@0: static StaticRefPtr sSingleton; michael@0: michael@0: nsTArray > mWakeLockListeners; michael@0: michael@0: int32_t mWatchdogTimeoutSecs; michael@0: }; michael@0: michael@0: } // namespace power michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_power_PowerManagerService_h