Title: [284051] trunk/Source/WebKit
Revision
284051
Author
[email protected]
Date
2021-10-12 15:48:22 -0700 (Tue, 12 Oct 2021)

Log Message

Reduce use of WebCore structures in adattributiond
https://bugs.webkit.org/show_bug.cgi?id=231617

Patch by Alex Christensen <[email protected]> on 2021-10-12
Reviewed by Chris Dumez.

In order to reduce the memory use of adattributiond, I'm planning to have it not link WebKit.framework.
This is progress towards that.
I use a RunLoop::Timer instead of a WebCore::Timer, which does the same thing on the main thread.
I use a WTF::String to represent the error description or lack thereof instead of sending the whole error.
I stop sending the response, because it was unused.

* NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.cpp:
(WebKit::PrivateClickMeasurementManager::PrivateClickMeasurementManager):
(WebKit::PrivateClickMeasurementManager::getTokenPublicKey):
(WebKit::PrivateClickMeasurementManager::getSignedUnlinkableToken):
(WebKit::PrivateClickMeasurementManager::attribute):
(WebKit::PrivateClickMeasurementManager::fireConversionRequestImpl):
* NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.h:
* NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementNetworkLoader.cpp:
(WebKit::PCM::NetworkLoader::start):
* NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementNetworkLoader.h:
* NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementNetworkLoaderCocoa.mm:
(WebKit::PCM::NetworkLoader::start):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (284050 => 284051)


--- trunk/Source/WebKit/ChangeLog	2021-10-12 22:47:34 UTC (rev 284050)
+++ trunk/Source/WebKit/ChangeLog	2021-10-12 22:48:22 UTC (rev 284051)
@@ -1,3 +1,29 @@
+2021-10-12  Alex Christensen  <[email protected]>
+
+        Reduce use of WebCore structures in adattributiond
+        https://bugs.webkit.org/show_bug.cgi?id=231617
+
+        Reviewed by Chris Dumez.
+
+        In order to reduce the memory use of adattributiond, I'm planning to have it not link WebKit.framework.
+        This is progress towards that.
+        I use a RunLoop::Timer instead of a WebCore::Timer, which does the same thing on the main thread.
+        I use a WTF::String to represent the error description or lack thereof instead of sending the whole error.
+        I stop sending the response, because it was unused.
+
+        * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.cpp:
+        (WebKit::PrivateClickMeasurementManager::PrivateClickMeasurementManager):
+        (WebKit::PrivateClickMeasurementManager::getTokenPublicKey):
+        (WebKit::PrivateClickMeasurementManager::getSignedUnlinkableToken):
+        (WebKit::PrivateClickMeasurementManager::attribute):
+        (WebKit::PrivateClickMeasurementManager::fireConversionRequestImpl):
+        * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.h:
+        * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementNetworkLoader.cpp:
+        (WebKit::PCM::NetworkLoader::start):
+        * NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementNetworkLoader.h:
+        * NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementNetworkLoaderCocoa.mm:
+        (WebKit::PCM::NetworkLoader::start):
+
 2021-10-12  Ryan Haddad  <[email protected]>
 
         Unreviewed, reverting r284022.

Modified: trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.cpp (284050 => 284051)


--- trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.cpp	2021-10-12 22:47:34 UTC (rev 284050)
+++ trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.cpp	2021-10-12 22:48:22 UTC (rev 284051)
@@ -54,7 +54,7 @@
 constexpr Seconds debugModeSecondsUntilSend { 10_s };
 
 PrivateClickMeasurementManager::PrivateClickMeasurementManager(UniqueRef<PCM::Client>&& client, const String& storageDirectory)
