Changeset 176683 in webkit


Ignore:
Timestamp:
Dec 2, 2014 12:30:17 PM (9 years ago)
Author:
barraclough@apple.com
Message:

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.
Location:
trunk
Files:
3 added
2 deleted
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r176622 r176683  
     12014-12-02  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Generalize PageActivityAssertionToken
     4        https://bugs.webkit.org/show_bug.cgi?id=139106
     5
     6        Reviewed by Sam Weinig.
     7
     8        PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler
     9        to count user visible activity in progress on the page (currently page load and media playback).
     10        Use of an RAII type is prevents a number of possible errors, including double counting a single
     11        media element, or failing to decrement the count after a media element has been deallocated.
     12
     13        The current implementation has a number of drawbacks that have been addressed by this refactoring:
     14         - specific to single use in PageThrottler class - not reusable.
     15         - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation
     16           are not encapsulated (are in the client type, PageThrottler).
     17         - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every
     18           increment requires an object allocation.
     19         - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this
     20           is internally implemented using a reference counted type, resulting in two counters being
     21           incremented (one in the PageActivityAssertionToken, one in the PageThrottler).
     22
     23        In the reimplementation:
     24         - a callback is provided via a lambda function, which allows for easy reuse without a lot of
     25           boilerplate code.
     26         - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the
     27           RefCounter type.
     28         - a single count within RefCounter::Count stores the counter value, and also manage the lifetime
     29           of this object.
     30         - standard RefPtrs are used to manage references to the RefCounter::Count.
     31
     32        * WTF.xcodeproj/project.pbxproj:
     33            - added RefCounter.cpp/.h
     34        * wtf/RefCounter.cpp: Added.
     35        (WTF::RefCounter::Count::ref):
     36            - increment the counter.
     37        (WTF::RefCounter::Count::deref):
     38            - decrement the counter, and delete as necessary.
     39        (WTF::RefCounter::RefCounter):
     40            - create a RefCounter::Count.
     41        (WTF::RefCounter::~RefCounter):
     42            - eagerly delete the Counter if it has no references, otherwise let it be deleted on last deref.
     43        * wtf/RefCounter.h: Added.
     44        (WTF::RefCounter::Count::Count):
     45            - initialize count to 0.
     46        (WTF::RefCounter::RefCounter):
     47            - takes a lambda to be called when the value changes.
     48        (WTF::RefCounter::count):
     49            - reference the counter (and in doing so increment the count).
     50        (WTF::RefCounter::value):
     51            - access the current value of the counter.
     52
    1532014-12-01  Andreas Kling  <akling@apple.com>
    254
  • trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj

    r176592 r176683  
    121121    <ClCompile Include="..\wtf\RandomNumber.cpp" />
    122122    <ClCompile Include="..\wtf\RefCountedLeakCounter.cpp" />
     123    <ClCompile Include="..\wtf\RefCounter.cpp" />
    123124    <ClCompile Include="..\wtf\RunLoop.cpp" />
    124125    <ClCompile Include="..\wtf\SHA1.cpp" />
     
    259260    <ClInclude Include="..\wtf\RefCounted.h" />
    260261    <ClInclude Include="..\wtf\RefCountedLeakCounter.h" />
     262    <ClInclude Include="..\wtf\RefCounter.h" />
    261263    <ClInclude Include="..\wtf\RefPtr.h" />
    262264    <ClInclude Include="..\wtf\RetainPtr.h" />
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r176592 r176683  
    8181                8134013915B092FD001FF0B8 /* Base64.h in Headers */ = {isa = PBXBuildFile; fileRef = 8134013715B092FD001FF0B8 /* Base64.h */; };
    8282                83FBA93219DF459700F30ADB /* TypeCasts.h in Headers */ = {isa = PBXBuildFile; fileRef = 83FBA93119DF459700F30ADB /* TypeCasts.h */; };
     83                86F46F601A2840EE00CCBF22 /* RefCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86F46F5E1A2840EE00CCBF22 /* RefCounter.cpp */; };
     84                86F46F611A2840EE00CCBF22 /* RefCounter.h in Headers */ = {isa = PBXBuildFile; fileRef = 86F46F5F1A2840EE00CCBF22 /* RefCounter.h */; settings = {ATTRIBUTES = (Private, ); }; };
    8385                93934BD318A1E8C300D0D6A1 /* StringViewObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93934BD218A1E8C300D0D6A1 /* StringViewObjC.mm */; };
    8486                93934BD518A1F16900D0D6A1 /* StringViewCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93934BD418A1F16900D0D6A1 /* StringViewCF.cpp */; };
     
    373375                8134013715B092FD001FF0B8 /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base64.h; sourceTree = "<group>"; };
    374376                83FBA93119DF459700F30ADB /* TypeCasts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypeCasts.h; sourceTree = "<group>"; };
     377                86F46F5E1A2840EE00CCBF22 /* RefCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefCounter.cpp; sourceTree = "<group>"; };
     378                86F46F5F1A2840EE00CCBF22 /* RefCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefCounter.h; sourceTree = "<group>"; };
    375379                93934BD218A1E8C300D0D6A1 /* StringViewObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = StringViewObjC.mm; path = mac/StringViewObjC.mm; sourceTree = "<group>"; };
    376380                93934BD418A1F16900D0D6A1 /* StringViewCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringViewCF.cpp; path = cf/StringViewCF.cpp; sourceTree = "<group>"; };
     
    837841                                A8A47301151A825B004123FF /* RefCountedLeakCounter.cpp */,
    838842                                A8A47302151A825B004123FF /* RefCountedLeakCounter.h */,
     843                                86F46F5E1A2840EE00CCBF22 /* RefCounter.cpp */,
     844                                86F46F5F1A2840EE00CCBF22 /* RefCounter.h */,
    839845                                A8A47303151A825B004123FF /* RefPtr.h */,
    840846                                A8A47305151A825B004123FF /* RetainPtr.h */,
     
    11671173                                A8A4741E151A825B004123FF /* RetainPtr.h in Headers */,
    11681174                                2CDED0F418115C85004DBA70 /* RunLoop.h in Headers */,
     1175                                86F46F611A2840EE00CCBF22 /* RefCounter.h in Headers */,
    11691176                                1469419216EAAF6D0024E146 /* RunLoopTimer.h in Headers */,
    11701177                                14F3B0F715E45E4600210069 /* SaturatedArithmetic.h in Headers */,
     
    13401347                                A8A47439151A825B004123FF /* CString.cpp in Sources */,
    13411348                                A8A4739C151A825B004123FF /* CurrentTime.cpp in Sources */,
     1349                                86F46F601A2840EE00CCBF22 /* RefCounter.cpp in Sources */,
    13421350                                A8A4739E151A825B004123FF /* DataLog.cpp in Sources */,
    13431351                                A8A473A0151A825B004123FF /* DateMath.cpp in Sources */,
  • trunk/Source/WTF/wtf/CMakeLists.txt

    r175203 r176683  
    8383    RefCounted.h
    8484    RefCountedLeakCounter.h
     85    RefCounter.h
    8586    RefPtr.h
    8687    RetainPtr.h
     
    176177    RandomNumber.cpp
    177178    RefCountedLeakCounter.cpp
     179    RefCounter.cpp
    178180    RunLoop.cpp
    179181    SHA1.cpp
  • trunk/Source/WebCore/CMakeLists.txt

    r176670 r176683  
    19101910    page/OriginAccessEntry.cpp
    19111911    page/Page.cpp
    1912     page/PageActivityAssertionToken.cpp
    19131912    page/PageConfiguration.cpp
    19141913    page/PageConsoleClient.cpp
  • trunk/Source/WebCore/ChangeLog

    r176682 r176683  
     12014-12-02  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Generalize PageActivityAssertionToken
     4        https://bugs.webkit.org/show_bug.cgi?id=139106
     5
     6        Reviewed by Sam Weinig.
     7
     8        PageActivityAssertionToken is a RAII mechanism implementing a counter, used by PageThrottler
     9        to count user visible activity in progress on the page (currently page load and media playback).
     10        Use of an RAII type is prevents a number of possible errors, including double counting a single
     11        media element, or failing to decrement the count after a media element has been deallocated.
     12
     13        The current implementation has a number of drawbacks that have been addressed by this refactoring:
     14         - specific to single use in PageThrottler class - not reusable.
     15         - incomplete encapsulation - the counter and WeakPtrFactory that comprise the current implementation
     16           are not encapsulated (are in the client type, PageThrottler).
     17         - tokens are not shared - PageActivityAssertionToken instances are managed by std::unique, every
     18           increment requires an object allocation.
     19         - redundancy - the current implementation uses a WeakPtr to safely reference the PageThrottler, this
     20           is internally implemented using a reference counted type, resulting in two counters being
     21           incremented (one in the PageActivityAssertionToken, one in the PageThrottler).
     22
     23        In the reimplementation:
     24         - a callback is provided via a lambda function, which allows for easy reuse without a lot of
     25           boilerplate code.
     26         - the counter, callback and ownership of the otherwise weakly-owned token is encapsulated within the
     27           RefCounter type.
     28         - a single count within RefCounter::Count stores the counter value, and also manage the lifetime
     29           of this object.
     30         - standard RefPtrs are used to manage references to the RefCounter::Count.
     31
     32        * WebCore.xcodeproj/project.pbxproj:
     33            - removed PageActivityAssertionToken.cpp/.h
     34        * html/HTMLMediaElement.cpp:
     35            - removed PageActivityAssertionToken.h
     36        * html/HTMLMediaElement.h:
     37            - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count>
     38        * loader/FrameLoader.cpp:
     39            - removed PageActivityAssertionToken.h
     40        * loader/FrameLoader.h:
     41            - std::unique_ptr<PageActivityAssertionToken> -> RefPtr<RefCounter::Count>
     42        * loader/SubresourceLoader.cpp:
     43            - removed PageActivityAssertionToken.h
     44        * loader/SubresourceLoader.h:
     45            - removed class PageActivityAssertionToken
     46        * page/Page.cpp:
     47            - removed PageActivityAssertionToken.h
     48        (WebCore::Page::Page):
     49            - removed Page* parameter to PageThrottler
     50        * page/Page.h:
     51            - removed class PageActivityAssertionToken
     52        * page/PageActivityAssertionToken.cpp: Removed.
     53        * page/PageActivityAssertionToken.h: Removed.
     54            - removed PageActivityAssertionToken.cpp/.h
     55        * page/PageThrottler.cpp:
     56        (WebCore::PageThrottler::PageThrottler):
     57            - removed m_page, m_weakPtrFactory, m_activityCount; added m_pageActivityCounter.
     58        (WebCore::PageThrottler::mediaActivityToken):
     59            - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count>
     60        (WebCore::PageThrottler::pageLoadActivityToken):
     61            - std::unique_ptr<PageActivityAssertionToken> -> PassRefPtr<RefCounter::Count>
     62        (WebCore::PageThrottler::pageActivityCounterValueDidChange):
     63            - merged functionality of incrementActivityCount/decrementActivityCount
     64        (WebCore::PageThrottler::incrementActivityCount): Deleted.
     65            - see pageActivityCounterValueDidChange
     66        (WebCore::PageThrottler::decrementActivityCount): Deleted.
     67            - see pageActivityCounterValueDidChange
     68        * page/PageThrottler.h:
     69        (WebCore::PageThrottler::weakPtr): Deleted.
     70            - no longer required; this functionality is now encapsulated within RefCounter.
     71
    1722014-12-02  Tim Horton  <timothy_horton@apple.com>
    273
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

    r176670 r176683  
    71897189    <ClCompile Include="..\page\OriginAccessEntry.cpp" />
    71907190    <ClCompile Include="..\page\Page.cpp" />
    7191     <ClCompile Include="..\page\PageActivityAssertionToken.cpp" />
    71927191    <ClCompile Include="..\page\PageConfiguration.cpp" />
    71937192    <ClCompile Include="..\page\PageConsoleClient.cpp" />
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r176670 r176683  
    55945594                CCC2B51515F613060048CDD6 /* DeviceController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CCC2B51115F613060048CDD6 /* DeviceController.cpp */; };
    55955595                CCC2B51615F613060048CDD6 /* DeviceController.h in Headers */ = {isa = PBXBuildFile; fileRef = CCC2B51215F613060048CDD6 /* DeviceController.h */; settings = {ATTRIBUTES = (Private, ); }; };
    5596                 CD08285C1757250F00EC5FB7 /* PageActivityAssertionToken.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD08285A1757250800EC5FB7 /* PageActivityAssertionToken.cpp */; };
    55975596                CD0EEE0E14743F39003EAFA2 /* AudioDestinationIOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD0EEE0B14743E35003EAFA2 /* AudioDestinationIOS.cpp */; };
    55985597                CD127DED14F3097D00E84779 /* WebCoreFullScreenWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD127DEB14F3097900E84779 /* WebCoreFullScreenWindow.mm */; };
     
    1305213051                CCC2B51115F613060048CDD6 /* DeviceController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeviceController.cpp; sourceTree = "<group>"; };
    1305313052                CCC2B51215F613060048CDD6 /* DeviceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceController.h; sourceTree = "<group>"; };
    13054                 CD08285A1757250800EC5FB7 /* PageActivityAssertionToken.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PageActivityAssertionToken.cpp; sourceTree = "<group>"; };
    13055                 CD08285B1757250800EC5FB7 /* PageActivityAssertionToken.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PageActivityAssertionToken.h; sourceTree = "<group>"; };
    1305613053                CD0EEE0A14743E34003EAFA2 /* AudioDestinationIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AudioDestinationIOS.h; path = ios/AudioDestinationIOS.h; sourceTree = "<group>"; };
    1305713054                CD0EEE0B14743E35003EAFA2 /* AudioDestinationIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AudioDestinationIOS.cpp; path = ios/AudioDestinationIOS.cpp; sourceTree = "<group>"; };
     
    1667216669                                65FEA86809833ADE00BED4AB /* Page.cpp */,
    1667316670                                65A21467097A329100B9050A /* Page.h */,
    16674                                 CD08285A1757250800EC5FB7 /* PageActivityAssertionToken.cpp */,
    16675                                 CD08285B1757250800EC5FB7 /* PageActivityAssertionToken.h */,
    1667616671                                CD5E5B601A15F156000C609E /* PageConfiguration.cpp */,
    1667716672                                CD5E5B5E1A15CE54000C609E /* PageConfiguration.h */,
     
    2911129106                                1A0D57360A5C77FE007EDD4C /* OverflowEvent.cpp in Sources */,
    2911229107                                65FEA86909833ADE00BED4AB /* Page.cpp in Sources */,
    29113                                 CD08285C1757250F00EC5FB7 /* PageActivityAssertionToken.cpp in Sources */,
    2911429108                                1477E7760BF4134A00152872 /* PageCache.cpp in Sources */,
    2911529109                                F3820892147D35F90010BC06 /* PageConsoleAgent.cpp in Sources */,
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r176604 r176683  
    6767#include "MediaSessionManager.h"
    6868#include "NetworkingContext.h"
    69 #include "PageActivityAssertionToken.h"
    7069#include "PageGroup.h"
    7170#include "PageThrottler.h"
  • trunk/Source/WebCore/html/HTMLMediaElement.h

    r176459 r176683  
    3636#include "MediaControllerInterface.h"
    3737#include "MediaPlayer.h"
     38#include "PageThrottler.h"
    3839
    3940#if ENABLE(VIDEO_TRACK)
     
    6667class MediaControlsHost;
    6768class MediaError;
    68 class PageActivityAssertionToken;
    6969class TimeRanges;
    7070#if ENABLE(ENCRYPTED_MEDIA_V2)
     
    900900
    901901    std::unique_ptr<HTMLMediaSession> m_mediaSession;
    902     std::unique_ptr<PageActivityAssertionToken> m_activityToken;
     902    PageActivityAssertionToken m_activityToken;
    903903    size_t m_reportedExtraMemoryCost;
    904904
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r176499 r176683  
    8686#include "MemoryCache.h"
    8787#include "Page.h"
    88 #include "PageActivityAssertionToken.h"
    8988#include "PageCache.h"
    9089#include "PageThrottler.h"
  • trunk/Source/WebCore/loader/FrameLoader.h

    r176459 r176683  
    3939#include "LayoutMilestones.h"
    4040#include "MixedContentChecker.h"
     41#include "PageThrottler.h"
    4142#include "ResourceHandleTypes.h"
    4243#include "ResourceLoadNotifier.h"
     
    6768class NetworkingContext;
    6869class Page;
    69 class PageActivityAssertionToken;
    7070class PolicyChecker;
    7171class ResourceError;
     
    444444    URL m_previousURL;
    445445    RefPtr<HistoryItem> m_requestedHistoryItem;
    446     std::unique_ptr<PageActivityAssertionToken> m_activityAssertion;
     446    PageActivityAssertionToken m_activityAssertion;
    447447};
    448448
  • trunk/Source/WebCore/loader/SubresourceLoader.cpp

    r176450 r176683  
    3838#include "MemoryCache.h"
    3939#include "Page.h"
    40 #include "PageActivityAssertionToken.h"
    4140#include <wtf/Ref.h>
    4241#include <wtf/RefCountedLeakCounter.h>
  • trunk/Source/WebCore/loader/SubresourceLoader.h

    r176172 r176683  
    4040class CachedResourceLoader;
    4141class Document;
    42 class PageActivityAssertionToken;
    4342class ResourceRequest;
    4443
  • trunk/Source/WebCore/page/Page.cpp

    r176670 r176683  
    5656#include "Navigator.h"
    5757#include "NetworkStateNotifier.h"
    58 #include "PageActivityAssertionToken.h"
    5958#include "PageCache.h"
    6059#include "PageConfiguration.h"
     
    196195    , m_alternativeTextClient(pageConfiguration.alternativeTextClient)
    197196    , m_scriptedAnimationsSuspended(false)
    198     , m_pageThrottler(*this, m_viewState)
     197    , m_pageThrottler(m_viewState)
    199198    , m_consoleClient(std::make_unique<PageConsoleClient>(*this))
    200199#if ENABLE(REMOTE_INSPECTOR)
  • trunk/Source/WebCore/page/Page.h

    r176670 r176683  
    8181class MainFrame;
    8282class MediaCanStartListener;
    83 class PageActivityAssertionToken;
    8483class PageConfiguration;
    8584class PageConsoleClient;
  • trunk/Source/WebCore/page/PageThrottler.cpp

    r173696 r176683  
    2727#include "PageThrottler.h"
    2828
    29 #include "PageActivityAssertionToken.h"
    30 
    3129namespace WebCore {
    3230
    33 PageThrottler::PageThrottler(Page& page, ViewState::Flags viewState)
    34     : m_page(page)
    35     , m_viewState(viewState)
    36     , m_weakPtrFactory(this)
     31PageThrottler::PageThrottler(ViewState::Flags viewState)
     32    : m_viewState(viewState)
    3733    , m_hysteresis(*this)
    38     , m_activityCount(0)
     34    , m_pageActivityCounter([this]() { pageActivityCounterValueDidChange(); })
    3935{
    4036    updateUserActivity();
     
    4844}
    4945
    50 std::unique_ptr<PageActivityAssertionToken> PageThrottler::mediaActivityToken()
     46PageActivityAssertionToken PageThrottler::mediaActivityToken()
    5147{
    52     return std::make_unique<PageActivityAssertionToken>(*this);
     48    return m_pageActivityCounter.count();
    5349}
    5450
    55 std::unique_ptr<PageActivityAssertionToken> PageThrottler::pageLoadActivityToken()
     51PageActivityAssertionToken PageThrottler::pageLoadActivityToken()
    5652{
    57     return std::make_unique<PageActivityAssertionToken>(*this);
     53    return m_pageActivityCounter.count();
    5854}
    5955
    60 void PageThrottler::incrementActivityCount()
     56void PageThrottler::pageActivityCounterValueDidChange()
    6157{
    62     // If m_activityCount is nonzero, state must be Started; if m_activityCount is zero, state may be Waiting or Stopped.
    63     ASSERT(!!m_activityCount == (m_hysteresis.state() == HysteresisState::Started));
    64 
    65     if (!m_activityCount++)
     58    if (m_pageActivityCounter.value())
    6659        m_hysteresis.start();
    67 
    68     ASSERT(m_activityCount && m_hysteresis.state() == HysteresisState::Started);
    69 }
    70 
    71 void PageThrottler::decrementActivityCount()
    72 {
    73     ASSERT(m_activityCount && m_hysteresis.state() == HysteresisState::Started);
    74 
    75     if (!--m_activityCount)
     60    else
    7661        m_hysteresis.stop();
    7762
    78     // If m_activityCount is nonzero, state must be Started; if m_activityCount is zero, state may be Waiting or Stopped.
    79     ASSERT(!!m_activityCount == (m_hysteresis.state() == HysteresisState::Started));
     63    // If the counter is nonzero, state must be Started; if the counter is zero, state may be Waiting or Stopped.
     64    ASSERT(!!m_pageActivityCounter.value() == (m_hysteresis.state() == HysteresisState::Started));
    8065}
    8166
  • trunk/Source/WebCore/page/PageThrottler.h

    r173696 r176683  
    3131#include "UserActivity.h"
    3232#include "ViewState.h"
    33 #include <wtf/WeakPtr.h>
     33#include <wtf/RefCounter.h>
    3434
    3535namespace WebCore {
    3636
    37 class Page;
    38 class PageActivityAssertionToken;
     37typedef RefPtr<RefCounter::Count> PageActivityAssertionToken;
    3938
    4039class PageThrottler {
    4140    WTF_MAKE_FAST_ALLOCATED;
    4241public:
    43     PageThrottler(Page&, ViewState::Flags);
     42    PageThrottler(ViewState::Flags);
    4443
    4544    void createUserActivity();
     
    4847    void didReceiveUserInput() { m_hysteresis.impulse(); }
    4948    void pluginDidEvaluateWhileAudioIsPlaying() { m_hysteresis.impulse(); }
    50     std::unique_ptr<PageActivityAssertionToken> mediaActivityToken();
    51     std::unique_ptr<PageActivityAssertionToken> pageLoadActivityToken();
     49    PageActivityAssertionToken mediaActivityToken();
     50    PageActivityAssertionToken pageLoadActivityToken();
    5251
    5352private:
    54     friend class PageActivityAssertionToken;
    55     WeakPtr<PageThrottler> weakPtr() { return m_weakPtrFactory.createWeakPtr(); }
    56     void incrementActivityCount();
    57     void decrementActivityCount();
     53    void pageActivityCounterValueDidChange();
    5854
    5955    void updateUserActivity();
     
    6359    void stopped();
    6460
    65     Page& m_page;
    6661    ViewState::Flags m_viewState;
    67     WeakPtrFactory<PageThrottler> m_weakPtrFactory;
    6862    HysteresisActivity<PageThrottler> m_hysteresis;
    6963    std::unique_ptr<UserActivity::Impl> m_activity;
    70     size_t m_activityCount;
     64    RefCounter m_pageActivityCounter;
    7165};
    7266
  • trunk/Tools/ChangeLog

    r176677 r176683  
     12014-12-02  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Generalize PageActivityAssertionToken
     4        https://bugs.webkit.org/show_bug.cgi?id=139106
     5
     6        Reviewed by Sam Weinig.
     7
     8        Add an API test for WTF::RefCounter.
     9
     10        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     11        * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added.
     12        (TestWebKitAPI::TEST):
     13            - added RefCounter test.
     14
    1152014-12-02  Alexey Proskuryakov  <ap@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r176574 r176683  
    135135                7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; };
    136136                81B50193140F232300D9EB58 /* StringBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81B50192140F232300D9EB58 /* StringBuilder.cpp */; };
     137                86BD19981A2DB05B006DCF0A /* RefCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86BD19971A2DB05B006DCF0A /* RefCounter.cpp */; };
    137138                8A2C750E16CED9550024F352 /* ResizeWindowAfterCrash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A2C750D16CED9550024F352 /* ResizeWindowAfterCrash.cpp */; };
    138139                8A3AF93B16C9ED2700D248C1 /* ReloadPageAfterCrash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A3AF93A16C9ED2700D248C1 /* ReloadPageAfterCrash.cpp */; };
     
    497498                7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad_Bundle.cpp; sourceTree = "<group>"; };
    498499                81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilder.cpp; sourceTree = "<group>"; };
     500                86BD19971A2DB05B006DCF0A /* RefCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefCounter.cpp; sourceTree = "<group>"; };
    499501                8A2C750D16CED9550024F352 /* ResizeWindowAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResizeWindowAfterCrash.cpp; sourceTree = "<group>"; };
    500502                8A3AF93A16C9ED2700D248C1 /* ReloadPageAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReloadPageAfterCrash.cpp; sourceTree = "<group>"; };
     
    962964                                0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */,
    963965                                93A427AA180DA26400CD24D7 /* Ref.cpp */,
     966                                86BD19971A2DB05B006DCF0A /* RefCounter.cpp */,
    964967                                93A427AD180DA60F00CD24D7 /* RefLogger.h */,
    965968                                93A427A8180D9B0700CD24D7 /* RefPtr.cpp */,
     
    13881391                                51FCF79A1534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp in Sources */,
    13891392                                1AFDE6561953B2C000C48FFA /* Optional.cpp in Sources */,
     1393                                86BD19981A2DB05B006DCF0A /* RefCounter.cpp in Sources */,
    13901394                                C540F776152E4DA000A40C8C /* SimplifyMarkup.mm in Sources */,
    13911395                                4A410F4C19AF7BD6002EBAB5 /* UserMedia.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.