<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[176683] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/176683">176683</a></dd>
<dt>Author</dt> <dd>barraclough@apple.com</dd>
<dt>Date</dt> <dd>2014-12-02 12:30:17 -0800 (Tue, 02 Dec 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>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.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFWTFvcxprojWTFvcxproj">trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj</a></li>
<li><a href="#trunkSourceWTFWTFxcodeprojprojectpbxproj">trunk/Source/WTF/WTF.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWTFwtfCMakeListstxt">trunk/Source/WTF/wtf/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebCoreCMakeListstxt">trunk/Source/WebCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorevcxprojWebCorevcxproj">trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementcpp">trunk/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementh">trunk/Source/WebCore/html/HTMLMediaElement.h</a></li>
<li><a href="#trunkSourceWebCoreloaderFrameLoadercpp">trunk/Source/WebCore/loader/FrameLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderFrameLoaderh">trunk/Source/WebCore/loader/FrameLoader.h</a></li>
<li><a href="#trunkSourceWebCoreloaderSubresourceLoadercpp">trunk/Source/WebCore/loader/SubresourceLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderSubresourceLoaderh">trunk/Source/WebCore/loader/SubresourceLoader.h</a></li>
<li><a href="#trunkSourceWebCorepagePagecpp">trunk/Source/WebCore/page/Page.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePageh">trunk/Source/WebCore/page/Page.h</a></li>
<li><a href="#trunkSourceWebCorepagePageThrottlercpp">trunk/Source/WebCore/page/PageThrottler.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePageThrottlerh">trunk/Source/WebCore/page/PageThrottler.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWTFwtfRefCountercpp">trunk/Source/WTF/wtf/RefCounter.cpp</a></li>
<li><a href="#trunkSourceWTFwtfRefCounterh">trunk/Source/WTF/wtf/RefCounter.h</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWTFRefCountercpp">trunk/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkSourceWebCorepagePageActivityAssertionTokencpp">trunk/Source/WebCore/page/PageActivityAssertionToken.cpp</a></li>
<li><a href="#trunkSourceWebCorepagePageActivityAssertionTokenh">trunk/Source/WebCore/page/PageActivityAssertionToken.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WTF/ChangeLog        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -1,3 +1,55 @@
</span><ins>+2014-12-02 Gavin Barraclough <barraclough@apple.com>
+
+ Generalize PageActivityAssertionToken
+ https://bugs.webkit.org/show_bug.cgi?id=139106
+
+ Reviewed by Sam Weinig.
+
+ 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.
+
</ins><span class="cx"> 2014-12-01 Andreas Kling <akling@apple.com>
</span><span class="cx">
</span><span class="cx"> Optimize constructing JSC::Identifier from AtomicString.
</span></span></pre></div>
<a id="trunkSourceWTFWTFvcxprojWTFvcxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -120,6 +120,7 @@
</span><span class="cx"> <ClCompile Include="..\wtf\RAMSize.cpp" />
</span><span class="cx"> <ClCompile Include="..\wtf\RandomNumber.cpp" />
</span><span class="cx"> <ClCompile Include="..\wtf\RefCountedLeakCounter.cpp" />
</span><ins>+ <ClCompile Include="..\wtf\RefCounter.cpp" />
</ins><span class="cx"> <ClCompile Include="..\wtf\RunLoop.cpp" />
</span><span class="cx"> <ClCompile Include="..\wtf\SHA1.cpp" />
</span><span class="cx"> <ClCompile Include="..\wtf\SixCharacterHash.cpp" />
</span><span class="lines">@@ -258,6 +259,7 @@
</span><span class="cx"> <ClInclude Include="..\wtf\RedBlackTree.h" />
</span><span class="cx"> <ClInclude Include="..\wtf\RefCounted.h" />
</span><span class="cx"> <ClInclude Include="..\wtf\RefCountedLeakCounter.h" />
</span><ins>+ <ClInclude Include="..\wtf\RefCounter.h" />
</ins><span class="cx"> <ClInclude Include="..\wtf\RefPtr.h" />
</span><span class="cx"> <ClInclude Include="..\wtf\RetainPtr.h" />
</span><span class="cx"> <ClInclude Include="..\wtf\RunLoop.h" />
</span></span></pre></div>
<a id="trunkSourceWTFWTFxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -80,6 +80,8 @@
</span><span class="cx">                 8134013815B092FD001FF0B8 /* Base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8134013615B092FD001FF0B8 /* Base64.cpp */; };
</span><span class="cx">                 8134013915B092FD001FF0B8 /* Base64.h in Headers */ = {isa = PBXBuildFile; fileRef = 8134013715B092FD001FF0B8 /* Base64.h */; };
</span><span class="cx">                 83FBA93219DF459700F30ADB /* TypeCasts.h in Headers */ = {isa = PBXBuildFile; fileRef = 83FBA93119DF459700F30ADB /* TypeCasts.h */; };
</span><ins>+                86F46F601A2840EE00CCBF22 /* RefCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86F46F5E1A2840EE00CCBF22 /* RefCounter.cpp */; };
+                86F46F611A2840EE00CCBF22 /* RefCounter.h in Headers */ = {isa = PBXBuildFile; fileRef = 86F46F5F1A2840EE00CCBF22 /* RefCounter.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 93934BD318A1E8C300D0D6A1 /* StringViewObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93934BD218A1E8C300D0D6A1 /* StringViewObjC.mm */; };
</span><span class="cx">                 93934BD518A1F16900D0D6A1 /* StringViewCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93934BD418A1F16900D0D6A1 /* StringViewCF.cpp */; };
</span><span class="cx">                 93AC91A818942FC400244939 /* LChar.h in Headers */ = {isa = PBXBuildFile; fileRef = 93AC91A718942FC400244939 /* LChar.h */; };
</span><span class="lines">@@ -372,6 +374,8 @@
</span><span class="cx">                 8134013615B092FD001FF0B8 /* Base64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Base64.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 8134013715B092FD001FF0B8 /* Base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Base64.h; sourceTree = "<group>"; };
</span><span class="cx">                 83FBA93119DF459700F30ADB /* TypeCasts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypeCasts.h; sourceTree = "<group>"; };
</span><ins>+                86F46F5E1A2840EE00CCBF22 /* RefCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefCounter.cpp; sourceTree = "<group>"; };
+                86F46F5F1A2840EE00CCBF22 /* RefCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefCounter.h; sourceTree = "<group>"; };
</ins><span class="cx">                 93934BD218A1E8C300D0D6A1 /* StringViewObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = StringViewObjC.mm; path = mac/StringViewObjC.mm; sourceTree = "<group>"; };
</span><span class="cx">                 93934BD418A1F16900D0D6A1 /* StringViewCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringViewCF.cpp; path = cf/StringViewCF.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 93AC91A718942FC400244939 /* LChar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LChar.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -836,6 +840,8 @@
</span><span class="cx">                                 A8A47300151A825B004123FF /* RefCountedArray.h */,
</span><span class="cx">                                 A8A47301151A825B004123FF /* RefCountedLeakCounter.cpp */,
</span><span class="cx">                                 A8A47302151A825B004123FF /* RefCountedLeakCounter.h */,
</span><ins>+                                86F46F5E1A2840EE00CCBF22 /* RefCounter.cpp */,
+                                86F46F5F1A2840EE00CCBF22 /* RefCounter.h */,
</ins><span class="cx">                                 A8A47303151A825B004123FF /* RefPtr.h */,
</span><span class="cx">                                 A8A47305151A825B004123FF /* RetainPtr.h */,
</span><span class="cx">                                 2CDED0F118115C85004DBA70 /* RunLoop.cpp */,
</span><span class="lines">@@ -1166,6 +1172,7 @@
</span><span class="cx">                                 A8A4741C151A825B004123FF /* RefPtr.h in Headers */,
</span><span class="cx">                                 A8A4741E151A825B004123FF /* RetainPtr.h in Headers */,
</span><span class="cx">                                 2CDED0F418115C85004DBA70 /* RunLoop.h in Headers */,
</span><ins>+                                86F46F611A2840EE00CCBF22 /* RefCounter.h in Headers */,
</ins><span class="cx">                                 1469419216EAAF6D0024E146 /* RunLoopTimer.h in Headers */,
</span><span class="cx">                                 14F3B0F715E45E4600210069 /* SaturatedArithmetic.h in Headers */,
</span><span class="cx">                                 1469419616EAAFF80024E146 /* SchedulePair.h in Headers */,
</span><span class="lines">@@ -1339,6 +1346,7 @@
</span><span class="cx">                                 A8A4739A151A825B004123FF /* CryptographicallyRandomNumber.cpp in Sources */,
</span><span class="cx">                                 A8A47439151A825B004123FF /* CString.cpp in Sources */,
</span><span class="cx">                                 A8A4739C151A825B004123FF /* CurrentTime.cpp in Sources */,
</span><ins>+                                86F46F601A2840EE00CCBF22 /* RefCounter.cpp in Sources */,
</ins><span class="cx">                                 A8A4739E151A825B004123FF /* DataLog.cpp in Sources */,
</span><span class="cx">                                 A8A473A0151A825B004123FF /* DateMath.cpp in Sources */,
</span><span class="cx">                                 A8A473A2151A825B004123FF /* DecimalNumber.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWTFwtfCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/CMakeLists.txt (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/CMakeLists.txt        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WTF/wtf/CMakeLists.txt        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -82,6 +82,7 @@
</span><span class="cx"> Ref.h
</span><span class="cx"> RefCounted.h
</span><span class="cx"> RefCountedLeakCounter.h
</span><ins>+ RefCounter.h
</ins><span class="cx"> RefPtr.h
</span><span class="cx"> RetainPtr.h
</span><span class="cx"> RunLoop.h
</span><span class="lines">@@ -175,6 +176,7 @@
</span><span class="cx"> RAMSize.cpp
</span><span class="cx"> RandomNumber.cpp
</span><span class="cx"> RefCountedLeakCounter.cpp
</span><ins>+ RefCounter.cpp
</ins><span class="cx"> RunLoop.cpp
</span><span class="cx"> SHA1.cpp
</span><span class="cx"> SixCharacterHash.cpp
</span></span></pre></div>
<a id="trunkSourceWTFwtfRefCountercpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WTF/wtf/RefCounter.cpp (0 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/RefCounter.cpp         (rev 0)
+++ trunk/Source/WTF/wtf/RefCounter.cpp        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -0,0 +1,72 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "RefCounter.h"
+
+namespace WTF {
+
+void RefCounter::Count::ref()
+{
+ ++m_value;
+
+ if (m_refCounter)
+ m_refCounter->m_valueDidChange();
+}
+
+void RefCounter::Count::deref()
+{
+ ASSERT(m_value);
+ --m_value;
+
+ // 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.
+ if (m_refCounter)
+ m_refCounter->m_valueDidChange();
+ else if (!m_value)
+ delete this;
+}
+
+RefCounter::RefCounter(std::function<void()> valueDidChange)
+ : m_valueDidChange(valueDidChange)
+ , m_count(new Count(*this))
+{
+}
+
+RefCounter::~RefCounter()
+{
+ // 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.
+ if (m_count->m_value)
+ m_count->m_refCounter = nullptr;
+ else
+ delete m_count;
+}
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWTFwtfRefCounterh"></a>
<div class="addfile"><h4>Added: trunk/Source/WTF/wtf/RefCounter.h (0 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/RefCounter.h         (rev 0)
+++ trunk/Source/WTF/wtf/RefCounter.h        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -0,0 +1,79 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef RefCounter_h
+#define RefCounter_h
+
+#include <functional>
+#include <wtf/Noncopyable.h>
+#include <wtf/RefPtr.h>
+
+namespace WTF {
+
+class RefCounter {
+ WTF_MAKE_NONCOPYABLE(RefCounter);
+public:
+ class Count {
+ WTF_MAKE_NONCOPYABLE(Count);
+ public:
+ WTF_EXPORT_PRIVATE void ref();
+ WTF_EXPORT_PRIVATE void deref();
+
+ private:
+ friend class RefCounter;
+
+ Count(RefCounter& refCounter)
+ : m_refCounter(&refCounter)
+ , m_value(0)
+ {
+ }
+
+ RefCounter* m_refCounter;
+ unsigned m_value;
+ };
+
+ WTF_EXPORT_PRIVATE RefCounter(std::function<void()> = []() { });
+ WTF_EXPORT_PRIVATE ~RefCounter();
+
+ PassRef<Count> count() const
+ {
+ return *m_count;
+ }
+
+ unsigned value() const
+ {
+ return m_count->m_value;
+ }
+
+private:
+ std::function<void()> m_valueDidChange;
+ Count* m_count;
+};
+
+} // namespace WTF
+
+using WTF::RefCounter;
+
+#endif // RefCounter_h
</ins></span></pre></div>
<a id="trunkSourceWebCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/CMakeLists.txt (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/CMakeLists.txt        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/CMakeLists.txt        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -1909,7 +1909,6 @@
</span><span class="cx"> page/NavigatorBase.cpp
</span><span class="cx"> page/OriginAccessEntry.cpp
</span><span class="cx"> page/Page.cpp
</span><del>- page/PageActivityAssertionToken.cpp
</del><span class="cx"> page/PageConfiguration.cpp
</span><span class="cx"> page/PageConsoleClient.cpp
</span><span class="cx"> page/PageGroup.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/ChangeLog        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -1,3 +1,74 @@
</span><ins>+2014-12-02 Gavin Barraclough <barraclough@apple.com>
+
+ Generalize PageActivityAssertionToken
+ https://bugs.webkit.org/show_bug.cgi?id=139106
+
+ Reviewed by Sam Weinig.
+
+ 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.
+
</ins><span class="cx"> 2014-12-02 Tim Horton <timothy_horton@apple.com>
</span><span class="cx">
</span><span class="cx"> Always show the arrow for text selection services
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorevcxprojWebCorevcxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -7188,7 +7188,6 @@
</span><span class="cx"> <ClCompile Include="..\page\NavigatorBase.cpp" />
</span><span class="cx"> <ClCompile Include="..\page\OriginAccessEntry.cpp" />
</span><span class="cx"> <ClCompile Include="..\page\Page.cpp" />
</span><del>- <ClCompile Include="..\page\PageActivityAssertionToken.cpp" />
</del><span class="cx"> <ClCompile Include="..\page\PageConfiguration.cpp" />
</span><span class="cx"> <ClCompile Include="..\page\PageConsoleClient.cpp" />
</span><span class="cx"> <ClCompile Include="..\page\PageGroup.cpp" />
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -5593,7 +5593,6 @@
</span><span class="cx">                 CCC2B51415F613060048CDD6 /* DeviceClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CCC2B51015F613060048CDD6 /* DeviceClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 CCC2B51515F613060048CDD6 /* DeviceController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CCC2B51115F613060048CDD6 /* DeviceController.cpp */; };
</span><span class="cx">                 CCC2B51615F613060048CDD6 /* DeviceController.h in Headers */ = {isa = PBXBuildFile; fileRef = CCC2B51215F613060048CDD6 /* DeviceController.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><del>-                CD08285C1757250F00EC5FB7 /* PageActivityAssertionToken.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD08285A1757250800EC5FB7 /* PageActivityAssertionToken.cpp */; };
</del><span class="cx">                 CD0EEE0E14743F39003EAFA2 /* AudioDestinationIOS.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD0EEE0B14743E35003EAFA2 /* AudioDestinationIOS.cpp */; };
</span><span class="cx">                 CD127DED14F3097D00E84779 /* WebCoreFullScreenWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD127DEB14F3097900E84779 /* WebCoreFullScreenWindow.mm */; };
</span><span class="cx">                 CD127DEE14F3098400E84779 /* WebCoreFullScreenWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = CD127DEA14F3097900E84779 /* WebCoreFullScreenWindow.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -13051,8 +13050,6 @@
</span><span class="cx">                 CCC2B51015F613060048CDD6 /* DeviceClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceClient.h; sourceTree = "<group>"; };
</span><span class="cx">                 CCC2B51115F613060048CDD6 /* DeviceController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeviceController.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 CCC2B51215F613060048CDD6 /* DeviceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceController.h; sourceTree = "<group>"; };
</span><del>-                CD08285A1757250800EC5FB7 /* PageActivityAssertionToken.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PageActivityAssertionToken.cpp; sourceTree = "<group>"; };
-                CD08285B1757250800EC5FB7 /* PageActivityAssertionToken.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PageActivityAssertionToken.h; sourceTree = "<group>"; };
</del><span class="cx">                 CD0EEE0A14743E34003EAFA2 /* AudioDestinationIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AudioDestinationIOS.h; path = ios/AudioDestinationIOS.h; sourceTree = "<group>"; };
</span><span class="cx">                 CD0EEE0B14743E35003EAFA2 /* AudioDestinationIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AudioDestinationIOS.cpp; path = ios/AudioDestinationIOS.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 CD127DEA14F3097900E84779 /* WebCoreFullScreenWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreFullScreenWindow.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -16671,8 +16668,6 @@
</span><span class="cx">                                 00146289103CD1DE000B20DB /* OriginAccessEntry.h */,
</span><span class="cx">                                 65FEA86809833ADE00BED4AB /* Page.cpp */,
</span><span class="cx">                                 65A21467097A329100B9050A /* Page.h */,
</span><del>-                                CD08285A1757250800EC5FB7 /* PageActivityAssertionToken.cpp */,
-                                CD08285B1757250800EC5FB7 /* PageActivityAssertionToken.h */,
</del><span class="cx">                                 CD5E5B601A15F156000C609E /* PageConfiguration.cpp */,
</span><span class="cx">                                 CD5E5B5E1A15CE54000C609E /* PageConfiguration.h */,
</span><span class="cx">                                 DAACB3D916F2416400666135 /* PageConsoleClient.cpp */,
</span><span class="lines">@@ -29110,7 +29105,6 @@
</span><span class="cx">                                 FD581FAE1520F91F003A7A75 /* OscillatorNode.cpp in Sources */,
</span><span class="cx">                                 1A0D57360A5C77FE007EDD4C /* OverflowEvent.cpp in Sources */,
</span><span class="cx">                                 65FEA86909833ADE00BED4AB /* Page.cpp in Sources */,
</span><del>-                                CD08285C1757250F00EC5FB7 /* PageActivityAssertionToken.cpp in Sources */,
</del><span class="cx">                                 1477E7760BF4134A00152872 /* PageCache.cpp in Sources */,
</span><span class="cx">                                 F3820892147D35F90010BC06 /* PageConsoleAgent.cpp in Sources */,
</span><span class="cx">                                 DAED203016F2442B0070EC0F /* PageConsoleClient.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.cpp        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -66,7 +66,6 @@
</span><span class="cx"> #include "MediaResourceLoader.h"
</span><span class="cx"> #include "MediaSessionManager.h"
</span><span class="cx"> #include "NetworkingContext.h"
</span><del>-#include "PageActivityAssertionToken.h"
</del><span class="cx"> #include "PageGroup.h"
</span><span class="cx"> #include "PageThrottler.h"
</span><span class="cx"> #include "ProgressTracker.h"
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLMediaElement.h        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include "MediaCanStartListener.h"
</span><span class="cx"> #include "MediaControllerInterface.h"
</span><span class="cx"> #include "MediaPlayer.h"
</span><ins>+#include "PageThrottler.h"
</ins><span class="cx">
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx"> #include "AudioTrack.h"
</span><span class="lines">@@ -65,7 +66,6 @@
</span><span class="cx"> class MediaControls;
</span><span class="cx"> class MediaControlsHost;
</span><span class="cx"> class MediaError;
</span><del>-class PageActivityAssertionToken;
</del><span class="cx"> class TimeRanges;
</span><span class="cx"> #if ENABLE(ENCRYPTED_MEDIA_V2)
</span><span class="cx"> class MediaKeys;
</span><span class="lines">@@ -899,7 +899,7 @@
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> std::unique_ptr<HTMLMediaSession> m_mediaSession;
</span><del>- std::unique_ptr<PageActivityAssertionToken> m_activityToken;
</del><ins>+ PageActivityAssertionToken m_activityToken;
</ins><span class="cx"> size_t m_reportedExtraMemoryCost;
</span><span class="cx">
</span><span class="cx"> #if ENABLE(MEDIA_CONTROLS_SCRIPT)
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderFrameLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/FrameLoader.cpp        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -85,7 +85,6 @@
</span><span class="cx"> #include "MainFrame.h"
</span><span class="cx"> #include "MemoryCache.h"
</span><span class="cx"> #include "Page.h"
</span><del>-#include "PageActivityAssertionToken.h"
</del><span class="cx"> #include "PageCache.h"
</span><span class="cx"> #include "PageThrottler.h"
</span><span class="cx"> #include "PageTransitionEvent.h"
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderFrameLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/FrameLoader.h (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/FrameLoader.h        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/loader/FrameLoader.h        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> #include "IconURL.h"
</span><span class="cx"> #include "LayoutMilestones.h"
</span><span class="cx"> #include "MixedContentChecker.h"
</span><ins>+#include "PageThrottler.h"
</ins><span class="cx"> #include "ResourceHandleTypes.h"
</span><span class="cx"> #include "ResourceLoadNotifier.h"
</span><span class="cx"> #include "SecurityContext.h"
</span><span class="lines">@@ -66,7 +67,6 @@
</span><span class="cx"> class NavigationAction;
</span><span class="cx"> class NetworkingContext;
</span><span class="cx"> class Page;
</span><del>-class PageActivityAssertionToken;
</del><span class="cx"> class PolicyChecker;
</span><span class="cx"> class ResourceError;
</span><span class="cx"> class ResourceRequest;
</span><span class="lines">@@ -443,7 +443,7 @@
</span><span class="cx">
</span><span class="cx"> URL m_previousURL;
</span><span class="cx"> RefPtr<HistoryItem> m_requestedHistoryItem;
</span><del>- std::unique_ptr<PageActivityAssertionToken> m_activityAssertion;
</del><ins>+ PageActivityAssertionToken m_activityAssertion;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> // This function is called by createWindow() in JSDOMWindowBase.cpp, for example, for
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderSubresourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/SubresourceLoader.cpp (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/SubresourceLoader.cpp        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/loader/SubresourceLoader.cpp        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -37,7 +37,6 @@
</span><span class="cx"> #include "Logging.h"
</span><span class="cx"> #include "MemoryCache.h"
</span><span class="cx"> #include "Page.h"
</span><del>-#include "PageActivityAssertionToken.h"
</del><span class="cx"> #include <wtf/Ref.h>
</span><span class="cx"> #include <wtf/RefCountedLeakCounter.h>
</span><span class="cx"> #include <wtf/StdLibExtras.h>
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderSubresourceLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/SubresourceLoader.h (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/SubresourceLoader.h        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/loader/SubresourceLoader.h        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -39,7 +39,6 @@
</span><span class="cx"> class CachedResource;
</span><span class="cx"> class CachedResourceLoader;
</span><span class="cx"> class Document;
</span><del>-class PageActivityAssertionToken;
</del><span class="cx"> class ResourceRequest;
</span><span class="cx">
</span><span class="cx"> class SubresourceLoader final : public ResourceLoader {
</span></span></pre></div>
<a id="trunkSourceWebCorepagePagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.cpp (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.cpp        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/page/Page.cpp        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -55,7 +55,6 @@
</span><span class="cx"> #include "MediaCanStartListener.h"
</span><span class="cx"> #include "Navigator.h"
</span><span class="cx"> #include "NetworkStateNotifier.h"
</span><del>-#include "PageActivityAssertionToken.h"
</del><span class="cx"> #include "PageCache.h"
</span><span class="cx"> #include "PageConfiguration.h"
</span><span class="cx"> #include "PageConsoleClient.h"
</span><span class="lines">@@ -195,7 +194,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> , m_alternativeTextClient(pageConfiguration.alternativeTextClient)
</span><span class="cx"> , m_scriptedAnimationsSuspended(false)
</span><del>- , m_pageThrottler(*this, m_viewState)
</del><ins>+ , m_pageThrottler(m_viewState)
</ins><span class="cx"> , m_consoleClient(std::make_unique<PageConsoleClient>(*this))
</span><span class="cx"> #if ENABLE(REMOTE_INSPECTOR)
</span><span class="cx"> , m_inspectorDebuggable(std::make_unique<PageDebuggable>(*this))
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Page.h (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Page.h        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/page/Page.h        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -80,7 +80,6 @@
</span><span class="cx"> class InspectorController;
</span><span class="cx"> class MainFrame;
</span><span class="cx"> class MediaCanStartListener;
</span><del>-class PageActivityAssertionToken;
</del><span class="cx"> class PageConfiguration;
</span><span class="cx"> class PageConsoleClient;
</span><span class="cx"> class PageDebuggable;
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageActivityAssertionTokencpp"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/page/PageActivityAssertionToken.cpp (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PageActivityAssertionToken.cpp        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/page/PageActivityAssertionToken.cpp        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -1,47 +0,0 @@
</span><del>-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * 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.
- */
-
-#include "config.h"
-#include "PageActivityAssertionToken.h"
-
-#include "PageThrottler.h"
-
-namespace WebCore {
-
-PageActivityAssertionToken::PageActivityAssertionToken(PageThrottler& throttler)
- : m_throttler(throttler.weakPtr())
-{
- throttler.incrementActivityCount();
-}
-
-PageActivityAssertionToken::~PageActivityAssertionToken()
-{
- if (PageThrottler* throttler = m_throttler.get())
- throttler->decrementActivityCount();
-}
-
-} // namespace WebCore
-
-
</del></span></pre></div>
<a id="trunkSourceWebCorepagePageActivityAssertionTokenh"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebCore/page/PageActivityAssertionToken.h (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PageActivityAssertionToken.h        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/page/PageActivityAssertionToken.h        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -1,48 +0,0 @@
</span><del>-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * 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.
- */
-
-#ifndef PageActivityAssertionToken_h
-#define PageActivityAssertionToken_h
-
-#include <wtf/Noncopyable.h>
-#include <wtf/WeakPtr.h>
-
-namespace WebCore {
-
-class PageThrottler;
-
-class PageActivityAssertionToken {
- WTF_MAKE_NONCOPYABLE(PageActivityAssertionToken);
-public:
- PageActivityAssertionToken(PageThrottler&);
- ~PageActivityAssertionToken();
-
-private:
- WeakPtr<PageThrottler> m_throttler;
-};
-
-} // namespace WebCore
-
-#endif // PageActivityAssertionToken_h
</del></span></pre></div>
<a id="trunkSourceWebCorepagePageThrottlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PageThrottler.cpp (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PageThrottler.cpp        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/page/PageThrottler.cpp        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -26,16 +26,12 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "PageThrottler.h"
</span><span class="cx">
</span><del>-#include "PageActivityAssertionToken.h"
-
</del><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><del>-PageThrottler::PageThrottler(Page& page, ViewState::Flags viewState)
- : m_page(page)
- , m_viewState(viewState)
- , m_weakPtrFactory(this)
</del><ins>+PageThrottler::PageThrottler(ViewState::Flags viewState)
+ : m_viewState(viewState)
</ins><span class="cx"> , m_hysteresis(*this)
</span><del>- , m_activityCount(0)
</del><ins>+ , m_pageActivityCounter([this]() { pageActivityCounterValueDidChange(); })
</ins><span class="cx"> {
</span><span class="cx"> updateUserActivity();
</span><span class="cx"> }
</span><span class="lines">@@ -47,36 +43,25 @@
</span><span class="cx"> updateUserActivity();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-std::unique_ptr<PageActivityAssertionToken> PageThrottler::mediaActivityToken()
</del><ins>+PageActivityAssertionToken PageThrottler::mediaActivityToken()
</ins><span class="cx"> {
</span><del>- return std::make_unique<PageActivityAssertionToken>(*this);
</del><ins>+ return m_pageActivityCounter.count();
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-std::unique_ptr<PageActivityAssertionToken> PageThrottler::pageLoadActivityToken()
</del><ins>+PageActivityAssertionToken PageThrottler::pageLoadActivityToken()
</ins><span class="cx"> {
</span><del>- return std::make_unique<PageActivityAssertionToken>(*this);
</del><ins>+ return m_pageActivityCounter.count();
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-void PageThrottler::incrementActivityCount()
</del><ins>+void PageThrottler::pageActivityCounterValueDidChange()
</ins><span class="cx"> {
</span><del>- // If m_activityCount is nonzero, state must be Started; if m_activityCount is zero, state may be Waiting or Stopped.
- ASSERT(!!m_activityCount == (m_hysteresis.state() == HysteresisState::Started));
-
- if (!m_activityCount++)
</del><ins>+ if (m_pageActivityCounter.value())
</ins><span class="cx"> m_hysteresis.start();
</span><del>-
- ASSERT(m_activityCount && m_hysteresis.state() == HysteresisState::Started);
-}
-
-void PageThrottler::decrementActivityCount()
-{
- ASSERT(m_activityCount && m_hysteresis.state() == HysteresisState::Started);
-
- if (!--m_activityCount)
</del><ins>+ else
</ins><span class="cx"> m_hysteresis.stop();
</span><span class="cx">
</span><del>- // If m_activityCount is nonzero, state must be Started; if m_activityCount is zero, state may be Waiting or Stopped.
- ASSERT(!!m_activityCount == (m_hysteresis.state() == HysteresisState::Started));
</del><ins>+ // If the counter is nonzero, state must be Started; if the counter is zero, state may be Waiting or Stopped.
+ ASSERT(!!m_pageActivityCounter.value() == (m_hysteresis.state() == HysteresisState::Started));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void PageThrottler::updateUserActivity()
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageThrottlerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PageThrottler.h (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PageThrottler.h        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Source/WebCore/page/PageThrottler.h        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -30,31 +30,27 @@
</span><span class="cx">
</span><span class="cx"> #include "UserActivity.h"
</span><span class="cx"> #include "ViewState.h"
</span><del>-#include <wtf/WeakPtr.h>
</del><ins>+#include <wtf/RefCounter.h>
</ins><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><del>-class Page;
-class PageActivityAssertionToken;
</del><ins>+typedef RefPtr<RefCounter::Count> PageActivityAssertionToken;
</ins><span class="cx">
</span><span class="cx"> class PageThrottler {
</span><span class="cx"> WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>- PageThrottler(Page&, ViewState::Flags);
</del><ins>+ PageThrottler(ViewState::Flags);
</ins><span class="cx">
</span><span class="cx"> void createUserActivity();
</span><span class="cx"> void setViewState(ViewState::Flags);
</span><span class="cx">
</span><span class="cx"> void didReceiveUserInput() { m_hysteresis.impulse(); }
</span><span class="cx"> void pluginDidEvaluateWhileAudioIsPlaying() { m_hysteresis.impulse(); }
</span><del>- std::unique_ptr<PageActivityAssertionToken> mediaActivityToken();
- std::unique_ptr<PageActivityAssertionToken> pageLoadActivityToken();
</del><ins>+ PageActivityAssertionToken mediaActivityToken();
+ PageActivityAssertionToken pageLoadActivityToken();
</ins><span class="cx">
</span><span class="cx"> private:
</span><del>- friend class PageActivityAssertionToken;
- WeakPtr<PageThrottler> weakPtr() { return m_weakPtrFactory.createWeakPtr(); }
- void incrementActivityCount();
- void decrementActivityCount();
</del><ins>+ void pageActivityCounterValueDidChange();
</ins><span class="cx">
</span><span class="cx"> void updateUserActivity();
</span><span class="cx">
</span><span class="lines">@@ -62,12 +58,10 @@
</span><span class="cx"> WEBCORE_EXPORT void started();
</span><span class="cx"> void stopped();
</span><span class="cx">
</span><del>- Page& m_page;
</del><span class="cx"> ViewState::Flags m_viewState;
</span><del>- WeakPtrFactory<PageThrottler> m_weakPtrFactory;
</del><span class="cx"> HysteresisActivity<PageThrottler> m_hysteresis;
</span><span class="cx"> std::unique_ptr<UserActivity::Impl> m_activity;
</span><del>- size_t m_activityCount;
</del><ins>+ RefCounter m_pageActivityCounter;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Tools/ChangeLog        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2014-12-02 Gavin Barraclough <barraclough@apple.com>
+
+ Generalize PageActivityAssertionToken
+ https://bugs.webkit.org/show_bug.cgi?id=139106
+
+ Reviewed by Sam Weinig.
+
+ Add an API test for WTF::RefCounter.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WTF/RefCounter.cpp: Added.
+ (TestWebKitAPI::TEST):
+ - added RefCounter test.
+
</ins><span class="cx"> 2014-12-02 Alexey Proskuryakov <ap@apple.com>
</span><span class="cx">
</span><span class="cx"> [Mac, iOS] Crash log application information contains latest main frame URL instead of test URL
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (176682 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2014-12-02 19:49:34 UTC (rev 176682)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -134,6 +134,7 @@
</span><span class="cx">                 7CFBCADF1743234F00B2BFCF /* WillLoad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */; };
</span><span class="cx">                 7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; };
</span><span class="cx">                 81B50193140F232300D9EB58 /* StringBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81B50192140F232300D9EB58 /* StringBuilder.cpp */; };
</span><ins>+                86BD19981A2DB05B006DCF0A /* RefCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86BD19971A2DB05B006DCF0A /* RefCounter.cpp */; };
</ins><span class="cx">                 8A2C750E16CED9550024F352 /* ResizeWindowAfterCrash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A2C750D16CED9550024F352 /* ResizeWindowAfterCrash.cpp */; };
</span><span class="cx">                 8A3AF93B16C9ED2700D248C1 /* ReloadPageAfterCrash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A3AF93A16C9ED2700D248C1 /* ReloadPageAfterCrash.cpp */; };
</span><span class="cx">                 8AA28C1A16D2FA7B002FF4DB /* LoadPageOnCrash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8AA28C1916D2FA7B002FF4DB /* LoadPageOnCrash.cpp */; };
</span><span class="lines">@@ -496,6 +497,7 @@
</span><span class="cx">                 7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad_Bundle.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilder.cpp; sourceTree = "<group>"; };
</span><ins>+                86BD19971A2DB05B006DCF0A /* RefCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefCounter.cpp; sourceTree = "<group>"; };
</ins><span class="cx">                 8A2C750D16CED9550024F352 /* ResizeWindowAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResizeWindowAfterCrash.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 8A3AF93A16C9ED2700D248C1 /* ReloadPageAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReloadPageAfterCrash.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 8AA28C1916D2FA7B002FF4DB /* LoadPageOnCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadPageOnCrash.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -961,6 +963,7 @@
</span><span class="cx">                                 1AFDE6541953B2C000C48FFA /* Optional.cpp */,
</span><span class="cx">                                 0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */,
</span><span class="cx">                                 93A427AA180DA26400CD24D7 /* Ref.cpp */,
</span><ins>+                                86BD19971A2DB05B006DCF0A /* RefCounter.cpp */,
</ins><span class="cx">                                 93A427AD180DA60F00CD24D7 /* RefLogger.h */,
</span><span class="cx">                                 93A427A8180D9B0700CD24D7 /* RefPtr.cpp */,
</span><span class="cx">                                 CD5393C91757BAC400C07123 /* SHA1.cpp */,
</span><span class="lines">@@ -1387,6 +1390,7 @@
</span><span class="cx">                                 CDC2C71517970DDB00E627FB /* TimeRanges.cpp in Sources */,
</span><span class="cx">                                 51FCF79A1534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp in Sources */,
</span><span class="cx">                                 1AFDE6561953B2C000C48FFA /* Optional.cpp in Sources */,
</span><ins>+                                86BD19981A2DB05B006DCF0A /* RefCounter.cpp in Sources */,
</ins><span class="cx">                                 C540F776152E4DA000A40C8C /* SimplifyMarkup.mm in Sources */,
</span><span class="cx">                                 4A410F4C19AF7BD6002EBAB5 /* UserMedia.cpp in Sources */,
</span><span class="cx">                                 C02B77F2126612140026BF0F /* SpacebarScrolling.cpp in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFRefCountercpp"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp (0 => 176683)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp         (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp        2014-12-02 20:30:17 UTC (rev 176683)
</span><span class="lines">@@ -0,0 +1,161 @@
</span><ins>+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * 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.
+ */
+
+#include "config.h"
+
+#include <wtf/Ref.h>
+#include <wtf/RefCounter.h>
+#include <wtf/text/WTFString.h>
+
+namespace TestWebKitAPI {
+
+static const int CallbackExpected = 0xC0FFEE;
+static const int CallbackNotExpected = 0xDECAF;
+
+TEST(WTF, RefCounter)
+{
+ // RefCounter API is pretty simple, containing the following 4 methods to test:
+ //
+ // 1) RefCounter(std::function<void()>);
+ // 2) ~RefCounter();
+ // 3) PassRef<Count> count() const;
+ // 4) unsigned value() const;
+ //
+ // We'll test:
+ // 1) Construction:
+ // 1a) with a callback
+ // 1b) without a callback
+ // 2) Destruction where the RefCounter::Count has:
+ // 2a) a non-zero reference count (Count outlives RefCounter).
+ // 2b) a zero reference count (Count is deleted by RefCounter's destructor).
+ // 3) Call count to ref/deref the Count object, where:
+ // 3a) ref with callback from 0 -> 1.
+ // 3b) ref with callback from 1 -> >1.
+ // 3c) deref with callback from >1 -> 1.
+ // 3d) deref with callback from 1 -> 0.
+ // 3d) deref with callback from 1 -> 0.
+ // 3e) ref with callback from 1 -> >1 AFTER RefCounter has been destroyed.
+ // 3f) deref with callback from >1 -> 1 AFTER RefCounter has been destroyed.
+ // 3g) deref with callback from 1 -> 0 AFTER RefCounter has been destroyed.
+ // 3h) ref without callback
+ // 3i) deref without callback
+ // 3j) ref using a Ref rather than a RefPtr (make sure there is no unnecessary reference count churn).
+ // 3k) deref using a Ref rather than a RefPtr (make sure there is no unnecessary reference count churn).
+ // 4) Test the value of the counter:
+ // 4a) at construction.
+ // 4b) as read within the callback.
+ // 4c) as read after the ref/deref.
+
+ // These values will outlive the following block.
+ int callbackValue = CallbackNotExpected;
+ RefPtr<RefCounter::Count> incTo1Again;
+
+ {
+ // Testing (1a) - Construction with a callback.
+ RefCounter* counterPtr = nullptr;
+ RefCounter counter([&]() {
+ // Check that the callback is called at the expected times, and the correct number of times.
+ EXPECT_EQ(callbackValue, CallbackExpected);
+ // return the value of the counter in the callback.
+ callbackValue = counterPtr->value();
+ });
+ counterPtr = &counter;
+ // Testing (4a) - after construction value() is 0.
+ EXPECT_EQ(0, static_cast<int>(counter.value()));
+
+ // Testing (3a) - ref with callback from 0 -> 1.
+ callbackValue = CallbackExpected;
+ RefPtr<RefCounter::Count> incTo1(counter.count());
+ // Testing (4b) & (4c) - values within & after callback.
+ EXPECT_EQ(1, callbackValue);
+ EXPECT_EQ(1, static_cast<int>(counter.value()));
+
+ // Testing (3b) - ref with callback from 1 -> 2.
+ callbackValue = CallbackExpected;
+ RefPtr<RefCounter::Count> incTo2(incTo1);
+ // Testing (4b) & (4c) - values within & after callback.
+ EXPECT_EQ(2, callbackValue);
+ EXPECT_EQ(2, static_cast<int>(counter.value()));
+
+ // Testing (3c) - deref with callback from >1 -> 1.
+ callbackValue = CallbackExpected;
+ incTo1.clear();
+ // Testing (4b) & (4c) - values within & after callback.
+ EXPECT_EQ(1, callbackValue);
+ EXPECT_EQ(1, static_cast<int>(counter.value()));
+
+ {
+ // Testing (3j) - ref using a Ref rather than a RefPtr.
+ callbackValue = CallbackExpected;
+ Ref<RefCounter::Count> incTo2Again(counter.count());
+ // Testing (4b) & (4c) - values within & after callback.
+ EXPECT_EQ(2, callbackValue);
+ EXPECT_EQ(2, static_cast<int>(counter.value()));
+ // Testing (3k) - deref using a Ref rather than a RefPtr.
+ callbackValue = CallbackExpected;
+ }
+ EXPECT_EQ(1, callbackValue);
+ EXPECT_EQ(1, static_cast<int>(counter.value()));
+ // Testing (4b) & (4c) - values within & after callback.
+
+ // Testing (3d) - deref with callback from 1 -> 0.
+ callbackValue = CallbackExpected;
+ incTo2.clear();
+ // Testing (4b) & (4c) - values within & after callback.
+ EXPECT_EQ(0, callbackValue);
+ EXPECT_EQ(0, static_cast<int>(counter.value()));
+
+ // Testing (2a) - Destruction where the RefCounter::Count has a non-zero reference count.
+ callbackValue = CallbackExpected;
+ incTo1Again = counter.count();
+ EXPECT_EQ(1, callbackValue);
+ EXPECT_EQ(1, static_cast<int>(counter.value()));
+ callbackValue = CallbackNotExpected;
+ }
+
+ // Testing (3e) - ref with callback from 1 -> >1 AFTER RefCounter has been destroyed.
+ RefPtr<RefCounter::Count> incTo2Again = incTo1Again;
+ // Testing (3f) - deref with callback from >1 -> 1 AFTER RefCounter has been destroyed.
+ incTo1Again.clear();
+ // Testing (3g) - deref with callback from 1 -> 0 AFTER RefCounter has been destroyed.
+ incTo2Again.clear();
+
+ // Testing (1b) - Construction without a callback.
+ RefCounter counter;
+ // Testing (4a) - after construction value() is 0.
+ EXPECT_EQ(0, static_cast<int>(counter.value()));
+ // Testing (3h) - ref without callback
+ RefPtr<RefCounter::Count> incTo1(counter.count());
+ // Testing (4c) - value as read after the ref.
+ EXPECT_EQ(1, static_cast<int>(counter.value()));
+ // Testing (3i) - deref without callback
+ incTo1.clear();
+ // Testing (4c) - value as read after the deref.
+ EXPECT_EQ(0, static_cast<int>(counter.value()));
+ // Testing (2b) - Destruction where the RefCounter::Count has a zero reference count.
+ // ... not a lot to test here! - we can at least ensure this code path is run & we don't crash!
+}
+
+} // namespace TestWebKitAPI
</ins></span></pre>
</div>
</div>
</body>
</html>