<!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>[208874] 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/208874">208874</a></dd>
<dt>Author</dt> <dd>wilander@apple.com</dd>
<dt>Date</dt> <dd>2016-11-17 19:32:53 -0800 (Thu, 17 Nov 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Resource load statistics: Cover further data records, count removed data records, and only fire handler when needed
https://bugs.webkit.org/show_bug.cgi?id=164659

Reviewed by Andy Estes.

Source/WebCore:

No new tests. This feature is behind a flag and off by default. Tests require real domain names.

* loader/ResourceLoadObserver.cpp:
(WebCore::ResourceLoadObserver::logFrameNavigation):
(WebCore::ResourceLoadObserver::logSubresourceLoading):
(WebCore::ResourceLoadObserver::logWebSocketLoading):
    All three functions are now more conservative in calls to
    m_store-&gt;fireDataModificationHandler(). They only fire when an important statistic has
    changed or data records have previously been removed for the domain in question.
* loader/ResourceLoadStatistics.cpp:
(WebCore::ResourceLoadStatistics::encode):
    Added the dataRecordsRemoved statistic.
(WebCore::ResourceLoadStatistics::decode):
    Now takes a version parameter to control which keys to expect.
    Added the dataRecordsRemoved statistic.
(WebCore::appendHashCountedSet):
    Removed stray linefeed.
(WebCore::ResourceLoadStatistics::toString):
    Added the dataRecordsRemoved statistic.
(WebCore::ResourceLoadStatistics::merge):
    Added the dataRecordsRemoved statistic.
* loader/ResourceLoadStatistics.h:
    Added the dataRecordsRemoved statistic.
* loader/ResourceLoadStatisticsStore.cpp:
(WebCore::ResourceLoadStatisticsStore::createEncoderFromData):
    Now encodes a version number for the statistics model.
(WebCore::ResourceLoadStatisticsStore::readDataFromDecoder):
    Now tries to decode a version number and passes it on to statistics decoding.
(WebCore::ResourceLoadStatisticsStore::processStatistics):
    No longer gates processing on the number of data captured.
(WebCore::ResourceLoadStatisticsStore::updateStatisticsForRemovedDataRecords):
    Update function for the new dataRecordsRemoved statistic.
(WebCore::ResourceLoadStatisticsStore::hasEnoughDataForStatisticsProcessing): Deleted.
    No longer needed since we no longer gate processing on the number of data captured.
* loader/ResourceLoadStatisticsStore.h:

Source/WebKit2:

* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::removeDataRecords):
    Consistent naming with 'remove' rather than 'delete'.
    Now removes localStorage, IndexDB, disk cache, and memory cache too.
    Updates statistics with number of times it has removed data records.
(WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated):
    No longer checks whether it has enough data since the classification rules
    are absolute, not relative.
(WebKit::WebResourceLoadStatisticsStore::clearDataRecords): Deleted.
* UIProcess/WebResourceLoadStatisticsStore.h:
    Consistent naming with 'remove' rather than 'delete'.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoadObservercpp">trunk/Source/WebCore/loader/ResourceLoadObserver.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoadStatisticscpp">trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoadStatisticsh">trunk/Source/WebCore/loader/ResourceLoadStatistics.h</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoadStatisticsStorecpp">trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderResourceLoadStatisticsStoreh">trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebResourceLoadStatisticsStorecpp">trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebResourceLoadStatisticsStoreh">trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (208873 => 208874)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-11-18 02:41:35 UTC (rev 208873)
