Title: [281886] trunk/Source/WebKit
Revision
281886
Author
[email protected]
Date
2021-09-01 16:26:50 -0700 (Wed, 01 Sep 2021)

Log Message

Move PCM::Store ownership from WebResourceLoadStatisticsStore to PrivateClickMeasurementManager
https://bugs.webkit.org/show_bug.cgi?id=229770

Patch by Alex Christensen <[email protected]> on 2021-09-01
Reviewed by Kate Cheney.

Now that PrivateClickMeasurement storage is separate from ResourceLoadStatistics storage, they don't need to know about each other.

* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
(WebKit::ResourceLoadStatisticsDatabaseStore::migrateDataToPCMDatabaseIfNecessary):
* NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
(WebKit::WebResourceLoadStatisticsStore::create):
(WebKit::WebResourceLoadStatisticsStore::didDestroyNetworkSession):
(WebKit::pcmStoreDirectory): Deleted.
* NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
* NetworkProcess/NetworkSession.cpp:
(WebKit::pcmStoreDirectory):
(WebKit::NetworkSession::NetworkSession):
(WebKit::NetworkSession::~NetworkSession):
(WebKit::NetworkSession::setResourceLoadStatisticsEnabled):
(WebKit::NetworkSession::recreateResourceLoadStatisticStore):
* NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDatabase.cpp:
(WebKit::PCM::Database::privateClickMeasurementToStringForTesting const):
(WebKit::PCM::Database::attributionToStringForTesting const):
(WebKit::PCM::Database::privateClickMeasurementToStringForTesting): Deleted.
(WebKit::PCM::Database::attributionToStringForTesting): Deleted.
* NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDatabase.h:
* NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementStore.cpp:
(WebKit::PCM::Store::postTask const):
(WebKit::PCM::Store::postTaskReply const):
(WebKit::PCM::Store::privateClickMeasurementToStringForTesting const):
(WebKit::PCM::Store::postTask): Deleted.
(WebKit::PCM::Store::postTaskReply): Deleted.
(WebKit::PCM::Store::privateClickMeasurementToStringForTesting): Deleted.
* NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementStore.h:
* NetworkProcess/PrivateClickMeasurementManager.cpp:
(WebKit::PrivateClickMeasurementManager::PrivateClickMeasurementManager):
(WebKit::PrivateClickMeasurementManager::insertPrivateClickMeasurement):
(WebKit::PrivateClickMeasurementManager::attribute):
(WebKit::PrivateClickMeasurementManager::clearSentAttribution):
(WebKit::PrivateClickMeasurementManager::firePendingAttributionRequests):
(WebKit::PrivateClickMeasurementManager::clear):
(WebKit::PrivateClickMeasurementManager::clearForRegistrableDomain):
(WebKit::PrivateClickMeasurementManager::clearExpired):
(WebKit::PrivateClickMeasurementManager::toStringForTesting const):
(WebKit::PrivateClickMeasurementManager::markAllUnattributedAsExpiredForTesting):
(WebKit::PrivateClickMeasurementManager::markAttributedPrivateClickMeasurementsAsExpiredForTesting):
* NetworkProcess/PrivateClickMeasurementManager.h:
(WebKit::PrivateClickMeasurementManager::store):
(WebKit::PrivateClickMeasurementManager::store const):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (281885 => 281886)


--- trunk/Source/WebKit/ChangeLog	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/ChangeLog	2021-09-01 23:26:50 UTC (rev 281886)
@@ -1,5 +1,58 @@
 2021-09-01  Alex Christensen  <[email protected]>
 
