Add prioritization of ad click conversions and cleaning of sent ad click conversions
authorwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Apr 2019 21:47:04 +0000 (21:47 +0000)
committerwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Apr 2019 21:47:04 +0000 (21:47 +0000)
commitc0251d5c773f1f5b32ac504e0c403904c9b588b5
treed29bd370ee6e4fb9d89d50d9f9a9dee716528e2f
parentc1aac37a18b54b985ec2d2d55f42335b08834056
Add prioritization of ad click conversions and cleaning of sent ad click conversions
https://bugs.webkit.org/show_bug.cgi?id=196934
<rdar://problem/49917773>

Reviewed by Chris Dumez.

Source/WebCore:

Tests: http/tests/adClickAttribution/second-attribution-converted-with-higher-priority.html
       http/tests/adClickAttribution/second-attribution-converted-with-lower-priority.html
       http/tests/adClickAttribution/second-conversion-with-higher-priority.html
       http/tests/adClickAttribution/second-conversion-with-lower-priority.html

* loader/AdClickAttribution.cpp:
(WebCore::AdClickAttribution::hasHigherPriorityThan const):
    Added to facilitate priority comparison between two attributions.
* loader/AdClickAttribution.h:
(WebCore::AdClickAttribution::Destination::Destination):
    Added a WTF::HashTableDeletedValueType constructor and changed the copy constructor to
    a move constructor.
(WebCore::AdClickAttribution::isEmpty const):

Source/WebKit:

In this description, by "pair" I mean { AdClickAttribution::Source, AdClickAttribution::Destination }.

This patch adds handling of prioritization of conversions according to these rules:
- If we have a matching unconverted attribution, convert it. This consumes the conversion.
- If we have no previously converted attribution for this pair, just store.
- If we have a previously converted attribution for this pair, replace it if the new one has higher priority.
- If we had no matching unconverted attribution but do have a previously converted attribution for this
pair, re-convert the previously converted attribution to make sure the highest priority gets set.

This handling is in part done by dividing the previous m_adClickAttributionMap into
m_unconvertedAdClickAttributionMap and m_convertedAdClickAttributionMap, which now use a std::pair
as key instead of a nested HashMap.

This patch also changes AdClickAttributionManager::firePendingConversionRequests() so that it now
removes attributions which have been sent out.

Finally, AdClickAttributionManager::clear() no longer clears m_conversionBaseURLForTesting and
m_isRunningTest since doing so caused test flakiness. It is now up to the test case that sets these
members to also clear them when done.

* NetworkProcess/AdClickAttributionManager.cpp:
(WebKit::AdClickAttributionManager::storeUnconverted):
(WebKit::AdClickAttributionManager::convert):
(WebKit::AdClickAttributionManager::firePendingConversionRequests):
(WebKit::AdClickAttributionManager::clear):
(WebKit::AdClickAttributionManager::toString const):
(WebKit::AdClickAttributionManager::setConversionURLForTesting):
(WebKit::AdClickAttributionManager::ensureDestinationMapForSource): Deleted.
(WebKit::AdClickAttributionManager::store): Deleted.
* NetworkProcess/AdClickAttributionManager.h:
(WebKit::AdClickAttributionManager::AdClickAttributionManager):
(WebKit::AdClickAttributionManager::setConversionURLForTesting): Deleted.
* NetworkProcess/NetworkSession.cpp:
(WebKit::NetworkSession::storeAdClickAttribution):

LayoutTests:

* http/tests/adClickAttribution/attribution-conversion-through-cross-site-image-redirect-expected.txt:
* http/tests/adClickAttribution/attribution-conversion-through-image-redirect-with-priority-expected.txt:
* http/tests/adClickAttribution/attribution-conversion-through-image-redirect-without-priority-expected.txt:
* http/tests/adClickAttribution/resources/getConversionData.php:
* http/tests/adClickAttribution/resources/redirectToConversion.php:
* http/tests/adClickAttribution/second-attribution-converted-with-higher-priority-expected.txt: Added.
* http/tests/adClickAttribution/second-attribution-converted-with-higher-priority.html: Added.
* http/tests/adClickAttribution/second-attribution-converted-with-lower-priority-expected.txt: Added.
* http/tests/adClickAttribution/second-attribution-converted-with-lower-priority.html: Added.
* http/tests/adClickAttribution/second-conversion-with-higher-priority-expected.txt: Added.
* http/tests/adClickAttribution/second-conversion-with-higher-priority.html: Added.
* http/tests/adClickAttribution/second-conversion-with-lower-priority-expected.txt: Added.
* http/tests/adClickAttribution/second-conversion-with-lower-priority.html: Added.
* http/tests/adClickAttribution/send-attribution-conversion-request-expected.txt:
* http/tests/adClickAttribution/send-attribution-conversion-request.html:
* http/tests/adClickAttribution/store-ad-click-attribution-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244402 268f45cc-cd09-0410-ab3c-d52691b4dbfc
24 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/adClickAttribution/attribution-conversion-through-cross-site-image-redirect-expected.txt
LayoutTests/http/tests/adClickAttribution/attribution-conversion-through-image-redirect-with-priority-expected.txt
LayoutTests/http/tests/adClickAttribution/attribution-conversion-through-image-redirect-without-priority-expected.txt
LayoutTests/http/tests/adClickAttribution/resources/getConversionData.php
LayoutTests/http/tests/adClickAttribution/resources/redirectToConversion.php
LayoutTests/http/tests/adClickAttribution/second-attribution-converted-with-higher-priority-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/adClickAttribution/second-attribution-converted-with-higher-priority.html [new file with mode: 0644]
LayoutTests/http/tests/adClickAttribution/second-attribution-converted-with-lower-priority-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/adClickAttribution/second-attribution-converted-with-lower-priority.html [new file with mode: 0644]
LayoutTests/http/tests/adClickAttribution/second-conversion-with-higher-priority-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/adClickAttribution/second-conversion-with-higher-priority.html [new file with mode: 0644]
LayoutTests/http/tests/adClickAttribution/second-conversion-with-lower-priority-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/adClickAttribution/second-conversion-with-lower-priority.html [new file with mode: 0644]
LayoutTests/http/tests/adClickAttribution/send-attribution-conversion-request-expected.txt
LayoutTests/http/tests/adClickAttribution/send-attribution-conversion-request.html
LayoutTests/http/tests/adClickAttribution/store-ad-click-attribution-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/loader/AdClickAttribution.cpp
Source/WebCore/loader/AdClickAttribution.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/AdClickAttributionManager.cpp
Source/WebKit/NetworkProcess/AdClickAttributionManager.h
Source/WebKit/NetworkProcess/NetworkSession.cpp