<!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>[177541] 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/177541">177541</a></dd>
<dt>Author</dt> <dd>barraclough@apple.com</dd>
<dt>Date</dt> <dd>2014-12-18 16:51:47 -0800 (Thu, 18 Dec 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add strong typing to RefCounter interface, return value as a bool.
https://bugs.webkit.org/show_bug.cgi?id=139776
Reviewed by Geoff Garen.
Currently all token vended by a RefCounter have the same type - Ref<RefCounter::Count>.
This means there is no compile time type checking to prevent mistakes. Update the count()
method to token<>(), templated on type used to identify the token being returned.
Calls to token<T>() will return a result of type RefCounter::Token<T>.
There are a few problems with the fact the counter will return you an exact count of the
number of outstanding tokens:
- It is desirable to only fire the callback on zero-edge changes; it is more consistent
to do so if the value is only readable as a boolean.
- It is desirable to provide the value as an argument to the callback, however to make
this useful for integer values it is also necessary to indicate the direction of change
(0->1 is often interesting where 2->1 is not).
- There is a mismatch between the precision of returning a count, and the inherent
imprecision of a token based mechanism, where it may be difficult to guarantee
absolutely no unnecessary refcount churn, and thus unintentional counter values.
Source/WebCore:
* page/PageThrottler.cpp:
(WebCore::m_mediaActivityCounter):
(WebCore::m_pageLoadActivityCounter):
- lambdas now passed the value.
(WebCore::PageThrottler::mediaActivityToken):
(WebCore::PageThrottler::pageLoadActivityToken):
- count() -> token<>().
* page/PageThrottler.h:
- specify tpoken type for PageActivityAssertionToken.
Source/WebKit2:
Removed PluginProcessManager::m_processSuppressionEnabled. Now the callback only fires on
zero-edge transitions we no longer need this to filter changes.
* UIProcess/Plugins/PluginProcessManager.cpp:
(WebKit::PluginProcessManager::PluginProcessManager):
- updateProcessSuppressionState -> updateProcessSuppressionDisabled.
* UIProcess/Plugins/PluginProcessManager.h:
(WebKit::PluginProcessManager::processSuppressionDisabledForPageCount): Deleted.
(WebKit::PluginProcessManager::processSuppressionDisabledToken):
- processSuppressionDisabledForPageCount -> processSuppressionDisabledToken.
(WebKit::PluginProcessManager::processSuppressionEnabled): Deleted.
(WebKit::PluginProcessManager::processSuppressionDisabled):
- processSuppressionEnabled -> processSuppressionDisabled.
* UIProcess/Plugins/PluginProcessProxy.cpp:
(WebKit::PluginProcessProxy::didFinishLaunching):
- processSuppressionEnabled -> processSuppressionDisabled.
* UIProcess/Plugins/mac/PluginProcessManagerMac.mm:
(WebKit::PluginProcessManager::updateProcessSuppressionState): Deleted.
(WebKit::PluginProcessManager::updateProcessSuppressionDisabled):
- updateProcessSuppressionState -> updateProcessSuppressionDisabled
* UIProcess/ProcessThrottler.h:
- added UserObservablePageToken, ProcessSuppressionDisabledToken types.
* UIProcess/WebContext.cpp:
(WebKit::WebContext::WebContext):
(WebKit::m_processSuppressionDisabledForPageCounter):
- lambda now has bool argument.
* UIProcess/WebContext.h:
(WebKit::WebContext::userObservablePageCount):
(WebKit::WebContext::processSuppressionDisabledForPageCount):
- count() -> token<>(), changed return type.
* UIProcess/WebPageProxy.h:
- changed types of token members.
* UIProcess/mac/WebContextMac.mm:
(WebKit::WebContext::updateProcessSuppressionState):
renamed m_pluginProcessManagerProcessSuppressionDisabledCount -> m_pluginProcessManagerProcessSuppressionDisabledToken.
Source/WTF:
* wtf/RefCounter.cpp:
(WTF::RefCounter::Count::ref):
(WTF::RefCounter::Count::deref):
- only call the callback on zero-edge changes; provide the value.
(WTF::RefCounter::RefCounter):
- callback now takes a bool argument.
* wtf/RefCounter.h:
(WTF::RefCounter::Token::Token):
- New opaque type to reference the RefCounter::Count.
(WTF::RefCounter::Token::operator!):
- ! operator checks for null / anasigned Tokens.
(WTF::RefCounter::RefCounter):
- callback now takes a bool argument.
(WTF::RefCounter::token):
- renamed from count(), templated on type of token returned.
(WTF::RefCounter::value):
- now returns a bool.
(WTF::RefCounter::Token<T>::Token):
(WTF::=):
- Tokens can be copied & assigned.
(WTF::RefCounter::count): Deleted.
- renamed to token<>().
Tools:
* TestWebKitAPI/Tests/WTF/RefCounter.cpp:
(TestWebKitAPI::TEST):
- update API test.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<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="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</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="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPImacWKViewInternalh">trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessPluginsPluginProcessManagercpp">trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessPluginsPluginProcessManagerh">trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessPluginsPluginProcessProxycpp">trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessPluginsmacPluginProcessManagerMacmm">trunk/Source/WebKit2/UIProcess/Plugins/mac/PluginProcessManagerMac.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessProcessThrottlerh">trunk/Source/WebKit2/UIProcess/ProcessThrottler.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebContextcpp">trunk/Source/WebKit2/UIProcess/WebContext.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebContexth">trunk/Source/WebKit2/UIProcess/WebContext.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWebContextMacmm">trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWTFRefCountercpp">trunk/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WTF/ChangeLog        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -1,3 +1,49 @@
</span><ins>+2014-12-18 Gavin Barraclough <barraclough@apple.com>
+
+ Add strong typing to RefCounter interface, return value as a bool.
+ https://bugs.webkit.org/show_bug.cgi?id=139776
+
+ Reviewed by Geoff Garen.
+
+ Currently all token vended by a RefCounter have the same type - Ref<RefCounter::Count>.
+ This means there is no compile time type checking to prevent mistakes. Update the count()
+ method to token<>(), templated on type used to identify the token being returned.
+ Calls to token<T>() will return a result of type RefCounter::Token<T>.
+
+ There are a few problems with the fact the counter will return you an exact count of the
+ number of outstanding tokens:
+ - It is desirable to only fire the callback on zero-edge changes; it is more consistent
+ to do so if the value is only readable as a boolean.
+ - It is desirable to provide the value as an argument to the callback, however to make
+ this useful for integer values it is also necessary to indicate the direction of change
+ (0->1 is often interesting where 2->1 is not).
+ - There is a mismatch between the precision of returning a count, and the inherent
+ imprecision of a token based mechanism, where it may be difficult to guarantee
+ absolutely no unnecessary refcount churn, and thus unintentional counter values.
+
+ * wtf/RefCounter.cpp:
+ (WTF::RefCounter::Count::ref):
+ (WTF::RefCounter::Count::deref):
+ - only call the callback on zero-edge changes; provide the value.
+ (WTF::RefCounter::RefCounter):
+ - callback now takes a bool argument.
+ * wtf/RefCounter.h:
+ (WTF::RefCounter::Token::Token):
+ - New opaque type to reference the RefCounter::Count.
+ (WTF::RefCounter::Token::operator!):
+ - ! operator checks for null / anasigned Tokens.
+ (WTF::RefCounter::RefCounter):
+ - callback now takes a bool argument.
+ (WTF::RefCounter::token):
+ - renamed from count(), templated on type of token returned.
+ (WTF::RefCounter::value):
+ - now returns a bool.
+ (WTF::RefCounter::Token<T>::Token):
+ (WTF::=):
+ - Tokens can be copied & assigned.
+ (WTF::RefCounter::count): Deleted.
+ - renamed to token<>().
+
</ins><span class="cx"> 2014-12-18 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><span class="cx"> Simplify smart pointer classes by using std::exchange
</span></span></pre></div>
<a id="trunkSourceWTFwtfRefCountercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/RefCounter.cpp (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/RefCounter.cpp        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WTF/wtf/RefCounter.cpp        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -30,10 +30,11 @@
</span><span class="cx">
</span><span class="cx"> void RefCounter::Count::ref()
</span><span class="cx"> {
</span><ins>+ bool valueWasZero = !m_value;
</ins><span class="cx"> ++m_value;
</span><del>-
- if (m_refCounter)
- m_refCounter->m_valueDidChange();
</del><ins>+
+ if (valueWasZero && m_refCounter)
+ m_refCounter->m_valueDidChange(true);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void RefCounter::Count::deref()
</span><span class="lines">@@ -41,17 +42,20 @@
</span><span class="cx"> ASSERT(m_value);
</span><span class="cx"> --m_value;
</span><span class="cx">
</span><ins>+ if (m_value)
+ return;
+
</ins><span class="cx"> // The Count object is kept alive so long as either the RefCounter that created it remains
</span><span class="cx"> // allocated, or so long as its reference count is non-zero.
</span><span class="cx"> // If the RefCounter has already been deallocted then delete the Count when its reference
</span><span class="cx"> // count reaches zero.
</span><span class="cx"> if (m_refCounter)
</span><del>- m_refCounter->m_valueDidChange();
- else if (!m_value)
</del><ins>+ m_refCounter->m_valueDidChange(false);
+ else
</ins><span class="cx"> delete this;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-RefCounter::RefCounter(std::function<void()> valueDidChange)
</del><ins>+RefCounter::RefCounter(std::function<void(bool)> valueDidChange)
</ins><span class="cx"> : m_valueDidChange(valueDidChange)
</span><span class="cx"> , m_count(new Count(*this))
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWTFwtfRefCounterh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/RefCounter.h (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/RefCounter.h        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WTF/wtf/RefCounter.h        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -34,7 +34,7 @@
</span><span class="cx">
</span><span class="cx"> class RefCounter {
</span><span class="cx"> WTF_MAKE_NONCOPYABLE(RefCounter);
</span><del>-public:
</del><ins>+
</ins><span class="cx"> class Count {
</span><span class="cx"> WTF_MAKE_NONCOPYABLE(Count);
</span><span class="cx"> public:
</span><span class="lines">@@ -54,24 +54,86 @@
</span><span class="cx"> unsigned m_value;
</span><span class="cx"> };
</span><span class="cx">
</span><del>- WTF_EXPORT_PRIVATE RefCounter(std::function<void()> = []() { });
</del><ins>+public:
+ template<typename T>
+ class Token {
+ public:
+ Token() { }
+ Token(std::nullptr_t) { }
+ inline Token(const Token<T>& token);
+ inline Token(Token<T>&& token);
+
+ inline Token<T>& operator=(std::nullptr_t);
+ inline Token<T>& operator=(const Token<T>& o);
+ inline Token<T>& operator=(Token<T>&& o);
+
+ bool operator!() const { return !m_ptr; }
+
+ private:
+ friend class RefCounter;
+ inline Token(Count* count);
+
+ RefPtr<Count> m_ptr;
+ };
+
+ WTF_EXPORT_PRIVATE RefCounter(std::function<void(bool)> = [](bool) { });
</ins><span class="cx"> WTF_EXPORT_PRIVATE ~RefCounter();
</span><span class="cx">
</span><del>- Ref<Count> count() const
</del><ins>+ template<typename T>
+ Token<T> token() const
</ins><span class="cx"> {
</span><del>- return *m_count;
</del><ins>+ return Token<T>(m_count);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- unsigned value() const
</del><ins>+ bool value() const
</ins><span class="cx"> {
</span><span class="cx"> return m_count->m_value;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- std::function<void()> m_valueDidChange;
</del><ins>+ std::function<void(bool)> m_valueDidChange;
</ins><span class="cx"> Count* m_count;
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+template<class T>
+inline RefCounter::Token<T>::Token(Count* count)
+ : m_ptr(count)
+{
+}
+
+template<class T>
+inline RefCounter::Token<T>::Token(const RefCounter::Token<T>::Token<T>& token)
+ : m_ptr(token.m_ptr)
+{
+}
+
+template<class T>
+inline RefCounter::Token<T>::Token(RefCounter::Token<T>::Token<T>&& token)
+ : m_ptr(token.m_ptr)
+{
+}
+
+template<class T>
+inline RefCounter::Token<T>& RefCounter::Token<T>::operator=(std::nullptr_t)
+{
+ m_ptr = nullptr;
+ return *this;
+}
+
+template<class T>
+inline RefCounter::Token<T>& RefCounter::Token<T>::operator=(const RefCounter::Token<T>& o)
+{
+ m_ptr = o.m_ptr;
+ return *this;
+}
+
+template<class T>
+inline RefCounter::Token<T>& RefCounter::Token<T>::operator=(RefCounter::Token<T>&& o)
+{
+ m_ptr = o.m_ptr;
+ return *this;
+}
+
</ins><span class="cx"> } // namespace WTF
</span><span class="cx">
</span><span class="cx"> using WTF::RefCounter;
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebCore/ChangeLog        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2014-12-18 Gavin Barraclough <barraclough@apple.com>
+
+ Add strong typing to RefCounter interface, return value as a bool.
+ https://bugs.webkit.org/show_bug.cgi?id=139776
+
+ Reviewed by Geoff Garen.
+
+ Currently all token vended by a RefCounter have the same type - Ref<RefCounter::Count>.
+ This means there is no compile time type checking to prevent mistakes. Update the count()
+ method to token<>(), templated on type used to identify the token being returned.
+ Calls to token<T>() will return a result of type RefCounter::Token<T>.
+
+ There are a few problems with the fact the counter will return you an exact count of the
+ number of outstanding tokens:
+ - It is desirable to only fire the callback on zero-edge changes; it is more consistent
+ to do so if the value is only readable as a boolean.
+ - It is desirable to provide the value as an argument to the callback, however to make
+ this useful for integer values it is also necessary to indicate the direction of change
+ (0->1 is often interesting where 2->1 is not).
+ - There is a mismatch between the precision of returning a count, and the inherent
+ imprecision of a token based mechanism, where it may be difficult to guarantee
+ absolutely no unnecessary refcount churn, and thus unintentional counter values.
+
+ * page/PageThrottler.cpp:
+ (WebCore::m_mediaActivityCounter):
+ (WebCore::m_pageLoadActivityCounter):
+ - lambdas now passed the value.
+ (WebCore::PageThrottler::mediaActivityToken):
+ (WebCore::PageThrottler::pageLoadActivityToken):
+ - count() -> token<>().
+ * page/PageThrottler.h:
+ - specify tpoken type for PageActivityAssertionToken.
+
</ins><span class="cx"> 2014-12-18 Benjamin Poulain <bpoulain@apple.com>
</span><span class="cx">
</span><span class="cx"> HTMLFormControlElement and HTMLObjectElement need not to look for an ancestor on construction
</span><span class="lines">@@ -1928,7 +1961,7 @@
</span><span class="cx"> with callbacks is limiting a number of ways. The callback names are very ambiguous, the callbacks
</span><span class="cx"> must either be on a separate object (more boilerplate), or the callback must be public for
</span><span class="cx"> HysteresisActivity to call them, or friends get involved. Without the boilerplate of extra
</span><del>- delegate objects it's hard to scale use of these objects – a single object can't serve as a
</del><ins>+ delegate objects it's hard to scale use of these objects - a single object can't serve as a
</ins><span class="cx"> delegate for multiple HysteresisActivity members.
</span><span class="cx">
</span><span class="cx"> Instead, make HysteresisActivity take a lambda to callback on state change. To simplify, changed
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageThrottlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PageThrottler.cpp (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PageThrottler.cpp        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebCore/page/PageThrottler.cpp        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -34,19 +34,19 @@
</span><span class="cx"> : m_page(page)
</span><span class="cx"> , m_userInputHysteresis([this](HysteresisState state) { setActivityFlag(PageActivityState::UserInputActivity, state == HysteresisState::Started); })
</span><span class="cx"> , m_audiblePluginHysteresis([this](HysteresisState state) { setActivityFlag(PageActivityState::AudiblePlugin, state == HysteresisState::Started); })
</span><del>- , m_mediaActivityCounter([this]() { setActivityFlag(PageActivityState::MediaActivity, m_mediaActivityCounter.value()); })
- , m_pageLoadActivityCounter([this]() { setActivityFlag(PageActivityState::PageLoadActivity, m_pageLoadActivityCounter.value()); })
</del><ins>+ , m_mediaActivityCounter([this](bool value) { setActivityFlag(PageActivityState::MediaActivity, value); })
+ , m_pageLoadActivityCounter([this](bool value) { setActivityFlag(PageActivityState::PageLoadActivity, value); })
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> PageActivityAssertionToken PageThrottler::mediaActivityToken()
</span><span class="cx"> {
</span><del>- return m_mediaActivityCounter.count();
</del><ins>+ return m_mediaActivityCounter.token<PageActivityAssertionTokenType>();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> PageActivityAssertionToken PageThrottler::pageLoadActivityToken()
</span><span class="cx"> {
</span><del>- return m_pageLoadActivityCounter.count();
</del><ins>+ return m_pageLoadActivityCounter.token<PageActivityAssertionTokenType>();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void PageThrottler::setActivityFlag(PageActivityState::Flags flag, bool value)
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageThrottlerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PageThrottler.h (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PageThrottler.h        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebCore/page/PageThrottler.h        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -36,7 +36,8 @@
</span><span class="cx">
</span><span class="cx"> class Page;
</span><span class="cx">
</span><del>-typedef RefPtr<RefCounter::Count> PageActivityAssertionToken;
</del><ins>+enum PageActivityAssertionTokenType { };
+typedef RefCounter::Token<PageActivityAssertionTokenType> PageActivityAssertionToken;
</ins><span class="cx">
</span><span class="cx"> struct PageActivityState {
</span><span class="cx"> enum {
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebKit2/ChangeLog        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -1,3 +1,62 @@
</span><ins>+2014-12-18 Gavin Barraclough <barraclough@apple.com>
+
+ Add strong typing to RefCounter interface, return value as a bool.
+ https://bugs.webkit.org/show_bug.cgi?id=139776
+
+ Reviewed by Geoff Garen.
+
+ Currently all token vended by a RefCounter have the same type - Ref<RefCounter::Count>.
+ This means there is no compile time type checking to prevent mistakes. Update the count()
+ method to token<>(), templated on type used to identify the token being returned.
+ Calls to token<T>() will return a result of type RefCounter::Token<T>.
+
+ There are a few problems with the fact the counter will return you an exact count of the
+ number of outstanding tokens:
+ - It is desirable to only fire the callback on zero-edge changes; it is more consistent
+ to do so if the value is only readable as a boolean.
+ - It is desirable to provide the value as an argument to the callback, however to make
+ this useful for integer values it is also necessary to indicate the direction of change
+ (0->1 is often interesting where 2->1 is not).
+ - There is a mismatch between the precision of returning a count, and the inherent
+ imprecision of a token based mechanism, where it may be difficult to guarantee
+ absolutely no unnecessary refcount churn, and thus unintentional counter values.
+
+ Removed PluginProcessManager::m_processSuppressionEnabled. Now the callback only fires on
+ zero-edge transitions we no longer need this to filter changes.
+
+ * UIProcess/Plugins/PluginProcessManager.cpp:
+ (WebKit::PluginProcessManager::PluginProcessManager):
+ - updateProcessSuppressionState -> updateProcessSuppressionDisabled.
+ * UIProcess/Plugins/PluginProcessManager.h:
+ (WebKit::PluginProcessManager::processSuppressionDisabledForPageCount): Deleted.
+ (WebKit::PluginProcessManager::processSuppressionDisabledToken):
+ - processSuppressionDisabledForPageCount -> processSuppressionDisabledToken.
+ (WebKit::PluginProcessManager::processSuppressionEnabled): Deleted.
+ (WebKit::PluginProcessManager::processSuppressionDisabled):
+ - processSuppressionEnabled -> processSuppressionDisabled.
+ * UIProcess/Plugins/PluginProcessProxy.cpp:
+ (WebKit::PluginProcessProxy::didFinishLaunching):
+ - processSuppressionEnabled -> processSuppressionDisabled.
+ * UIProcess/Plugins/mac/PluginProcessManagerMac.mm:
+ (WebKit::PluginProcessManager::updateProcessSuppressionState): Deleted.
+ (WebKit::PluginProcessManager::updateProcessSuppressionDisabled):
+ - updateProcessSuppressionState -> updateProcessSuppressionDisabled
+ * UIProcess/ProcessThrottler.h:
+ - added UserObservablePageToken, ProcessSuppressionDisabledToken types.
+ * UIProcess/WebContext.cpp:
+ (WebKit::WebContext::WebContext):
+ (WebKit::m_processSuppressionDisabledForPageCounter):
+ - lambda now has bool argument.
+ * UIProcess/WebContext.h:
+ (WebKit::WebContext::userObservablePageCount):
+ (WebKit::WebContext::processSuppressionDisabledForPageCount):
+ - count() -> token<>(), changed return type.
+ * UIProcess/WebPageProxy.h:
+ - changed types of token members.
+ * UIProcess/mac/WebContextMac.mm:
+ (WebKit::WebContext::updateProcessSuppressionState):
+ renamed m_pluginProcessManagerProcessSuppressionDisabledCount -> m_pluginProcessManagerProcessSuppressionDisabledToken.
+
</ins><span class="cx"> 2014-12-18 Timothy Horton <timothy_horton@apple.com>
</span><span class="cx">
</span><span class="cx"> Try to fix some builds.
</span><span class="lines">@@ -1103,7 +1162,7 @@
</span><span class="cx"> with callbacks is limiting a number of ways. The callback names are very ambiguous, the callbacks
</span><span class="cx"> must either be on a separate object (more boilerplate), or the callback must be public for
</span><span class="cx"> HysteresisActivity to call them, or friends get involved. Without the boilerplate of extra
</span><del>- delegate objects it's hard to scale use of these objects – a single object can't serve as a
</del><ins>+ delegate objects it's hard to scale use of these objects - a single object can't serve as a
</ins><span class="cx"> delegate for multiple HysteresisActivity members.
</span><span class="cx">
</span><span class="cx"> Instead, make HysteresisActivity take a lambda to callback on state change. To simplify, changed
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPImacWKViewInternalh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -25,6 +25,7 @@
</span><span class="cx">
</span><span class="cx"> #import "WKViewPrivate.h"
</span><span class="cx">
</span><ins>+#import "APIObject.h"
</ins><span class="cx"> #import "PluginComplexTextInputState.h"
</span><span class="cx"> #import "SameDocumentNavigationType.h"
</span><span class="cx"> #import "WebFindOptions.h"
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessPluginsPluginProcessManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.cpp (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.cpp        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.cpp        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -44,7 +44,7 @@
</span><span class="cx">
</span><span class="cx"> PluginProcessManager::PluginProcessManager()
</span><span class="cx"> #if PLATFORM(COCOA)
</span><del>- : m_processSuppressionDisabledForPageCounter([this] { updateProcessSuppressionState(); })
</del><ins>+ : m_processSuppressionDisabledForPageCounter([this](bool value) { updateProcessSuppressionDisabled(value); })
</ins><span class="cx"> #endif
</span><span class="cx"> {
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessPluginsPluginProcessManagerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.h (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.h        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessManager.h        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include "PluginModuleInfo.h"
</span><span class="cx"> #include "PluginProcess.h"
</span><span class="cx"> #include "PluginProcessAttributes.h"
</span><ins>+#include "ProcessThrottler.h"
</ins><span class="cx"> #include "WebProcessProxyMessages.h"
</span><span class="cx"> #include <wtf/Forward.h>
</span><span class="cx"> #include <wtf/HashSet.h>
</span><span class="lines">@@ -65,9 +66,9 @@
</span><span class="cx"> void clearSiteData(const PluginModuleInfo&, WebPluginSiteDataManager*, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID);
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(COCOA)
</span><del>- inline PassRefPtr<RefCounter::Count> processSuppressionDisabledForPageCount();
- inline bool processSuppressionEnabled() const;
- void updateProcessSuppressionState();
</del><ins>+ inline ProcessSuppressionDisabledToken processSuppressionDisabledToken();
+ inline bool processSuppressionDisabled() const;
+ void updateProcessSuppressionDisabled(bool);
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> private:
</span><span class="lines">@@ -82,19 +83,18 @@
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx"> RefCounter m_processSuppressionDisabledForPageCounter;
</span><del>- bool m_processSuppressionEnabled { true };
</del><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(COCOA)
</span><del>-inline PassRefPtr<RefCounter::Count> PluginProcessManager::processSuppressionDisabledForPageCount()
</del><ins>+inline ProcessSuppressionDisabledToken PluginProcessManager::processSuppressionDisabledToken()
</ins><span class="cx"> {
</span><del>- return m_processSuppressionDisabledForPageCounter.count();
</del><ins>+ return m_processSuppressionDisabledForPageCounter.token<ProcessSuppressionDisabledTokenType>();
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-inline bool PluginProcessManager::processSuppressionEnabled() const
</del><ins>+inline bool PluginProcessManager::processSuppressionDisabled() const
</ins><span class="cx"> {
</span><del>- return m_processSuppressionEnabled;
</del><ins>+ return m_processSuppressionDisabledForPageCounter.value();
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessPluginsPluginProcessProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.cpp        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -229,7 +229,7 @@
</span><span class="cx"> m_numPendingConnectionRequests = 0;
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(COCOA)
</span><del>- if (PluginProcessManager::shared().processSuppressionEnabled())
</del><ins>+ if (!PluginProcessManager::shared().processSuppressionDisabled())
</ins><span class="cx"> setProcessSuppressionEnabled(true);
</span><span class="cx"> #endif
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessPluginsmacPluginProcessManagerMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Plugins/mac/PluginProcessManagerMac.mm (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Plugins/mac/PluginProcessManagerMac.mm        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebKit2/UIProcess/Plugins/mac/PluginProcessManagerMac.mm        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -32,15 +32,12 @@
</span><span class="cx">
</span><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><del>-void PluginProcessManager::updateProcessSuppressionState()
</del><ins>+void PluginProcessManager::updateProcessSuppressionDisabled(bool disabled)
</ins><span class="cx"> {
</span><del>- bool processSuppressionEnabled = !m_processSuppressionDisabledForPageCounter.value();
- if (m_processSuppressionEnabled == processSuppressionEnabled)
- return;
-
- m_processSuppressionEnabled = processSuppressionEnabled;
</del><ins>+ bool enabled = !disabled;
+
</ins><span class="cx"> for (auto& pluginProcess : m_pluginProcesses)
</span><del>- pluginProcess->setProcessSuppressionEnabled(processSuppressionEnabled);
</del><ins>+ pluginProcess->setProcessSuppressionEnabled(enabled);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessProcessThrottlerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ProcessThrottler.h (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ProcessThrottler.h        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebKit2/UIProcess/ProcessThrottler.h        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -28,11 +28,17 @@
</span><span class="cx">
</span><span class="cx"> #include "ProcessAssertion.h"
</span><span class="cx">
</span><ins>+#include <WTF/RefCounter.h>
</ins><span class="cx"> #include <wtf/RunLoop.h>
</span><span class="cx"> #include <wtf/WeakPtr.h>
</span><span class="cx">
</span><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><ins>+enum UserObservablePageTokenType { };
+typedef RefCounter::Token<UserObservablePageTokenType> UserObservablePageToken;
+enum ProcessSuppressionDisabledTokenType { };
+typedef RefCounter::Token<ProcessSuppressionDisabledTokenType> ProcessSuppressionDisabledToken;
+
</ins><span class="cx"> class WebProcessProxy;
</span><span class="cx">
</span><span class="cx"> class ProcessThrottler {
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebContext.cpp (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebContext.cpp        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebKit2/UIProcess/WebContext.cpp        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -194,8 +194,8 @@
</span><span class="cx"> , m_ignoreTLSErrors(true)
</span><span class="cx"> #endif
</span><span class="cx"> , m_memoryCacheDisabled(false)
</span><del>- , m_userObservablePageCounter([this] { updateProcessSuppressionState(); })
- , m_processSuppressionDisabledForPageCounter([this] { updateProcessSuppressionState(); })
</del><ins>+ , m_userObservablePageCounter([this](bool) { updateProcessSuppressionState(); })
+ , m_processSuppressionDisabledForPageCounter([this](bool) { updateProcessSuppressionState(); })
</ins><span class="cx"> {
</span><span class="cx"> platformInitialize();
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebContexth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebContext.h (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebContext.h        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebKit2/UIProcess/WebContext.h        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include "PlugInAutoStartProvider.h"
</span><span class="cx"> #include "PluginInfoStore.h"
</span><span class="cx"> #include "ProcessModel.h"
</span><ins>+#include "ProcessThrottler.h"
</ins><span class="cx"> #include "StatisticsRequest.h"
</span><span class="cx"> #include "StorageManager.h"
</span><span class="cx"> #include "VisitedLinkProvider.h"
</span><span class="lines">@@ -354,14 +355,14 @@
</span><span class="cx">
</span><span class="cx"> void setMemoryCacheDisabled(bool);
</span><span class="cx">
</span><del>- PassRefPtr<RefCounter::Count> userObservablePageCount()
</del><ins>+ UserObservablePageToken userObservablePageCount()
</ins><span class="cx"> {
</span><del>- return m_userObservablePageCounter.count();
</del><ins>+ return m_userObservablePageCounter.token<UserObservablePageTokenType>();
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- PassRefPtr<RefCounter::Count> processSuppressionDisabledForPageCount()
</del><ins>+ ProcessSuppressionDisabledToken processSuppressionDisabledForPageCount()
</ins><span class="cx"> {
</span><del>- return m_processSuppressionDisabledForPageCounter.count();
</del><ins>+ return m_processSuppressionDisabledForPageCounter.token<ProcessSuppressionDisabledTokenType>();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> private:
</span><span class="lines">@@ -573,7 +574,7 @@
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx"> RetainPtr<NSMutableDictionary> m_bundleParameters;
</span><del>- RefPtr<RefCounter::Count> m_pluginProcessManagerProcessSuppressionDisabledCount;
</del><ins>+ ProcessSuppressionDisabledToken m_pluginProcessManagerProcessSuppressionDisabledToken;
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -43,6 +43,7 @@
</span><span class="cx"> #include "NotificationPermissionRequestManagerProxy.h"
</span><span class="cx"> #include "PageLoadState.h"
</span><span class="cx"> #include "PlatformProcessIdentifier.h"
</span><ins>+#include "ProcessThrottler.h"
</ins><span class="cx"> #include "SandboxExtension.h"
</span><span class="cx"> #include "ShareableBitmap.h"
</span><span class="cx"> #include "UserMediaPermissionRequestManagerProxy.h"
</span><span class="lines">@@ -1583,8 +1584,8 @@
</span><span class="cx"> HashMap<String, String> m_temporaryPDFFiles;
</span><span class="cx"> std::unique_ptr<WebCore::RunLoopObserver> m_viewStateChangeDispatcher;
</span><span class="cx"> #endif
</span><del>- RefPtr<RefCounter::Count> m_pageIsUserObservableCount;
- RefPtr<RefCounter::Count> m_preventProcessSuppressionCount;
</del><ins>+ UserObservablePageToken m_pageIsUserObservableCount;
+ ProcessSuppressionDisabledToken m_preventProcessSuppressionCount;
</ins><span class="cx">
</span><span class="cx"> WebCore::ScrollPinningBehavior m_scrollPinningBehavior;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWebContextMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -112,9 +112,9 @@
</span><span class="cx">
</span><span class="cx"> #if ENABLE(NETSCAPE_PLUGIN_API)
</span><span class="cx"> if (!m_processSuppressionDisabledForPageCounter.value())
</span><del>- m_pluginProcessManagerProcessSuppressionDisabledCount = nullptr;
- else if (!m_pluginProcessManagerProcessSuppressionDisabledCount)
- m_pluginProcessManagerProcessSuppressionDisabledCount = PluginProcessManager::shared().processSuppressionDisabledForPageCount();
</del><ins>+ m_pluginProcessManagerProcessSuppressionDisabledToken = nullptr;
+ else if (!m_pluginProcessManagerProcessSuppressionDisabledToken)
+ m_pluginProcessManagerProcessSuppressionDisabledToken = PluginProcessManager::shared().processSuppressionDisabledToken();
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Tools/ChangeLog        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2014-12-18 Gavin Barraclough <barraclough@apple.com>
+
+ Add strong typing to RefCounter interface, return value as a bool.
+ https://bugs.webkit.org/show_bug.cgi?id=139776
+
+ Reviewed by Geoff Garen.
+
+ Currently all token vended by a RefCounter have the same type - Ref<RefCounter::Count>.
+ This means there is no compile time type checking to prevent mistakes. Update the count()
+ method to token<>(), templated on type used to identify the token being returned.
+ Calls to token<T>() will return a result of type RefCounter::Token<T>.
+
+ There are a few problems with the fact the counter will return you an exact count of the
+ number of outstanding tokens:
+ - It is desirable to only fire the callback on zero-edge changes; it is more consistent
+ to do so if the value is only readable as a boolean.
+ - It is desirable to provide the value as an argument to the callback, however to make
+ this useful for integer values it is also necessary to indicate the direction of change
+ (0->1 is often interesting where 2->1 is not).
+ - There is a mismatch between the precision of returning a count, and the inherent
+ imprecision of a token based mechanism, where it may be difficult to guarantee
+ absolutely no unnecessary refcount churn, and thus unintentional counter values.
+
+ * TestWebKitAPI/Tests/WTF/RefCounter.cpp:
+ (TestWebKitAPI::TEST):
+ - update API test.
+
</ins><span class="cx"> 2014-12-18 Alexey Proskuryakov <ap@apple.com>
</span><span class="cx">
</span><span class="cx"> Disable retries on Mac Release WK2 testers
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFRefCountercpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp (177540 => 177541)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp        2014-12-19 00:27:20 UTC (rev 177540)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/RefCounter.cpp        2014-12-19 00:51:47 UTC (rev 177541)
</span><span class="lines">@@ -34,13 +34,16 @@
</span><span class="cx"> static const int CallbackExpected = 0xC0FFEE;
</span><span class="cx"> static const int CallbackNotExpected = 0xDECAF;
</span><span class="cx">
</span><ins>+enum CounterType { };
+typedef RefCounter::Token<CounterType> TokenType;
+
</ins><span class="cx"> TEST(WTF, RefCounter)
</span><span class="cx"> {
</span><span class="cx"> // RefCounter API is pretty simple, containing the following 4 methods to test:
</span><span class="cx"> //
</span><span class="cx"> // 1) RefCounter(std::function<void()>);
</span><span class="cx"> // 2) ~RefCounter();
</span><del>- // 3) Ref<Count> count() const;
</del><ins>+ // 3) Ref<Count> token() const;
</ins><span class="cx"> // 4) unsigned value() const;
</span><span class="cx"> //
</span><span class="cx"> // We'll test:
</span><span class="lines">@@ -70,90 +73,84 @@
</span><span class="cx">
</span><span class="cx"> // These values will outlive the following block.
</span><span class="cx"> int callbackValue = CallbackNotExpected;
</span><del>- RefPtr<RefCounter::Count> incTo1Again;
</del><ins>+ TokenType incTo1Again;
</ins><span class="cx">
</span><span class="cx"> {
</span><span class="cx"> // Testing (1a) - Construction with a callback.
</span><span class="cx"> RefCounter* counterPtr = nullptr;
</span><del>- RefCounter counter([&]() {
</del><ins>+ RefCounter counter([&](bool value) {
</ins><span class="cx"> // Check that the callback is called at the expected times, and the correct number of times.
</span><span class="cx"> EXPECT_EQ(callbackValue, CallbackExpected);
</span><ins>+ // Value provided should be equal to the counter value.
+ EXPECT_EQ(value, counterPtr->value());
</ins><span class="cx"> // return the value of the counter in the callback.
</span><del>- callbackValue = counterPtr->value();
</del><ins>+ callbackValue = value;
</ins><span class="cx"> });
</span><span class="cx"> counterPtr = &counter;
</span><span class="cx"> // Testing (4a) - after construction value() is 0.
</span><del>- EXPECT_EQ(0, static_cast<int>(counter.value()));
</del><ins>+ EXPECT_EQ(false, static_cast<int>(counter.value()));
</ins><span class="cx">
</span><span class="cx"> // Testing (3a) - ref with callback from 0 -> 1.
</span><span class="cx"> callbackValue = CallbackExpected;
</span><del>- RefPtr<RefCounter::Count> incTo1(counter.count());
</del><ins>+ TokenType incTo1(counter.token<CounterType>());
</ins><span class="cx"> // Testing (4b) & (4c) - values within & after callback.
</span><del>- EXPECT_EQ(1, callbackValue);
- EXPECT_EQ(1, static_cast<int>(counter.value()));
</del><ins>+ EXPECT_EQ(true, callbackValue);
+ EXPECT_EQ(true, static_cast<int>(counter.value()));
</ins><span class="cx">
</span><span class="cx"> // Testing (3b) - ref with callback from 1 -> 2.
</span><del>- callbackValue = CallbackExpected;
- RefPtr<RefCounter::Count> incTo2(incTo1);
</del><ins>+ TokenType incTo2(incTo1);
</ins><span class="cx"> // Testing (4b) & (4c) - values within & after callback.
</span><del>- EXPECT_EQ(2, callbackValue);
- EXPECT_EQ(2, static_cast<int>(counter.value()));
</del><ins>+ EXPECT_EQ(true, static_cast<int>(counter.value()));
</ins><span class="cx">
</span><span class="cx"> // Testing (3c) - deref with callback from >1 -> 1.
</span><del>- callbackValue = CallbackExpected;
- incTo1.clear();
</del><ins>+ incTo1 = nullptr;
</ins><span class="cx"> // Testing (4b) & (4c) - values within & after callback.
</span><del>- EXPECT_EQ(1, callbackValue);
- EXPECT_EQ(1, static_cast<int>(counter.value()));
</del><ins>+ EXPECT_EQ(true, static_cast<int>(counter.value()));
</ins><span class="cx">
</span><span class="cx"> {
</span><span class="cx"> // Testing (3j) - ref using a Ref rather than a RefPtr.
</span><del>- callbackValue = CallbackExpected;
- Ref<RefCounter::Count> incTo2Again(counter.count());
</del><ins>+ TokenType incTo2Again(counter.token<CounterType>());
</ins><span class="cx"> // Testing (4b) & (4c) - values within & after callback.
</span><del>- EXPECT_EQ(2, callbackValue);
- EXPECT_EQ(2, static_cast<int>(counter.value()));
</del><ins>+ EXPECT_EQ(true, static_cast<int>(counter.value()));
</ins><span class="cx"> // Testing (3k) - deref using a Ref rather than a RefPtr.
</span><del>- callbackValue = CallbackExpected;
</del><span class="cx"> }
</span><del>- EXPECT_EQ(1, callbackValue);
- EXPECT_EQ(1, static_cast<int>(counter.value()));
</del><ins>+ EXPECT_EQ(true, static_cast<int>(counter.value()));
</ins><span class="cx"> // Testing (4b) & (4c) - values within & after callback.
</span><span class="cx">
</span><span class="cx"> // Testing (3d) - deref with callback from 1 -> 0.
</span><span class="cx"> callbackValue = CallbackExpected;
</span><del>- incTo2.clear();
</del><ins>+ incTo2 = nullptr;
</ins><span class="cx"> // Testing (4b) & (4c) - values within & after callback.
</span><del>- EXPECT_EQ(0, callbackValue);
- EXPECT_EQ(0, static_cast<int>(counter.value()));
</del><ins>+ EXPECT_EQ(false, callbackValue);
+ EXPECT_EQ(false, static_cast<int>(counter.value()));
</ins><span class="cx">
</span><span class="cx"> // Testing (2a) - Destruction where the RefCounter::Count has a non-zero reference count.
</span><span class="cx"> callbackValue = CallbackExpected;
</span><del>- incTo1Again = counter.count();
- EXPECT_EQ(1, callbackValue);
- EXPECT_EQ(1, static_cast<int>(counter.value()));
</del><ins>+ incTo1Again = counter.token<CounterType>();
+ EXPECT_EQ(true, callbackValue);
+ EXPECT_EQ(true, static_cast<int>(counter.value()));
</ins><span class="cx"> callbackValue = CallbackNotExpected;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Testing (3e) - ref with callback from 1 -> >1 AFTER RefCounter has been destroyed.
</span><del>- RefPtr<RefCounter::Count> incTo2Again = incTo1Again;
</del><ins>+ TokenType incTo2Again = incTo1Again;
</ins><span class="cx"> // Testing (3f) - deref with callback from >1 -> 1 AFTER RefCounter has been destroyed.
</span><del>- incTo1Again.clear();
</del><ins>+ incTo1Again = nullptr;
</ins><span class="cx"> // Testing (3g) - deref with callback from 1 -> 0 AFTER RefCounter has been destroyed.
</span><del>- incTo2Again.clear();
</del><ins>+ incTo2Again = nullptr;
</ins><span class="cx">
</span><span class="cx"> // Testing (1b) - Construction without a callback.
</span><span class="cx"> RefCounter counter;
</span><span class="cx"> // Testing (4a) - after construction value() is 0.
</span><del>- EXPECT_EQ(0, static_cast<int>(counter.value()));
</del><ins>+ EXPECT_EQ(false, static_cast<int>(counter.value()));
</ins><span class="cx"> // Testing (3h) - ref without callback
</span><del>- RefPtr<RefCounter::Count> incTo1(counter.count());
</del><ins>+ TokenType incTo1(counter.token<CounterType>());
</ins><span class="cx"> // Testing (4c) - value as read after the ref.
</span><del>- EXPECT_EQ(1, static_cast<int>(counter.value()));
</del><ins>+ EXPECT_EQ(true, static_cast<int>(counter.value()));
</ins><span class="cx"> // Testing (3i) - deref without callback
</span><del>- incTo1.clear();
</del><ins>+ incTo1 = nullptr;
</ins><span class="cx"> // Testing (4c) - value as read after the deref.
</span><del>- EXPECT_EQ(0, static_cast<int>(counter.value()));
</del><ins>+ EXPECT_EQ(false, static_cast<int>(counter.value()));
</ins><span class="cx"> // Testing (2b) - Destruction where the RefCounter::Count has a zero reference count.
</span><span class="cx"> // ... not a lot to test here! - we can at least ensure this code path is run & we don't crash!
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>