<!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>[177295] trunk/Source</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/177295">177295</a></dd>
<dt>Author</dt> <dd>barraclough@apple.com</dd>
<dt>Date</dt> <dd>2014-12-15 11:37:33 -0800 (Mon, 15 Dec 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Change HysteresisActivity to use a lambda
https://bugs.webkit.org/show_bug.cgi?id=139636

Reviewed by Darin Adler.

The current implementation provides notifications via callbacks to a delegate. Using a delegate
with callbacks is limiting a number of ways. The callback names are very ambiguous, the callbacks
must either be on a separate object (more boilerplate), or the callback must be public for
HysteresisActivity to call them, or friends get involved. Without the boilerplate of extra
delegate objects it's hard to scale use of these objects – a single object can't serve as a
delegate for multiple HysteresisActivity members.

Instead, make HysteresisActivity take a lambda to callback on state change. To simplify, changed
HysteresisState to only track Started/Stopped states (removed WillStopPendingTimeout).

Source/WebCore:

* WebCore.exp.in:
    - removed exports of deleted functions.
* page/PageThrottler.cpp:
(WebCore::PageThrottler::PageThrottler):
    - m_hysteresis lambda calls updateUserActivity.
(WebCore::PageThrottler::pageActivityCounterValueDidChange):
    - ASSERT updated due to removal of WillStopPendingTimeout state.
(WebCore::PageThrottler::started): Deleted.
(WebCore::PageThrottler::stopped): Deleted.
    - functionality replaced by lambda.
* page/PageThrottler.h:
    - HysteresisActivity is no longer templated on delegate type, removed function declarations &amp; friend.
* platform/HysteresisActivity.h:
(WebCore::HysteresisActivity::HysteresisActivity):
    - HysteresisActivity takes a lambda, not a delegate.
(WebCore::HysteresisActivity::start):
    - delegate call -&gt; callback.
(WebCore::HysteresisActivity::state):
    - simplified to remove WillStopPendingTimeout.
(WebCore::HysteresisActivity::hysteresisTimerFired):
    - delegate call -&gt; callback.
* platform/UserActivity.cpp:
(WebCore::UserActivity::UserActivity):
    - HysteresisActivity lambda calls hysteresisUpdated.
(WebCore::UserActivity::hysteresisUpdated):
(WebCore::UserActivity::started): Deleted.
(WebCore::UserActivity::stopped): Deleted.
    - started/stopped -&gt; hysteresisUpdated.
* platform/UserActivity.h:
    - started/stopped -&gt; hysteresisUpdated, removed friend.

Source/WebKit2:

* WebProcess/WebCoreSupport/WebSQLiteDatabaseTracker.cpp:
(WebKit::WebSQLiteDatabaseTracker::WebSQLiteDatabaseTracker):
    - HysteresisActivity now takes a lambda, not a delegate.
(WebKit::WebSQLiteDatabaseTracker::hysteresisUpdated):
(WebKit::WebSQLiteDatabaseTracker::started): Deleted.
(WebKit::WebSQLiteDatabaseTracker::stopped): Deleted.
    - started/stopped merged into hysteresisUpdated
* WebProcess/WebCoreSupport/WebSQLiteDatabaseTracker.h:
    - HysteresisActivity is no longer templated on delegate type, changed function declarations.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</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="#trunkSourceWebCoreplatformHysteresisActivityh">trunk/Source/WebCore/platform/HysteresisActivity.h</a></li>
<li><a href="#trunkSourceWebCoreplatformUserActivitycpp">trunk/Source/WebCore/platform/UserActivity.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformUserActivityh">trunk/Source/WebCore/platform/UserActivity.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebSQLiteDatabaseTrackercpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebSQLiteDatabaseTracker.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebSQLiteDatabaseTrackerh">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebSQLiteDatabaseTracker.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (177294 => 177295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-12-15 19:25:23 UTC (rev 177294)
+++ trunk/Source/WebCore/ChangeLog        2014-12-15 19:37:33 UTC (rev 177295)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2014-12-15  Gavin Barraclough  &lt;barraclough@apple.com&gt;
+
+        Change HysteresisActivity to use a lambda
+        https://bugs.webkit.org/show_bug.cgi?id=139636
+
+        Reviewed by Darin Adler.
+
+        The current implementation provides notifications via callbacks to a delegate. Using a delegate
+        with callbacks is limiting a number of ways. The callback names are very ambiguous, the callbacks
+        must either be on a separate object (more boilerplate), or the callback must be public for
+        HysteresisActivity to call them, or friends get involved. Without the boilerplate of extra
+        delegate objects it's hard to scale use of these objects – a single object can't serve as a
+        delegate for multiple HysteresisActivity members.
+
+        Instead, make HysteresisActivity take a lambda to callback on state change. To simplify, changed
+        HysteresisState to only track Started/Stopped states (removed WillStopPendingTimeout).
+
+        * WebCore.exp.in:
+            - removed exports of deleted functions.
+        * page/PageThrottler.cpp:
+        (WebCore::PageThrottler::PageThrottler):
+            - m_hysteresis lambda calls updateUserActivity.
+        (WebCore::PageThrottler::pageActivityCounterValueDidChange):
+            - ASSERT updated due to removal of WillStopPendingTimeout state.
+        (WebCore::PageThrottler::started): Deleted.
+        (WebCore::PageThrottler::stopped): Deleted.
+            - functionality replaced by lambda.
+        * page/PageThrottler.h:
+            - HysteresisActivity is no longer templated on delegate type, removed function declarations &amp; friend.
+        * platform/HysteresisActivity.h:
+        (WebCore::HysteresisActivity::HysteresisActivity):
+            - HysteresisActivity takes a lambda, not a delegate.
+        (WebCore::HysteresisActivity::start):
+            - delegate call -&gt; callback.
+        (WebCore::HysteresisActivity::state):
+            - simplified to remove WillStopPendingTimeout.
+        (WebCore::HysteresisActivity::hysteresisTimerFired):
+            - delegate call -&gt; callback.
+        * platform/UserActivity.cpp:
+        (WebCore::UserActivity::UserActivity):
+            - HysteresisActivity lambda calls hysteresisUpdated.
+        (WebCore::UserActivity::hysteresisUpdated):
+        (WebCore::UserActivity::started): Deleted.
+        (WebCore::UserActivity::stopped): Deleted.
+            - started/stopped -&gt; hysteresisUpdated.
+        * platform/UserActivity.h:
+            - started/stopped -&gt; hysteresisUpdated, removed friend.
+
</ins><span class="cx"> 2014-12-15  Antti Koivisto  &lt;antti@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         WebKit level persistent caching
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (177294 => 177295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-12-15 19:25:23 UTC (rev 177294)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-12-15 19:37:33 UTC (rev 177295)
</span><span class="lines">@@ -270,7 +270,6 @@
</span><span class="cx"> __ZN7WebCore12TextIteratorC1EPKNS_5RangeEt
</span><span class="cx"> __ZN7WebCore12TextIteratorD1Ev
</span><span class="cx"> __ZN7WebCore12UTF8EncodingEv
</span><del>-__ZN7WebCore12UserActivity7startedEv
</del><span class="cx"> __ZN7WebCore12UserActivityC1EPKc
</span><span class="cx"> __ZN7WebCore12WorkerThread17workerThreadCountEv
</span><span class="cx"> __ZN7WebCore12blobRegistryEv
</span><span class="lines">@@ -329,7 +328,6 @@
</span><span class="cx"> __ZN7WebCore13NodeTraversal13deepLastChildEPNS_4NodeE
</span><span class="cx"> __ZN7WebCore13NodeTraversal19nextAncestorSiblingEPKNS_4NodeE
</span><span class="cx"> __ZN7WebCore13NodeTraversal19nextAncestorSiblingEPKNS_4NodeES3_
</span><del>-__ZN7WebCore13PageThrottler7startedEv
</del><span class="cx"> __ZN7WebCore13ResourceErrorC1EP7NSError
</span><span class="cx"> __ZN7WebCore13ResourceErrorC1EP9__CFError
</span><span class="cx"> __ZN7WebCore13SQLResultDoneE
</span></span></pre></div>
<a id="trunkSourceWebCorepagePageThrottlercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PageThrottler.cpp (177294 => 177295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PageThrottler.cpp        2014-12-15 19:25:23 UTC (rev 177294)
+++ trunk/Source/WebCore/page/PageThrottler.cpp        2014-12-15 19:37:33 UTC (rev 177295)
</span><span class="lines">@@ -30,7 +30,7 @@
</span><span class="cx"> 
</span><span class="cx"> PageThrottler::PageThrottler(ViewState::Flags viewState)
</span><span class="cx">     : m_viewState(viewState)
</span><del>-    , m_hysteresis(*this)
</del><ins>+    , m_hysteresis([this](HysteresisState) { updateUserActivity(); })
</ins><span class="cx">     , m_pageActivityCounter([this]() { pageActivityCounterValueDidChange(); })
</span><span class="cx"> {
</span><span class="cx">     updateUserActivity();
</span><span class="lines">@@ -60,8 +60,8 @@
</span><span class="cx">     else
</span><span class="cx">         m_hysteresis.stop();
</span><span class="cx"> 
</span><del>-    // If the counter is nonzero, state must be Started; if the counter is zero, state may be Waiting or Stopped.
-    ASSERT(!!m_pageActivityCounter.value() == (m_hysteresis.state() == HysteresisState::Started));
</del><ins>+    // If the counter is nonzero, state cannot be Stopped.
+    ASSERT(!(m_pageActivityCounter.value() &amp;&amp; m_hysteresis.state() == HysteresisState::Stopped));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void PageThrottler::updateUserActivity()
</span><span class="lines">@@ -85,14 +85,4 @@
</span><span class="cx">         updateUserActivity();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void PageThrottler::started()
-{
-    updateUserActivity();
</del><span class="cx"> }
</span><del>-
-void PageThrottler::stopped()
-{
-    updateUserActivity();
-}
-
-}
</del></span></pre></div>
<a id="trunkSourceWebCorepagePageThrottlerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/PageThrottler.h (177294 => 177295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/PageThrottler.h        2014-12-15 19:25:23 UTC (rev 177294)
+++ trunk/Source/WebCore/page/PageThrottler.h        2014-12-15 19:37:33 UTC (rev 177295)
</span><span class="lines">@@ -51,15 +51,10 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     void pageActivityCounterValueDidChange();
</span><del>-
</del><span class="cx">     void updateUserActivity();
</span><span class="cx"> 
</span><del>-    friend class HysteresisActivity&lt;PageThrottler&gt;;
-    WEBCORE_EXPORT void started();
-    void stopped();
-
</del><span class="cx">     ViewState::Flags m_viewState;
</span><del>-    HysteresisActivity&lt;PageThrottler&gt; m_hysteresis;
</del><ins>+    HysteresisActivity m_hysteresis;
</ins><span class="cx">     std::unique_ptr&lt;UserActivity::Impl&gt; m_activity;
</span><span class="cx">     RefCounter m_pageActivityCounter;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformHysteresisActivityh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/HysteresisActivity.h (177294 => 177295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/HysteresisActivity.h        2014-12-15 19:25:23 UTC (rev 177294)
+++ trunk/Source/WebCore/platform/HysteresisActivity.h        2014-12-15 19:37:33 UTC (rev 177295)
</span><span class="lines">@@ -34,18 +34,16 @@
</span><span class="cx"> 
</span><span class="cx"> enum class HysteresisState {
</span><span class="cx">     Started,
</span><del>-    WillStopPendingTimeout,
</del><span class="cx">     Stopped
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-template&lt;typename Delegate&gt;
</del><span class="cx"> class HysteresisActivity {
</span><span class="cx"> public:
</span><del>-    explicit HysteresisActivity(Delegate&amp; delegate, double hysteresisSeconds = DefaultHysteresisSeconds)
-        : m_delegate(delegate)
</del><ins>+    explicit HysteresisActivity(std::function&lt;void(HysteresisState)&gt; callback = [](HysteresisState) { }, double hysteresisSeconds = DefaultHysteresisSeconds)
+        : m_callback(callback)
</ins><span class="cx">         , m_hysteresisSeconds(hysteresisSeconds)
</span><span class="cx">         , m_active(false)
</span><del>-        , m_timer(*this, &amp;HysteresisActivity&lt;Delegate&gt;::hysteresisTimerFired)
</del><ins>+        , m_timer(*this, &amp;HysteresisActivity::hysteresisTimerFired)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -58,7 +56,7 @@
</span><span class="cx">         if (m_timer.isActive())
</span><span class="cx">             m_timer.stop();
</span><span class="cx">         else
</span><del>-            m_delegate.started();
</del><ins>+            m_callback(HysteresisState::Started);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     void stop()
</span><span class="lines">@@ -80,21 +78,17 @@
</span><span class="cx"> 
</span><span class="cx">     HysteresisState state() const
</span><span class="cx">     {
</span><del>-        if (m_active)
-            return HysteresisState::Started;
-        if (m_timer.isActive())
-            return HysteresisState::WillStopPendingTimeout;
-        return HysteresisState::Stopped;
</del><ins>+        return m_active || m_timer.isActive() ? HysteresisState::Started : HysteresisState::Stopped;
</ins><span class="cx">     }
</span><span class="cx">     
</span><span class="cx"> private:
</span><span class="cx">     void hysteresisTimerFired()
</span><span class="cx">     {
</span><del>-        m_delegate.stopped();
</del><span class="cx">         m_timer.stop();
</span><ins>+        m_callback(HysteresisState::Stopped);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    Delegate&amp; m_delegate;
</del><ins>+    std::function&lt;void(HysteresisState)&gt; m_callback;
</ins><span class="cx">     double m_hysteresisSeconds;
</span><span class="cx">     bool m_active;
</span><span class="cx">     Timer m_timer;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformUserActivitycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/UserActivity.cpp (177294 => 177295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/UserActivity.cpp        2014-12-15 19:25:23 UTC (rev 177294)
+++ trunk/Source/WebCore/platform/UserActivity.cpp        2014-12-15 19:37:33 UTC (rev 177295)
</span><span class="lines">@@ -45,19 +45,17 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> UserActivity::UserActivity(const char* description)
</span><del>-    : HysteresisActivity&lt;UserActivity&gt;(*this)
</del><ins>+    : HysteresisActivity([this](HysteresisState state) { hysteresisUpdated(state); })
</ins><span class="cx">     , m_impl(description)
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void UserActivity::started()
</del><ins>+void UserActivity::hysteresisUpdated(HysteresisState state)
</ins><span class="cx"> {
</span><del>-    m_impl.beginActivity();
</del><ins>+    if (state == HysteresisState::Started)
+        m_impl.beginActivity();
+    else
+        m_impl.endActivity();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void UserActivity::stopped()
-{
-    m_impl.endActivity();
-}
-
</del><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformUserActivityh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/UserActivity.h (177294 => 177295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/UserActivity.h        2014-12-15 19:25:23 UTC (rev 177294)
+++ trunk/Source/WebCore/platform/UserActivity.h        2014-12-15 19:37:33 UTC (rev 177295)
</span><span class="lines">@@ -39,7 +39,7 @@
</span><span class="cx"> // The UserActivity type is used to indicate to the operating system that
</span><span class="cx"> // a user initiated or visible action is taking place, and as such that
</span><span class="cx"> // resources should be allocated to the process accordingly.
</span><del>-class UserActivity : public HysteresisActivity&lt;UserActivity&gt; {
</del><ins>+class UserActivity : public HysteresisActivity {
</ins><span class="cx"> public:
</span><span class="cx">     class Impl {
</span><span class="cx">     public:
</span><span class="lines">@@ -58,11 +58,8 @@
</span><span class="cx">     WEBCORE_EXPORT explicit UserActivity(const char* description);
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    friend class HysteresisActivity&lt;UserActivity&gt;;
</del><ins>+    void hysteresisUpdated(HysteresisState);
</ins><span class="cx"> 
</span><del>-    WEBCORE_EXPORT void started();
-    void stopped();
-
</del><span class="cx">     Impl m_impl;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (177294 => 177295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-12-15 19:25:23 UTC (rev 177294)
+++ trunk/Source/WebKit2/ChangeLog        2014-12-15 19:37:33 UTC (rev 177295)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2014-12-15  Gavin Barraclough  &lt;barraclough@apple.com&gt;
+
+        Change HysteresisActivity to use a lambda
+        https://bugs.webkit.org/show_bug.cgi?id=139636
+
+        Reviewed by Darin Adler.
+
+        The current implementation provides notifications via callbacks to a delegate. Using a delegate
+        with callbacks is limiting a number of ways. The callback names are very ambiguous, the callbacks
+        must either be on a separate object (more boilerplate), or the callback must be public for
+        HysteresisActivity to call them, or friends get involved. Without the boilerplate of extra
+        delegate objects it's hard to scale use of these objects – a single object can't serve as a
+        delegate for multiple HysteresisActivity members.
+
+        Instead, make HysteresisActivity take a lambda to callback on state change. To simplify, changed
+        HysteresisState to only track Started/Stopped states (removed WillStopPendingTimeout).
+
+        * WebProcess/WebCoreSupport/WebSQLiteDatabaseTracker.cpp:
+        (WebKit::WebSQLiteDatabaseTracker::WebSQLiteDatabaseTracker):
+            - HysteresisActivity now takes a lambda, not a delegate.
+        (WebKit::WebSQLiteDatabaseTracker::hysteresisUpdated):
+        (WebKit::WebSQLiteDatabaseTracker::started): Deleted.
+        (WebKit::WebSQLiteDatabaseTracker::stopped): Deleted.
+            - started/stopped merged into hysteresisUpdated
+        * WebProcess/WebCoreSupport/WebSQLiteDatabaseTracker.h:
+            - HysteresisActivity is no longer templated on delegate type, changed function declarations.
+
</ins><span class="cx"> 2014-12-15  Antti Koivisto  &lt;antti@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         WebKit level persistent caching
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebSQLiteDatabaseTrackercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebSQLiteDatabaseTracker.cpp (177294 => 177295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebSQLiteDatabaseTracker.cpp        2014-12-15 19:25:23 UTC (rev 177294)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebSQLiteDatabaseTracker.cpp        2014-12-15 19:37:33 UTC (rev 177295)
</span><span class="lines">@@ -44,7 +44,7 @@
</span><span class="cx"> 
</span><span class="cx"> WebSQLiteDatabaseTracker::WebSQLiteDatabaseTracker(WebProcess* process)
</span><span class="cx">     : m_process(process)
</span><del>-    , m_hysteresis(*this)
</del><ins>+    , m_hysteresis([this](HysteresisState state) { hysteresisUpdated(state); })
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -67,16 +67,11 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebSQLiteDatabaseTracker::started()
</del><ins>+void WebSQLiteDatabaseTracker::hysteresisUpdated(HysteresisState state)
</ins><span class="cx"> {
</span><del>-    m_process-&gt;parentProcessConnection()-&gt;send(Messages::WebProcessProxy::SetIsHoldingLockedFiles(true), 0);
</del><ins>+    m_process-&gt;parentProcessConnection()-&gt;send(Messages::WebProcessProxy::SetIsHoldingLockedFiles(state == HysteresisState::Started), 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebSQLiteDatabaseTracker::stopped()
-{
-    m_process-&gt;parentProcessConnection()-&gt;send(Messages::WebProcessProxy::SetIsHoldingLockedFiles(false), 0);
-}
-
</del><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(SQL_DATABASE)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebSQLiteDatabaseTrackerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebSQLiteDatabaseTracker.h (177294 => 177295)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebSQLiteDatabaseTracker.h        2014-12-15 19:25:23 UTC (rev 177294)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebSQLiteDatabaseTracker.h        2014-12-15 19:37:33 UTC (rev 177295)
</span><span class="lines">@@ -52,13 +52,10 @@
</span><span class="cx">     virtual void didFinishLastTransaction() override;
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    // WebCore::HysteresisActivity
-    friend class WebCore::HysteresisActivity&lt;WebSQLiteDatabaseTracker&gt;;
-    void started();
-    void stopped();
</del><ins>+    void hysteresisUpdated(WebCore::HysteresisState);
</ins><span class="cx"> 
</span><span class="cx">     WebProcess* m_process;
</span><del>-    WebCore::HysteresisActivity&lt;WebSQLiteDatabaseTracker&gt; m_hysteresis;
</del><ins>+    WebCore::HysteresisActivity m_hysteresis;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre>
</div>
</div>

</body>
</html>