From 4bec908ccce1180a63493f606df491a44a507580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kan-Ru=20Chen=20=28=E9=99=B3=E4=BE=83=E5=A6=82=29?= Date: Tue, 27 Nov 2012 10:28:11 +0800 Subject: [PATCH] Bug 814822 - Notify wake lock change when content crashes. r=jlebar --- hal/HalWakeLock.cpp | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/hal/HalWakeLock.cpp b/hal/HalWakeLock.cpp index 5c9f0e1bba3a..654eb1d087da 100644 --- a/hal/HalWakeLock.cpp +++ b/hal/HalWakeLock.cpp @@ -53,17 +53,6 @@ static StaticAutoPtr sLockTable; static bool sInitialized = false; static bool sIsShuttingDown = false; -static PLDHashOperator -RemoveChildFromList(const nsAString& aKey, ProcessLockTable* aTable, void* aUserArg) -{ - MOZ_ASSERT(aUserArg); - - uint64_t childID = *static_cast(aUserArg); - aTable->Remove(childID); - - return PL_DHASH_NEXT; -} - static PLDHashOperator CountWakeLocks(const uint64_t& aKey, LockCount aCount, void* aUserArg) { @@ -76,6 +65,31 @@ CountWakeLocks(const uint64_t& aKey, LockCount aCount, void* aUserArg) return PL_DHASH_NEXT; } +static PLDHashOperator +RemoveChildFromList(const nsAString& aKey, ProcessLockTable* aTable, void* aUserArg) +{ + MOZ_ASSERT(aUserArg); + + uint64_t childID = *static_cast(aUserArg); + if (aTable->Get(childID, NULL)) { + aTable->Remove(childID); + if (sActiveListeners) { + LockCount totalCount; + WakeLockInformation info; + aTable->EnumerateRead(CountWakeLocks, &totalCount); + if (!totalCount.numLocks) { + sLockTable->Remove(aKey); + } + info.numLocks() = totalCount.numLocks; + info.numHidden() = totalCount.numHidden; + info.topic() = aKey; + NotifyWakeLockChange(info); + } + } + + return PL_DHASH_NEXT; +} + class ClearHashtableOnShutdown MOZ_FINAL : public nsIObserver { public: NS_DECL_ISUPPORTS @@ -162,6 +176,8 @@ ModifyWakeLockInternal(const nsAString& aTopic, hal::WakeLockControl aHiddenAdjust, uint64_t aProcessID) { + MOZ_ASSERT(NS_IsMainThread()); + if (sIsShuttingDown) { return; }