Title: [279802] trunk/Source
Revision
279802
Author
[email protected]
Date
2021-07-09 20:07:32 -0700 (Fri, 09 Jul 2021)

Log Message

[ITP] Improve ResourceLoadStatisticsDatabaseStore's buildList() and use it in more places
https://bugs.webkit.org/show_bug.cgi?id=227843

Reviewed by Sam Weinig.

Source/WebCore:

Support passing a RegistrableDomain directly to StringBuilder::append().

* platform/RegistrableDomain.h:

Source/WebKit:

Improve ResourceLoadStatisticsDatabaseStore's buildList() and use it in more places.

buildList() now works with String types (RegistrableDomain in this particular case) and
can take any container type in parameter.

* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
(WebKit::buildList):
(WebKit::ResourceLoadStatisticsDatabaseStore::incrementRecordsDeletedCountForDomains):
(WebKit::ResourceLoadStatisticsDatabaseStore::markAsPrevalentIfHasRedirectedToPrevalent):
(WebKit::ResourceLoadStatisticsDatabaseStore::findNotVeryPrevalentResources):
(WebKit::ResourceLoadStatisticsDatabaseStore::grandfatherDataForDomains):
(WebKit::ResourceLoadStatisticsDatabaseStore::setDomainsAsPrevalent):
(WebKit::ResourceLoadStatisticsDatabaseStore::clearGrandfathering):
(WebKit::ResourceLoadStatisticsDatabaseStore::pruneStatisticsIfNeeded):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (279801 => 279802)


--- trunk/Source/WebCore/ChangeLog	2021-07-10 03:00:31 UTC (rev 279801)
+++ trunk/Source/WebCore/ChangeLog	2021-07-10 03:07:32 UTC (rev 279802)
@@ -1,3 +1,14 @@
+2021-07-09  Chris Dumez  <[email protected]>
+
+        [ITP] Improve ResourceLoadStatisticsDatabaseStore's buildList() and use it in more places
+        https://bugs.webkit.org/show_bug.cgi?id=227843
+
+        Reviewed by Sam Weinig.
+
+        Support passing a RegistrableDomain directly to StringBuilder::append().
+
+        * platform/RegistrableDomain.h:
+
 2021-07-09  Ryosuke Niwa  <[email protected]>
 
         ResizeObserver / IntersectionObserver memory leak on detached & out of reference elements

Modified: trunk/Source/WebCore/platform/RegistrableDomain.h (279801 => 279802)


--- trunk/Source/WebCore/platform/RegistrableDomain.h	2021-07-10 03:00:31 UTC (rev 279801)
+++ trunk/Source/WebCore/platform/RegistrableDomain.h	2021-07-10 03:07:32 UTC (rev 279802)
@@ -164,4 +164,12 @@
 namespace WTF {
 template<> struct DefaultHash<WebCore::RegistrableDomain> : WebCore::RegistrableDomain::RegistrableDomainHash { };
 template<> struct HashTraits<WebCore::RegistrableDomain> : SimpleClassHashTraits<WebCore::RegistrableDomain> { };
-}
+
+template<> class StringTypeAdapter<WebCore::RegistrableDomain, void> : public StringTypeAdapter<String, void> {
+public:
+    StringTypeAdapter(const WebCore::RegistrableDomain& domain)
+        : StringTypeAdapter<String, void>(domain.string())
+    { }
+};
+
+} // namespace WTF

Modified: trunk/Source/WebKit/ChangeLog (279801 => 279802)


--- trunk/Source/WebKit/ChangeLog	2021-07-10 03:00:31 UTC (rev 279801)
+++ trunk/Source/WebKit/ChangeLog	2021-07-10 03:07:32 UTC (rev 279802)
@@ -1,3 +1,25 @@
+2021-07-09  Chris Dumez  <[email protected]>
+
+        [ITP] Improve ResourceLoadStatisticsDatabaseStore's buildList() and use it in more places
+        https://bugs.webkit.org/show_bug.cgi?id=227843
+
+        Reviewed by Sam Weinig.
+
+        Improve ResourceLoadStatisticsDatabaseStore's buildList() and use it in more places.
+
+        buildList() now works with String types (RegistrableDomain in this particular case) and
+        can take any container type in parameter.
+
+        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
+        (WebKit::buildList):
+        (WebKit::ResourceLoadStatisticsDatabaseStore::incrementRecordsDeletedCountForDomains):
+        (WebKit::ResourceLoadStatisticsDatabaseStore::markAsPrevalentIfHasRedirectedToPrevalent):
+        (WebKit::ResourceLoadStatisticsDatabaseStore::findNotVeryPrevalentResources):
+        (WebKit::ResourceLoadStatisticsDatabaseStore::grandfatherDataForDomains):
+        (WebKit::ResourceLoadStatisticsDatabaseStore::setDomainsAsPrevalent):
+        (WebKit::ResourceLoadStatisticsDatabaseStore::clearGrandfathering):
+        (WebKit::ResourceLoadStatisticsDatabaseStore::pruneStatisticsIfNeeded):
+
 2021-07-09  Jer Noble  <[email protected]>
 
         [Cocoa] Allow the UIProcess to set logging parameters in the GPUProcess

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp (279801 => 279802)