+++ trunk/Source/WebCore/ChangeLog        2016-11-18 03:32:53 UTC (rev 208874)
</span><span class="lines">@@ -1,3 +1,46 @@
</span><ins>+2016-11-17  John Wilander  &lt;wilander@apple.com&gt;
+
+        Resource load statistics: Cover further data records, count removed data records, and only fire handler when needed
+        https://bugs.webkit.org/show_bug.cgi?id=164659
+
+        Reviewed by Andy Estes.
+
+        No new tests. This feature is behind a flag and off by default. Tests require real domain names.
+
+        * loader/ResourceLoadObserver.cpp:
+        (WebCore::ResourceLoadObserver::logFrameNavigation):
+        (WebCore::ResourceLoadObserver::logSubresourceLoading):
+        (WebCore::ResourceLoadObserver::logWebSocketLoading):
+            All three functions are now more conservative in calls to
+            m_store-&gt;fireDataModificationHandler(). They only fire when an important statistic has
+            changed or data records have previously been removed for the domain in question.
+        * loader/ResourceLoadStatistics.cpp:
+        (WebCore::ResourceLoadStatistics::encode):
+            Added the dataRecordsRemoved statistic.
+        (WebCore::ResourceLoadStatistics::decode):
+            Now takes a version parameter to control which keys to expect.
+            Added the dataRecordsRemoved statistic.
+        (WebCore::appendHashCountedSet):
+            Removed stray linefeed.
+        (WebCore::ResourceLoadStatistics::toString):
+            Added the dataRecordsRemoved statistic.
+        (WebCore::ResourceLoadStatistics::merge):
+            Added the dataRecordsRemoved statistic.
+        * loader/ResourceLoadStatistics.h:
+            Added the dataRecordsRemoved statistic.
+        * loader/ResourceLoadStatisticsStore.cpp:
+        (WebCore::ResourceLoadStatisticsStore::createEncoderFromData):
+            Now encodes a version number for the statistics model.
+        (WebCore::ResourceLoadStatisticsStore::readDataFromDecoder):
+            Now tries to decode a version number and passes it on to statistics decoding.
+        (WebCore::ResourceLoadStatisticsStore::processStatistics):
+            No longer gates processing on the number of data captured.
+        (WebCore::ResourceLoadStatisticsStore::updateStatisticsForRemovedDataRecords):
+            Update function for the new dataRecordsRemoved statistic.
+        (WebCore::ResourceLoadStatisticsStore::hasEnoughDataForStatisticsProcessing): Deleted.
+            No longer needed since we no longer gate processing on the number of data captured.
+        * loader/ResourceLoadStatisticsStore.h:
+
</ins><span class="cx"> 2016-11-17  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Fix WinCairo build after r208740
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoadObservercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoadObserver.cpp (208873 => 208874)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceLoadObserver.cpp        2016-11-18 02:41:35 UTC (rev 208873)
+++ trunk/Source/WebCore/loader/ResourceLoadObserver.cpp        2016-11-18 03:32:53 UTC (rev 208874)
</span><span class="lines">@@ -103,10 +103,13 @@
</span><span class="cx">     
</span><span class="cx">     if (targetPrimaryDomain == mainFramePrimaryDomain || targetPrimaryDomain == sourcePrimaryDomain)
</span><span class="cx">         return;
</span><del>-    
</del><ins>+
</ins><span class="cx">     auto targetOrigin = SecurityOrigin::create(targetURL);
</span><span class="cx">     auto targetStatistics = m_store-&gt;ensureResourceStatisticsForPrimaryDomain(targetPrimaryDomain);
</span><del>-    
</del><ins>+
+    // Always fire if we have previously removed data records for this domain
+    bool shouldFireDataModificationHandler = targetStatistics.dataRecordsRemoved &gt; 0;
+
</ins><span class="cx">     if (isMainFrame)
</span><span class="cx">         targetStatistics.topFrameHasBeenNavigatedToBefore = true;
</span><span class="cx">     else {
</span><span class="lines">@@ -113,7 +116,9 @@
</span><span class="cx">         targetStatistics.subframeHasBeenLoadedBefore = true;
</span><span class="cx"> 
</span><span class="cx">         auto mainFrameOrigin = SecurityOrigin::create(mainFrameURL);
</span><del>-        targetStatistics.subframeUnderTopFrameOrigins.add(mainFramePrimaryDomain);
</del><ins>+        auto subframeUnderTopFrameOriginsResult = targetStatistics.subframeUnderTopFrameOrigins.add(mainFramePrimaryDomain);
+        if (subframeUnderTopFrameOriginsResult.isNewEntry)
+            shouldFireDataModificationHandler = true;
</ins><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     if (isRedirect) {
</span><span class="lines">@@ -152,7 +157,8 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     m_store-&gt;setResourceStatisticsForPrimaryDomain(targetPrimaryDomain, WTFMove(targetStatistics));
</span><del>-    m_store-&gt;fireDataModificationHandler();
</del><ins>+    if (shouldFireDataModificationHandler)
+        m_store-&gt;fireDataModificationHandler();
</ins><span class="cx"> }
</span><span class="cx">     
</span><span class="cx"> void ResourceLoadObserver::logSubresourceLoading(const Frame* frame, const ResourceRequest&amp; newRequest, const ResourceResponse&amp; redirectResponse)
</span><span class="lines">@@ -185,8 +191,13 @@
</span><span class="cx"> 
</span><span class="cx">     auto&amp; targetStatistics = m_store-&gt;ensureResourceStatisticsForPrimaryDomain(targetPrimaryDomain);
</span><span class="cx"> 
</span><ins>+    // Always fire if we have previously removed data records for this domain
+    bool shouldFireDataModificationHandler = targetStatistics.dataRecordsRemoved &gt; 0;
+
</ins><span class="cx">     auto mainFrameOrigin = SecurityOrigin::create(mainFrameURL);
</span><del>-    targetStatistics.subresourceUnderTopFrameOrigins.add(mainFramePrimaryDomain);
</del><ins>+    auto subresourceUnderTopFrameOriginsResult = targetStatistics.subresourceUnderTopFrameOrigins.add(mainFramePrimaryDomain);
+    if (subresourceUnderTopFrameOriginsResult.isNewEntry)
+        shouldFireDataModificationHandler = true;
</ins><span class="cx"> 
</span><span class="cx">     if (isRedirect) {
</span><span class="cx">         auto&amp; redirectingOriginStatistics = m_store-&gt;ensureResourceStatisticsForPrimaryDomain(sourcePrimaryDomain);
</span><span class="lines">@@ -200,7 +211,9 @@
</span><span class="cx">         ++redirectingOriginStatistics.subresourceHasBeenRedirectedFrom;
</span><span class="cx">         ++updatedTargetStatistics.subresourceHasBeenRedirectedTo;
</span><span class="cx"> 
</span><del>-        redirectingOriginStatistics.subresourceUniqueRedirectsTo.add(targetPrimaryDomain);
</del><ins>+        auto subresourceUniqueRedirectsToResult = redirectingOriginStatistics.subresourceUniqueRedirectsTo.add(targetPrimaryDomain);
+        if (subresourceUniqueRedirectsToResult.isNewEntry)
+            shouldFireDataModificationHandler = true;
</ins><span class="cx"> 
</span><span class="cx">         ++updatedTargetStatistics.subresourceHasBeenSubresourceCount;
</span><span class="cx"> 
</span><span class="lines">@@ -214,8 +227,9 @@
</span><span class="cx">         
</span><span class="cx">         targetStatistics.subresourceHasBeenSubresourceCountDividedByTotalNumberOfOriginsVisited = static_cast&lt;double&gt;(targetStatistics.subresourceHasBeenSubresourceCount) / totalVisited;
</span><span class="cx">     }
</span><del>-    
-    m_store-&gt;fireDataModificationHandler();
</del><ins>+
+    if (shouldFireDataModificationHandler)
+        m_store-&gt;fireDataModificationHandler();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ResourceLoadObserver::logWebSocketLoading(const Frame* frame, const URL&amp; targetURL)
</span><span class="lines">@@ -245,10 +259,15 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     auto&amp; targetStatistics = m_store-&gt;ensureResourceStatisticsForPrimaryDomain(targetPrimaryDomain);
</span><ins>+
+    // Always fire if we have previously removed data records for this domain
+    bool shouldFireDataModificationHandler = targetStatistics.dataRecordsRemoved &gt; 0;
</ins><span class="cx">     
</span><span class="cx">     auto mainFrameOrigin = SecurityOrigin::create(mainFrameURL);
</span><del>-    targetStatistics.subresourceUnderTopFrameOrigins.add(mainFramePrimaryDomain);
-    
</del><ins>+    auto subresourceUnderTopFrameOriginsResult = targetStatistics.subresourceUnderTopFrameOrigins.add(mainFramePrimaryDomain);
+    if (subresourceUnderTopFrameOriginsResult.isNewEntry)
+        shouldFireDataModificationHandler = true;
+
</ins><span class="cx">     ++targetStatistics.subresourceHasBeenSubresourceCount;
</span><span class="cx">     
</span><span class="cx">     auto totalVisited = std::max(m_originsVisitedMap.size(), 1U);
</span><span class="lines">@@ -255,7 +274,8 @@
</span><span class="cx">     
</span><span class="cx">     targetStatistics.subresourceHasBeenSubresourceCountDividedByTotalNumberOfOriginsVisited = static_cast&lt;double&gt;(targetStatistics.subresourceHasBeenSubresourceCount) / totalVisited;
</span><span class="cx"> 
</span><del>-    m_store-&gt;fireDataModificationHandler();
</del><ins>+    if (shouldFireDataModificationHandler)
+        m_store-&gt;fireDataModificationHandler();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ResourceLoadObserver::logUserInteraction(const Document&amp; document)
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoadStatisticscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp (208873 => 208874)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp        2016-11-18 02:41:35 UTC (rev 208873)
+++ trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp        2016-11-18 03:32:53 UTC (rev 208874)
</span><span class="lines">@@ -81,6 +81,7 @@
</span><span class="cx">     // Prevalent Resource
</span><span class="cx">     encodeHashCountedSet(encoder, &quot;redirectedToOtherPrevalentResourceOrigins&quot;, redirectedToOtherPrevalentResourceOrigins);
</span><span class="cx">     encoder.encodeBool(&quot;isPrevalentResource&quot;, isPrevalentResource);
</span><ins>+    encoder.encodeUInt32(&quot;dataRecordsRemoved&quot;, dataRecordsRemoved);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static void decodeHashCountedSet(KeyedDecoder&amp; decoder, const String&amp; label, HashCountedSet&lt;String&gt;&amp; hashCountedSet)
</span><span class="lines">@@ -99,7 +100,7 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool ResourceLoadStatistics::decode(KeyedDecoder&amp; decoder)
</del><ins>+bool ResourceLoadStatistics::decode(KeyedDecoder&amp; decoder, unsigned version)
</ins><span class="cx"> {
</span><span class="cx">     if (!decoder.decodeString(&quot;PrevalentResourceOrigin&quot;, highLevelDomain))
</span><span class="cx">         return false;
</span><span class="lines">@@ -170,6 +171,12 @@
</span><span class="cx">     
</span><span class="cx">     if (!decoder.decodeBool(&quot;isPrevalentResource&quot;, isPrevalentResource))
</span><span class="cx">         return false;
</span><ins>+
+    if (version &lt; 2)
+        return true;
+
+    if (!decoder.decodeUInt32(&quot;dataRecordsRemoved&quot;, dataRecordsRemoved))
+        return false;
</ins><span class="cx">     
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="lines">@@ -198,7 +205,6 @@
</span><span class="cx">         builder.appendNumber(entry.value);
</span><span class="cx">         builder.append('\n');
</span><span class="cx">     }
</span><del>-    
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> String ResourceLoadStatistics::toString() const
</span><span class="lines">@@ -268,8 +274,12 @@
</span><span class="cx">     // Prevalent Resource
</span><span class="cx">     appendHashCountedSet(builder, &quot;redirectedToOtherPrevalentResourceOrigins&quot;, redirectedToOtherPrevalentResourceOrigins);
</span><span class="cx">     appendBoolean(builder, &quot;isPrevalentResource&quot;, isPrevalentResource);
</span><ins>+    builder.appendLiteral(&quot;    dataRecordsRemoved: &quot;);
+    builder.appendNumber(dataRecordsRemoved);
</ins><span class="cx">     builder.append('\n');
</span><span class="cx"> 
</span><ins>+    builder.append('\n');
+
</ins><span class="cx">     return builder.toString();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -314,6 +324,7 @@
</span><span class="cx">     // Prevalent resource stats
</span><span class="cx">     mergeHashCountedSet(redirectedToOtherPrevalentResourceOrigins, other.redirectedToOtherPrevalentResourceOrigins);
</span><span class="cx">     isPrevalentResource |= other.isPrevalentResource;
</span><ins>+    dataRecordsRemoved += other.dataRecordsRemoved;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoadStatisticsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoadStatistics.h (208873 => 208874)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceLoadStatistics.h        2016-11-18 02:41:35 UTC (rev 208873)
+++ trunk/Source/WebCore/loader/ResourceLoadStatistics.h        2016-11-18 03:32:53 UTC (rev 208874)
</span><span class="lines">@@ -43,7 +43,7 @@
</span><span class="cx">     ResourceLoadStatistics() = default;
</span><span class="cx"> 
</span><span class="cx">     void encode(KeyedEncoder&amp;) const;
</span><del>-    bool decode(KeyedDecoder&amp;);
</del><ins>+    bool decode(KeyedDecoder&amp;, unsigned version);
</ins><span class="cx"> 
</span><span class="cx">     String toString() const;
</span><span class="cx"> 
</span><span class="lines">@@ -83,6 +83,7 @@
</span><span class="cx">     // Prevalent resource stats
</span><span class="cx">     HashCountedSet&lt;String&gt; redirectedToOtherPrevalentResourceOrigins;
</span><span class="cx">     bool isPrevalentResource { false };
</span><ins>+    unsigned dataRecordsRemoved { 0 };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoadStatisticsStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.cpp (208873 => 208874)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.cpp        2016-11-18 02:41:35 UTC (rev 208873)
+++ trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.cpp        2016-11-18 03:32:53 UTC (rev 208874)
</span><span class="lines">@@ -38,7 +38,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-static const unsigned minimumOriginsLoadedForProcessing = 100;
</del><ins>+static const auto statisticsModelVersion = 2;
</ins><span class="cx"> 
</span><span class="cx"> Ref&lt;ResourceLoadStatisticsStore&gt; ResourceLoadStatisticsStore::create()
</span><span class="cx"> {
</span><span class="lines">@@ -73,7 +73,8 @@
</span><span class="cx"> std::unique_ptr&lt;KeyedEncoder&gt; ResourceLoadStatisticsStore::createEncoderFromData()
</span><span class="cx"> {
</span><span class="cx">     auto encoder = KeyedEncoder::encoder();
</span><del>-    
</del><ins>+
+    encoder-&gt;encodeUInt32(&quot;version&quot;, statisticsModelVersion);
</ins><span class="cx">     encoder-&gt;encodeObjects(&quot;browsingStatistics&quot;, m_resourceStatisticsMap.begin(), m_resourceStatisticsMap.end(), [this](KeyedEncoder&amp; encoderInner, const StatisticsValue&amp; origin) {
</span><span class="cx">         origin.value.encode(encoderInner);
</span><span class="cx">     });
</span><span class="lines">@@ -86,9 +87,12 @@
</span><span class="cx">     if (m_resourceStatisticsMap.size())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    unsigned version;
+    if (!decoder.decodeUInt32(&quot;version&quot;, version))
+        version = 1;
</ins><span class="cx">     Vector&lt;ResourceLoadStatistics&gt; loadedStatistics;
</span><del>-    bool succeeded = decoder.decodeObjects(&quot;browsingStatistics&quot;, loadedStatistics, [this](KeyedDecoder&amp; decoderInner, ResourceLoadStatistics&amp; statistics) {
-        return statistics.decode(decoderInner);
</del><ins>+    bool succeeded = decoder.decodeObjects(&quot;browsingStatistics&quot;, loadedStatistics, [this, version](KeyedDecoder&amp; decoderInner, ResourceLoadStatistics&amp; statistics) {
+        return statistics.decode(decoderInner, version);
</ins><span class="cx">     });
</span><span class="cx"> 
</span><span class="cx">     if (!succeeded)
</span><span class="lines">@@ -141,14 +145,8 @@
</span><span class="cx">         m_dataAddedHandler();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool ResourceLoadStatisticsStore::hasEnoughDataForStatisticsProcessing()
-{
-    return m_resourceStatisticsMap.size() &gt;= minimumOriginsLoadedForProcessing;
-}
-
</del><span class="cx"> void ResourceLoadStatisticsStore::processStatistics(std::function&lt;void(ResourceLoadStatistics&amp;)&gt;&amp;&amp; processFunction)
</span><span class="cx"> {
</span><del>-    ASSERT(hasEnoughDataForStatisticsProcessing());
</del><span class="cx">     for (auto&amp; resourceStatistic : m_resourceStatisticsMap.values())
</span><span class="cx">         processFunction(resourceStatistic);
</span><span class="cx"> }
</span><span class="lines">@@ -162,4 +160,12 @@
</span><span class="cx">     }
</span><span class="cx">     return prevalentResources;
</span><span class="cx"> }
</span><ins>+
+void ResourceLoadStatisticsStore::updateStatisticsForRemovedDataRecords(const Vector&lt;String&gt;&amp; prevalentResourceDomains)
+{
+    for (auto&amp; prevalentResourceDomain : prevalentResourceDomains) {
+        ResourceLoadStatistics&amp; statisic = ensureResourceStatisticsForPrimaryDomain(prevalentResourceDomain);
+        ++statisic.dataRecordsRemoved;
+    }
</ins><span class="cx"> }
</span><ins>+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreloaderResourceLoadStatisticsStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.h (208873 => 208874)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.h        2016-11-18 02:41:35 UTC (rev 208873)
+++ trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.h        2016-11-18 03:32:53 UTC (rev 208874)
</span><span class="lines">@@ -60,10 +60,10 @@
</span><span class="cx"> 
</span><span class="cx">     void fireDataModificationHandler();
</span><span class="cx"> 
</span><del>-    WEBCORE_EXPORT bool hasEnoughDataForStatisticsProcessing();
</del><span class="cx">     WEBCORE_EXPORT void processStatistics(std::function&lt;void(ResourceLoadStatistics&amp;)&gt;&amp;&amp;);
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT Vector&lt;String&gt; prevalentResourceDomainsWithoutUserInteraction();
</span><ins>+    WEBCORE_EXPORT void updateStatisticsForRemovedDataRecords(const Vector&lt;String&gt;&amp; prevalentResourceDomains);
</ins><span class="cx"> private:
</span><span class="cx">     ResourceLoadStatisticsStore() = default;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (208873 => 208874)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-11-18 02:41:35 UTC (rev 208873)
+++ trunk/Source/WebKit2/ChangeLog        2016-11-18 03:32:53 UTC (rev 208874)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2016-11-17  John Wilander  &lt;wilander@apple.com&gt;
+
+        Resource load statistics: Cover further data records, count removed data records, and only fire handler when needed
+        https://bugs.webkit.org/show_bug.cgi?id=164659
+
+        Reviewed by Andy Estes.
+
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::removeDataRecords):
+            Consistent naming with 'remove' rather than 'delete'.
+            Now removes localStorage, IndexDB, disk cache, and memory cache too.
+            Updates statistics with number of times it has removed data records.
+        (WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated):
+            No longer checks whether it has enough data since the classification rules
+            are absolute, not relative.
+        (WebKit::WebResourceLoadStatisticsStore::clearDataRecords): Deleted.
+        * UIProcess/WebResourceLoadStatisticsStore.h:
+            Consistent naming with 'remove' rather than 'delete'.
+
</ins><span class="cx"> 2016-11-17  Brady Eidson  &lt;beidson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add _WKIconLoadingDelegate SPI.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebResourceLoadStatisticsStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp (208873 => 208874)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp        2016-11-18 02:41:35 UTC (rev 208873)
+++ trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp        2016-11-18 03:32:53 UTC (rev 208874)
</span><span class="lines">@@ -44,8 +44,9 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-static const auto numberOfSecondsBetweenClearingDataRecords = 600;
</del><ins>+static const auto numberOfSecondsBetweenRemovingDataRecords = 60;
</ins><span class="cx"> static const auto featureVectorLengthThreshold = 3;
</span><ins>+static OptionSet&lt;WebKit::WebsiteDataType&gt; dataTypesToRemove;
</ins><span class="cx"> 
</span><span class="cx"> Ref&lt;WebResourceLoadStatisticsStore&gt; WebResourceLoadStatisticsStore::create(const String&amp; resourceLoadStatisticsDirectory)
</span><span class="cx"> {
</span><span class="lines">@@ -99,9 +100,9 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebResourceLoadStatisticsStore::clearDataRecords()
</del><ins>+void WebResourceLoadStatisticsStore::removeDataRecords()
</ins><span class="cx"> {
</span><del>-    if (m_dataStoreClearPending)
</del><ins>+    if (m_dataRecordsRemovalPending)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;String&gt; prevalentResourceDomains = coreStore().prevalentResourceDomainsWithoutUserInteraction();
</span><span class="lines">@@ -109,41 +110,53 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     double now = currentTime();
</span><del>-    if (!m_lastTimeDataRecordsWereCleared) {
-        m_lastTimeDataRecordsWereCleared = now;
</del><ins>+    if (!m_lastTimeDataRecordsWereRemoved) {
+        m_lastTimeDataRecordsWereRemoved = now;
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (now &lt; (m_lastTimeDataRecordsWereCleared + numberOfSecondsBetweenClearingDataRecords))
</del><ins>+    if (now &lt; (m_lastTimeDataRecordsWereRemoved + numberOfSecondsBetweenRemovingDataRecords))
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    m_dataStoreClearPending = true;
-    m_lastTimeDataRecordsWereCleared = now;
</del><ins>+    m_dataRecordsRemovalPending = true;
+    m_lastTimeDataRecordsWereRemoved = now;
</ins><span class="cx"> 
</span><ins>+    if (dataTypesToRemove.isEmpty()) {
+        dataTypesToRemove |= WebsiteDataType::Cookies;
+        dataTypesToRemove |= WebsiteDataType::LocalStorage;
+        dataTypesToRemove |= WebsiteDataType::IndexedDBDatabases;
+        dataTypesToRemove |= WebsiteDataType::DiskCache;
+        dataTypesToRemove |= WebsiteDataType::MemoryCache;
+    }
+
</ins><span class="cx">     // Switch to the main thread to get the default website data store
</span><span class="cx">     RunLoop::main().dispatch([prevalentResourceDomains = WTFMove(prevalentResourceDomains), this] () mutable {
</span><span class="cx">         auto&amp; websiteDataStore = API::WebsiteDataStore::defaultDataStore()-&gt;websiteDataStore();
</span><span class="cx"> 
</span><del>-        websiteDataStore.fetchData(WebsiteDataType::Cookies, { }, [prevalentResourceDomains = WTFMove(prevalentResourceDomains), this](auto websiteDataRecords) {
</del><ins>+        websiteDataStore.fetchData(dataTypesToRemove, { }, [prevalentResourceDomains = WTFMove(prevalentResourceDomains), this](auto websiteDataRecords) {
</ins><span class="cx">             Vector&lt;WebsiteDataRecord&gt; dataRecords;
</span><ins>+            Vector&lt;String&gt; prevalentResourceDomainsWithDataRecords;
</ins><span class="cx">             for (auto&amp; websiteDataRecord : websiteDataRecords) {
</span><span class="cx">                 for (auto&amp; prevalentResourceDomain : prevalentResourceDomains) {
</span><span class="cx">                     if (websiteDataRecord.displayName.endsWithIgnoringASCIICase(prevalentResourceDomain)) {
</span><span class="cx">                         auto suffixStart = websiteDataRecord.displayName.length() - prevalentResourceDomain.length();
</span><del>-                        if (!suffixStart || websiteDataRecord.displayName[suffixStart - 1] == '.')
</del><ins>+                        if (!suffixStart || websiteDataRecord.displayName[suffixStart - 1] == '.') {
</ins><span class="cx">                             dataRecords.append(websiteDataRecord);
</span><ins>+                            prevalentResourceDomainsWithDataRecords.append(prevalentResourceDomain);
+                        }
</ins><span class="cx">                     }
</span><span class="cx">                 }
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             if (!dataRecords.size()) {
</span><del>-                m_dataStoreClearPending = false;
</del><ins>+                m_dataRecordsRemovalPending = false;
</ins><span class="cx">                 return;
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             auto&amp; websiteDataStore = API::WebsiteDataStore::defaultDataStore()-&gt;websiteDataStore();
</span><del>-            websiteDataStore.removeData(WebsiteDataType::Cookies, { WTFMove(dataRecords) }, [this] {
-                m_dataStoreClearPending = false;
</del><ins>+            websiteDataStore.removeData(dataTypesToRemove, dataRecords, [prevalentResourceDomainsWithDataRecords = WTFMove(prevalentResourceDomainsWithDataRecords), this] {
+                this-&gt;coreStore().updateStatisticsForRemovedDataRecords(prevalentResourceDomainsWithDataRecords);
+                m_dataRecordsRemovalPending = false;
</ins><span class="cx">             });
</span><span class="cx">         });
</span><span class="cx">     });
</span><span class="lines">@@ -153,13 +166,11 @@
</span><span class="cx"> {
</span><span class="cx">     coreStore().mergeStatistics(origins);
</span><span class="cx"> 
</span><del>-    if (coreStore().hasEnoughDataForStatisticsProcessing()) {
-        coreStore().processStatistics([this] (ResourceLoadStatistics&amp; resourceStatistic) {
-            classifyResource(resourceStatistic);
-            clearDataRecords();
-        });
-    }
-
</del><ins>+    coreStore().processStatistics([this] (ResourceLoadStatistics&amp; resourceStatistic) {
+        classifyResource(resourceStatistic);
+        removeDataRecords();
+    });
+    
</ins><span class="cx">     auto encoder = coreStore().createEncoderFromData();
</span><span class="cx">     
</span><span class="cx">     writeEncoderToDisk(*encoder.get(), &quot;full_browsing_session&quot;);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebResourceLoadStatisticsStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h (208873 => 208874)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h        2016-11-18 02:41:35 UTC (rev 208873)
+++ trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h        2016-11-18 03:32:53 UTC (rev 208874)
</span><span class="lines">@@ -74,7 +74,7 @@
</span><span class="cx"> 
</span><span class="cx">     bool hasPrevalentResourceCharacteristics(const WebCore::ResourceLoadStatistics&amp;);
</span><span class="cx">     void classifyResource(WebCore::ResourceLoadStatistics&amp;);
</span><del>-    void clearDataRecords();
</del><ins>+    void removeDataRecords();
</ins><span class="cx"> 
</span><span class="cx">     String persistentStoragePath(const String&amp; label) const;
</span><span class="cx"> 
</span><span class="lines">@@ -89,8 +89,8 @@
</span><span class="cx">     String m_storagePath;
</span><span class="cx">     bool m_resourceLoadStatisticsEnabled { false };
</span><span class="cx"> 
</span><del>-    double m_lastTimeDataRecordsWereCleared { 0 };
-    bool m_dataStoreClearPending { false };
</del><ins>+    double m_lastTimeDataRecordsWereRemoved { 0 };
+    bool m_dataRecordsRemovalPending { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre>
</div>
</div>

</body>
</html>