-    : m_firePendingAttributionRequestsTimer(*this, &PrivateClickMeasurementManager::firePendingAttributionRequests)
+    : m_firePendingAttributionRequestsTimer(RunLoop::main(), this, &PrivateClickMeasurementManager::firePendingAttributionRequests)
     , m_storageDirectory(storageDirectory)
     , m_client(WTFMove(client))
 {
@@ -136,12 +136,12 @@
     RELEASE_LOG_INFO(PrivateClickMeasurement, "About to fire a token public key request.");
     m_client->broadcastConsoleMessage(MessageLevel::Log, "[Private Click Measurement] About to fire a token public key request."_s);
 
-    PCM::NetworkLoader::start(WTFMove(tokenPublicKeyURL), nullptr, pcmDataCarried, [weakThis = WeakPtr { *this }, this, attribution = WTFMove(attribution), callback = WTFMove(callback)] (auto& error, auto& response, auto& jsonObject) mutable {
+    PCM::NetworkLoader::start(WTFMove(tokenPublicKeyURL), nullptr, pcmDataCarried, [weakThis = WeakPtr { *this }, this, attribution = WTFMove(attribution), callback = WTFMove(callback)] (auto& errorDescription, auto& jsonObject) mutable {
         if (!weakThis)
             return;
 
-        if (!error.isNull()) {
-            m_client->broadcastConsoleMessage(MessageLevel::Error, makeString("[Private Click Measurement] Received error: '"_s, error.localizedDescription(), "' for token public key request."_s));
+        if (!errorDescription.isNull()) {
+            m_client->broadcastConsoleMessage(MessageLevel::Error, makeString("[Private Click Measurement] Received error: '"_s, errorDescription, "' for token public key request."_s));
             return;
         }
 
@@ -179,12 +179,12 @@
     RELEASE_LOG_INFO(PrivateClickMeasurement, "About to fire a unlinkable token signing request.");
     m_client->broadcastConsoleMessage(MessageLevel::Log, "[Private Click Measurement] About to fire a unlinkable token signing request."_s);
 
-    PCM::NetworkLoader::start(WTFMove(tokenSignatureURL), measurement.tokenSignatureJSON(), pcmDataCarried, [weakThis = WeakPtr { *this }, this, measurement = WTFMove(measurement)] (auto& error, auto& response, auto& jsonObject) mutable {
+    PCM::NetworkLoader::start(WTFMove(tokenSignatureURL), measurement.tokenSignatureJSON(), pcmDataCarried, [weakThis = WeakPtr { *this }, this, measurement = WTFMove(measurement)] (auto& errorDescription, auto& jsonObject) mutable {
         if (!weakThis)
             return;
 
-        if (!error.isNull()) {
-            m_client->broadcastConsoleMessage(MessageLevel::Error, makeString("[Private Click Measurement] Received error: '"_s, error.localizedDescription(), "' for secret token signing request."_s));
+        if (!errorDescription.isNull()) {
+            m_client->broadcastConsoleMessage(MessageLevel::Error, makeString("[Private Click Measurement] Received error: '"_s, errorDescription, "' for secret token signing request."_s));
             return;
         }
 
@@ -300,7 +300,7 @@
             if (!minSecondsUntilSend)
                 return;
 
-            if (m_firePendingAttributionRequestsTimer.isActive() && m_firePendingAttributionRequestsTimer.nextFireInterval() < *minSecondsUntilSend)
+            if (m_firePendingAttributionRequestsTimer.isActive() && m_firePendingAttributionRequestsTimer.secondsUntilFire() < *minSecondsUntilSend)
                 return;
 
             if (UNLIKELY(debugModeEnabled())) {
@@ -365,12 +365,12 @@
     RELEASE_LOG_INFO(PrivateClickMeasurement, "About to fire an attribution request.");
     m_client->broadcastConsoleMessage(MessageLevel::Log, "[Private Click Measurement] About to fire an attribution request."_s);
 
-    PCM::NetworkLoader::start(WTFMove(attributionURL), attribution.attributionReportJSON(), pcmDataCarried, [weakThis = WeakPtr { *this }, this](auto& error, auto& response, auto&) {
+    PCM::NetworkLoader::start(WTFMove(attributionURL), attribution.attributionReportJSON(), pcmDataCarried, [weakThis = WeakPtr { *this }, this](auto& errorDescription, auto&) {
         if (!weakThis)
             return;
 
-        if (!error.isNull())
-            m_client->broadcastConsoleMessage(MessageLevel::Error, makeString("[Private Click Measurement] Received error: '"_s, error.localizedDescription(), "' for ad click attribution request."_s));
+        if (!errorDescription.isNull())
+            m_client->broadcastConsoleMessage(MessageLevel::Error, makeString("[Private Click Measurement] Received error: '"_s, errorDescription, "' for ad click attribution request."_s));
     });
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.h (284050 => 284051)


--- trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.h	2021-10-12 22:47:34 UTC (rev 284050)
+++ trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.h	2021-10-12 22:48:22 UTC (rev 284051)
@@ -83,7 +83,7 @@
     bool featureEnabled() const;
     bool debugModeEnabled() const;
 
-    WebCore::Timer m_firePendingAttributionRequestsTimer;
+    RunLoop::Timer<PrivateClickMeasurementManager> m_firePendingAttributionRequestsTimer;
     bool m_isRunningTest { false };
     std::optional<URL> m_tokenPublicKeyURLForTesting;
     std::optional<URL> m_tokenSignatureURLForTesting;

Modified: trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementNetworkLoader.cpp (284050 => 284051)


--- trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementNetworkLoader.cpp	2021-10-12 22:47:34 UTC (rev 284050)
+++ trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementNetworkLoader.cpp	2021-10-12 22:48:22 UTC (rev 284051)
@@ -38,7 +38,7 @@
 void NetworkLoader::start(URL&&, RefPtr<JSON::Object>&&, WebCore::PrivateClickMeasurement::PcmDataCarried, Callback&& completionHandler)
 {
     notImplemented();
-    completionHandler({ }, { }, { });
+    completionHandler({ }, { });
 }
 
 void NetworkLoader::allowTLSCertificateChainForLocalPCMTesting(const WebCore::CertificateInfo&)

Modified: trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementNetworkLoader.h (284050 => 284051)


--- trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementNetworkLoader.h	2021-10-12 22:47:34 UTC (rev 284050)
+++ trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementNetworkLoader.h	2021-10-12 22:48:22 UTC (rev 284051)
@@ -42,7 +42,7 @@
 class NetworkLoader {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    using Callback = CompletionHandler<void(const WebCore::ResourceError&, const WebCore::ResourceResponse&, const RefPtr<JSON::Object>&)>;
+    using Callback = CompletionHandler<void(const String&, const RefPtr<JSON::Object>&)>;
     static void start(URL&&, RefPtr<JSON::Object>&&, WebCore::PrivateClickMeasurement::PcmDataCarried, Callback&&);
     static void allowTLSCertificateChainForLocalPCMTesting(const WebCore::CertificateInfo&);
 };

Modified: trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementNetworkLoaderCocoa.mm (284050 => 284051)


--- trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementNetworkLoaderCocoa.mm	2021-10-12 22:47:34 UTC (rev 284050)
+++ trunk/Source/WebKit/NetworkProcess/PrivateClickMeasurement/cocoa/PrivateClickMeasurementNetworkLoaderCocoa.mm	2021-10-12 22:48:22 UTC (rev 284051)
@@ -112,7 +112,7 @@
     // Prevent contacting non-local servers when a test certificate chain is used for 127.0.0.1.
     // FIXME: Use a proxy server to have tests cover the reports sent to the destination, too.
     if (allowedLocalTestServerTrust() && url.host() != "127.0.0.1")
-        return callback({ }, { }, { });
+        return callback({ }, { });
 
     auto request = adoptNS([[NSMutableURLRequest alloc] initWithURL:url]);
     [request setValue:WebCore::HTTPHeaderValues::maxAge0() forHTTPHeaderField:@"Cache-Control"];
@@ -129,10 +129,10 @@
     NSURLSessionDataTask *task = [statelessSessionWithoutRedirects() dataTaskWithRequest:request.get() completionHandler:makeBlockPtr([callback = WTFMove(callback), identifier](NSData *data, NSURLResponse *response, NSError *error) mutable {
         taskMap().remove(identifier);
         if (error)
-            return callback(error, { }, { });
+            return callback(error.localizedDescription, { });
         if (auto jsonValue = JSON::Value::parseJSON(String::fromUTF8(static_cast<const LChar*>(data.bytes), data.length)))
-            return callback({ }, response, jsonValue->asObject());
-        callback({ }, response, nullptr);
+            return callback({ }, jsonValue->asObject());
+        callback({ }, nullptr);
     }).get()];
     [task resume];
     taskMap().add(identifier, task);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to