+        Move PCM::Store ownership from WebResourceLoadStatisticsStore to PrivateClickMeasurementManager
+        https://bugs.webkit.org/show_bug.cgi?id=229770
+
+        Reviewed by Kate Cheney.
+
+        Now that PrivateClickMeasurement storage is separate from ResourceLoadStatistics storage, they don't need to know about each other.
+
+        * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
+        (WebKit::ResourceLoadStatisticsDatabaseStore::migrateDataToPCMDatabaseIfNecessary):
+        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
+        (WebKit::WebResourceLoadStatisticsStore::create):
+        (WebKit::WebResourceLoadStatisticsStore::didDestroyNetworkSession):
+        (WebKit::pcmStoreDirectory): Deleted.
+        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
+        * NetworkProcess/NetworkSession.cpp:
+        (WebKit::pcmStoreDirectory):
+        (WebKit::NetworkSession::NetworkSession):
+        (WebKit::NetworkSession::~NetworkSession):
+        (WebKit::NetworkSession::setResourceLoadStatisticsEnabled):
+        (WebKit::NetworkSession::recreateResourceLoadStatisticStore):
+        * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDatabase.cpp:
+        (WebKit::PCM::Database::privateClickMeasurementToStringForTesting const):
+        (WebKit::PCM::Database::attributionToStringForTesting const):
+        (WebKit::PCM::Database::privateClickMeasurementToStringForTesting): Deleted.
+        (WebKit::PCM::Database::attributionToStringForTesting): Deleted.
+        * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDatabase.h:
+        * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementStore.cpp:
+        (WebKit::PCM::Store::postTask const):
+        (WebKit::PCM::Store::postTaskReply const):
+        (WebKit::PCM::Store::privateClickMeasurementToStringForTesting const):
+        (WebKit::PCM::Store::postTask): Deleted.
+        (WebKit::PCM::Store::postTaskReply): Deleted.
+        (WebKit::PCM::Store::privateClickMeasurementToStringForTesting): Deleted.
+        * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementStore.h:
+        * NetworkProcess/PrivateClickMeasurementManager.cpp:
+        (WebKit::PrivateClickMeasurementManager::PrivateClickMeasurementManager):
+        (WebKit::PrivateClickMeasurementManager::insertPrivateClickMeasurement):
+        (WebKit::PrivateClickMeasurementManager::attribute):
+        (WebKit::PrivateClickMeasurementManager::clearSentAttribution):
+        (WebKit::PrivateClickMeasurementManager::firePendingAttributionRequests):
+        (WebKit::PrivateClickMeasurementManager::clear):
+        (WebKit::PrivateClickMeasurementManager::clearForRegistrableDomain):
+        (WebKit::PrivateClickMeasurementManager::clearExpired):
+        (WebKit::PrivateClickMeasurementManager::toStringForTesting const):
+        (WebKit::PrivateClickMeasurementManager::markAllUnattributedAsExpiredForTesting):
+        (WebKit::PrivateClickMeasurementManager::markAttributedPrivateClickMeasurementsAsExpiredForTesting):
+        * NetworkProcess/PrivateClickMeasurementManager.h:
+        (WebKit::PrivateClickMeasurementManager::store):
+        (WebKit::PrivateClickMeasurementManager::store const):
+
+2021-09-01  Alex Christensen  <[email protected]>
+
         Remove _statisticsDatabaseColumnsForTable and related unused test functions
         https://bugs.webkit.org/show_bug.cgi?id=229771
 

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp	2021-09-01 23:26:50 UTC (rev 281886)
@@ -552,7 +552,11 @@
 
     if (!unattributed.isEmpty() || !attributed.isEmpty()) {
         RunLoop::main().dispatch([store = makeRef(store()), unattributed = unattributed.isolatedCopy(), attributed = attributed.isolatedCopy()] () mutable {
-            auto& pcmStore = store->privateClickMeasurementStore();
+            auto* networkSession = store->networkSession();
+            if (!networkSession)
+                return;
+
+            auto& pcmStore = networkSession->privateClickMeasurement().store();
             for (auto& pcm : WTFMove(attributed))
                 pcmStore.insertPrivateClickMeasurement(WTFMove(pcm), PrivateClickMeasurementAttributionType::Attributed);
             for (auto& pcm : WTFMove(unattributed))

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h	2021-09-01 23:26:50 UTC (rev 281886)
@@ -49,12 +49,7 @@
 static constexpr std::array<unsigned, numberOfBucketsPerStatistic> bucketSizes {{ 1, 3, 10, 50, 100 }};
 
 class ResourceLoadStatisticsMemoryStore;
-class PrivateClickMeasurementManager;
 
-using SourceSite = WebCore::PrivateClickMeasurement::SourceSite;
-using AttributionDestinationSite = WebCore::PrivateClickMeasurement::AttributionDestinationSite;
-using AttributionTriggerData = WebCore::PrivateClickMeasurement::AttributionTriggerData;
-
 typedef std::pair<String, std::optional<String>> TableAndIndexPair;
 
 // This is always constructed / used / destroyed on the WebResourceLoadStatisticsStore's statistics queue.

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp	2021-09-01 23:26:50 UTC (rev 281886)
@@ -150,23 +150,11 @@
     return queue.get().copyRef();
 }
 
-static String pcmStoreDirectory(const NetworkSession& session, const String& resourceLoadStatisticsDirectory, const String& privateClickMeasurementStorageDirectory)
-{
-    if (session.sessionID().isEphemeral())
-        return { };
-
-    if (!privateClickMeasurementStorageDirectory.isEmpty())
-        return privateClickMeasurementStorageDirectory;
-
-    return resourceLoadStatisticsDirectory;
-}
-
-WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore(NetworkSession& networkSession, const String& resourceLoadStatisticsDirectory, const String& privateClickMeasurementStorageDirectory, ShouldIncludeLocalhost shouldIncludeLocalhost, ResourceLoadStatistics::IsEphemeral isEphemeral)
+WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore(NetworkSession& networkSession, const String& resourceLoadStatisticsDirectory, ShouldIncludeLocalhost shouldIncludeLocalhost, ResourceLoadStatistics::IsEphemeral isEphemeral)
     : m_networkSession(makeWeakPtr(networkSession))
     , m_statisticsQueue(sharedStatisticsQueue())
     , m_dailyTasksTimer(RunLoop::main(), this, &WebResourceLoadStatisticsStore::performDailyTasks)
     , m_isEphemeral(isEphemeral)
-    , m_pcmStore(PCM::Store::create(pcmStoreDirectory(networkSession, resourceLoadStatisticsDirectory, privateClickMeasurementStorageDirectory)))
 {
     RELEASE_ASSERT(RunLoop::isMain());
 
@@ -198,9 +186,9 @@
     RELEASE_ASSERT(!m_statisticsStore);
 }
 
-Ref<WebResourceLoadStatisticsStore> WebResourceLoadStatisticsStore::create(NetworkSession& networkSession, const String& resourceLoadStatisticsDirectory, const String& privateClickMeasurementStorageDirectory, ShouldIncludeLocalhost shouldIncludeLocalhost, WebCore::ResourceLoadStatistics::IsEphemeral isEphemeral)
+Ref<WebResourceLoadStatisticsStore> WebResourceLoadStatisticsStore::create(NetworkSession& networkSession, const String& resourceLoadStatisticsDirectory, ShouldIncludeLocalhost shouldIncludeLocalhost, WebCore::ResourceLoadStatistics::IsEphemeral isEphemeral)
 {
-    return adoptRef(*new WebResourceLoadStatisticsStore(networkSession, resourceLoadStatisticsDirectory, privateClickMeasurementStorageDirectory, shouldIncludeLocalhost, isEphemeral));
+    return adoptRef(*new WebResourceLoadStatisticsStore(networkSession, resourceLoadStatisticsDirectory, shouldIncludeLocalhost, isEphemeral));
 }
 
 void WebResourceLoadStatisticsStore::didDestroyNetworkSession(CompletionHandler<void()>&& completionHandler)
@@ -213,7 +201,6 @@
 
     m_networkSession = nullptr;
     destroyResourceLoadStatisticsStore([callbackAggregator] { });
-    privateClickMeasurementStore().close([callbackAggregator] { });
 }
 
 inline void WebResourceLoadStatisticsStore::postTask(WTF::Function<void()>&& task)

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h	2021-09-01 23:26:50 UTC (rev 281886)
@@ -30,7 +30,6 @@
 #include "ArgumentCoders.h"
 #include "Decoder.h"
 #include "Encoder.h"
-#include "PrivateClickMeasurementStore.h"
 #include "StorageAccessStatus.h"
 #include "WebPageProxyIdentifier.h"
 #include "WebsiteDataType.h"
@@ -38,7 +37,6 @@
 #include <WebCore/FrameIdentifier.h>
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/PageIdentifier.h>
-#include <WebCore/PrivateClickMeasurement.h>
 #include <WebCore/RegistrableDomain.h>
 #include <WebCore/ResourceLoadObserver.h>
 #include <wtf/CompletionHandler.h>
@@ -66,7 +64,6 @@
 class ResourceLoadStatisticsStore;
 class WebFrameProxy;
 class WebProcessProxy;
-enum class PrivateClickMeasurementAttributionType : bool;
 enum class ShouldGrandfatherStatistics : bool;
 enum class ShouldIncludeLocalhost : bool { No, Yes };
 enum class EnableResourceLoadStatisticsDebugMode : bool { No, Yes };
@@ -109,7 +106,7 @@
     using StorageAccessScope = WebCore::StorageAccessScope;
     using RequestStorageAccessResult = WebCore::RequestStorageAccessResult;
 
-    static Ref<WebResourceLoadStatisticsStore> create(NetworkSession&, const String& resourceLoadStatisticsDirectory, const String& privateClickMeasurementStorageDirectory, ShouldIncludeLocalhost, ResourceLoadStatistics::IsEphemeral);
+    static Ref<WebResourceLoadStatisticsStore> create(NetworkSession&, const String& resourceLoadStatisticsDirectory, ShouldIncludeLocalhost, ResourceLoadStatistics::IsEphemeral);
 
     ~WebResourceLoadStatisticsStore();
 
@@ -239,9 +236,8 @@
     bool isEphemeral() const { return m_isEphemeral == WebCore::ResourceLoadStatistics::IsEphemeral::Yes; };
     void insertExpiredStatisticForTesting(const RegistrableDomain&, unsigned numberOfOperatingDaysPassed, bool hadUserInteraction, bool isScheduledForAllButCookieDataRemoval, bool isPrevalent, CompletionHandler<void()>&&);
 
-    PCM::Store& privateClickMeasurementStore() { return m_pcmStore.get(); }
 private:
-    explicit WebResourceLoadStatisticsStore(NetworkSession&, const String&, const String&, ShouldIncludeLocalhost, WebCore::ResourceLoadStatistics::IsEphemeral);
+    explicit WebResourceLoadStatisticsStore(NetworkSession&, const String&, ShouldIncludeLocalhost, WebCore::ResourceLoadStatistics::IsEphemeral);
 
     void postTask(WTF::Function<void()>&&);
     static void postTaskReply(WTF::Function<void()>&&);
@@ -276,8 +272,6 @@
     bool m_hasScheduledProcessStats { false };
 
     bool m_firstNetworkProcessCreated { false };
-    
-    Ref<PCM::Store> m_pcmStore;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp	2021-09-01 23:26:50 UTC (rev 281886)
@@ -2580,15 +2580,14 @@
 
 void NetworkProcess::simulateResourceLoadStatisticsSessionRestart(PAL::SessionID sessionID, CompletionHandler<void()>&& completionHandler)
 {
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
+    // FIXME: Rename this to simulatePrivateClickMeasurementSessionRestart.
     if (auto* session = networkSession(sessionID)) {
-        session->recreateResourceLoadStatisticStore([this, sessionID, completionHandler = WTFMove(completionHandler)] () mutable {
+        session->recreatePrivateClickMeasurementStore([this, sessionID, completionHandler = WTFMove(completionHandler)] () mutable {
             firePrivateClickMeasurementTimerImmediately(sessionID);
             completionHandler();
         });
         return;
     }
-#endif
     completionHandler();
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp	2021-09-01 23:26:50 UTC (rev 281886)
@@ -80,6 +80,17 @@
     return storageSession;
 }
 
+static String pcmStoreDirectory(const NetworkSession& session, const String& resourceLoadStatisticsDirectory, const String& privateClickMeasurementStorageDirectory)
+{
+    if (session.sessionID().isEphemeral())
+        return { };
+
+    if (!privateClickMeasurementStorageDirectory.isEmpty())
+        return privateClickMeasurementStorageDirectory;
+
+    return resourceLoadStatisticsDirectory;
+}
+
 NetworkSession::NetworkSession(NetworkProcess& networkProcess, const NetworkSessionCreationParameters& parameters)
     : m_sessionID(parameters.sessionID)
     , m_networkProcess(networkProcess)
@@ -128,7 +139,7 @@
 
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     setResourceLoadStatisticsEnabled(parameters.resourceLoadStatisticsParameters.enabled);
-    m_privateClickMeasurement = makeUnique<PrivateClickMeasurementManager>(*this, networkProcess, parameters.sessionID, [weakThis = makeWeakPtr(this)] (auto&& loadParameters, auto&& completionHandler) {
+    m_privateClickMeasurement = makeUnique<PrivateClickMeasurementManager>(*this, networkProcess, parameters.sessionID, pcmStoreDirectory(*this, parameters.resourceLoadStatisticsParameters.directory, parameters.resourceLoadStatisticsParameters.privateClickMeasurementStorageDirectory), [weakThis = makeWeakPtr(this)] (auto&& loadParameters, auto&& completionHandler) {
         if (!weakThis)
             return completionHandler(ResourceError(ResourceError::Type::Cancellation), { }, { });
 
@@ -142,6 +153,7 @@
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     destroyResourceLoadStatistics([] { });
 #endif
+    privateClickMeasurement().store().close([] { });
     for (auto& loader : std::exchange(m_keptAliveLoads, { }))
         loader->abort();
 }
@@ -170,6 +182,11 @@
 #endif
 }
 
+void NetworkSession::recreatePrivateClickMeasurementStore(CompletionHandler<void()>&& completionHandler)
+{
+    privateClickMeasurement().destroyStoreForTesting(WTFMove(completionHandler));
+}
+
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
 void NetworkSession::setResourceLoadStatisticsEnabled(bool enable)
 {
@@ -184,7 +201,7 @@
     if (m_resourceLoadStatistics)
         return;
 
-    m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(*this, m_resourceLoadStatisticsDirectory, m_privateClickMeasurementStorageDirectory, m_shouldIncludeLocalhostInResourceLoadStatistics, (m_sessionID.isEphemeral() ? ResourceLoadStatistics::IsEphemeral::Yes : ResourceLoadStatistics::IsEphemeral::No));
+    m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(*this, m_resourceLoadStatisticsDirectory, m_shouldIncludeLocalhostInResourceLoadStatistics, (m_sessionID.isEphemeral() ? ResourceLoadStatistics::IsEphemeral::Yes : ResourceLoadStatistics::IsEphemeral::No));
     if (!m_sessionID.isEphemeral())
         m_resourceLoadStatistics->populateMemoryStoreFromDisk([] { });
 
@@ -196,20 +213,6 @@
     forwardResourceLoadStatisticsSettings();
 }
 
-void NetworkSession::recreateResourceLoadStatisticStore(CompletionHandler<void()>&& completionHandler)
-{
-    destroyResourceLoadStatistics([this, weakThis = makeWeakPtr(*this), completionHandler = WTFMove(completionHandler)] () mutable {
-        if (!weakThis)
-            return completionHandler();
-        m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(*this, m_resourceLoadStatisticsDirectory, m_privateClickMeasurementStorageDirectory,  m_shouldIncludeLocalhostInResourceLoadStatistics, (m_sessionID.isEphemeral() ? ResourceLoadStatistics::IsEphemeral::Yes : ResourceLoadStatistics::IsEphemeral::No));
-        forwardResourceLoadStatisticsSettings();
-        if (!m_sessionID.isEphemeral())
-            m_resourceLoadStatistics->populateMemoryStoreFromDisk(WTFMove(completionHandler));
-        else
-            completionHandler();
-    });
-}
-
 void NetworkSession::forwardResourceLoadStatisticsSettings()
 {
     m_resourceLoadStatistics->setThirdPartyCookieBlockingMode(m_thirdPartyCookieBlockingMode);

Modified: trunk/Source/WebKit/NetworkProcess/NetworkSession.h (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/NetworkSession.h	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/NetworkSession.h	2021-09-01 23:26:50 UTC (rev 281886)
@@ -94,10 +94,11 @@
     void registerNetworkDataTask(NetworkDataTask&);
     void unregisterNetworkDataTask(NetworkDataTask&);
 
+    void recreatePrivateClickMeasurementStore(CompletionHandler<void()>&&);
+
 #if ENABLE(RESOURCE_LOAD_STATISTICS)
     WebResourceLoadStatisticsStore* resourceLoadStatistics() const { return m_resourceLoadStatistics.get(); }
     void setResourceLoadStatisticsEnabled(bool);
-    void recreateResourceLoadStatisticStore(CompletionHandler<void()>&&);
     bool isResourceLoadStatisticsEnabled() const;
     void notifyResourceLoadStatisticsProcessed();
     void deleteAndRestrictWebsiteDataForRegistrableDomains(OptionSet<WebsiteDataType>, RegistrableDomainsToDeleteOrRestrictWebsiteDataFor&&, bool shouldNotifyPage, CompletionHandler<void(const HashSet<WebCore::RegistrableDomain>&)>&&);

Modified: trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDatabase.cpp (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDatabase.cpp	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDatabase.cpp	2021-09-01 23:26:50 UTC (rev 281886)
@@ -338,7 +338,7 @@
     return attributions;
 }
 
-String Database::privateClickMeasurementToStringForTesting()
+String Database::privateClickMeasurementToStringForTesting() const
 {
     ASSERT(!RunLoop::isMain());
     auto privateClickMeasurementDataExists = m_database.prepareStatement("SELECT (SELECT COUNT(*) FROM UnattributedPrivateClickMeasurement) as cnt1, (SELECT COUNT(*) FROM AttributedPrivateClickMeasurement) as cnt2"_s);
@@ -385,7 +385,7 @@
     return builder.toString();
 }
 
-String Database::attributionToStringForTesting(WebCore::SQLiteStatement& statement, PrivateClickMeasurementAttributionType attributionType)
+String Database::attributionToStringForTesting(WebCore::SQLiteStatement& statement, PrivateClickMeasurementAttributionType attributionType) const
 {
     ASSERT(!RunLoop::isMain());
     auto sourceSiteDomain = getDomainStringFromDomainID(statement.columnInt(0));

Modified: trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDatabase.h (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDatabase.h	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementDatabase.h	2021-09-01 23:26:50 UTC (rev 281886)
@@ -51,7 +51,7 @@
     void clearExpiredPrivateClickMeasurement();
     void clearSentAttribution(WebCore::PrivateClickMeasurement&&, WebCore::PrivateClickMeasurement::AttributionReportEndpoint);
 
-    String privateClickMeasurementToStringForTesting();
+    String privateClickMeasurementToStringForTesting() const;
     void markAllUnattributedPrivateClickMeasurementAsExpiredForTesting();
     void markAttributedPrivateClickMeasurementsAsExpiredForTesting();
 
@@ -68,7 +68,7 @@
     void destroyStatements() final;
     std::pair<std::optional<UnattributedPrivateClickMeasurement>, std::optional<AttributedPrivateClickMeasurement>> findPrivateClickMeasurement(const WebCore::PrivateClickMeasurement::SourceSite&, const WebCore::PrivateClickMeasurement::AttributionDestinationSite&);
     void removeUnattributed(WebCore::PrivateClickMeasurement&);
-    String attributionToStringForTesting(WebCore::SQLiteStatement&, PrivateClickMeasurementAttributionType);
+    String attributionToStringForTesting(WebCore::SQLiteStatement&, PrivateClickMeasurementAttributionType) const;
     void markReportAsSentToDestination(SourceDomainID, DestinationDomainID);
     void markReportAsSentToSource(SourceDomainID, DestinationDomainID);
     std::pair<std::optional<SourceEarliestTimeToSend>, std::optional<DestinationEarliestTimeToSend>> earliestTimesToSend(const WebCore::PrivateClickMeasurement&);

Modified: trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementStore.cpp (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementStore.cpp	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementStore.cpp	2021-09-01 23:26:50 UTC (rev 281886)
@@ -67,13 +67,13 @@
 
 Store::~Store() = default;
 
-void Store::postTask(Function<void()>&& task)
+void Store::postTask(Function<void()>&& task) const
 {
     ASSERT(RunLoop::isMain());
     m_queue->dispatch(WTFMove(task));
 }
 
-void Store::postTaskReply(WTF::Function<void()>&& reply)
+void Store::postTaskReply(WTF::Function<void()>&& reply) const
 {
     ASSERT(!RunLoop::isMain());
     RunLoop::main().dispatch(WTFMove(reply));
@@ -118,7 +118,7 @@
     });
 }
 
-void Store::privateClickMeasurementToStringForTesting(CompletionHandler<void(String)>&& completionHandler)
+void Store::privateClickMeasurementToStringForTesting(CompletionHandler<void(String)>&& completionHandler) const
 {
     postTask([this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)]() mutable {
         String result;

Modified: trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementStore.h (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementStore.h	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementStore.h	2021-09-01 23:26:50 UTC (rev 281886)
@@ -53,7 +53,7 @@
     void insertPrivateClickMeasurement(WebCore::PrivateClickMeasurement&&, WebKit::PrivateClickMeasurementAttributionType);
     void attributePrivateClickMeasurement(const WebCore::PrivateClickMeasurement::SourceSite&, const WebCore::PrivateClickMeasurement::AttributionDestinationSite&, WebCore::PrivateClickMeasurement::AttributionTriggerData&&, std::optional<WebCore::PrivateClickMeasurement>&& ephemeralMeasurement, CompletionHandler<void(std::optional<WebCore::PrivateClickMeasurement::AttributionSecondsUntilSendData>&&, DebugInfo&&)>&&);
 
-    void privateClickMeasurementToStringForTesting(CompletionHandler<void(String)>&&);
+    void privateClickMeasurementToStringForTesting(CompletionHandler<void(String)>&&) const;
     void markAllUnattributedPrivateClickMeasurementAsExpiredForTesting();
     void markAttributedPrivateClickMeasurementsAsExpiredForTesting(CompletionHandler<void()>&&);
 
@@ -68,8 +68,8 @@
 private:
     Store(const String& databaseDirectory);
 
-    void postTask(Function<void()>&&);
-    void postTaskReply(Function<void()>&&);
+    void postTask(Function<void()>&&) const;
+    void postTaskReply(Function<void()>&&) const;
 
     std::unique_ptr<Database> m_database;
     Ref<SuspendableWorkQueue> m_queue;

Modified: trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurementManager.cpp (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurementManager.cpp	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurementManager.cpp	2021-09-01 23:26:50 UTC (rev 281886)
@@ -53,11 +53,12 @@
 
 constexpr Seconds debugModeSecondsUntilSend { 10_s };
 
-PrivateClickMeasurementManager::PrivateClickMeasurementManager(NetworkSession& networkSession, NetworkProcess& networkProcess, PAL::SessionID sessionID, Function<void(NetworkLoadParameters&&, NetworkLoadCallback&&)>&& networkLoadFunction)
+PrivateClickMeasurementManager::PrivateClickMeasurementManager(NetworkSession& networkSession, NetworkProcess& networkProcess, PAL::SessionID sessionID, const String& storageDirectory, Function<void(NetworkLoadParameters&&, NetworkLoadCallback&&)>&& networkLoadFunction)
     : m_firePendingAttributionRequestsTimer(*this, &PrivateClickMeasurementManager::firePendingAttributionRequests)
     , m_networkSession(makeWeakPtr(networkSession))
     , m_networkProcess(networkProcess)
     , m_sessionID(sessionID)
+    , m_storageDirectory(storageDirectory)
     , m_networkLoadFunction(WTFMove(networkLoadFunction))
 {
     ASSERT(m_networkLoadFunction);
@@ -249,10 +250,7 @@
         m_ephemeralMeasurement = WTFMove(measurement);
         return;
     }
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
-        if (auto* resourceLoadStatistics = m_networkSession->resourceLoadStatistics())
-            resourceLoadStatistics->privateClickMeasurementStore().insertPrivateClickMeasurement(WTFMove(measurement), type);
-#endif
+    store().insertPrivateClickMeasurement(WTFMove(measurement), type);
 }
 
 void PrivateClickMeasurementManager::handleAttribution(AttributionTriggerData&& attributionTriggerData, const URL& requestURL, const WebCore::ResourceRequest& redirectRequest)
@@ -285,7 +283,6 @@
 
 void PrivateClickMeasurementManager::attribute(const SourceSite& sourceSite, const AttributionDestinationSite& destinationSite, AttributionTriggerData&& attributionTriggerData)
 {
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
     if (!featureEnabled())
         return;
 
@@ -297,40 +294,37 @@
             return;
     }
         
-    if (auto* resourceLoadStatistics = m_networkSession->resourceLoadStatistics()) {
-        resourceLoadStatistics->privateClickMeasurementStore().attributePrivateClickMeasurement(sourceSite, destinationSite, WTFMove(attributionTriggerData), std::exchange(m_ephemeralMeasurement, std::nullopt), [this, weakThis = makeWeakPtr(*this)] (auto attributionSecondsUntilSendData, auto debugInfo) {
-            if (!weakThis)
-                return;
-            
-            if (!attributionSecondsUntilSendData)
-                return;
+    store().attributePrivateClickMeasurement(sourceSite, destinationSite, WTFMove(attributionTriggerData), std::exchange(m_ephemeralMeasurement, std::nullopt), [this, weakThis = makeWeakPtr(*this)] (auto attributionSecondsUntilSendData, auto debugInfo) {
+        if (!weakThis)
+            return;
+        
+        if (!attributionSecondsUntilSendData)
+            return;
 
-            if (UNLIKELY(debugModeEnabled())) {
-                for (auto& message : debugInfo.messages)
-                    m_networkProcess->broadcastConsoleMessage(m_sessionID, MessageSource::PrivateClickMeasurement, message.messageLevel, message.message);
-            }
+        if (UNLIKELY(debugModeEnabled())) {
+            for (auto& message : debugInfo.messages)
+                m_networkProcess->broadcastConsoleMessage(m_sessionID, MessageSource::PrivateClickMeasurement, message.messageLevel, message.message);
+        }
 
-            if (attributionSecondsUntilSendData.value().hasValidSecondsUntilSendValues()) {
-                auto minSecondsUntilSend = attributionSecondsUntilSendData.value().minSecondsUntilSend();
+        if (attributionSecondsUntilSendData.value().hasValidSecondsUntilSendValues()) {
+            auto minSecondsUntilSend = attributionSecondsUntilSendData.value().minSecondsUntilSend();
 
-                ASSERT(minSecondsUntilSend);
-                if (!minSecondsUntilSend)
-                    return;
+            ASSERT(minSecondsUntilSend);
+            if (!minSecondsUntilSend)
+                return;
 
-                if (m_firePendingAttributionRequestsTimer.isActive() && m_firePendingAttributionRequestsTimer.nextFireInterval() < *minSecondsUntilSend)
-                    return;
+            if (m_firePendingAttributionRequestsTimer.isActive() && m_firePendingAttributionRequestsTimer.nextFireInterval() < *minSecondsUntilSend)
+                return;
 
-                if (UNLIKELY(debugModeEnabled())) {
-                    m_networkProcess->broadcastConsoleMessage(m_sessionID, MessageSource::PrivateClickMeasurement, MessageLevel::Log, makeString("[Private Click Measurement] Setting timer for firing attribution request to the debug mode timeout of "_s, debugModeSecondsUntilSend.seconds(), " seconds where the regular timeout would have been "_s, minSecondsUntilSend.value().seconds(), " seconds."_s));
-                    minSecondsUntilSend = debugModeSecondsUntilSend;
-                } else
-                    m_networkProcess->broadcastConsoleMessage(m_sessionID, MessageSource::PrivateClickMeasurement, MessageLevel::Log, makeString("[Private Click Measurement] Setting timer for firing attribution request to the timeout of "_s, minSecondsUntilSend.value().seconds(), " seconds."_s));
+            if (UNLIKELY(debugModeEnabled())) {
+                m_networkProcess->broadcastConsoleMessage(m_sessionID, MessageSource::PrivateClickMeasurement, MessageLevel::Log, makeString("[Private Click Measurement] Setting timer for firing attribution request to the debug mode timeout of "_s, debugModeSecondsUntilSend.seconds(), " seconds where the regular timeout would have been "_s, minSecondsUntilSend.value().seconds(), " seconds."_s));
+                minSecondsUntilSend = debugModeSecondsUntilSend;
+            } else
+                m_networkProcess->broadcastConsoleMessage(m_sessionID, MessageSource::PrivateClickMeasurement, MessageLevel::Log, makeString("[Private Click Measurement] Setting timer for firing attribution request to the timeout of "_s, minSecondsUntilSend.value().seconds(), " seconds."_s));
 
-                startTimer(*minSecondsUntilSend);
-            }
-        });
-    }
-#endif
+            startTimer(*minSecondsUntilSend);
+        }
+    });
 }
 
 void PrivateClickMeasurementManager::fireConversionRequest(const PrivateClickMeasurement& attribution, PrivateClickMeasurement::AttributionReportEndpoint attributionReportEndpoint)
@@ -396,26 +390,18 @@
 
 void PrivateClickMeasurementManager::clearSentAttribution(PrivateClickMeasurement&& sentConversion, PrivateClickMeasurement::AttributionReportEndpoint attributionReportEndpoint)
 {
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
     if (!featureEnabled())
         return;
 
-    if (auto* resourceLoadStatistics = m_networkSession->resourceLoadStatistics())
-        resourceLoadStatistics->privateClickMeasurementStore().clearSentAttribution(WTFMove(sentConversion), attributionReportEndpoint);
-#endif
+    store().clearSentAttribution(WTFMove(sentConversion), attributionReportEndpoint);
 }
 
 void PrivateClickMeasurementManager::firePendingAttributionRequests()
 {
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
     if (!featureEnabled())
         return;
 
-    auto* resourceLoadStatistics = m_networkSession->resourceLoadStatistics();
-    if (!resourceLoadStatistics)
-        return;
-
-    resourceLoadStatistics->privateClickMeasurementStore().allAttributedPrivateClickMeasurement([this, weakThis = makeWeakPtr(*this)] (auto&& attributions) {
+    store().allAttributedPrivateClickMeasurement([this, weakThis = makeWeakPtr(*this)] (auto&& attributions) {
         if (!weakThis)
             return;
         auto nextTimeToFire = Seconds::infinity();
@@ -465,7 +451,6 @@
         if (nextTimeToFire < Seconds::infinity())
             startTimer(nextTimeToFire);
     });
-#endif
 }
 
 void PrivateClickMeasurementManager::clear(CompletionHandler<void()>&& completionHandler)
@@ -474,53 +459,34 @@
     m_ephemeralMeasurement = std::nullopt;
     m_isRunningEphemeralMeasurementTest = false;
 
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
     if (!featureEnabled())
         return completionHandler();
 
-    if (auto* resourceLoadStatistics = m_networkSession->resourceLoadStatistics())
-        return resourceLoadStatistics->privateClickMeasurementStore().clearPrivateClickMeasurement(WTFMove(completionHandler));
-#endif
-    completionHandler();
+    store().clearPrivateClickMeasurement(WTFMove(completionHandler));
 }
 
 void PrivateClickMeasurementManager::clearForRegistrableDomain(const RegistrableDomain& domain, CompletionHandler<void()>&& completionHandler)
 {
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
     if (!featureEnabled())
         return completionHandler();
 
-    if (auto* resourceLoadStatistics = m_networkSession->resourceLoadStatistics())
-        return resourceLoadStatistics->privateClickMeasurementStore().clearPrivateClickMeasurementForRegistrableDomain(domain, WTFMove(completionHandler));
-#endif
-    completionHandler();
+    store().clearPrivateClickMeasurementForRegistrableDomain(domain, WTFMove(completionHandler));
 }
 
 void PrivateClickMeasurementManager::clearExpired()
 {
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
     if (!featureEnabled())
         return;
 
-    if (auto* resourceLoadStatistics = m_networkSession->resourceLoadStatistics())
-        resourceLoadStatistics->privateClickMeasurementStore().clearExpiredPrivateClickMeasurement();
-#endif
+    store().clearExpiredPrivateClickMeasurement();
 }
 
 void PrivateClickMeasurementManager::toStringForTesting(CompletionHandler<void(String)>&& completionHandler) const
 {
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
-    if (!featureEnabled()) {
-        completionHandler("\nNo stored Private Click Measurement data.\n"_s);
-        return;
-    }
+    if (!featureEnabled())
+        return completionHandler("\nNo stored Private Click Measurement data.\n"_s);
 
-    if (auto* resourceLoadStatistics = m_networkSession->resourceLoadStatistics()) {
-        resourceLoadStatistics->privateClickMeasurementStore().privateClickMeasurementToStringForTesting(WTFMove(completionHandler));
-        return;
-    }
-#endif
-    completionHandler("\nNo stored Private Click Measurement data.\n"_s);
+    store().privateClickMeasurementToStringForTesting(WTFMove(completionHandler));
 }
 
 void PrivateClickMeasurementManager::setTokenPublicKeyURLForTesting(URL&& testURL)
@@ -548,13 +514,10 @@
 
 void PrivateClickMeasurementManager::markAllUnattributedAsExpiredForTesting()
 {
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
     if (!featureEnabled())
         return;
 
-    if (auto* resourceLoadStatistics = m_networkSession->resourceLoadStatistics())
-        resourceLoadStatistics->privateClickMeasurementStore().markAllUnattributedPrivateClickMeasurementAsExpiredForTesting();
-#endif
+    store().markAllUnattributedPrivateClickMeasurementAsExpiredForTesting();
 }
 
 void PrivateClickMeasurementManager::setPCMFraudPreventionValuesForTesting(String&& unlinkableToken, String&& secretToken, String&& signature, String&& keyID)
@@ -576,18 +539,35 @@
 
 void PrivateClickMeasurementManager::markAttributedPrivateClickMeasurementsAsExpiredForTesting(CompletionHandler<void()>&& completionHandler)
 {
-#if ENABLE(RESOURCE_LOAD_STATISTICS)
-    if (!featureEnabled()) {
-        completionHandler();
-        return;
-    }
+    if (!featureEnabled())
+        return completionHandler();
 
-    if (auto* resourceLoadStatistics = m_networkSession->resourceLoadStatistics()) {
-        resourceLoadStatistics->privateClickMeasurementStore().markAttributedPrivateClickMeasurementsAsExpiredForTesting(WTFMove(completionHandler));
-        return;
-    }
-#endif
-    completionHandler();
+    store().markAttributedPrivateClickMeasurementsAsExpiredForTesting(WTFMove(completionHandler));
 }
 
+PCM::Store& PrivateClickMeasurementManager::store()
+{
+    if (!m_store)
+        m_store = PCM::Store::create(m_storageDirectory);
+    return *m_store;
+}
+
+const PCM::Store& PrivateClickMeasurementManager::store() const
+{
+    if (!m_store)
+        m_store = PCM::Store::create(m_storageDirectory);
+    return *m_store;
+}
+
+void PrivateClickMeasurementManager::destroyStoreForTesting(CompletionHandler<void()>&& completionHandler)
+{
+    if (!m_store)
+        return completionHandler();
+    m_store->close([weakThis = makeWeakPtr(*this), completionHandler = WTFMove(completionHandler)] () mutable {
+        if (weakThis)
+            weakThis->m_store = nullptr;
+        return completionHandler();
+    });
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurementManager.h (281885 => 281886)


--- trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurementManager.h	2021-09-01 22:54:42 UTC (rev 281885)
+++ trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurementManager.h	2021-09-01 23:26:50 UTC (rev 281886)
@@ -27,6 +27,7 @@
 
 #include "NetworkLoadParameters.h"
 #include "NetworkProcess.h"
+#include "PrivateClickMeasurementStore.h"
 #include <WebCore/PrivateClickMeasurement.h>
 #include <WebCore/RegistrableDomain.h>
 #include <WebCore/ResourceError.h>
@@ -52,7 +53,7 @@
     using PrivateClickMeasurement = WebCore::PrivateClickMeasurement;
     using RegistrableDomain = WebCore::RegistrableDomain;
     using SourceSite = WebCore::PrivateClickMeasurement::SourceSite;
-    explicit PrivateClickMeasurementManager(NetworkSession&, NetworkProcess&, PAL::SessionID, Function<void(NetworkLoadParameters&&, NetworkLoadCallback&&)>&&);
+    explicit PrivateClickMeasurementManager(NetworkSession&, NetworkProcess&, PAL::SessionID, const String& storageDirectory, Function<void(NetworkLoadParameters&&, NetworkLoadCallback&&)>&&);
 
     void storeUnattributed(PrivateClickMeasurement&&);
     void handleAttribution(AttributionTriggerData&&, const URL& requestURL, const WebCore::ResourceRequest& redirectRequest);
@@ -69,6 +70,11 @@
     void setPCMFraudPreventionValuesForTesting(String&& unlinkableToken, String&& secretToken, String&& signature, String&& keyID);
     void startTimer(Seconds);
 
+    void destroyStoreForTesting(CompletionHandler<void()>&&);
+
+    PCM::Store& store();
+    const PCM::Store& store() const;
+
 private:
     void getTokenPublicKey(PrivateClickMeasurement&&, PrivateClickMeasurement::AttributionReportEndpoint, PrivateClickMeasurement::PcmDataCarried, Function<void(PrivateClickMeasurement&& attribution, const String& publicKeyBase64URL)>&&);
     void getSignedUnlinkableToken(PrivateClickMeasurement&&);
@@ -91,6 +97,8 @@
     WeakPtr<NetworkSession> m_networkSession;
     Ref<NetworkProcess> m_networkProcess;
     PAL::SessionID m_sessionID;
+    mutable RefPtr<PCM::Store> m_store;
+    String m_storageDirectory;
     Function<void(NetworkLoadParameters&&, NetworkLoadCallback&&)> m_networkLoadFunction;
 
     struct AttributionReportTestConfig {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to