<!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&lt;RefCounter::Count&gt;.
This means there is no compile time type checking to prevent mistakes. Update the count()
method to token&lt;&gt;(), templated on type used to identify the token being returned.
Calls to token&lt;T&gt;() will return a result of type RefCounter::Token&lt;T&gt;.

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-&gt;1 is often interesting where 2-&gt;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() -&gt; token&lt;&gt;().
* 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 -&gt; updateProcessSuppressionDisabled.
* UIProcess/Plugins/PluginProcessManager.h:
(WebKit::PluginProcessManager::processSuppressionDisabledForPageCount): Deleted.
(WebKit::PluginProcessManager::processSuppressionDisabledToken):
    - processSuppressionDisabledForPageCount -&gt; processSuppressionDisabledToken.
(WebKit::PluginProcessManager::processSuppressionEnabled): Deleted.
(WebKit::PluginProcessManager::processSuppressionDisabled):
    - processSuppressionEnabled -&gt; processSuppressionDisabled.
* UIProcess/Plugins/PluginProcessProxy.cpp:
(WebKit::PluginProcessProxy::didFinishLaunching):
    - processSuppressionEnabled -&gt; processSuppressionDisabled.
* UIProcess/Plugins/mac/PluginProcessManagerMac.mm:
(WebKit::PluginProcessManager::updateProcessSuppressionState): Deleted.
(WebKit::PluginProcessManager::updateProcessSuppressionDisabled):
    - updateProcessSuppressionState -&gt; 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() -&gt; token&lt;&gt;(), changed return type.
* UIProcess/WebPageProxy.h:
    - changed types of token members.
* UIProcess/mac/WebContextMac.mm:
(WebKit::WebContext::updateProcessSuppressionState):
    renamed m_pluginProcessManagerProcessSuppressionDisabledCount -&gt; 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&lt;T&gt;::Token):
(WTF::=):
    - Tokens can be copied &amp; assigned.
