haikuwebkit/Source/WTF/wtf/RefCounter.h

149 lines
4.1 KiB
C
Raw Permalink Normal View History

HTMLMediaElement will not unthrottle page when playback stops for nreasons other than user-initiated pause. https://bugs.webkit.org/show_bug.cgi?id=117016 Reviewed by Oliver Hunt. Add a new class PageActivityAssertionToken to allow HTMLMediaElement to decouple knowledge of and control over the lifetime of PageThrottler. The new class will have weak references to and from the PageThrottler so that holders of the token will not need to care if the Page or PageThrottler has been destroyed. HTMLMediaElement will create one of these PageActivityAssertionTokens when playback begins and destroy it when playback stops for any reason, or when the element is destroyed. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::~HTMLMediaElement): (WebCore::HTMLMediaElement::playInternal): (WebCore::HTMLMediaElement::pauseInternal): (WebCore::HTMLMediaElement::playbackProgressTimerFired): (WebCore::HTMLMediaElement::updatePlayState): * html/HTMLMediaElement.h: * page/Page.cpp: (WebCore::createActivityToken): Added simple factory method. * page/Page.h: * page/PageActivityAssertionToken.cpp: (WebCore::PageActivityAssertionToken::PageActivityAssertionToken): Call addActivityToken(); (WebCore::PageActivityAssertionToken::~PageActivityAssertionToken): Call removeActivityToken(); (WebCore::PageActivityAssertionToken::invalidate): Clear m_throttler. * page/PageActivityAssertionToken.h: * page/PageThrottler.cpp: (WebCore::PageThrottler::~PageThrottler): Invalidate all outstanding tokens. (WebCore::PageThrottler::addActivityToken): Bump the activity count. (WebCore::PageThrottler::removeActivityToken): Lower the activity count. * page/PageThrottler.h: Add the new files to the various build systems: * CMakeLists.txt: * GNUmakefile.list.am: * Target.pri: * WebCore.vcproj/WebCore.vcproj: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/135303@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@150971 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-05-30 18:19:00 +00:00
/*
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
* Copyright (C) 2014 Apple Inc. All rights reserved.
HTMLMediaElement will not unthrottle page when playback stops for nreasons other than user-initiated pause. https://bugs.webkit.org/show_bug.cgi?id=117016 Reviewed by Oliver Hunt. Add a new class PageActivityAssertionToken to allow HTMLMediaElement to decouple knowledge of and control over the lifetime of PageThrottler. The new class will have weak references to and from the PageThrottler so that holders of the token will not need to care if the Page or PageThrottler has been destroyed. HTMLMediaElement will create one of these PageActivityAssertionTokens when playback begins and destroy it when playback stops for any reason, or when the element is destroyed. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::~HTMLMediaElement): (WebCore::HTMLMediaElement::playInternal): (WebCore::HTMLMediaElement::pauseInternal): (WebCore::HTMLMediaElement::playbackProgressTimerFired): (WebCore::HTMLMediaElement::updatePlayState): * html/HTMLMediaElement.h: * page/Page.cpp: (WebCore::createActivityToken): Added simple factory method. * page/Page.h: * page/PageActivityAssertionToken.cpp: (WebCore::PageActivityAssertionToken::PageActivityAssertionToken): Call addActivityToken(); (WebCore::PageActivityAssertionToken::~PageActivityAssertionToken): Call removeActivityToken(); (WebCore::PageActivityAssertionToken::invalidate): Clear m_throttler. * page/PageActivityAssertionToken.h: * page/PageThrottler.cpp: (WebCore::PageThrottler::~PageThrottler): Invalidate all outstanding tokens. (WebCore::PageThrottler::addActivityToken): Bump the activity count. (WebCore::PageThrottler::removeActivityToken): Lower the activity count. * page/PageThrottler.h: Add the new files to the various build systems: * CMakeLists.txt: * GNUmakefile.list.am: * Target.pri: * WebCore.vcproj/WebCore.vcproj: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/135303@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@150971 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-05-30 18:19:00 +00:00
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
Use pragma once in WTF https://bugs.webkit.org/show_bug.cgi?id=190527 Reviewed by Chris Dumez. Source/WTF: We also need to consistently include wtf headers from within wtf so we can build wtf without symbol redefinition errors from including the copy in Source and the copy in the build directory. * wtf/ASCIICType.h: * wtf/Assertions.cpp: * wtf/Assertions.h: * wtf/Atomics.h: * wtf/AutomaticThread.cpp: * wtf/AutomaticThread.h: * wtf/BackwardsGraph.h: * wtf/Bag.h: * wtf/BagToHashMap.h: * wtf/BitVector.cpp: * wtf/BitVector.h: * wtf/Bitmap.h: * wtf/BloomFilter.h: * wtf/Box.h: * wtf/BubbleSort.h: * wtf/BumpPointerAllocator.h: * wtf/ByteOrder.h: * wtf/CPUTime.cpp: * wtf/CallbackAggregator.h: * wtf/CheckedArithmetic.h: * wtf/CheckedBoolean.h: * wtf/ClockType.cpp: * wtf/ClockType.h: * wtf/CommaPrinter.h: * wtf/CompilationThread.cpp: * wtf/CompilationThread.h: * wtf/Compiler.h: * wtf/ConcurrentPtrHashSet.cpp: * wtf/ConcurrentVector.h: * wtf/Condition.h: * wtf/CountingLock.cpp: * wtf/CrossThreadTaskHandler.cpp: * wtf/CryptographicUtilities.cpp: * wtf/CryptographicUtilities.h: * wtf/CryptographicallyRandomNumber.cpp: * wtf/CryptographicallyRandomNumber.h: * wtf/CurrentTime.cpp: * wtf/DataLog.cpp: * wtf/DataLog.h: * wtf/DateMath.cpp: * wtf/DateMath.h: * wtf/DecimalNumber.cpp: * wtf/DecimalNumber.h: * wtf/Deque.h: * wtf/DisallowCType.h: * wtf/Dominators.h: * wtf/DoublyLinkedList.h: * wtf/FastBitVector.cpp: * wtf/FastMalloc.cpp: * wtf/FastMalloc.h: * wtf/FeatureDefines.h: * wtf/FilePrintStream.cpp: * wtf/FilePrintStream.h: * wtf/FlipBytes.h: * wtf/FunctionDispatcher.cpp: * wtf/FunctionDispatcher.h: * wtf/GetPtr.h: * wtf/Gigacage.cpp: * wtf/GlobalVersion.cpp: * wtf/GraphNodeWorklist.h: * wtf/GregorianDateTime.cpp: * wtf/GregorianDateTime.h: * wtf/HashFunctions.h: * wtf/HashMap.h: * wtf/HashMethod.h: * wtf/HashSet.h: * wtf/HashTable.cpp: * wtf/HashTraits.h: * wtf/Indenter.h: * wtf/IndexSparseSet.h: * wtf/InlineASM.h: * wtf/Insertion.h: * wtf/IteratorAdaptors.h: * wtf/IteratorRange.h: * wtf/JSONValues.cpp: * wtf/JSValueMalloc.cpp: * wtf/LEBDecoder.h: * wtf/Language.cpp: * wtf/ListDump.h: * wtf/Lock.cpp: * wtf/Lock.h: * wtf/LockAlgorithm.h: * wtf/LockedPrintStream.cpp: * wtf/Locker.h: * wtf/MD5.cpp: * wtf/MD5.h: * wtf/MainThread.cpp: * wtf/MainThread.h: * wtf/MallocPtr.h: * wtf/MathExtras.h: * wtf/MediaTime.cpp: * wtf/MediaTime.h: * wtf/MemoryPressureHandler.cpp: * wtf/MessageQueue.h: * wtf/MetaAllocator.cpp: * wtf/MetaAllocator.h: * wtf/MetaAllocatorHandle.h: * wtf/MonotonicTime.cpp: * wtf/MonotonicTime.h: * wtf/NakedPtr.h: * wtf/NoLock.h: * wtf/NoTailCalls.h: * wtf/Noncopyable.h: * wtf/NumberOfCores.cpp: * wtf/NumberOfCores.h: * wtf/OSAllocator.h: * wtf/OSAllocatorPosix.cpp: * wtf/OSRandomSource.cpp: * wtf/OSRandomSource.h: * wtf/ObjcRuntimeExtras.h: * wtf/OrderMaker.h: * wtf/PackedIntVector.h: * wtf/PageAllocation.h: * wtf/PageBlock.cpp: * wtf/PageBlock.h: * wtf/PageReservation.h: * wtf/ParallelHelperPool.cpp: * wtf/ParallelHelperPool.h: * wtf/ParallelJobs.h: * wtf/ParallelJobsLibdispatch.h: * wtf/ParallelVectorIterator.h: * wtf/ParkingLot.cpp: * wtf/ParkingLot.h: * wtf/Platform.h: * wtf/PointerComparison.h: * wtf/Poisoned.cpp: * wtf/PrintStream.cpp: * wtf/PrintStream.h: * wtf/ProcessID.h: * wtf/ProcessPrivilege.cpp: * wtf/RAMSize.cpp: * wtf/RAMSize.h: * wtf/RandomDevice.cpp: * wtf/RandomNumber.cpp: * wtf/RandomNumber.h: * wtf/RandomNumberSeed.h: * wtf/RangeSet.h: * wtf/RawPointer.h: * wtf/ReadWriteLock.cpp: * wtf/RedBlackTree.h: * wtf/Ref.h: * wtf/RefCountedArray.h: * wtf/RefCountedLeakCounter.cpp: * wtf/RefCountedLeakCounter.h: * wtf/RefCounter.h: * wtf/RefPtr.h: * wtf/RetainPtr.h: * wtf/RunLoop.cpp: * wtf/RunLoop.h: * wtf/RunLoopTimer.h: * wtf/RunLoopTimerCF.cpp: * wtf/SHA1.cpp: * wtf/SHA1.h: * wtf/SaturatedArithmetic.h: (saturatedSubtraction): * wtf/SchedulePair.h: * wtf/SchedulePairCF.cpp: * wtf/SchedulePairMac.mm: * wtf/ScopedLambda.h: * wtf/Seconds.cpp: * wtf/Seconds.h: * wtf/SegmentedVector.h: * wtf/SentinelLinkedList.h: * wtf/SharedTask.h: * wtf/SimpleStats.h: * wtf/SingleRootGraph.h: * wtf/SinglyLinkedList.h: * wtf/SixCharacterHash.cpp: * wtf/SixCharacterHash.h: * wtf/SmallPtrSet.h: * wtf/Spectrum.h: * wtf/StackBounds.cpp: * wtf/StackBounds.h: * wtf/StackStats.cpp: * wtf/StackStats.h: * wtf/StackTrace.cpp: * wtf/StdLibExtras.h: * wtf/StreamBuffer.h: * wtf/StringHashDumpContext.h: * wtf/StringPrintStream.cpp: * wtf/StringPrintStream.h: * wtf/ThreadGroup.cpp: * wtf/ThreadMessage.cpp: * wtf/ThreadSpecific.h: * wtf/Threading.cpp: * wtf/Threading.h: * wtf/ThreadingPrimitives.h: * wtf/ThreadingPthreads.cpp: * wtf/TimeWithDynamicClockType.cpp: * wtf/TimeWithDynamicClockType.h: * wtf/TimingScope.cpp: * wtf/TinyLRUCache.h: * wtf/TinyPtrSet.h: * wtf/TriState.h: * wtf/TypeCasts.h: * wtf/UUID.cpp: * wtf/UnionFind.h: * wtf/VMTags.h: * wtf/ValueCheck.h: * wtf/Vector.h: * wtf/VectorTraits.h: * wtf/WallTime.cpp: * wtf/WallTime.h: * wtf/WeakPtr.h: * wtf/WeakRandom.h: * wtf/WordLock.cpp: * wtf/WordLock.h: * wtf/WorkQueue.cpp: * wtf/WorkQueue.h: * wtf/WorkerPool.cpp: * wtf/cf/LanguageCF.cpp: * wtf/cf/RunLoopCF.cpp: * wtf/cocoa/Entitlements.mm: * wtf/cocoa/MachSendRight.cpp: * wtf/cocoa/MainThreadCocoa.mm: * wtf/cocoa/MemoryFootprintCocoa.cpp: * wtf/cocoa/WorkQueueCocoa.cpp: * wtf/dtoa.cpp: * wtf/dtoa.h: * wtf/ios/WebCoreThread.cpp: * wtf/ios/WebCoreThread.h: * wtf/mac/AppKitCompatibilityDeclarations.h: * wtf/mac/DeprecatedSymbolsUsedBySafari.mm: * wtf/mbmalloc.cpp: * wtf/persistence/PersistentCoders.cpp: * wtf/persistence/PersistentDecoder.cpp: * wtf/persistence/PersistentEncoder.cpp: * wtf/spi/cf/CFBundleSPI.h: * wtf/spi/darwin/CommonCryptoSPI.h: * wtf/text/ASCIIFastPath.h: * wtf/text/ASCIILiteral.cpp: * wtf/text/AtomicString.cpp: * wtf/text/AtomicString.h: * wtf/text/AtomicStringHash.h: * wtf/text/AtomicStringImpl.cpp: * wtf/text/AtomicStringImpl.h: * wtf/text/AtomicStringTable.cpp: * wtf/text/AtomicStringTable.h: * wtf/text/Base64.cpp: * wtf/text/CString.cpp: * wtf/text/CString.h: * wtf/text/ConversionMode.h: * wtf/text/ExternalStringImpl.cpp: * wtf/text/IntegerToStringConversion.h: * wtf/text/LChar.h: * wtf/text/LineEnding.cpp: * wtf/text/StringBuffer.h: * wtf/text/StringBuilder.cpp: * wtf/text/StringBuilder.h: * wtf/text/StringBuilderJSON.cpp: * wtf/text/StringCommon.h: * wtf/text/StringConcatenate.h: * wtf/text/StringHash.h: * wtf/text/StringImpl.cpp: * wtf/text/StringImpl.h: * wtf/text/StringOperators.h: * wtf/text/StringView.cpp: * wtf/text/StringView.h: * wtf/text/SymbolImpl.cpp: * wtf/text/SymbolRegistry.cpp: * wtf/text/SymbolRegistry.h: * wtf/text/TextBreakIterator.cpp: * wtf/text/TextBreakIterator.h: * wtf/text/TextBreakIteratorInternalICU.h: * wtf/text/TextPosition.h: * wtf/text/TextStream.cpp: * wtf/text/UniquedStringImpl.h: * wtf/text/WTFString.cpp: * wtf/text/WTFString.h: * wtf/text/cocoa/StringCocoa.mm: * wtf/text/cocoa/StringViewCocoa.mm: * wtf/text/cocoa/TextBreakIteratorInternalICUCocoa.cpp: * wtf/text/icu/UTextProvider.cpp: * wtf/text/icu/UTextProvider.h: * wtf/text/icu/UTextProviderLatin1.cpp: * wtf/text/icu/UTextProviderLatin1.h: * wtf/text/icu/UTextProviderUTF16.cpp: * wtf/text/icu/UTextProviderUTF16.h: * wtf/threads/BinarySemaphore.cpp: * wtf/threads/BinarySemaphore.h: * wtf/threads/Signals.cpp: * wtf/unicode/CharacterNames.h: * wtf/unicode/Collator.h: * wtf/unicode/CollatorDefault.cpp: * wtf/unicode/UTF8.cpp: * wtf/unicode/UTF8.h: Tools: Put WorkQueue in namespace DRT so it does not conflict with WTF::WorkQueue. * DumpRenderTree/TestRunner.cpp: (TestRunner::queueLoadHTMLString): (TestRunner::queueLoadAlternateHTMLString): (TestRunner::queueBackNavigation): (TestRunner::queueForwardNavigation): (TestRunner::queueLoadingScript): (TestRunner::queueNonLoadingScript): (TestRunner::queueReload): * DumpRenderTree/WorkQueue.cpp: (WorkQueue::singleton): Deleted. (WorkQueue::WorkQueue): Deleted. (WorkQueue::queue): Deleted. (WorkQueue::dequeue): Deleted. (WorkQueue::count): Deleted. (WorkQueue::clear): Deleted. (WorkQueue::processWork): Deleted. * DumpRenderTree/WorkQueue.h: (WorkQueue::setFrozen): Deleted. * DumpRenderTree/WorkQueueItem.h: * DumpRenderTree/mac/DumpRenderTree.mm: (runTest): * DumpRenderTree/mac/FrameLoadDelegate.mm: (-[FrameLoadDelegate processWork:]): (-[FrameLoadDelegate webView:locationChangeDone:forDataSource:]): * DumpRenderTree/mac/TestRunnerMac.mm: (TestRunner::notifyDone): (TestRunner::forceImmediateCompletion): (TestRunner::queueLoad): * DumpRenderTree/win/DumpRenderTree.cpp: (runTest): * DumpRenderTree/win/FrameLoadDelegate.cpp: (FrameLoadDelegate::processWork): (FrameLoadDelegate::locationChangeDone): * DumpRenderTree/win/TestRunnerWin.cpp: (TestRunner::notifyDone): (TestRunner::forceImmediateCompletion): (TestRunner::queueLoad): Canonical link: https://commits.webkit.org/205473@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237099 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-10-15 14:24:49 +00:00
#pragma once
HTMLMediaElement will not unthrottle page when playback stops for nreasons other than user-initiated pause. https://bugs.webkit.org/show_bug.cgi?id=117016 Reviewed by Oliver Hunt. Add a new class PageActivityAssertionToken to allow HTMLMediaElement to decouple knowledge of and control over the lifetime of PageThrottler. The new class will have weak references to and from the PageThrottler so that holders of the token will not need to care if the Page or PageThrottler has been destroyed. HTMLMediaElement will create one of these PageActivityAssertionTokens when playback begins and destroy it when playback stops for any reason, or when the element is destroyed. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::~HTMLMediaElement): (WebCore::HTMLMediaElement::playInternal): (WebCore::HTMLMediaElement::pauseInternal): (WebCore::HTMLMediaElement::playbackProgressTimerFired): (WebCore::HTMLMediaElement::updatePlayState): * html/HTMLMediaElement.h: * page/Page.cpp: (WebCore::createActivityToken): Added simple factory method. * page/Page.h: * page/PageActivityAssertionToken.cpp: (WebCore::PageActivityAssertionToken::PageActivityAssertionToken): Call addActivityToken(); (WebCore::PageActivityAssertionToken::~PageActivityAssertionToken): Call removeActivityToken(); (WebCore::PageActivityAssertionToken::invalidate): Clear m_throttler. * page/PageActivityAssertionToken.h: * page/PageThrottler.cpp: (WebCore::PageThrottler::~PageThrottler): Invalidate all outstanding tokens. (WebCore::PageThrottler::addActivityToken): Bump the activity count. (WebCore::PageThrottler::removeActivityToken): Lower the activity count. * page/PageThrottler.h: Add the new files to the various build systems: * CMakeLists.txt: * GNUmakefile.list.am: * Target.pri: * WebCore.vcproj/WebCore.vcproj: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/135303@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@150971 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-05-30 18:19:00 +00:00
Use WTF::Function instead of std::function in WTF/ https://bugs.webkit.org/show_bug.cgi?id=173519 Reviewed by Sam Weinig. Source/WebCore: Replace a few uses of std::function with WTF::Function in WebCore/ as well. It was either this or including <functional> and I decided it made more sense to port the code. * platform/graphics/FontSelectionAlgorithm.h: (WebCore::FontSelectionAlgorithm::iterateActiveCapabilitiesWithReturn): * platform/mediastream/MediaConstraints.cpp: (WebCore::StringConstraint::find): (WebCore::MediaTrackConstraintSetMap::forEach): (WebCore::MediaTrackConstraintSetMap::filter): (WebCore::MediaConstraints::isConstraintSet): * platform/mediastream/MediaConstraints.h: (WebCore::NumericConstraint::find): * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::applyConstraint): Source/WTF: Use WTF::Function instead of std::function in WTF/ to avoid copying. * wtf/Brigand.h: * wtf/Condition.h: * wtf/Expected.h: * wtf/FunctionDispatcher.h: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: (WTF::MemoryPressureHandler::setMemoryKillCallback): (WTF::MemoryPressureHandler::setMemoryPressureStatusChangedCallback): (WTF::MemoryPressureHandler::setDidExceedInactiveLimitWhileActiveCallback): * wtf/Optional.h: * wtf/ParkingLot.h: * wtf/RefCounter.h: (WTF::RefCounter<T>::RefCounter): * wtf/WorkQueue.h: * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): * wtf/text/WTFString.cpp: (WTF::String::split): * wtf/text/WTFString.h: Canonical link: https://commits.webkit.org/190415@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-18 19:49:12 +00:00
#include <wtf/Function.h>
HTMLMediaElement will not unthrottle page when playback stops for nreasons other than user-initiated pause. https://bugs.webkit.org/show_bug.cgi?id=117016 Reviewed by Oliver Hunt. Add a new class PageActivityAssertionToken to allow HTMLMediaElement to decouple knowledge of and control over the lifetime of PageThrottler. The new class will have weak references to and from the PageThrottler so that holders of the token will not need to care if the Page or PageThrottler has been destroyed. HTMLMediaElement will create one of these PageActivityAssertionTokens when playback begins and destroy it when playback stops for any reason, or when the element is destroyed. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::~HTMLMediaElement): (WebCore::HTMLMediaElement::playInternal): (WebCore::HTMLMediaElement::pauseInternal): (WebCore::HTMLMediaElement::playbackProgressTimerFired): (WebCore::HTMLMediaElement::updatePlayState): * html/HTMLMediaElement.h: * page/Page.cpp: (WebCore::createActivityToken): Added simple factory method. * page/Page.h: * page/PageActivityAssertionToken.cpp: (WebCore::PageActivityAssertionToken::PageActivityAssertionToken): Call addActivityToken(); (WebCore::PageActivityAssertionToken::~PageActivityAssertionToken): Call removeActivityToken(); (WebCore::PageActivityAssertionToken::invalidate): Clear m_throttler. * page/PageActivityAssertionToken.h: * page/PageThrottler.cpp: (WebCore::PageThrottler::~PageThrottler): Invalidate all outstanding tokens. (WebCore::PageThrottler::addActivityToken): Bump the activity count. (WebCore::PageThrottler::removeActivityToken): Lower the activity count. * page/PageThrottler.h: Add the new files to the various build systems: * CMakeLists.txt: * GNUmakefile.list.am: * Target.pri: * WebCore.vcproj/WebCore.vcproj: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/135303@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@150971 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-05-30 18:19:00 +00:00
#include <wtf/Noncopyable.h>
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
#include <wtf/RefPtr.h>
#include <wtf/SetForScope.h>
HTMLMediaElement will not unthrottle page when playback stops for nreasons other than user-initiated pause. https://bugs.webkit.org/show_bug.cgi?id=117016 Reviewed by Oliver Hunt. Add a new class PageActivityAssertionToken to allow HTMLMediaElement to decouple knowledge of and control over the lifetime of PageThrottler. The new class will have weak references to and from the PageThrottler so that holders of the token will not need to care if the Page or PageThrottler has been destroyed. HTMLMediaElement will create one of these PageActivityAssertionTokens when playback begins and destroy it when playback stops for any reason, or when the element is destroyed. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::~HTMLMediaElement): (WebCore::HTMLMediaElement::playInternal): (WebCore::HTMLMediaElement::pauseInternal): (WebCore::HTMLMediaElement::playbackProgressTimerFired): (WebCore::HTMLMediaElement::updatePlayState): * html/HTMLMediaElement.h: * page/Page.cpp: (WebCore::createActivityToken): Added simple factory method. * page/Page.h: * page/PageActivityAssertionToken.cpp: (WebCore::PageActivityAssertionToken::PageActivityAssertionToken): Call addActivityToken(); (WebCore::PageActivityAssertionToken::~PageActivityAssertionToken): Call removeActivityToken(); (WebCore::PageActivityAssertionToken::invalidate): Clear m_throttler. * page/PageActivityAssertionToken.h: * page/PageThrottler.cpp: (WebCore::PageThrottler::~PageThrottler): Invalidate all outstanding tokens. (WebCore::PageThrottler::addActivityToken): Bump the activity count. (WebCore::PageThrottler::removeActivityToken): Lower the activity count. * page/PageThrottler.h: Add the new files to the various build systems: * CMakeLists.txt: * GNUmakefile.list.am: * Target.pri: * WebCore.vcproj/WebCore.vcproj: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/135303@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@150971 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-05-30 18:19:00 +00:00
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
namespace WTF {
HTMLMediaElement will not unthrottle page when playback stops for nreasons other than user-initiated pause. https://bugs.webkit.org/show_bug.cgi?id=117016 Reviewed by Oliver Hunt. Add a new class PageActivityAssertionToken to allow HTMLMediaElement to decouple knowledge of and control over the lifetime of PageThrottler. The new class will have weak references to and from the PageThrottler so that holders of the token will not need to care if the Page or PageThrottler has been destroyed. HTMLMediaElement will create one of these PageActivityAssertionTokens when playback begins and destroy it when playback stops for any reason, or when the element is destroyed. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::~HTMLMediaElement): (WebCore::HTMLMediaElement::playInternal): (WebCore::HTMLMediaElement::pauseInternal): (WebCore::HTMLMediaElement::playbackProgressTimerFired): (WebCore::HTMLMediaElement::updatePlayState): * html/HTMLMediaElement.h: * page/Page.cpp: (WebCore::createActivityToken): Added simple factory method. * page/Page.h: * page/PageActivityAssertionToken.cpp: (WebCore::PageActivityAssertionToken::PageActivityAssertionToken): Call addActivityToken(); (WebCore::PageActivityAssertionToken::~PageActivityAssertionToken): Call removeActivityToken(); (WebCore::PageActivityAssertionToken::invalidate): Clear m_throttler. * page/PageActivityAssertionToken.h: * page/PageThrottler.cpp: (WebCore::PageThrottler::~PageThrottler): Invalidate all outstanding tokens. (WebCore::PageThrottler::addActivityToken): Bump the activity count. (WebCore::PageThrottler::removeActivityToken): Lower the activity count. * page/PageThrottler.h: Add the new files to the various build systems: * CMakeLists.txt: * GNUmakefile.list.am: * Target.pri: * WebCore.vcproj/WebCore.vcproj: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/135303@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@150971 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-05-30 18:19:00 +00:00
RefCounter<T>::Event -> RefCounterEvent https://bugs.webkit.org/show_bug.cgi?id=154767 Reviewed by Darin Adler. RefCounter<T>::Event is kinda verbose to use, and there is no need for this to be specific to a particular typeof RefCounter. Move the enum class up to the top level & rename to RefCounterEvent. Source/WebCore: * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): (WebCore::m_audiblePluginHysteresis): (WebCore::m_mediaActivityCounter): (WebCore::m_pageLoadActivityCounter): * platform/VNodeTracker.cpp: (WebCore::VNodeTracker::singleton): (WebCore::VNodeTracker::VNodeTracker): (WebCore::m_lastWarningTime): Source/WebKit2: Also remove UserObservablePageToken - this is vestigial & not really offering anything over just using UserObservablePageCounter::Token directly. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): * UIProcess/Plugins/PluginProcessManager.h: * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): * UIProcess/ProcessThrottler.cpp: (WebKit::ProcessThrottler::ProcessThrottler): (WebKit::m_backgroundCounter): (WebKit::m_suspendMessageCount): * UIProcess/ProcessThrottler.h: * UIProcess/WebPageProxy.h: * UIProcess/WebProcessPool.cpp: (WebKit::WebProcessPool::WebProcessPool): (WebKit::m_processSuppressionDisabledForPageCounter): (WebKit::m_hiddenPageThrottlingAutoIncreasesCounter): * UIProcess/WebProcessPool.h: Source/WTF: * wtf/RefCounter.h: (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): Tools: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172920@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197360 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-29 18:55:21 +00:00
enum class RefCounterEvent { Decrement, Increment };
Should template RefCounter instead of RefCounter::Token https://bugs.webkit.org/show_bug.cgi?id=154691 Reviewed by Anders Carlsson. Source/WebCore: Mechanical update per RefCounter interface change. * page/PageThrottler.cpp: (WebCore::PageThrottler::mediaActivityToken): (WebCore::PageThrottler::pageLoadActivityToken): (WebCore::PageThrottler::setActivityFlag): * page/PageThrottler.h: * platform/VNodeTracker.h: Source/WebKit2: Mechanical update per RefCounter interface change. * UIProcess/Plugins/PluginProcessManager.h: (WebKit::PluginProcessManager::processSuppressionDisabledToken): (WebKit::PluginProcessManager::processSuppressionDisabled): * UIProcess/ProcessThrottler.h: (WebKit::ProcessThrottler::foregroundActivityToken): (WebKit::ProcessThrottler::backgroundActivityToken): * UIProcess/WebProcessPool.h: Source/WTF: My real goal here is to make the counter accurate. Currently returning a Token from token<>() results in ref-count churn. Fixing this either means changing the return value, or improving Token (which will probably mean replacing it with RefPtr). Either way would break the current type checking. Move type tag to RefCount so this can still be enforced. * WTF.vcxproj/WTF.vcxproj: * WTF.vcxproj/WTF.vcxproj.filters: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/RefCounter.cpp: Removed. - Removed RefCounter.cpp. * wtf/RefCounter.h: (WTF::RefCounter::Token::Token): (WTF::RefCounter::Token::operator bool): (WTF::RefCounter::RefCounter): (WTF::RefCounter::count): (WTF::RefCounter::value): (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): (WTF::RefCounter<T>::RefCounter): (WTF::RefCounter<T>::~RefCounter): (WTF::RefCounter<T>::Token::Token): (WTF::=): (WTF::RefCounter::token): Deleted. (WTF::RefCounter::Token<T>::Token): Deleted. - RefCounter -> RefCounter<T>, - Token<T> -> Token, - renamed token<>() -> count(). Tools: Mechanical update per RefCounter interface change. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172780@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197132 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-25 22:24:32 +00:00
template<typename T>
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
class RefCounter {
Mark more heap-allocated classes as fast allocated https://bugs.webkit.org/show_bug.cgi?id=194422 Reviewed by Ryosuke Niwa. Source/WebCore: * Modules/applepay/PaymentCoordinator.h: * Modules/beacon/NavigatorBeacon.h: * Modules/cache/DOMWindowCaches.h: * Modules/cache/WorkerGlobalScopeCaches.h: * Modules/credentialmanagement/NavigatorCredentials.h: * Modules/encryptedmedia/legacy/LegacyCDMPrivateClearKey.h: * Modules/gamepad/NavigatorGamepad.h: * Modules/indexeddb/IDBGetAllResult.h: * Modules/indexeddb/IDBGetResult.h: * Modules/indexeddb/IDBKeyData.h: * Modules/indexeddb/IDBValue.h: * Modules/indexeddb/WorkerGlobalScopeIndexedDatabase.h: * Modules/indexeddb/server/IndexValueEntry.h: * Modules/indexeddb/server/IndexValueStore.h: * Modules/indexeddb/server/MemoryBackingStoreTransaction.h: * Modules/indexeddb/server/MemoryCursor.h: * Modules/indexeddb/server/MemoryIDBBackingStore.h: * Modules/indexeddb/server/SQLiteIDBBackingStore.h: * Modules/indexeddb/server/SQLiteIDBCursor.h: * Modules/indexeddb/server/SQLiteIDBTransaction.h: * Modules/indexeddb/server/UniqueIDBDatabase.h: * Modules/indexeddb/shared/IDBDatabaseInfo.h: * Modules/indexeddb/shared/IDBResourceIdentifier.h: * Modules/indexeddb/shared/IDBTransactionInfo.h: * Modules/mediacapabilities/NavigatorMediaCapabilities.h: * Modules/mediasession/WebMediaSessionManager.cpp: * Modules/mediastream/NavigatorMediaDevices.h: * Modules/mediastream/libwebrtc/LibWebRTCDataChannelHandler.h: * Modules/mediastream/libwebrtc/LibWebRTCRtpReceiverBackend.h: * Modules/mediastream/libwebrtc/LibWebRTCRtpSenderBackend.h: * Modules/mediastream/libwebrtc/LibWebRTCRtpTransceiverBackend.h: * Modules/navigatorcontentutils/NavigatorContentUtils.h: * Modules/quota/DOMWindowQuota.h: * Modules/quota/NavigatorStorageQuota.h: * Modules/quota/WorkerNavigatorStorageQuota.h: * Modules/speech/DOMWindowSpeechSynthesis.h: * Modules/webaudio/BiquadProcessor.h: * Modules/webaudio/DelayProcessor.h: * Modules/webauthn/fido/FidoHidPacket.h: * Modules/webdriver/NavigatorWebDriver.h: * Modules/webgpu/DOMWindowWebGPU.h: * Modules/websockets/WebSocketChannel.h: * Modules/webvr/NavigatorWebVR.h: * accessibility/AXObjectCache.h: * bindings/js/DOMGCOutputConstraint.h: * bindings/js/DOMPromiseProxy.h: * bridge/c/c_runtime.h: * contentextensions/CombinedURLFilters.cpp: * crypto/CryptoAlgorithmParameters.h: * css/CSSComputedStyleDeclaration.h: * css/CSSRegisteredCustomProperty.h: * css/DOMCSSPaintWorklet.h: * css/DOMCSSRegisterCustomProperty.h: * css/StyleRule.h: * dom/ConstantPropertyMap.h: * dom/CustomElementReactionQueue.h: * dom/Document.h: * dom/GenericEventQueue.h: * dom/RejectedPromiseTracker.h: * dom/UserGestureIndicator.h: * editing/ReplaceSelectionCommand.cpp: * editing/SelectionRectGatherer.h: * editing/TextIterator.h: * editing/cocoa/HTMLConverter.mm: * fileapi/AsyncFileStream.cpp: * fileapi/AsyncFileStream.h: * html/forms/FileIconLoader.h: * html/parser/HTMLTreeBuilder.h: * html/track/WebVTTParser.h: * inspector/DOMPatchSupport.cpp: * loader/FrameLoaderClient.h: * loader/WorkerThreadableLoader.cpp: * page/IntersectionObserver.h: * page/PerformanceMonitor.h: * page/PerformanceUserTiming.h: * page/PrintContext.h: * page/ValidationMessageClient.h: * platform/ColorChooser.h: * platform/ControlStates.h: * platform/DataListSuggestionPicker.h: * platform/FileStream.h: * platform/KeyedCoding.h: * platform/LowPowerModeNotifier.h: * platform/PlatformSpeechSynthesizer.h: * platform/WebGLStateTracker.h: * platform/audio/AudioArray.h: * platform/audio/AudioDestination.h: * platform/audio/DownSampler.h: * platform/audio/DynamicsCompressor.h: * platform/audio/FFTFrame.h: * platform/audio/HRTFDatabase.h: * platform/audio/MultiChannelResampler.h: * platform/audio/Panner.h: * platform/audio/Reverb.h: * platform/audio/ReverbConvolver.h: * platform/audio/ReverbConvolverStage.h: * platform/audio/UpSampler.h: * platform/audio/mac/AudioSessionMac.cpp: * platform/audio/mac/CAAudioStreamDescription.h: * platform/audio/mac/CARingBuffer.h: * platform/cocoa/ScrollSnapAnimatorState.h: * platform/gamepad/PlatformGamepad.h: * platform/graphics/GraphicsLayer.cpp: * platform/graphics/GraphicsLayerFactory.h: * platform/graphics/PlatformTimeRanges.h: * platform/graphics/TextTrackRepresentation.h: * platform/graphics/avfoundation/objc/CDMSessionAVContentKeySession.h: * platform/graphics/avfoundation/objc/CDMSessionAVStreamSession.h: * platform/graphics/avfoundation/objc/MediaPlaybackTargetPickerMac.h: * platform/graphics/displaylists/DisplayListRecorder.h: * platform/network/cocoa/WebCoreNSURLSession.mm: * platform/sql/SQLiteDatabase.h: * platform/text/TextCodecICU.h: * rendering/GridBaselineAlignment.h: * rendering/GridTrackSizingAlgorithm.h: * rendering/RenderObject.h: * rendering/style/GridArea.h: * workers/service/context/SWContextManager.h: Source/WebCore/PAL: * pal/crypto/openssl/CryptoDigestOpenSSL.cpp: * pal/system/Clock.h: Source/WebKit: * NetworkProcess/NetworkLoad.cpp: * NetworkProcess/NetworkLoadChecker.h: * NetworkProcess/NetworkResourceLoader.cpp: * Platform/IPC/Connection.h: * Platform/IPC/mac/ImportanceAssertion.h: * PluginProcess/PluginCreationParameters.h: * Shared/API/Cocoa/RemoteObjectRegistry.h: * Shared/WebEvent.h: * UIProcess/API/APIHTTPCookieStore.cpp: * UIProcess/API/APINotificationProvider.h: * UIProcess/API/Cocoa/PageLoadStateObserver.h: * UIProcess/API/Cocoa/WKHTTPCookieStore.mm: * UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _setInputDelegate:]): * UIProcess/API/gtk/PageClientImpl.h: * UIProcess/BackingStore.h: * UIProcess/Cocoa/AutomationClient.h: * UIProcess/Cocoa/DiagnosticLoggingClient.h: * UIProcess/Cocoa/DownloadClient.h: * UIProcess/Cocoa/FindClient.h: * UIProcess/Cocoa/NavigationState.h: * UIProcess/Cocoa/UIDelegate.h: * UIProcess/Cocoa/ViewGestureController.h: * UIProcess/DeviceIdHashSaltStorage.h: * UIProcess/Downloads/DownloadProxyMap.h: * UIProcess/Gamepad/UIGamepad.h: * UIProcess/Notifications/WebNotificationProvider.h: * UIProcess/ProcessAssertion.h: * UIProcess/RemoteLayerTree/RemoteLayerTreeHost.h: * UIProcess/WebContextInjectedBundleClient.h: * UIProcess/WebFormClient.h: * UIProcess/WebGeolocationProvider.h: * UIProcess/WebPageProxy.h: * WebProcess/Automation/WebAutomationSessionProxy.h: * WebProcess/InjectedBundle/API/APIInjectedBundleBundleClient.h: * WebProcess/InjectedBundle/API/APIInjectedBundleEditorClient.h: * WebProcess/InjectedBundle/API/APIInjectedBundlePageContextMenuClient.h: * WebProcess/InjectedBundle/API/APIInjectedBundlePageLoaderClient.h: * WebProcess/InjectedBundle/API/APIInjectedBundlePageResourceLoadClient.h: * WebProcess/InjectedBundle/API/APIInjectedBundlePageUIClient.h: * WebProcess/InjectedBundle/APIInjectedBundleFormClient.h: * WebProcess/Network/webrtc/LibWebRTCNetwork.h: * WebProcess/Network/webrtc/LibWebRTCSocket.h: * WebProcess/Network/webrtc/WebRTCResolver.h: * WebProcess/WebCoreSupport/WebInspectorClient.cpp: * WebProcess/WebPage/DrawingArea.h: Source/WTF: * wtf/Function.h: (WTF::Function<Out): * wtf/RefCounter.h: * wtf/URL.h: * wtf/text/StringView.cpp: Canonical link: https://commits.webkit.org/208851@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@241183 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-02-08 02:38:46 +00:00
WTF_MAKE_FAST_ALLOCATED;
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
WTF_MAKE_NONCOPYABLE(RefCounter);
Add strong typing to RefCounter interface, return value as a bool. https://bugs.webkit.org/show_bug.cgi?id=139776 Reviewed by Geoff Garen. Currently all token vended by a RefCounter have the same type - Ref<RefCounter::Count>. This means there is no compile time type checking to prevent mistakes. Update the count() method to token<>(), templated on type used to identify the token being returned. Calls to token<T>() will return a result of type RefCounter::Token<T>. There are a few problems with the fact the counter will return you an exact count of the number of outstanding tokens: - It is desirable to only fire the callback on zero-edge changes; it is more consistent to do so if the value is only readable as a boolean. - It is desirable to provide the value as an argument to the callback, however to make this useful for integer values it is also necessary to indicate the direction of change (0->1 is often interesting where 2->1 is not). - There is a mismatch between the precision of returning a count, and the inherent imprecision of a token based mechanism, where it may be difficult to guarantee absolutely no unnecessary refcount churn, and thus unintentional counter values. Source/WebCore: * page/PageThrottler.cpp: (WebCore::m_mediaActivityCounter): (WebCore::m_pageLoadActivityCounter): - lambdas now passed the value. (WebCore::PageThrottler::mediaActivityToken): (WebCore::PageThrottler::pageLoadActivityToken): - count() -> token<>(). * page/PageThrottler.h: - specify tpoken type for PageActivityAssertionToken. Source/WebKit2: Removed PluginProcessManager::m_processSuppressionEnabled. Now the callback only fires on zero-edge transitions we no longer need this to filter changes. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): - updateProcessSuppressionState -> updateProcessSuppressionDisabled. * UIProcess/Plugins/PluginProcessManager.h: (WebKit::PluginProcessManager::processSuppressionDisabledForPageCount): Deleted. (WebKit::PluginProcessManager::processSuppressionDisabledToken): - processSuppressionDisabledForPageCount -> processSuppressionDisabledToken. (WebKit::PluginProcessManager::processSuppressionEnabled): Deleted. (WebKit::PluginProcessManager::processSuppressionDisabled): - processSuppressionEnabled -> processSuppressionDisabled. * UIProcess/Plugins/PluginProcessProxy.cpp: (WebKit::PluginProcessProxy::didFinishLaunching): - processSuppressionEnabled -> processSuppressionDisabled. * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionState): Deleted. (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): - updateProcessSuppressionState -> updateProcessSuppressionDisabled * UIProcess/ProcessThrottler.h: - added UserObservablePageToken, ProcessSuppressionDisabledToken types. * UIProcess/WebContext.cpp: (WebKit::WebContext::WebContext): (WebKit::m_processSuppressionDisabledForPageCounter): - lambda now has bool argument. * UIProcess/WebContext.h: (WebKit::WebContext::userObservablePageCount): (WebKit::WebContext::processSuppressionDisabledForPageCount): - count() -> token<>(), changed return type. * UIProcess/WebPageProxy.h: - changed types of token members. * UIProcess/mac/WebContextMac.mm: (WebKit::WebContext::updateProcessSuppressionState): renamed m_pluginProcessManagerProcessSuppressionDisabledCount -> m_pluginProcessManagerProcessSuppressionDisabledToken. Source/WTF: * wtf/RefCounter.cpp: (WTF::RefCounter::Count::ref): (WTF::RefCounter::Count::deref): - only call the callback on zero-edge changes; provide the value. (WTF::RefCounter::RefCounter): - callback now takes a bool argument. * wtf/RefCounter.h: (WTF::RefCounter::Token::Token): - New opaque type to reference the RefCounter::Count. (WTF::RefCounter::Token::operator!): - ! operator checks for null / anasigned Tokens. (WTF::RefCounter::RefCounter): - callback now takes a bool argument. (WTF::RefCounter::token): - renamed from count(), templated on type of token returned. (WTF::RefCounter::value): - now returns a bool. (WTF::RefCounter::Token<T>::Token): (WTF::=): - Tokens can be copied & assigned. (WTF::RefCounter::count): Deleted. - renamed to token<>(). Tools: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): - update API test. Canonical link: https://commits.webkit.org/157717@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177541 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-19 00:51:47 +00:00
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
class Count {
WTF_MAKE_NONCOPYABLE(Count);
public:
void ref();
void deref();
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
void refCounterWasDeleted();
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
private:
friend class RefCounter;
Count(RefCounter& refCounter)
: m_refCounter(&refCounter)
, m_value(0)
{
}
RefCounter* m_refCounter;
Source/WebCore: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Anders Carlsson. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - Updated for change in RefCounter callback siganture. * platform/VNodeTracker.cpp: (WebCore::VNodeTracker::VNodeTracker): - Can now use RefCounter callback to trigger checkPressureState(). (WebCore::VNodeTracker::pressureWarningTimerFired): - RefCounter count is now a size_t (%d -> %ul). * platform/VNodeTracker.h: - simplified VNodeTracker::token() [no longer needs to call checkPressureState()]. Source/WebKit2: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Anders Carlsson. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): - Updated for change in RefCounter callback siganture. * UIProcess/Plugins/PluginProcessManager.h: - Updated for change in RefCounter callback siganture. * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): - updated logic for enabling process supression. * UIProcess/ProcessThrottler.cpp: (WebKit::ProcessThrottler::ProcessThrottler): - Updated for change in RefCounter callback siganture. * UIProcess/WebProcessPool.cpp: (WebKit::WebProcessPool::WebProcessPool): - Updated for change in RefCounter callback siganture. Source/WTF: Unreviewed, rolling out r197168. https://bugs.webkit.org/show_bug.cgi?id=154728 crashing on some devices (Requested by kling on #webkit). Reverted changeset: "[Darwin] Use vm_kernel_page_size for WTF::pageSize()." https://bugs.webkit.org/show_bug.cgi?id=154726 http://trac.webkit.org/changeset/197168 Patch by Commit Queue <commit-queue@webkit.org> on 2016-02-26 Tools: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Geoff Garen. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): - Updated for change in RefCounter callback siganture & behaviour. Canonical link: https://commits.webkit.org/172825@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-26 18:20:07 +00:00
size_t m_value;
bool m_inValueDidChange { false };
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
};
Add strong typing to RefCounter interface, return value as a bool. https://bugs.webkit.org/show_bug.cgi?id=139776 Reviewed by Geoff Garen. Currently all token vended by a RefCounter have the same type - Ref<RefCounter::Count>. This means there is no compile time type checking to prevent mistakes. Update the count() method to token<>(), templated on type used to identify the token being returned. Calls to token<T>() will return a result of type RefCounter::Token<T>. There are a few problems with the fact the counter will return you an exact count of the number of outstanding tokens: - It is desirable to only fire the callback on zero-edge changes; it is more consistent to do so if the value is only readable as a boolean. - It is desirable to provide the value as an argument to the callback, however to make this useful for integer values it is also necessary to indicate the direction of change (0->1 is often interesting where 2->1 is not). - There is a mismatch between the precision of returning a count, and the inherent imprecision of a token based mechanism, where it may be difficult to guarantee absolutely no unnecessary refcount churn, and thus unintentional counter values. Source/WebCore: * page/PageThrottler.cpp: (WebCore::m_mediaActivityCounter): (WebCore::m_pageLoadActivityCounter): - lambdas now passed the value. (WebCore::PageThrottler::mediaActivityToken): (WebCore::PageThrottler::pageLoadActivityToken): - count() -> token<>(). * page/PageThrottler.h: - specify tpoken type for PageActivityAssertionToken. Source/WebKit2: Removed PluginProcessManager::m_processSuppressionEnabled. Now the callback only fires on zero-edge transitions we no longer need this to filter changes. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): - updateProcessSuppressionState -> updateProcessSuppressionDisabled. * UIProcess/Plugins/PluginProcessManager.h: (WebKit::PluginProcessManager::processSuppressionDisabledForPageCount): Deleted. (WebKit::PluginProcessManager::processSuppressionDisabledToken): - processSuppressionDisabledForPageCount -> processSuppressionDisabledToken. (WebKit::PluginProcessManager::processSuppressionEnabled): Deleted. (WebKit::PluginProcessManager::processSuppressionDisabled): - processSuppressionEnabled -> processSuppressionDisabled. * UIProcess/Plugins/PluginProcessProxy.cpp: (WebKit::PluginProcessProxy::didFinishLaunching): - processSuppressionEnabled -> processSuppressionDisabled. * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionState): Deleted. (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): - updateProcessSuppressionState -> updateProcessSuppressionDisabled * UIProcess/ProcessThrottler.h: - added UserObservablePageToken, ProcessSuppressionDisabledToken types. * UIProcess/WebContext.cpp: (WebKit::WebContext::WebContext): (WebKit::m_processSuppressionDisabledForPageCounter): - lambda now has bool argument. * UIProcess/WebContext.h: (WebKit::WebContext::userObservablePageCount): (WebKit::WebContext::processSuppressionDisabledForPageCount): - count() -> token<>(), changed return type. * UIProcess/WebPageProxy.h: - changed types of token members. * UIProcess/mac/WebContextMac.mm: (WebKit::WebContext::updateProcessSuppressionState): renamed m_pluginProcessManagerProcessSuppressionDisabledCount -> m_pluginProcessManagerProcessSuppressionDisabledToken. Source/WTF: * wtf/RefCounter.cpp: (WTF::RefCounter::Count::ref): (WTF::RefCounter::Count::deref): - only call the callback on zero-edge changes; provide the value. (WTF::RefCounter::RefCounter): - callback now takes a bool argument. * wtf/RefCounter.h: (WTF::RefCounter::Token::Token): - New opaque type to reference the RefCounter::Count. (WTF::RefCounter::Token::operator!): - ! operator checks for null / anasigned Tokens. (WTF::RefCounter::RefCounter): - callback now takes a bool argument. (WTF::RefCounter::token): - renamed from count(), templated on type of token returned. (WTF::RefCounter::value): - now returns a bool. (WTF::RefCounter::Token<T>::Token): (WTF::=): - Tokens can be copied & assigned. (WTF::RefCounter::count): Deleted. - renamed to token<>(). Tools: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): - update API test. Canonical link: https://commits.webkit.org/157717@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177541 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-19 00:51:47 +00:00
public:
using Token = RefPtr<Count>;
Use WTF::Function instead of std::function in WTF/ https://bugs.webkit.org/show_bug.cgi?id=173519 Reviewed by Sam Weinig. Source/WebCore: Replace a few uses of std::function with WTF::Function in WebCore/ as well. It was either this or including <functional> and I decided it made more sense to port the code. * platform/graphics/FontSelectionAlgorithm.h: (WebCore::FontSelectionAlgorithm::iterateActiveCapabilitiesWithReturn): * platform/mediastream/MediaConstraints.cpp: (WebCore::StringConstraint::find): (WebCore::MediaTrackConstraintSetMap::forEach): (WebCore::MediaTrackConstraintSetMap::filter): (WebCore::MediaConstraints::isConstraintSet): * platform/mediastream/MediaConstraints.h: (WebCore::NumericConstraint::find): * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::applyConstraint): Source/WTF: Use WTF::Function instead of std::function in WTF/ to avoid copying. * wtf/Brigand.h: * wtf/Condition.h: * wtf/Expected.h: * wtf/FunctionDispatcher.h: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: (WTF::MemoryPressureHandler::setMemoryKillCallback): (WTF::MemoryPressureHandler::setMemoryPressureStatusChangedCallback): (WTF::MemoryPressureHandler::setDidExceedInactiveLimitWhileActiveCallback): * wtf/Optional.h: * wtf/ParkingLot.h: * wtf/RefCounter.h: (WTF::RefCounter<T>::RefCounter): * wtf/WorkQueue.h: * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): * wtf/text/WTFString.cpp: (WTF::String::split): * wtf/text/WTFString.h: Canonical link: https://commits.webkit.org/190415@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-18 19:49:12 +00:00
using ValueChangeFunction = WTF::Function<void (RefCounterEvent)>;
Add strong typing to RefCounter interface, return value as a bool. https://bugs.webkit.org/show_bug.cgi?id=139776 Reviewed by Geoff Garen. Currently all token vended by a RefCounter have the same type - Ref<RefCounter::Count>. This means there is no compile time type checking to prevent mistakes. Update the count() method to token<>(), templated on type used to identify the token being returned. Calls to token<T>() will return a result of type RefCounter::Token<T>. There are a few problems with the fact the counter will return you an exact count of the number of outstanding tokens: - It is desirable to only fire the callback on zero-edge changes; it is more consistent to do so if the value is only readable as a boolean. - It is desirable to provide the value as an argument to the callback, however to make this useful for integer values it is also necessary to indicate the direction of change (0->1 is often interesting where 2->1 is not). - There is a mismatch between the precision of returning a count, and the inherent imprecision of a token based mechanism, where it may be difficult to guarantee absolutely no unnecessary refcount churn, and thus unintentional counter values. Source/WebCore: * page/PageThrottler.cpp: (WebCore::m_mediaActivityCounter): (WebCore::m_pageLoadActivityCounter): - lambdas now passed the value. (WebCore::PageThrottler::mediaActivityToken): (WebCore::PageThrottler::pageLoadActivityToken): - count() -> token<>(). * page/PageThrottler.h: - specify tpoken type for PageActivityAssertionToken. Source/WebKit2: Removed PluginProcessManager::m_processSuppressionEnabled. Now the callback only fires on zero-edge transitions we no longer need this to filter changes. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): - updateProcessSuppressionState -> updateProcessSuppressionDisabled. * UIProcess/Plugins/PluginProcessManager.h: (WebKit::PluginProcessManager::processSuppressionDisabledForPageCount): Deleted. (WebKit::PluginProcessManager::processSuppressionDisabledToken): - processSuppressionDisabledForPageCount -> processSuppressionDisabledToken. (WebKit::PluginProcessManager::processSuppressionEnabled): Deleted. (WebKit::PluginProcessManager::processSuppressionDisabled): - processSuppressionEnabled -> processSuppressionDisabled. * UIProcess/Plugins/PluginProcessProxy.cpp: (WebKit::PluginProcessProxy::didFinishLaunching): - processSuppressionEnabled -> processSuppressionDisabled. * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionState): Deleted. (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): - updateProcessSuppressionState -> updateProcessSuppressionDisabled * UIProcess/ProcessThrottler.h: - added UserObservablePageToken, ProcessSuppressionDisabledToken types. * UIProcess/WebContext.cpp: (WebKit::WebContext::WebContext): (WebKit::m_processSuppressionDisabledForPageCounter): - lambda now has bool argument. * UIProcess/WebContext.h: (WebKit::WebContext::userObservablePageCount): (WebKit::WebContext::processSuppressionDisabledForPageCount): - count() -> token<>(), changed return type. * UIProcess/WebPageProxy.h: - changed types of token members. * UIProcess/mac/WebContextMac.mm: (WebKit::WebContext::updateProcessSuppressionState): renamed m_pluginProcessManagerProcessSuppressionDisabledCount -> m_pluginProcessManagerProcessSuppressionDisabledToken. Source/WTF: * wtf/RefCounter.cpp: (WTF::RefCounter::Count::ref): (WTF::RefCounter::Count::deref): - only call the callback on zero-edge changes; provide the value. (WTF::RefCounter::RefCounter): - callback now takes a bool argument. * wtf/RefCounter.h: (WTF::RefCounter::Token::Token): - New opaque type to reference the RefCounter::Count. (WTF::RefCounter::Token::operator!): - ! operator checks for null / anasigned Tokens. (WTF::RefCounter::RefCounter): - callback now takes a bool argument. (WTF::RefCounter::token): - renamed from count(), templated on type of token returned. (WTF::RefCounter::value): - now returns a bool. (WTF::RefCounter::Token<T>::Token): (WTF::=): - Tokens can be copied & assigned. (WTF::RefCounter::count): Deleted. - renamed to token<>(). Tools: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): - update API test. Canonical link: https://commits.webkit.org/157717@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177541 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-19 00:51:47 +00:00
Use WTF::Function instead of std::function in WTF/ https://bugs.webkit.org/show_bug.cgi?id=173519 Reviewed by Sam Weinig. Source/WebCore: Replace a few uses of std::function with WTF::Function in WebCore/ as well. It was either this or including <functional> and I decided it made more sense to port the code. * platform/graphics/FontSelectionAlgorithm.h: (WebCore::FontSelectionAlgorithm::iterateActiveCapabilitiesWithReturn): * platform/mediastream/MediaConstraints.cpp: (WebCore::StringConstraint::find): (WebCore::MediaTrackConstraintSetMap::forEach): (WebCore::MediaTrackConstraintSetMap::filter): (WebCore::MediaConstraints::isConstraintSet): * platform/mediastream/MediaConstraints.h: (WebCore::NumericConstraint::find): * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::applyConstraint): Source/WTF: Use WTF::Function instead of std::function in WTF/ to avoid copying. * wtf/Brigand.h: * wtf/Condition.h: * wtf/Expected.h: * wtf/FunctionDispatcher.h: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: (WTF::MemoryPressureHandler::setMemoryKillCallback): (WTF::MemoryPressureHandler::setMemoryPressureStatusChangedCallback): (WTF::MemoryPressureHandler::setDidExceedInactiveLimitWhileActiveCallback): * wtf/Optional.h: * wtf/ParkingLot.h: * wtf/RefCounter.h: (WTF::RefCounter<T>::RefCounter): * wtf/WorkQueue.h: * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): * wtf/text/WTFString.cpp: (WTF::String::split): * wtf/text/WTFString.h: Canonical link: https://commits.webkit.org/190415@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-18 19:49:12 +00:00
RefCounter(ValueChangeFunction&& = nullptr);
~RefCounter();
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
Should template RefCounter instead of RefCounter::Token https://bugs.webkit.org/show_bug.cgi?id=154691 Reviewed by Anders Carlsson. Source/WebCore: Mechanical update per RefCounter interface change. * page/PageThrottler.cpp: (WebCore::PageThrottler::mediaActivityToken): (WebCore::PageThrottler::pageLoadActivityToken): (WebCore::PageThrottler::setActivityFlag): * page/PageThrottler.h: * platform/VNodeTracker.h: Source/WebKit2: Mechanical update per RefCounter interface change. * UIProcess/Plugins/PluginProcessManager.h: (WebKit::PluginProcessManager::processSuppressionDisabledToken): (WebKit::PluginProcessManager::processSuppressionDisabled): * UIProcess/ProcessThrottler.h: (WebKit::ProcessThrottler::foregroundActivityToken): (WebKit::ProcessThrottler::backgroundActivityToken): * UIProcess/WebProcessPool.h: Source/WTF: My real goal here is to make the counter accurate. Currently returning a Token from token<>() results in ref-count churn. Fixing this either means changing the return value, or improving Token (which will probably mean replacing it with RefPtr). Either way would break the current type checking. Move type tag to RefCount so this can still be enforced. * WTF.vcxproj/WTF.vcxproj: * WTF.vcxproj/WTF.vcxproj.filters: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/RefCounter.cpp: Removed. - Removed RefCounter.cpp. * wtf/RefCounter.h: (WTF::RefCounter::Token::Token): (WTF::RefCounter::Token::operator bool): (WTF::RefCounter::RefCounter): (WTF::RefCounter::count): (WTF::RefCounter::value): (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): (WTF::RefCounter<T>::RefCounter): (WTF::RefCounter<T>::~RefCounter): (WTF::RefCounter<T>::Token::Token): (WTF::=): (WTF::RefCounter::token): Deleted. (WTF::RefCounter::Token<T>::Token): Deleted. - RefCounter -> RefCounter<T>, - Token<T> -> Token, - renamed token<>() -> count(). Tools: Mechanical update per RefCounter interface change. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172780@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197132 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-25 22:24:32 +00:00
Token count() const
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
{
return m_count;
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
}
Source/WebCore: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Anders Carlsson. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - Updated for change in RefCounter callback siganture. * platform/VNodeTracker.cpp: (WebCore::VNodeTracker::VNodeTracker): - Can now use RefCounter callback to trigger checkPressureState(). (WebCore::VNodeTracker::pressureWarningTimerFired): - RefCounter count is now a size_t (%d -> %ul). * platform/VNodeTracker.h: - simplified VNodeTracker::token() [no longer needs to call checkPressureState()]. Source/WebKit2: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Anders Carlsson. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): - Updated for change in RefCounter callback siganture. * UIProcess/Plugins/PluginProcessManager.h: - Updated for change in RefCounter callback siganture. * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): - updated logic for enabling process supression. * UIProcess/ProcessThrottler.cpp: (WebKit::ProcessThrottler::ProcessThrottler): - Updated for change in RefCounter callback siganture. * UIProcess/WebProcessPool.cpp: (WebKit::WebProcessPool::WebProcessPool): - Updated for change in RefCounter callback siganture. Source/WTF: Unreviewed, rolling out r197168. https://bugs.webkit.org/show_bug.cgi?id=154728 crashing on some devices (Requested by kling on #webkit). Reverted changeset: "[Darwin] Use vm_kernel_page_size for WTF::pageSize()." https://bugs.webkit.org/show_bug.cgi?id=154726 http://trac.webkit.org/changeset/197168 Patch by Commit Queue <commit-queue@webkit.org> on 2016-02-26 Tools: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Geoff Garen. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): - Updated for change in RefCounter callback siganture & behaviour. Canonical link: https://commits.webkit.org/172825@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-26 18:20:07 +00:00
size_t value() const
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
{
return m_count->m_value;
}
HTMLMediaElement will not unthrottle page when playback stops for nreasons other than user-initiated pause. https://bugs.webkit.org/show_bug.cgi?id=117016 Reviewed by Oliver Hunt. Add a new class PageActivityAssertionToken to allow HTMLMediaElement to decouple knowledge of and control over the lifetime of PageThrottler. The new class will have weak references to and from the PageThrottler so that holders of the token will not need to care if the Page or PageThrottler has been destroyed. HTMLMediaElement will create one of these PageActivityAssertionTokens when playback begins and destroy it when playback stops for any reason, or when the element is destroyed. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::~HTMLMediaElement): (WebCore::HTMLMediaElement::playInternal): (WebCore::HTMLMediaElement::pauseInternal): (WebCore::HTMLMediaElement::playbackProgressTimerFired): (WebCore::HTMLMediaElement::updatePlayState): * html/HTMLMediaElement.h: * page/Page.cpp: (WebCore::createActivityToken): Added simple factory method. * page/Page.h: * page/PageActivityAssertionToken.cpp: (WebCore::PageActivityAssertionToken::PageActivityAssertionToken): Call addActivityToken(); (WebCore::PageActivityAssertionToken::~PageActivityAssertionToken): Call removeActivityToken(); (WebCore::PageActivityAssertionToken::invalidate): Clear m_throttler. * page/PageActivityAssertionToken.h: * page/PageThrottler.cpp: (WebCore::PageThrottler::~PageThrottler): Invalidate all outstanding tokens. (WebCore::PageThrottler::addActivityToken): Bump the activity count. (WebCore::PageThrottler::removeActivityToken): Lower the activity count. * page/PageThrottler.h: Add the new files to the various build systems: * CMakeLists.txt: * GNUmakefile.list.am: * Target.pri: * WebCore.vcproj/WebCore.vcproj: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/135303@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@150971 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-05-30 18:19:00 +00:00
private:
Source/WebCore: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Anders Carlsson. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - Updated for change in RefCounter callback siganture. * platform/VNodeTracker.cpp: (WebCore::VNodeTracker::VNodeTracker): - Can now use RefCounter callback to trigger checkPressureState(). (WebCore::VNodeTracker::pressureWarningTimerFired): - RefCounter count is now a size_t (%d -> %ul). * platform/VNodeTracker.h: - simplified VNodeTracker::token() [no longer needs to call checkPressureState()]. Source/WebKit2: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Anders Carlsson. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): - Updated for change in RefCounter callback siganture. * UIProcess/Plugins/PluginProcessManager.h: - Updated for change in RefCounter callback siganture. * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): - updated logic for enabling process supression. * UIProcess/ProcessThrottler.cpp: (WebKit::ProcessThrottler::ProcessThrottler): - Updated for change in RefCounter callback siganture. * UIProcess/WebProcessPool.cpp: (WebKit::WebProcessPool::WebProcessPool): - Updated for change in RefCounter callback siganture. Source/WTF: Unreviewed, rolling out r197168. https://bugs.webkit.org/show_bug.cgi?id=154728 crashing on some devices (Requested by kling on #webkit). Reverted changeset: "[Darwin] Use vm_kernel_page_size for WTF::pageSize()." https://bugs.webkit.org/show_bug.cgi?id=154726 http://trac.webkit.org/changeset/197168 Patch by Commit Queue <commit-queue@webkit.org> on 2016-02-26 Tools: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Geoff Garen. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): - Updated for change in RefCounter callback siganture & behaviour. Canonical link: https://commits.webkit.org/172825@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-26 18:20:07 +00:00
ValueChangeFunction m_valueDidChange;
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
Count* m_count;
HTMLMediaElement will not unthrottle page when playback stops for nreasons other than user-initiated pause. https://bugs.webkit.org/show_bug.cgi?id=117016 Reviewed by Oliver Hunt. Add a new class PageActivityAssertionToken to allow HTMLMediaElement to decouple knowledge of and control over the lifetime of PageThrottler. The new class will have weak references to and from the PageThrottler so that holders of the token will not need to care if the Page or PageThrottler has been destroyed. HTMLMediaElement will create one of these PageActivityAssertionTokens when playback begins and destroy it when playback stops for any reason, or when the element is destroyed. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::~HTMLMediaElement): (WebCore::HTMLMediaElement::playInternal): (WebCore::HTMLMediaElement::pauseInternal): (WebCore::HTMLMediaElement::playbackProgressTimerFired): (WebCore::HTMLMediaElement::updatePlayState): * html/HTMLMediaElement.h: * page/Page.cpp: (WebCore::createActivityToken): Added simple factory method. * page/Page.h: * page/PageActivityAssertionToken.cpp: (WebCore::PageActivityAssertionToken::PageActivityAssertionToken): Call addActivityToken(); (WebCore::PageActivityAssertionToken::~PageActivityAssertionToken): Call removeActivityToken(); (WebCore::PageActivityAssertionToken::invalidate): Clear m_throttler. * page/PageActivityAssertionToken.h: * page/PageThrottler.cpp: (WebCore::PageThrottler::~PageThrottler): Invalidate all outstanding tokens. (WebCore::PageThrottler::addActivityToken): Bump the activity count. (WebCore::PageThrottler::removeActivityToken): Lower the activity count. * page/PageThrottler.h: Add the new files to the various build systems: * CMakeLists.txt: * GNUmakefile.list.am: * Target.pri: * WebCore.vcproj/WebCore.vcproj: * WebCore.vcxproj/WebCore.vcxproj: * WebCore.vcxproj/WebCore.vcxproj.filters: * WebCore.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/135303@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@150971 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2013-05-30 18:19:00 +00:00
};
Should template RefCounter instead of RefCounter::Token https://bugs.webkit.org/show_bug.cgi?id=154691 Reviewed by Anders Carlsson. Source/WebCore: Mechanical update per RefCounter interface change. * page/PageThrottler.cpp: (WebCore::PageThrottler::mediaActivityToken): (WebCore::PageThrottler::pageLoadActivityToken): (WebCore::PageThrottler::setActivityFlag): * page/PageThrottler.h: * platform/VNodeTracker.h: Source/WebKit2: Mechanical update per RefCounter interface change. * UIProcess/Plugins/PluginProcessManager.h: (WebKit::PluginProcessManager::processSuppressionDisabledToken): (WebKit::PluginProcessManager::processSuppressionDisabled): * UIProcess/ProcessThrottler.h: (WebKit::ProcessThrottler::foregroundActivityToken): (WebKit::ProcessThrottler::backgroundActivityToken): * UIProcess/WebProcessPool.h: Source/WTF: My real goal here is to make the counter accurate. Currently returning a Token from token<>() results in ref-count churn. Fixing this either means changing the return value, or improving Token (which will probably mean replacing it with RefPtr). Either way would break the current type checking. Move type tag to RefCount so this can still be enforced. * WTF.vcxproj/WTF.vcxproj: * WTF.vcxproj/WTF.vcxproj.filters: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/RefCounter.cpp: Removed. - Removed RefCounter.cpp. * wtf/RefCounter.h: (WTF::RefCounter::Token::Token): (WTF::RefCounter::Token::operator bool): (WTF::RefCounter::RefCounter): (WTF::RefCounter::count): (WTF::RefCounter::value): (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): (WTF::RefCounter<T>::RefCounter): (WTF::RefCounter<T>::~RefCounter): (WTF::RefCounter<T>::Token::Token): (WTF::=): (WTF::RefCounter::token): Deleted. (WTF::RefCounter::Token<T>::Token): Deleted. - RefCounter -> RefCounter<T>, - Token<T> -> Token, - renamed token<>() -> count(). Tools: Mechanical update per RefCounter interface change. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172780@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197132 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-25 22:24:32 +00:00
template<typename T>
inline void RefCounter<T>::Count::ref()
{
++m_value;
Source/WebCore: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Anders Carlsson. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - Updated for change in RefCounter callback siganture. * platform/VNodeTracker.cpp: (WebCore::VNodeTracker::VNodeTracker): - Can now use RefCounter callback to trigger checkPressureState(). (WebCore::VNodeTracker::pressureWarningTimerFired): - RefCounter count is now a size_t (%d -> %ul). * platform/VNodeTracker.h: - simplified VNodeTracker::token() [no longer needs to call checkPressureState()]. Source/WebKit2: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Anders Carlsson. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): - Updated for change in RefCounter callback siganture. * UIProcess/Plugins/PluginProcessManager.h: - Updated for change in RefCounter callback siganture. * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): - updated logic for enabling process supression. * UIProcess/ProcessThrottler.cpp: (WebKit::ProcessThrottler::ProcessThrottler): - Updated for change in RefCounter callback siganture. * UIProcess/WebProcessPool.cpp: (WebKit::WebProcessPool::WebProcessPool): - Updated for change in RefCounter callback siganture. Source/WTF: Unreviewed, rolling out r197168. https://bugs.webkit.org/show_bug.cgi?id=154728 crashing on some devices (Requested by kling on #webkit). Reverted changeset: "[Darwin] Use vm_kernel_page_size for WTF::pageSize()." https://bugs.webkit.org/show_bug.cgi?id=154726 http://trac.webkit.org/changeset/197168 Patch by Commit Queue <commit-queue@webkit.org> on 2016-02-26 Tools: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Geoff Garen. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): - Updated for change in RefCounter callback siganture & behaviour. Canonical link: https://commits.webkit.org/172825@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-26 18:20:07 +00:00
if (m_refCounter && m_refCounter->m_valueDidChange)
RefCounter<T>::Event -> RefCounterEvent https://bugs.webkit.org/show_bug.cgi?id=154767 Reviewed by Darin Adler. RefCounter<T>::Event is kinda verbose to use, and there is no need for this to be specific to a particular typeof RefCounter. Move the enum class up to the top level & rename to RefCounterEvent. Source/WebCore: * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): (WebCore::m_audiblePluginHysteresis): (WebCore::m_mediaActivityCounter): (WebCore::m_pageLoadActivityCounter): * platform/VNodeTracker.cpp: (WebCore::VNodeTracker::singleton): (WebCore::VNodeTracker::VNodeTracker): (WebCore::m_lastWarningTime): Source/WebKit2: Also remove UserObservablePageToken - this is vestigial & not really offering anything over just using UserObservablePageCounter::Token directly. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): * UIProcess/Plugins/PluginProcessManager.h: * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): * UIProcess/ProcessThrottler.cpp: (WebKit::ProcessThrottler::ProcessThrottler): (WebKit::m_backgroundCounter): (WebKit::m_suspendMessageCount): * UIProcess/ProcessThrottler.h: * UIProcess/WebPageProxy.h: * UIProcess/WebProcessPool.cpp: (WebKit::WebProcessPool::WebProcessPool): (WebKit::m_processSuppressionDisabledForPageCounter): (WebKit::m_hiddenPageThrottlingAutoIncreasesCounter): * UIProcess/WebProcessPool.h: Source/WTF: * wtf/RefCounter.h: (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): Tools: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172920@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197360 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-29 18:55:21 +00:00
m_refCounter->m_valueDidChange(RefCounterEvent::Increment);
Should template RefCounter instead of RefCounter::Token https://bugs.webkit.org/show_bug.cgi?id=154691 Reviewed by Anders Carlsson. Source/WebCore: Mechanical update per RefCounter interface change. * page/PageThrottler.cpp: (WebCore::PageThrottler::mediaActivityToken): (WebCore::PageThrottler::pageLoadActivityToken): (WebCore::PageThrottler::setActivityFlag): * page/PageThrottler.h: * platform/VNodeTracker.h: Source/WebKit2: Mechanical update per RefCounter interface change. * UIProcess/Plugins/PluginProcessManager.h: (WebKit::PluginProcessManager::processSuppressionDisabledToken): (WebKit::PluginProcessManager::processSuppressionDisabled): * UIProcess/ProcessThrottler.h: (WebKit::ProcessThrottler::foregroundActivityToken): (WebKit::ProcessThrottler::backgroundActivityToken): * UIProcess/WebProcessPool.h: Source/WTF: My real goal here is to make the counter accurate. Currently returning a Token from token<>() results in ref-count churn. Fixing this either means changing the return value, or improving Token (which will probably mean replacing it with RefPtr). Either way would break the current type checking. Move type tag to RefCount so this can still be enforced. * WTF.vcxproj/WTF.vcxproj: * WTF.vcxproj/WTF.vcxproj.filters: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/RefCounter.cpp: Removed. - Removed RefCounter.cpp. * wtf/RefCounter.h: (WTF::RefCounter::Token::Token): (WTF::RefCounter::Token::operator bool): (WTF::RefCounter::RefCounter): (WTF::RefCounter::count): (WTF::RefCounter::value): (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): (WTF::RefCounter<T>::RefCounter): (WTF::RefCounter<T>::~RefCounter): (WTF::RefCounter<T>::Token::Token): (WTF::=): (WTF::RefCounter::token): Deleted. (WTF::RefCounter::Token<T>::Token): Deleted. - RefCounter -> RefCounter<T>, - Token<T> -> Token, - renamed token<>() -> count(). Tools: Mechanical update per RefCounter interface change. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172780@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197132 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-25 22:24:32 +00:00
}
template<typename T>
inline void RefCounter<T>::Count::deref()
{
ASSERT(m_value);
Source/WebCore: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Anders Carlsson. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - Updated for change in RefCounter callback siganture. * platform/VNodeTracker.cpp: (WebCore::VNodeTracker::VNodeTracker): - Can now use RefCounter callback to trigger checkPressureState(). (WebCore::VNodeTracker::pressureWarningTimerFired): - RefCounter count is now a size_t (%d -> %ul). * platform/VNodeTracker.h: - simplified VNodeTracker::token() [no longer needs to call checkPressureState()]. Source/WebKit2: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Anders Carlsson. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): - Updated for change in RefCounter callback siganture. * UIProcess/Plugins/PluginProcessManager.h: - Updated for change in RefCounter callback siganture. * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): - updated logic for enabling process supression. * UIProcess/ProcessThrottler.cpp: (WebKit::ProcessThrottler::ProcessThrottler): - Updated for change in RefCounter callback siganture. * UIProcess/WebProcessPool.cpp: (WebKit::WebProcessPool::WebProcessPool): - Updated for change in RefCounter callback siganture. Source/WTF: Unreviewed, rolling out r197168. https://bugs.webkit.org/show_bug.cgi?id=154728 crashing on some devices (Requested by kling on #webkit). Reverted changeset: "[Darwin] Use vm_kernel_page_size for WTF::pageSize()." https://bugs.webkit.org/show_bug.cgi?id=154726 http://trac.webkit.org/changeset/197168 Patch by Commit Queue <commit-queue@webkit.org> on 2016-02-26 Tools: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Geoff Garen. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): - Updated for change in RefCounter callback siganture & behaviour. Canonical link: https://commits.webkit.org/172825@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-26 18:20:07 +00:00
--m_value;
if (m_refCounter && m_refCounter->m_valueDidChange) {
SetForScope<bool> inCallback(m_inValueDidChange, true);
RefCounter<T>::Event -> RefCounterEvent https://bugs.webkit.org/show_bug.cgi?id=154767 Reviewed by Darin Adler. RefCounter<T>::Event is kinda verbose to use, and there is no need for this to be specific to a particular typeof RefCounter. Move the enum class up to the top level & rename to RefCounterEvent. Source/WebCore: * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): (WebCore::m_audiblePluginHysteresis): (WebCore::m_mediaActivityCounter): (WebCore::m_pageLoadActivityCounter): * platform/VNodeTracker.cpp: (WebCore::VNodeTracker::singleton): (WebCore::VNodeTracker::VNodeTracker): (WebCore::m_lastWarningTime): Source/WebKit2: Also remove UserObservablePageToken - this is vestigial & not really offering anything over just using UserObservablePageCounter::Token directly. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): * UIProcess/Plugins/PluginProcessManager.h: * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): * UIProcess/ProcessThrottler.cpp: (WebKit::ProcessThrottler::ProcessThrottler): (WebKit::m_backgroundCounter): (WebKit::m_suspendMessageCount): * UIProcess/ProcessThrottler.h: * UIProcess/WebPageProxy.h: * UIProcess/WebProcessPool.cpp: (WebKit::WebProcessPool::WebProcessPool): (WebKit::m_processSuppressionDisabledForPageCounter): (WebKit::m_hiddenPageThrottlingAutoIncreasesCounter): * UIProcess/WebProcessPool.h: Source/WTF: * wtf/RefCounter.h: (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): Tools: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172920@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197360 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-29 18:55:21 +00:00
m_refCounter->m_valueDidChange(RefCounterEvent::Decrement);
}
Should template RefCounter instead of RefCounter::Token https://bugs.webkit.org/show_bug.cgi?id=154691 Reviewed by Anders Carlsson. Source/WebCore: Mechanical update per RefCounter interface change. * page/PageThrottler.cpp: (WebCore::PageThrottler::mediaActivityToken): (WebCore::PageThrottler::pageLoadActivityToken): (WebCore::PageThrottler::setActivityFlag): * page/PageThrottler.h: * platform/VNodeTracker.h: Source/WebKit2: Mechanical update per RefCounter interface change. * UIProcess/Plugins/PluginProcessManager.h: (WebKit::PluginProcessManager::processSuppressionDisabledToken): (WebKit::PluginProcessManager::processSuppressionDisabled): * UIProcess/ProcessThrottler.h: (WebKit::ProcessThrottler::foregroundActivityToken): (WebKit::ProcessThrottler::backgroundActivityToken): * UIProcess/WebProcessPool.h: Source/WTF: My real goal here is to make the counter accurate. Currently returning a Token from token<>() results in ref-count churn. Fixing this either means changing the return value, or improving Token (which will probably mean replacing it with RefPtr). Either way would break the current type checking. Move type tag to RefCount so this can still be enforced. * WTF.vcxproj/WTF.vcxproj: * WTF.vcxproj/WTF.vcxproj.filters: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/RefCounter.cpp: Removed. - Removed RefCounter.cpp. * wtf/RefCounter.h: (WTF::RefCounter::Token::Token): (WTF::RefCounter::Token::operator bool): (WTF::RefCounter::RefCounter): (WTF::RefCounter::count): (WTF::RefCounter::value): (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): (WTF::RefCounter<T>::RefCounter): (WTF::RefCounter<T>::~RefCounter): (WTF::RefCounter<T>::Token::Token): (WTF::=): (WTF::RefCounter::token): Deleted. (WTF::RefCounter::Token<T>::Token): Deleted. - RefCounter -> RefCounter<T>, - Token<T> -> Token, - renamed token<>() -> count(). Tools: Mechanical update per RefCounter interface change. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172780@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197132 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-25 22:24:32 +00:00
// The Count object is kept alive so long as either the RefCounter that created it remains
// allocated, or so long as its reference count is non-zero.
// If the RefCounter has already been deallocted then delete the Count when its reference
// count reaches zero.
Source/WebCore: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Anders Carlsson. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - Updated for change in RefCounter callback siganture. * platform/VNodeTracker.cpp: (WebCore::VNodeTracker::VNodeTracker): - Can now use RefCounter callback to trigger checkPressureState(). (WebCore::VNodeTracker::pressureWarningTimerFired): - RefCounter count is now a size_t (%d -> %ul). * platform/VNodeTracker.h: - simplified VNodeTracker::token() [no longer needs to call checkPressureState()]. Source/WebKit2: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Anders Carlsson. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): - Updated for change in RefCounter callback siganture. * UIProcess/Plugins/PluginProcessManager.h: - Updated for change in RefCounter callback siganture. * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): - updated logic for enabling process supression. * UIProcess/ProcessThrottler.cpp: (WebKit::ProcessThrottler::ProcessThrottler): - Updated for change in RefCounter callback siganture. * UIProcess/WebProcessPool.cpp: (WebKit::WebProcessPool::WebProcessPool): - Updated for change in RefCounter callback siganture. Source/WTF: Unreviewed, rolling out r197168. https://bugs.webkit.org/show_bug.cgi?id=154728 crashing on some devices (Requested by kling on #webkit). Reverted changeset: "[Darwin] Use vm_kernel_page_size for WTF::pageSize()." https://bugs.webkit.org/show_bug.cgi?id=154726 http://trac.webkit.org/changeset/197168 Patch by Commit Queue <commit-queue@webkit.org> on 2016-02-26 Tools: RefCounter value changed callback should be called on all changes (not just zero edge). https://bugs.webkit.org/show_bug.cgi?id=154699 Reviewed by Geoff Garen. RefCounter currently only triggers a callback when the count goes from zero to non-zero and vice-versa. Change that, to be useful to more clients. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): - Updated for change in RefCounter callback siganture & behaviour. Canonical link: https://commits.webkit.org/172825@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197178 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-26 18:20:07 +00:00
if (!m_refCounter && !m_value)
Should template RefCounter instead of RefCounter::Token https://bugs.webkit.org/show_bug.cgi?id=154691 Reviewed by Anders Carlsson. Source/WebCore: Mechanical update per RefCounter interface change. * page/PageThrottler.cpp: (WebCore::PageThrottler::mediaActivityToken): (WebCore::PageThrottler::pageLoadActivityToken): (WebCore::PageThrottler::setActivityFlag): * page/PageThrottler.h: * platform/VNodeTracker.h: Source/WebKit2: Mechanical update per RefCounter interface change. * UIProcess/Plugins/PluginProcessManager.h: (WebKit::PluginProcessManager::processSuppressionDisabledToken): (WebKit::PluginProcessManager::processSuppressionDisabled): * UIProcess/ProcessThrottler.h: (WebKit::ProcessThrottler::foregroundActivityToken): (WebKit::ProcessThrottler::backgroundActivityToken): * UIProcess/WebProcessPool.h: Source/WTF: My real goal here is to make the counter accurate. Currently returning a Token from token<>() results in ref-count churn. Fixing this either means changing the return value, or improving Token (which will probably mean replacing it with RefPtr). Either way would break the current type checking. Move type tag to RefCount so this can still be enforced. * WTF.vcxproj/WTF.vcxproj: * WTF.vcxproj/WTF.vcxproj.filters: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/RefCounter.cpp: Removed. - Removed RefCounter.cpp. * wtf/RefCounter.h: (WTF::RefCounter::Token::Token): (WTF::RefCounter::Token::operator bool): (WTF::RefCounter::RefCounter): (WTF::RefCounter::count): (WTF::RefCounter::value): (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): (WTF::RefCounter<T>::RefCounter): (WTF::RefCounter<T>::~RefCounter): (WTF::RefCounter<T>::Token::Token): (WTF::=): (WTF::RefCounter::token): Deleted. (WTF::RefCounter::Token<T>::Token): Deleted. - RefCounter -> RefCounter<T>, - Token<T> -> Token, - renamed token<>() -> count(). Tools: Mechanical update per RefCounter interface change. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172780@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197132 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-25 22:24:32 +00:00
delete this;
}
template<typename T>
inline void RefCounter<T>::Count::refCounterWasDeleted()
{
// The Count object is kept alive so long as either the RefCounter that created it remains
// allocated, or so long as its reference count is non-zero.
// If the reference count of the Count is already zero then delete it now, otherwise
// clear its m_refCounter pointer.
m_refCounter = nullptr;
if (m_inValueDidChange)
return;
if (!m_value)
delete this;
}
Should template RefCounter instead of RefCounter::Token https://bugs.webkit.org/show_bug.cgi?id=154691 Reviewed by Anders Carlsson. Source/WebCore: Mechanical update per RefCounter interface change. * page/PageThrottler.cpp: (WebCore::PageThrottler::mediaActivityToken): (WebCore::PageThrottler::pageLoadActivityToken): (WebCore::PageThrottler::setActivityFlag): * page/PageThrottler.h: * platform/VNodeTracker.h: Source/WebKit2: Mechanical update per RefCounter interface change. * UIProcess/Plugins/PluginProcessManager.h: (WebKit::PluginProcessManager::processSuppressionDisabledToken): (WebKit::PluginProcessManager::processSuppressionDisabled): * UIProcess/ProcessThrottler.h: (WebKit::ProcessThrottler::foregroundActivityToken): (WebKit::ProcessThrottler::backgroundActivityToken): * UIProcess/WebProcessPool.h: Source/WTF: My real goal here is to make the counter accurate. Currently returning a Token from token<>() results in ref-count churn. Fixing this either means changing the return value, or improving Token (which will probably mean replacing it with RefPtr). Either way would break the current type checking. Move type tag to RefCount so this can still be enforced. * WTF.vcxproj/WTF.vcxproj: * WTF.vcxproj/WTF.vcxproj.filters: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/RefCounter.cpp: Removed. - Removed RefCounter.cpp. * wtf/RefCounter.h: (WTF::RefCounter::Token::Token): (WTF::RefCounter::Token::operator bool): (WTF::RefCounter::RefCounter): (WTF::RefCounter::count): (WTF::RefCounter::value): (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): (WTF::RefCounter<T>::RefCounter): (WTF::RefCounter<T>::~RefCounter): (WTF::RefCounter<T>::Token::Token): (WTF::=): (WTF::RefCounter::token): Deleted. (WTF::RefCounter::Token<T>::Token): Deleted. - RefCounter -> RefCounter<T>, - Token<T> -> Token, - renamed token<>() -> count(). Tools: Mechanical update per RefCounter interface change. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172780@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197132 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-25 22:24:32 +00:00
template<typename T>
Use WTF::Function instead of std::function in WTF/ https://bugs.webkit.org/show_bug.cgi?id=173519 Reviewed by Sam Weinig. Source/WebCore: Replace a few uses of std::function with WTF::Function in WebCore/ as well. It was either this or including <functional> and I decided it made more sense to port the code. * platform/graphics/FontSelectionAlgorithm.h: (WebCore::FontSelectionAlgorithm::iterateActiveCapabilitiesWithReturn): * platform/mediastream/MediaConstraints.cpp: (WebCore::StringConstraint::find): (WebCore::MediaTrackConstraintSetMap::forEach): (WebCore::MediaTrackConstraintSetMap::filter): (WebCore::MediaConstraints::isConstraintSet): * platform/mediastream/MediaConstraints.h: (WebCore::NumericConstraint::find): * platform/mediastream/RealtimeMediaSource.cpp: (WebCore::RealtimeMediaSource::applyConstraint): Source/WTF: Use WTF::Function instead of std::function in WTF/ to avoid copying. * wtf/Brigand.h: * wtf/Condition.h: * wtf/Expected.h: * wtf/FunctionDispatcher.h: * wtf/MainThread.h: * wtf/MemoryPressureHandler.h: (WTF::MemoryPressureHandler::setMemoryKillCallback): (WTF::MemoryPressureHandler::setMemoryPressureStatusChangedCallback): (WTF::MemoryPressureHandler::setDidExceedInactiveLimitWhileActiveCallback): * wtf/Optional.h: * wtf/ParkingLot.h: * wtf/RefCounter.h: (WTF::RefCounter<T>::RefCounter): * wtf/WorkQueue.h: * wtf/linux/MemoryPressureHandlerLinux.cpp: (WTF::MemoryPressureHandler::EventFDPoller::EventFDPoller): * wtf/text/WTFString.cpp: (WTF::String::split): * wtf/text/WTFString.h: Canonical link: https://commits.webkit.org/190415@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-18 19:49:12 +00:00
inline RefCounter<T>::RefCounter(ValueChangeFunction&& valueDidChange)
: m_valueDidChange(WTFMove(valueDidChange))
Should template RefCounter instead of RefCounter::Token https://bugs.webkit.org/show_bug.cgi?id=154691 Reviewed by Anders Carlsson. Source/WebCore: Mechanical update per RefCounter interface change. * page/PageThrottler.cpp: (WebCore::PageThrottler::mediaActivityToken): (WebCore::PageThrottler::pageLoadActivityToken): (WebCore::PageThrottler::setActivityFlag): * page/PageThrottler.h: * platform/VNodeTracker.h: Source/WebKit2: Mechanical update per RefCounter interface change. * UIProcess/Plugins/PluginProcessManager.h: (WebKit::PluginProcessManager::processSuppressionDisabledToken): (WebKit::PluginProcessManager::processSuppressionDisabled): * UIProcess/ProcessThrottler.h: (WebKit::ProcessThrottler::foregroundActivityToken): (WebKit::ProcessThrottler::backgroundActivityToken): * UIProcess/WebProcessPool.h: Source/WTF: My real goal here is to make the counter accurate. Currently returning a Token from token<>() results in ref-count churn. Fixing this either means changing the return value, or improving Token (which will probably mean replacing it with RefPtr). Either way would break the current type checking. Move type tag to RefCount so this can still be enforced. * WTF.vcxproj/WTF.vcxproj: * WTF.vcxproj/WTF.vcxproj.filters: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/RefCounter.cpp: Removed. - Removed RefCounter.cpp. * wtf/RefCounter.h: (WTF::RefCounter::Token::Token): (WTF::RefCounter::Token::operator bool): (WTF::RefCounter::RefCounter): (WTF::RefCounter::count): (WTF::RefCounter::value): (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): (WTF::RefCounter<T>::RefCounter): (WTF::RefCounter<T>::~RefCounter): (WTF::RefCounter<T>::Token::Token): (WTF::=): (WTF::RefCounter::token): Deleted. (WTF::RefCounter::Token<T>::Token): Deleted. - RefCounter -> RefCounter<T>, - Token<T> -> Token, - renamed token<>() -> count(). Tools: Mechanical update per RefCounter interface change. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172780@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197132 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-25 22:24:32 +00:00
, m_count(new Count(*this))
{
}
template<typename T>
inline RefCounter<T>::~RefCounter()
{
m_count->refCounterWasDeleted();
Should template RefCounter instead of RefCounter::Token https://bugs.webkit.org/show_bug.cgi?id=154691 Reviewed by Anders Carlsson. Source/WebCore: Mechanical update per RefCounter interface change. * page/PageThrottler.cpp: (WebCore::PageThrottler::mediaActivityToken): (WebCore::PageThrottler::pageLoadActivityToken): (WebCore::PageThrottler::setActivityFlag): * page/PageThrottler.h: * platform/VNodeTracker.h: Source/WebKit2: Mechanical update per RefCounter interface change. * UIProcess/Plugins/PluginProcessManager.h: (WebKit::PluginProcessManager::processSuppressionDisabledToken): (WebKit::PluginProcessManager::processSuppressionDisabled): * UIProcess/ProcessThrottler.h: (WebKit::ProcessThrottler::foregroundActivityToken): (WebKit::ProcessThrottler::backgroundActivityToken): * UIProcess/WebProcessPool.h: Source/WTF: My real goal here is to make the counter accurate. Currently returning a Token from token<>() results in ref-count churn. Fixing this either means changing the return value, or improving Token (which will probably mean replacing it with RefPtr). Either way would break the current type checking. Move type tag to RefCount so this can still be enforced. * WTF.vcxproj/WTF.vcxproj: * WTF.vcxproj/WTF.vcxproj.filters: * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/RefCounter.cpp: Removed. - Removed RefCounter.cpp. * wtf/RefCounter.h: (WTF::RefCounter::Token::Token): (WTF::RefCounter::Token::operator bool): (WTF::RefCounter::RefCounter): (WTF::RefCounter::count): (WTF::RefCounter::value): (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): (WTF::RefCounter<T>::RefCounter): (WTF::RefCounter<T>::~RefCounter): (WTF::RefCounter<T>::Token::Token): (WTF::=): (WTF::RefCounter::token): Deleted. (WTF::RefCounter::Token<T>::Token): Deleted. - RefCounter -> RefCounter<T>, - Token<T> -> Token, - renamed token<>() -> count(). Tools: Mechanical update per RefCounter interface change. * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172780@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197132 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-25 22:24:32 +00:00
}
Generalize PageActivityAssertionToken https://bugs.webkit.org/show_bug.cgi?id=139106 Reviewed by Sam Weinig. Source/WebCore: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WebCore.xcodeproj/project.pbxproj: - removed PageActivityAssertionToken.cpp/.h * html/HTMLMediaElement.cpp: - removed PageActivityAssertionToken.h * html/HTMLMediaElement.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/FrameLoader.cpp: - removed PageActivityAssertionToken.h * loader/FrameLoader.h: - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count> * loader/SubresourceLoader.cpp: - removed PageActivityAssertionToken.h * loader/SubresourceLoader.h: - removed class PageActivityAssertionToken * page/Page.cpp: - removed PageActivityAssertionToken.h (WebCore::Page::Page): - removed Page* parameter to PageThrottler * page/Page.h: - removed class PageActivityAssertionToken * page/PageActivityAssertionToken.cpp: Removed. * page/PageActivityAssertionToken.h: Removed. - removed PageActivityAssertionToken.cpp/.h * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter. (WebCore::PageThrottler::mediaActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageLoadActivityToken): - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count> (WebCore::PageThrottler::pageActivityCounterValueDidChange): - merged functionality of incrementActivityCount/decrementActivityCount (WebCore::PageThrottler::incrementActivityCount): Deleted. - see pageActivityCounterValueDidChange (WebCore::PageThrottler::decrementActivityCount): Deleted. - see pageActivityCounterValueDidChange * page/PageThrottler.h: (WebCore::PageThrottler::weakPtr): Deleted. - no longer required; this functionality is now encapsulated within RefCounter. Source/WTF: PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler to count user visible activity in progress on the page (currently page load and media playback). Use of an RAII type is prevents a number of possible errors, including double counting a single media element, or failing to decrement the count after a media element has been deallocated. The current implementation has a number of drawbacks that have been addressed by this refactoring: - specific to single use in PageThrottler class - not reusable. - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation are not encapsulated (are in the client type, PageThrottler). - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every increment requires an object allocation. - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this is internally implemented using a reference counted type, resulting in two counters being incremented (one in the PageActivityAssertionToken, one in the PageThrottler). In the reimplementation: - a callback is provided via a lambda function, which allows for easy reuse without a lot of boilerplate code. - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the RefCounter type. - a single count within RefCounter::Count stores the counter value, and also manage the lifetime of this object. - standard RefPtrs are used to manage references to the RefCounter::Count. * WTF.xcodeproj/project.pbxproj: - added RefCounter.cpp/.h * wtf/RefCounter.cpp: Added. (WTF::RefCounter::Count::ref): - increment the counter. (WTF::RefCounter::Count::deref): - decrement the counter, and delete as necessary. (WTF::RefCounter::RefCounter): - create a RefCounter::Count. (WTF::RefCounter::~RefCounter): - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref. * wtf/RefCounter.h: Added. (WTF::RefCounter::Count::Count): - initialize count to 0. (WTF::RefCounter::RefCounter): - takes a lambda to be called when the value changes. (WTF::RefCounter::count): - reference the counter (and in doing so increment the count). (WTF::RefCounter::value): - access the current value of the counter. Tools: Add an API test for WTF::RefCounter. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added. (TestWebKitAPI::TEST): - added RefCounter test. Canonical link: https://commits.webkit.org/157031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176683 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2014-12-02 20:30:17 +00:00
} // namespace WTF
using WTF::RefCounter;
RefCounter<T>::Event -> RefCounterEvent https://bugs.webkit.org/show_bug.cgi?id=154767 Reviewed by Darin Adler. RefCounter<T>::Event is kinda verbose to use, and there is no need for this to be specific to a particular typeof RefCounter. Move the enum class up to the top level & rename to RefCounterEvent. Source/WebCore: * page/PageThrottler.cpp: (WebCore::PageThrottler::PageThrottler): (WebCore::m_audiblePluginHysteresis): (WebCore::m_mediaActivityCounter): (WebCore::m_pageLoadActivityCounter): * platform/VNodeTracker.cpp: (WebCore::VNodeTracker::singleton): (WebCore::VNodeTracker::VNodeTracker): (WebCore::m_lastWarningTime): Source/WebKit2: Also remove UserObservablePageToken - this is vestigial & not really offering anything over just using UserObservablePageCounter::Token directly. * UIProcess/Plugins/PluginProcessManager.cpp: (WebKit::PluginProcessManager::PluginProcessManager): * UIProcess/Plugins/PluginProcessManager.h: * UIProcess/Plugins/mac/PluginProcessManagerMac.mm: (WebKit::PluginProcessManager::updateProcessSuppressionDisabled): * UIProcess/ProcessThrottler.cpp: (WebKit::ProcessThrottler::ProcessThrottler): (WebKit::m_backgroundCounter): (WebKit::m_suspendMessageCount): * UIProcess/ProcessThrottler.h: * UIProcess/WebPageProxy.h: * UIProcess/WebProcessPool.cpp: (WebKit::WebProcessPool::WebProcessPool): (WebKit::m_processSuppressionDisabledForPageCounter): (WebKit::m_hiddenPageThrottlingAutoIncreasesCounter): * UIProcess/WebProcessPool.h: Source/WTF: * wtf/RefCounter.h: (WTF::RefCounter<T>::Count::ref): (WTF::RefCounter<T>::Count::deref): Tools: * TestWebKitAPI/Tests/WTF/RefCounter.cpp: (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/172920@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@197360 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-02-29 18:55:21 +00:00
using WTF::RefCounterEvent;