Bug 196934

Summary: Add prioritization of ad click conversions and cleaning of sent ad click conversions
Product: WebKit Reporter: John Wilander <wilander>
Component: WebKit Misc.Assignee: John Wilander <wilander>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, cdumez, commit-queue, dbates, ews-watchlist, japhet, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=196838
Attachments:
Description Flags
Patch
none
Patch none

Description John Wilander 2019-04-15 14:29:34 PDT
We should clean the Map in WebKit::AdClickAttributionManager from attributions that have already been converted and sent out.

The fix should cover these comments on the patch in https://bugs.webkit.org/show_bug.cgi?id=196838:

Instead of having one big m_adClickAttributionMap map, it might be better to have two maps:
- One for not yet converted ad click attributions
- One for converted ad click attributions that are pending being sent.
Here, we would only iterate over the second one, which would make earliestTimeToSend always available.

Maybe that would call for two structures, one with an earliestTimeToSend and one without.
Comment 1 Radar WebKit Bug Importer 2019-04-15 14:32:21 PDT
<rdar://problem/49917773>
Comment 2 John Wilander 2019-04-16 19:24:51 PDT
Created attachment 367598 [details]
Patch
Comment 3 Chris Dumez 2019-04-17 10:18:29 PDT
Comment on attachment 367598 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=367598&action=review

> Source/WebCore/loader/AdClickAttribution.h:144
> +        : registrableDomain { WTFMove(domain) }

Bad indentation.

> Source/WebKit/NetworkProcess/AdClickAttributionManager.cpp:74
> +    auto didConvertAttribution = false;

bool

> Source/WebKit/NetworkProcess/AdClickAttributionManager.cpp:79
> +        if (sourceIter->value.contains(destination)) {

You're doing a double lookup here, first for contains() then for take(). You can avoid this by using find() instead.

> Source/WebKit/NetworkProcess/AdClickAttributionManager.h:74
> +    HashMap<Source, DestinationMap> m_convertedAdClickAttributionMap;

Could these be written as follows?
HashMap<std::pair<Source, Destination>, AdClickAttribution> ?

If possible, it seems like it'd be simpler to use and easier to reason about.
Comment 4 John Wilander 2019-04-17 10:47:09 PDT
(In reply to Chris Dumez from comment #3)
> Comment on attachment 367598 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=367598&action=review
> 
> > Source/WebCore/loader/AdClickAttribution.h:144
> > +        : registrableDomain { WTFMove(domain) }
> 
> Bad indentation.

Will fix.

> > Source/WebKit/NetworkProcess/AdClickAttributionManager.cpp:74
> > +    auto didConvertAttribution = false;
> 
> bool

Will fix.

> > Source/WebKit/NetworkProcess/AdClickAttributionManager.cpp:79
> > +        if (sourceIter->value.contains(destination)) {
> 
> You're doing a double lookup here, first for contains() then for take(). You
> can avoid this by using find() instead.

Ah. This was a left over from the when I had the problems with the copy of the ref-counted string. Will fix.

> > Source/WebKit/NetworkProcess/AdClickAttributionManager.h:74
> > +    HashMap<Source, DestinationMap> m_convertedAdClickAttributionMap;
> 
> Could these be written as follows?
> HashMap<std::pair<Source, Destination>, AdClickAttribution> ?
> 
> If possible, it seems like it'd be simpler to use and easier to reason about.

I think so. I discussed moving to a std::pair it with Joe last night. I'll take a stab at it.

Thanks!
Comment 5 John Wilander 2019-04-17 13:40:28 PDT
Created attachment 367672 [details]
Patch
Comment 6 John Wilander 2019-04-17 13:41:21 PDT
Comment on attachment 367672 [details]
Patch

Just letting it run on EWS to see that everything is OK before landing.
Comment 7 WebKit Commit Bot 2019-04-17 14:47:10 PDT
Comment on attachment 367672 [details]
Patch

Clearing flags on attachment: 367672

Committed r244402: <https://trac.webkit.org/changeset/244402>
Comment 8 WebKit Commit Bot 2019-04-17 14:47:12 PDT
All reviewed patches have been landed.  Closing bug.