(WTF::RefCounter::count): Deleted.
    - renamed to token&lt;&gt;().

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  &lt;barraclough@apple.com&gt;
+
+        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&lt;RefCounter::Count&gt;.
+        This means there is no compile time type checking to prevent mistakes. Update the count()
+        method to token&lt;&gt;(), templated on type used to identify the token being returned.
+        Calls to token&lt;T&gt;() will return a result of type RefCounter::Token&lt;T&gt;.
+
+        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-&gt;1 is often interesting where 2-&gt;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&lt;T&gt;::Token):
+        (WTF::=):
+            - Tokens can be copied &amp; assigned.
+        (WTF::RefCounter::count): Deleted.
+            - renamed to token&lt;&gt;().
+
</ins><span class="cx"> 2014-12-18  Anders Carlsson  &lt;andersca@apple.com&gt;
</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-&gt;m_valueDidChange();
</del><ins>+    
+    if (valueWasZero &amp;&amp; m_refCounter)
+        m_refCounter-&gt;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-&gt;m_valueDidChange();
-    else if (!m_value)
</del><ins>+        m_refCounter-&gt;m_valueDidChange(false);
+    else
</ins><span class="cx">         delete this;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-RefCounter::RefCounter(std::function&lt;void()&gt; valueDidChange)
</del><ins>+RefCounter::RefCounter(std::function&lt;void(bool)&gt; 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&lt;void()&gt; = []() { });
</del><ins>+public:
+    template&lt;typename T&gt;
+    class Token  {
+    public:
+        Token() { }
+        Token(std::nullptr_t) { }
+        inline Token(const Token&lt;T&gt;&amp; token);
+        inline Token(Token&lt;T&gt;&amp;&amp; token);
+
+        inline Token&lt;T&gt;&amp; operator=(std::nullptr_t);
+        inline Token&lt;T&gt;&amp; operator=(const Token&lt;T&gt;&amp; o);
+        inline Token&lt;T&gt;&amp; operator=(Token&lt;T&gt;&amp;&amp; o);
+
+        bool operator!() const { return !m_ptr; }
+
+    private:
+        friend class RefCounter;
+        inline Token(Count* count);
+
+        RefPtr&lt;Count&gt; m_ptr;
+    };
+
+    WTF_EXPORT_PRIVATE RefCounter(std::function&lt;void(bool)&gt; = [](bool) { });
</ins><span class="cx">     WTF_EXPORT_PRIVATE ~RefCounter();
</span><span class="cx"> 
</span><del>-    Ref&lt;Count&gt; count() const
</del><ins>+    template&lt;typename T&gt;
+    Token&lt;T&gt; token() const
</ins><span class="cx">     {
</span><del>-        return *m_count;
</del><ins>+        return Token&lt;T&gt;(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-&gt;m_value;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    std::function&lt;void()&gt; m_valueDidChange;
</del><ins>+    std::function&lt;void(bool)&gt; m_valueDidChange;
</ins><span class="cx">     Count* m_count;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+template&lt;class T&gt;
+inline RefCounter::Token&lt;T&gt;::Token(Count* count)
+    : m_ptr(count)
+{
+}
+
+template&lt;class T&gt;
+inline RefCounter::Token&lt;T&gt;::Token(const RefCounter::Token&lt;T&gt;::Token&lt;T&gt;&amp; token)
+    : m_ptr(token.m_ptr)
+{
+}
+
+template&lt;class T&gt;
+inline RefCounter::Token&lt;T&gt;::Token(RefCounter::Token&lt;T&gt;::Token&lt;T&gt;&amp;&amp; token)
+    : m_ptr(token.m_ptr)
+{
+}
+
+template&lt;class T&gt;
+inline RefCounter::Token&lt;T&gt;&amp; RefCounter::Token&lt;T&gt;::operator=(std::nullptr_t)
+{
+    m_ptr = nullptr;
+    return *this;
+}
+
+template&lt;class T&gt;
+inline RefCounter::Token&lt;T&gt;&amp; RefCounter::Token&lt;T&gt;::operator=(const RefCounter::Token&lt;T&gt;&amp; o)
+{
+    m_ptr = o.m_ptr;
+    return *this;
+}
+
+template&lt;class T&gt;
+inline RefCounter::Token&lt;T&gt;&amp; RefCounter::Token&lt;T&gt;::operator=(RefCounter::Token&lt;T&gt;&amp;&amp; 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  &lt;barraclough@apple.com&gt;
+
+        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&lt;RefCounter::Count&gt;.
+        This means there is no compile time type checking to prevent mistakes. Update the count()
+        method to token&lt;&gt;(), templated on type used to identify the token being returned.
+        Calls to token&lt;T&gt;() will return a result of type RefCounter::Token&lt;T&gt;.
+
+        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-&gt;1 is often interesting where 2-&gt;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() -&gt; token&lt;&gt;().
+        * page/PageThrottler.h:
+            - specify tpoken type for PageActivityAssertionToken.
+
</ins><span class="cx"> 2014-12-18  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
</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&lt;PageActivityAssertionTokenType&gt;();
</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&lt;PageActivityAssertionTokenType&gt;();
</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&lt;RefCounter::Count&gt; PageActivityAssertionToken;
</del><ins>+enum PageActivityAssertionTokenType { };
+typedef RefCounter::Token&lt;PageActivityAssertionTokenType&gt; 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  &lt;barraclough@apple.com&gt;
+
+        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&lt;RefCounter::Count&gt;.
+        This means there is no compile time type checking to prevent mistakes. Update the count()
+        method to token&lt;&gt;(), templated on type used to identify the token being returned.
+        Calls to token&lt;T&gt;() will return a result of type RefCounter::Token&lt;T&gt;.
+
+        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-&gt;1 is often interesting where 2-&gt;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 -&gt; updateProcessSuppressionDisabled.
+        * UIProcess/Plugins/PluginProcessManager.h:
+        (WebKit::PluginProcessManager::processSuppressionDisabledForPageCount): Deleted.
+        (WebKit::PluginProcessManager::processSuppressionDisabledToken):
+            - processSuppressionDisabledForPageCount -&gt; processSuppressionDisabledToken.
+        (WebKit::PluginProcessManager::processSuppressionEnabled): Deleted.
+        (WebKit::PluginProcessManager::processSuppressionDisabled):
+            - processSuppressionEnabled -&gt; processSuppressionDisabled.
+        * UIProcess/Plugins/PluginProcessProxy.cpp:
+        (WebKit::PluginProcessProxy::didFinishLaunching):
+            - processSuppressionEnabled -&gt; processSuppressionDisabled.
+        * UIProcess/Plugins/mac/PluginProcessManagerMac.mm:
+        (WebKit::PluginProcessManager::updateProcessSuppressionState): Deleted.
+        (WebKit::PluginProcessManager::updateProcessSuppressionDisabled):
+            - updateProcessSuppressionState -&gt; 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() -&gt; token&lt;&gt;(), changed return type.
+        * UIProcess/WebPageProxy.h:
+            - changed types of token members.
+        * UIProcess/mac/WebContextMac.mm:
+        (WebKit::WebContext::updateProcessSuppressionState):
+            renamed m_pluginProcessManagerProcessSuppressionDisabledCount -&gt; m_pluginProcessManagerProcessSuppressionDisabledToken.
+
</ins><span class="cx"> 2014-12-18  Timothy Horton  &lt;timothy_horton@apple.com&gt;
</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 &quot;WKViewPrivate.h&quot;
</span><span class="cx"> 
</span><ins>+#import &quot;APIObject.h&quot;
</ins><span class="cx"> #import &quot;PluginComplexTextInputState.h&quot;
</span><span class="cx"> #import &quot;SameDocumentNavigationType.h&quot;
</span><span class="cx"> #import &quot;WebFindOptions.h&quot;
</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 &quot;PluginModuleInfo.h&quot;
</span><span class="cx"> #include &quot;PluginProcess.h&quot;
</span><span class="cx"> #include &quot;PluginProcessAttributes.h&quot;
</span><ins>+#include &quot;ProcessThrottler.h&quot;
</ins><span class="cx"> #include &quot;WebProcessProxyMessages.h&quot;
</span><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><span class="cx"> #include &lt;wtf/HashSet.h&gt;
</span><span class="lines">@@ -65,9 +66,9 @@
</span><span class="cx">     void clearSiteData(const PluginModuleInfo&amp;, WebPluginSiteDataManager*, const Vector&lt;String&gt;&amp; 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&lt;RefCounter::Count&gt; 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&lt;RefCounter::Count&gt; PluginProcessManager::processSuppressionDisabledForPageCount()
</del><ins>+inline ProcessSuppressionDisabledToken PluginProcessManager::processSuppressionDisabledToken()
</ins><span class="cx"> {
</span><del>-    return m_processSuppressionDisabledForPageCounter.count();
</del><ins>+    return m_processSuppressionDisabledForPageCounter.token&lt;ProcessSuppressionDisabledTokenType&gt;();
</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&amp; pluginProcess : m_pluginProcesses)
</span><del>-        pluginProcess-&gt;setProcessSuppressionEnabled(processSuppressionEnabled);
</del><ins>+        pluginProcess-&gt;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 &quot;ProcessAssertion.h&quot;
</span><span class="cx"> 
</span><ins>+#include &lt;WTF/RefCounter.h&gt;
</ins><span class="cx"> #include &lt;wtf/RunLoop.h&gt;
</span><span class="cx"> #include &lt;wtf/WeakPtr.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx">     
</span><ins>+enum UserObservablePageTokenType { };
+typedef RefCounter::Token&lt;UserObservablePageTokenType&gt; UserObservablePageToken;
+enum ProcessSuppressionDisabledTokenType { };
+typedef RefCounter::Token&lt;ProcessSuppressionDisabledTokenType&gt; 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 &quot;PlugInAutoStartProvider.h&quot;
</span><span class="cx"> #include &quot;PluginInfoStore.h&quot;
</span><span class="cx"> #include &quot;ProcessModel.h&quot;
</span><ins>+#include &quot;ProcessThrottler.h&quot;
</ins><span class="cx"> #include &quot;StatisticsRequest.h&quot;
</span><span class="cx"> #include &quot;StorageManager.h&quot;
</span><span class="cx"> #include &quot;VisitedLinkProvider.h&quot;
</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&lt;RefCounter::Count&gt; userObservablePageCount()
</del><ins>+    UserObservablePageToken userObservablePageCount()
</ins><span class="cx">     {
</span><del>-        return m_userObservablePageCounter.count();
</del><ins>+        return m_userObservablePageCounter.token&lt;UserObservablePageTokenType&gt;();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    PassRefPtr&lt;RefCounter::Count&gt; processSuppressionDisabledForPageCount()
</del><ins>+    ProcessSuppressionDisabledToken processSuppressionDisabledForPageCount()
</ins><span class="cx">     {
</span><del>-        return m_processSuppressionDisabledForPageCounter.count();
</del><ins>+        return m_processSuppressionDisabledForPageCounter.token&lt;ProcessSuppressionDisabledTokenType&gt;();
</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&lt;NSMutableDictionary&gt; m_bundleParameters;
</span><del>-    RefPtr&lt;RefCounter::Count&gt; 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 &quot;NotificationPermissionRequestManagerProxy.h&quot;
</span><span class="cx"> #include &quot;PageLoadState.h&quot;
</span><span class="cx"> #include &quot;PlatformProcessIdentifier.h&quot;
</span><ins>+#include &quot;ProcessThrottler.h&quot;
</ins><span class="cx"> #include &quot;SandboxExtension.h&quot;
</span><span class="cx"> #include &quot;ShareableBitmap.h&quot;
</span><span class="cx"> #include &quot;UserMediaPermissionRequestManagerProxy.h&quot;
</span><span class="lines">@@ -1583,8 +1584,8 @@
</span><span class="cx">     HashMap&lt;String, String&gt; m_temporaryPDFFiles;
</span><span class="cx">     std::unique_ptr&lt;WebCore::RunLoopObserver&gt; m_viewStateChangeDispatcher;
</span><span class="cx"> #endif
</span><del>-    RefPtr&lt;RefCounter::Count&gt; m_pageIsUserObservableCount;
-    RefPtr&lt;RefCounter::Count&gt; 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  &lt;barraclough@apple.com&gt;
+
+        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&lt;RefCounter::Count&gt;.
+        This means there is no compile time type checking to prevent mistakes. Update the count()
+        method to token&lt;&gt;(), templated on type used to identify the token being returned.
+        Calls to token&lt;T&gt;() will return a result of type RefCounter::Token&lt;T&gt;.
+
+        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-&gt;1 is often interesting where 2-&gt;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  &lt;ap@apple.com&gt;
</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&lt;CounterType&gt; 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&lt;void()&gt;);
</span><span class="cx">     // 2) ~RefCounter();
</span><del>-    // 3) Ref&lt;Count&gt; count() const;
</del><ins>+    // 3) Ref&lt;Count&gt; 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&lt;RefCounter::Count&gt; 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([&amp;]() {
</del><ins>+        RefCounter counter([&amp;](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-&gt;value());
</ins><span class="cx">             // return the value of the counter in the callback.
</span><del>-            callbackValue = counterPtr-&gt;value();
</del><ins>+            callbackValue = value;
</ins><span class="cx">         });
</span><span class="cx">         counterPtr = &amp;counter;
</span><span class="cx">         // Testing (4a) - after construction value() is 0.
</span><del>-        EXPECT_EQ(0, static_cast&lt;int&gt;(counter.value()));
</del><ins>+        EXPECT_EQ(false, static_cast&lt;int&gt;(counter.value()));
</ins><span class="cx"> 
</span><span class="cx">         // Testing (3a) - ref with callback from 0 -&gt; 1.
</span><span class="cx">         callbackValue = CallbackExpected;
</span><del>-        RefPtr&lt;RefCounter::Count&gt; incTo1(counter.count());
</del><ins>+        TokenType incTo1(counter.token&lt;CounterType&gt;());
</ins><span class="cx">         // Testing (4b) &amp; (4c) - values within &amp; after callback.
</span><del>-        EXPECT_EQ(1, callbackValue);
-        EXPECT_EQ(1, static_cast&lt;int&gt;(counter.value()));
</del><ins>+        EXPECT_EQ(true, callbackValue);
+        EXPECT_EQ(true, static_cast&lt;int&gt;(counter.value()));
</ins><span class="cx"> 
</span><span class="cx">         // Testing (3b) - ref with callback from 1 -&gt; 2.
</span><del>-        callbackValue = CallbackExpected;
-        RefPtr&lt;RefCounter::Count&gt; incTo2(incTo1);
</del><ins>+        TokenType incTo2(incTo1);
</ins><span class="cx">         // Testing (4b) &amp; (4c) - values within &amp; after callback.
</span><del>-        EXPECT_EQ(2, callbackValue);
-        EXPECT_EQ(2, static_cast&lt;int&gt;(counter.value()));
</del><ins>+        EXPECT_EQ(true, static_cast&lt;int&gt;(counter.value()));
</ins><span class="cx"> 
</span><span class="cx">         // Testing (3c) - deref with callback from &gt;1 -&gt; 1.
</span><del>-        callbackValue = CallbackExpected;
-        incTo1.clear();
</del><ins>+        incTo1 = nullptr;
</ins><span class="cx">         // Testing (4b) &amp; (4c) - values within &amp; after callback.
</span><del>-        EXPECT_EQ(1, callbackValue);
-        EXPECT_EQ(1, static_cast&lt;int&gt;(counter.value()));
</del><ins>+        EXPECT_EQ(true, static_cast&lt;int&gt;(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&lt;RefCounter::Count&gt; incTo2Again(counter.count());
</del><ins>+            TokenType incTo2Again(counter.token&lt;CounterType&gt;());
</ins><span class="cx">             // Testing (4b) &amp; (4c) - values within &amp; after callback.
</span><del>-            EXPECT_EQ(2, callbackValue);
-            EXPECT_EQ(2, static_cast&lt;int&gt;(counter.value()));
</del><ins>+            EXPECT_EQ(true, static_cast&lt;int&gt;(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&lt;int&gt;(counter.value()));
</del><ins>+        EXPECT_EQ(true, static_cast&lt;int&gt;(counter.value()));
</ins><span class="cx">         // Testing (4b) &amp; (4c) - values within &amp; after callback.
</span><span class="cx"> 
</span><span class="cx">         // Testing (3d) - deref with callback from 1 -&gt; 0.
</span><span class="cx">         callbackValue = CallbackExpected;
</span><del>-        incTo2.clear();
</del><ins>+        incTo2 = nullptr;
</ins><span class="cx">         // Testing (4b) &amp; (4c) - values within &amp; after callback.
</span><del>-        EXPECT_EQ(0, callbackValue);
-        EXPECT_EQ(0, static_cast&lt;int&gt;(counter.value()));
</del><ins>+        EXPECT_EQ(false, callbackValue);
+        EXPECT_EQ(false, static_cast&lt;int&gt;(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&lt;int&gt;(counter.value()));
</del><ins>+        incTo1Again = counter.token&lt;CounterType&gt;();
+        EXPECT_EQ(true, callbackValue);
+        EXPECT_EQ(true, static_cast&lt;int&gt;(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 -&gt; &gt;1 AFTER RefCounter has been destroyed.
</span><del>-    RefPtr&lt;RefCounter::Count&gt; incTo2Again = incTo1Again;
</del><ins>+    TokenType incTo2Again = incTo1Again;
</ins><span class="cx">     // Testing (3f) - deref with callback from &gt;1 -&gt; 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 -&gt; 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&lt;int&gt;(counter.value()));
</del><ins>+    EXPECT_EQ(false, static_cast&lt;int&gt;(counter.value()));
</ins><span class="cx">     // Testing (3h) - ref without callback
</span><del>-    RefPtr&lt;RefCounter::Count&gt; incTo1(counter.count());
</del><ins>+    TokenType incTo1(counter.token&lt;CounterType&gt;());
</ins><span class="cx">     // Testing (4c) - value as read after the ref.
</span><del>-    EXPECT_EQ(1, static_cast&lt;int&gt;(counter.value()));
</del><ins>+    EXPECT_EQ(true, static_cast&lt;int&gt;(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&lt;int&gt;(counter.value()));
</del><ins>+    EXPECT_EQ(false, static_cast&lt;int&gt;(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 &amp; we don't crash!
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>