Bug 173955

Summary: ResourceLoadObserver clean up
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebCore Misc.Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: bfulgham, buildbot, commit-queue, dbates, japhet, sam, wilander
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch sam: review+

Description Chris Dumez 2017-06-28 20:02:11 PDT
ResourceLoadObserver clean up: Modernize code a bit and get rid of unused variables.
Comment 1 Chris Dumez 2017-06-28 20:03:21 PDT
Created attachment 314098 [details]
Patch
Comment 2 Sam Weinig 2017-06-28 20:20:10 PDT
Comment on attachment 314098 [details]
Patch

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

> Source/WebCore/loader/ResourceLoadObserver.cpp:80
> +    m_queue->dispatch([this] {

Is this safe? What is keeping this alive?  Don't we usually do [protectedThis = makeRef(*this)] for things like this? (Same question for other queue usage.

> Source/WebCore/loader/ResourceLoadObserver.cpp:114
> +    return Settings::resourceLoadStatisticsEnabled() && !page->usesEphemeralSession() && m_store;

Not related to the cleanup, but why is this a static setting?
Comment 3 Chris Dumez 2017-06-28 20:22:31 PDT
Comment on attachment 314098 [details]
Patch

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

>> Source/WebCore/loader/ResourceLoadObserver.cpp:80
>> +    m_queue->dispatch([this] {
> 
> Is this safe? What is keeping this alive?  Don't we usually do [protectedThis = makeRef(*this)] for things like this? (Same question for other queue usage.

I guess this wasn't done in this class because ResourceLoadObserver is a singleton.

>> Source/WebCore/loader/ResourceLoadObserver.cpp:114
>> +    return Settings::resourceLoadStatisticsEnabled() && !page->usesEphemeralSession() && m_store;
> 
> Not related to the cleanup, but why is this a static setting?

question for Brent or John.
Comment 4 Brent Fulgham 2017-06-28 20:33:12 PDT
Comment on attachment 314098 [details]
Patch

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

R=me

>>> Source/WebCore/loader/ResourceLoadObserver.cpp:80
>>> +    m_queue->dispatch([this] {
>> 
>> Is this safe? What is keeping this alive?  Don't we usually do [protectedThis = makeRef(*this)] for things like this? (Same question for other queue usage.
> 
> I guess this wasn't done in this class because ResourceLoadObserver is a singleton.

Yeah, ResourceLoadObserver is NeverDestroyed.

>>> Source/WebCore/loader/ResourceLoadObserver.cpp:114
>>> +    return Settings::resourceLoadStatisticsEnabled() && !page->usesEphemeralSession() && m_store;
>> 
>> Not related to the cleanup, but why is this a static setting?
> 
> question for Brent or John.

It’s certainly a system-wide setting, but it really should be at the same level as cookie accept policy. I’m not tied to it being a static setting if there is a cleaner way to represent it,  It’s certainly not something we control on a page level.

> Source/WebCore/loader/ResourceLoadObserver.cpp:-616
> -    return primaryDomain;

Should we hold onto the comment here? (Use host if there is no TLD)

That’s not obvious to me, and might be surprising to others, too.
Comment 5 Sam Weinig 2017-06-28 20:36:09 PDT
(In reply to Chris Dumez from comment #3)
> Comment on attachment 314098 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=314098&action=review
> 
> >> Source/WebCore/loader/ResourceLoadObserver.cpp:80
> >> +    m_queue->dispatch([this] {
> > 
> > Is this safe? What is keeping this alive?  Don't we usually do [protectedThis = makeRef(*this)] for things like this? (Same question for other queue usage.
> 
> I guess this wasn't done in this class because ResourceLoadObserver is a
> singleton.

Ah. It's quite sad that we added another singleton. I've been working for a couple of years to make things owner (or at least shared ownership) by the page/view so separate users of WebKit in the same address space can not stomp on each other. Non-ephemeral session state is the white whale we haven't gotten to yet, but here lies another.
Comment 6 Brent Fulgham 2017-06-28 20:38:21 PDT
(In reply to Sam Weinig from comment #5)
> (In reply to Chris Dumez from comment #3)
> > Comment on attachment 314098 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=314098&action=review
> > 
> > >> Source/WebCore/loader/ResourceLoadObserver.cpp:80
> > >> +    m_queue->dispatch([this] {
> > > 
> > > Is this safe? What is keeping this alive?  Don't we usually do [protectedThis = makeRef(*this)] for things like this? (Same question for other queue usage.
> > 
> > I guess this wasn't done in this class because ResourceLoadObserver is a
> > singleton.
> 
> Ah. It's quite sad that we added another singleton. I've been working for a
> couple of years to make things owner (or at least shared ownership) by the
> page/view so separate users of WebKit in the same address space can not
> stomp on each other. Non-ephemeral session state is the white whale we
> haven't gotten to yet, but here lies another.

White whale! :)

I.m totally happy to change this to something better. We think this is a global setting, but maybe there are cases where we want to compartmentalize this more,
Comment 7 Sam Weinig 2017-06-28 20:43:36 PDT
(In reply to Brent Fulgham from comment #4)
> Comment on attachment 314098 [details]
> 
> >>> Source/WebCore/loader/ResourceLoadObserver.cpp:114
> >>> +    return Settings::resourceLoadStatisticsEnabled() && !page->usesEphemeralSession() && m_store;
> >> 
> >> Not related to the cleanup, but why is this a static setting?
> > 
> > question for Brent or John.
> 
> It’s certainly a system-wide setting, but it really should be at the same
> level as cookie accept policy. I’m not tied to it being a static setting if
> there is a cleaner way to represent it,  It’s certainly not something we
> control on a page level.

In WebCore, there really isn't supposed to be anything wider than the Page level. Network and storage policies might be shared among WKWebViews at the WebKit level (via WKPreferences or maybe one day, the WKWebSiteDataStore will hold them), but when you get down to WebCore, the goal is to allow Pages to be maintain that state for all the objects below it. Some of those come through Setting (or properties directly on Page, like SessionID), some though clients registered with the Page at its creation.
Comment 8 Sam Weinig 2017-06-28 20:44:20 PDT
(In reply to Brent Fulgham from comment #6)
> (In reply to Sam Weinig from comment #5)
> > (In reply to Chris Dumez from comment #3)
> > > Comment on attachment 314098 [details]
> > > Patch
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=314098&action=review
> > > 
> > > >> Source/WebCore/loader/ResourceLoadObserver.cpp:80
> > > >> +    m_queue->dispatch([this] {
> > > > 
> > > > Is this safe? What is keeping this alive?  Don't we usually do [protectedThis = makeRef(*this)] for things like this? (Same question for other queue usage.
> > > 
> > > I guess this wasn't done in this class because ResourceLoadObserver is a
> > > singleton.
> > 
> > Ah. It's quite sad that we added another singleton. I've been working for a
> > couple of years to make things owner (or at least shared ownership) by the
> > page/view so separate users of WebKit in the same address space can not
> > stomp on each other. Non-ephemeral session state is the white whale we
> > haven't gotten to yet, but here lies another.
> 
> White whale! :)
> 
> I.m totally happy to change this to something better. We think this is a
> global setting, but maybe there are cases where we want to compartmentalize
> this more,

What exactly do you mean by "we think this is a global setting"?  What makes a setting a good candidate for being global?
Comment 9 Chris Dumez 2017-06-28 20:55:33 PDT
Committed r218914: <http://trac.webkit.org/changeset/218914>