--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp	2021-07-10 03:00:31 UTC (rev 279801)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp	2021-07-10 03:07:32 UTC (rev 279802)
@@ -326,6 +326,19 @@
     return expectedTableAndIndexQueries;
 }
 
+template <typename ContainerType>
+static String buildList(const ContainerType& values)
+{
+    StringBuilder builder;
+    for (auto& value : values) {
+        if constexpr (std::is_arithmetic_v<std::remove_reference_t<decltype(value)>>) {
+            builder.append(builder.isEmpty() ? "" : ", ", value);
+        } else
+            builder.append(builder.isEmpty() ? "" : ", ", '"', value, '"');
+    }
+    return builder.toString();
+}
+
 HashSet<ResourceLoadStatisticsDatabaseStore*>& ResourceLoadStatisticsDatabaseStore::allStores()
 {
     ASSERT(!RunLoop::isMain());
@@ -1275,19 +1288,11 @@
     return thirdPartyDataList;
 }
 
-static String domainsToString(const HashSet<RegistrableDomain>& domains)
-{
-    StringBuilder builder;
-    for (const auto& domainName : domains)
-        builder.append(builder.isEmpty() ? "" : ", ", '"', domainName.string(), '"');
-    return builder.toString();
-}
-
 void ResourceLoadStatisticsDatabaseStore::incrementRecordsDeletedCountForDomains(HashSet<RegistrableDomain>&& domains)
 {
     ASSERT(!RunLoop::isMain());
 
-    auto domainsToUpdateStatement = m_database.prepareStatementSlow(makeString("UPDATE ObservedDomains SET dataRecordsRemoved = dataRecordsRemoved + 1 WHERE registrableDomain IN (", domainsToString(domains), ")"));
+    auto domainsToUpdateStatement = m_database.prepareStatementSlow(makeString("UPDATE ObservedDomains SET dataRecordsRemoved = dataRecordsRemoved + 1 WHERE registrableDomain IN (", buildList(domains), ")"));
     if (!domainsToUpdateStatement || domainsToUpdateStatement->step() != SQLITE_DONE) {
         ITP_RELEASE_LOG_ERROR(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::incrementStatisticsForDomains failed, error message: %" PRIVATE_LOG_STRING, this, m_database.lastErrorMsg());
         ASSERT_NOT_REACHED();
@@ -1344,15 +1349,6 @@
     return numberOfRecursiveCalls;
 }
 
-template <typename IteratorType>
-static String buildList(const WTF::IteratorRange<IteratorType>& values)
-{
-    StringBuilder builder;
-    for (auto domainID : values)
-        builder.append(builder.isEmpty() ? "" : ", ", domainID);
-    return builder.toString();
-}
-
 void ResourceLoadStatisticsDatabaseStore::markAsPrevalentIfHasRedirectedToPrevalent()
 {
     ASSERT(!RunLoop::isMain());
@@ -1370,7 +1366,7 @@
             prevalentDueToRedirect.insert(topFrameRedirectStatement->columnInt(0));
     }
 
-    auto markPrevalentStatement = m_database.prepareStatementSlow(makeString("UPDATE ObservedDomains SET isPrevalent = 1 WHERE domainID IN (", buildList(WTF::IteratorRange<StdSet<unsigned>::iterator>(prevalentDueToRedirect.begin(), prevalentDueToRedirect.end())), ")"));
+    auto markPrevalentStatement = m_database.prepareStatementSlow(makeString("UPDATE ObservedDomains SET isPrevalent = 1 WHERE domainID IN (", buildList(prevalentDueToRedirect), ")"));
     if (!markPrevalentStatement || markPrevalentStatement->step() != SQLITE_DONE) {
         ITP_RELEASE_LOG_ERROR(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::markAsPrevalentIfHasRedirectedToPrevalent failed to execute, error message: %" PRIVATE_LOG_STRING, this, m_database.lastErrorMsg());
         ASSERT_NOT_REACHED();
@@ -1395,10 +1391,7 @@
         }
     }
 
-    StringBuilder builder;
-    for (auto value : results.keys())
-        builder.append(builder.isEmpty() ? "" : ", ", value);
-    auto domainIDsOfInterest = builder.toString();
+    auto domainIDsOfInterest = buildList(results.keys());
 
     auto subresourceUnderTopFrameDomainsStatement = m_database.prepareStatementSlow(makeString("SELECT subresourceDomainID, COUNT(topFrameDomainID) FROM SubresourceUnderTopFrameDomains WHERE subresourceDomainID IN (", domainIDsOfInterest, ") GROUP BY subresourceDomainID"));
     if (subresourceUnderTopFrameDomainsStatement) {
@@ -1697,7 +1690,7 @@
             ITP_RELEASE_LOG_ERROR(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::grandfatherDataForDomains was not completed due to failed insert attempt", this);
     }
 
-    auto domainsToUpdateStatement = m_database.prepareStatementSlow(makeString("UPDATE ObservedDomains SET grandfathered = 1 WHERE registrableDomain IN (", domainsToString(domains), ")"));
+    auto domainsToUpdateStatement = m_database.prepareStatementSlow(makeString("UPDATE ObservedDomains SET grandfathered = 1 WHERE registrableDomain IN (", buildList(domains), ")"));
     if (!domainsToUpdateStatement || domainsToUpdateStatement->step() != SQLITE_DONE) {
         ITP_RELEASE_LOG_ERROR(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::grandfatherDataForDomains failed, error message: %" PRIVATE_LOG_STRING, this, m_database.lastErrorMsg());
         ASSERT_NOT_REACHED();
@@ -2027,7 +2020,7 @@
 {
     ASSERT(!RunLoop::isMain());
 
-    auto domainsToUpdateStatement = m_database.prepareStatementSlow(makeString("UPDATE ObservedDomains SET isPrevalent = 1 WHERE domainID IN (", buildList(WTF::IteratorRange<StdSet<unsigned>::iterator>(domains.begin(), domains.end())), ")"));
+    auto domainsToUpdateStatement = m_database.prepareStatementSlow(makeString("UPDATE ObservedDomains SET isPrevalent = 1 WHERE domainID IN (", buildList(domains), ")"));
     if (!domainsToUpdateStatement || domainsToUpdateStatement->step() != SQLITE_DONE) {
         ITP_RELEASE_LOG_ERROR(m_sessionID, "%p - ResourceLoadStatisticsDatabaseStore::setDomainsAsPrevalent failed, error message: %" PRIVATE_LOG_STRING, this, m_database.lastErrorMsg());
         ASSERT_NOT_REACHED();
@@ -2621,7 +2614,7 @@
     if (domainIDsToClear.isEmpty())
         return;
 
-    auto listToClear = buildList(WTF::IteratorRange<Vector<unsigned>::iterator>(domainIDsToClear.begin(), domainIDsToClear.end()));
+    auto listToClear = buildList(domainIDsToClear);
 
     auto clearGrandfatheringStatement = m_database.prepareStatementSlow(makeString("UPDATE ObservedDomains SET grandfathered = 0 WHERE domainID IN (", listToClear, ")"));
     if (!clearGrandfatheringStatement)
@@ -2784,7 +2777,7 @@
     while (recordsToPrune->step() == SQLITE_ROW)
         entriesToPrune.append(recordsToPrune->columnInt(0));
 
-    auto listToPrune = buildList(WTF::IteratorRange<Vector<unsigned>::iterator>(entriesToPrune.begin(), entriesToPrune.end()));
+    auto listToPrune = buildList(entriesToPrune);
 
     auto pruneCommand = m_database.prepareStatementSlow(makeString("DELETE from ObservedDomains WHERE domainID IN (", listToPrune, ")"));
     if (!pruneCommand || pruneCommand->step() != SQLITE_DONE) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to