Bug 214896 - ProcessThrottler should register itself as client to its new assertion if already registered to the old assertion
Summary: ProcessThrottler should register itself as client to its new assertion if alr...
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Page Loading (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-07-28 14:36 PDT by youenn fablet
Modified: 2020-08-03 00:53 PDT (History)
3 users (show)

See Also:


Attachments
Patch (2.29 KB, patch)
2020-07-28 14:41 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (7.26 KB, patch)
2020-07-29 02:30 PDT, youenn fablet
cdumez: review-
cdumez: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2020-07-28 14:36:44 PDT
ProcessThrottler should register itself as client to its new assertion if already registered to the old assertion
Comment 1 youenn fablet 2020-07-28 14:41:15 PDT
Created attachment 405416 [details]
Patch
Comment 2 Chris Dumez 2020-07-28 14:49:59 PDT
Comment on attachment 405416 [details]
Patch

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

> Source/WebKit/UIProcess/ProcessThrottler.cpp:138
> +        m_assertion->setClient(*this);

Good catch but I think this should be done unconditionally.
Comment 3 Chris Dumez 2020-07-28 14:51:50 PDT
Comment on attachment 405416 [details]
Patch

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

>> Source/WebKit/UIProcess/ProcessThrottler.cpp:138
>> +        m_assertion->setClient(*this);
> 
> Good catch but I think this should be done unconditionally.

Also we probably want to drop the m_assertion->setClient(*this) call in ProcessThrottler::didConnectToProcess()
Comment 4 Chris Dumez 2020-07-28 14:52:32 PDT
Comment on attachment 405416 [details]
Patch

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

> Source/WebKit/UIProcess/ProcessThrottler.cpp:129
> +    bool hasClient = !!m_assertion->client();

m_assertion can be null so this will crash.
Comment 5 youenn fablet 2020-07-29 02:30:42 PDT
Created attachment 405445 [details]
Patch
Comment 6 youenn fablet 2020-07-29 02:31:07 PDT
<rdar://problem/65138628>
Comment 7 Chris Dumez 2020-07-29 09:20:31 PDT
Comment on attachment 405445 [details]
Patch

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

> Source/WebKit/UIProcess/ProcessAssertion.h:69
> +    ProcessAssertion(ProcessID, const String& reason, ProcessAssertionType, Client* = nullptr);

It is not really less error-prone if the parameter is optional.. Also, why can it be null?

> Source/WebKit/UIProcess/ProcessAssertion.h:100
> +    ProcessAndUIAssertion(ProcessID, const String& reason, ProcessAssertionType, Client* = nullptr);

Ditto.

> Source/WebKit/UIProcess/ProcessThrottler.h:54
> +class ProcessThrottler : public CanMakeWeakPtr<ProcessThrottler>, public ProcessAssertion::Client {

Why is this needed?
Comment 8 Chris Dumez 2020-07-29 09:24:11 PDT
Comment on attachment 405445 [details]
Patch

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

>> Source/WebKit/UIProcess/ProcessAssertion.h:69
>> +    ProcessAssertion(ProcessID, const String& reason, ProcessAssertionType, Client* = nullptr);
> 
> It is not really less error-prone if the parameter is optional.. Also, why can it be null?

Ok, I see that ProcessAssertion is used by other things than ProcessThrottler (like DownloadMap) and those don't set themselves as client. So using a raw pointer seems OK. That said, I don't think the parameter should be optional. If it is optional, then it is not any less error-prone than setting the client later using a setter.
Comment 9 youenn fablet 2020-07-29 09:36:05 PDT
> Ok, I see that ProcessAssertion is used by other things than
> ProcessThrottler (like DownloadMap) and those don't set themselves as
> client. So using a raw pointer seems OK. That said, I don't think the
> parameter should be optional. If it is optional, then it is not any less
> error-prone than setting the client later using a setter.

Plan is to make it mandatory and pass a ref instead of a pointer.
But this should be a follow-up because of other assertions (download and media ones at least).
Probably we should be also using a WeakPtr instead of a pointer.
Comment 10 youenn fablet 2020-07-29 09:36:25 PDT
Keeping it optional just reduces the size of the patch basically.
Comment 11 Chris Dumez 2020-07-29 09:36:49 PDT
(In reply to youenn fablet from comment #9)
> > Ok, I see that ProcessAssertion is used by other things than
> > ProcessThrottler (like DownloadMap) and those don't set themselves as
> > client. So using a raw pointer seems OK. That said, I don't think the
> > parameter should be optional. If it is optional, then it is not any less
> > error-prone than setting the client later using a setter.
> 
> Plan is to make it mandatory and pass a ref instead of a pointer.
> But this should be a follow-up because of other assertions (download and
> media ones at least).
> Probably we should be also using a WeakPtr instead of a pointer.

I think parameter should be mandatory. Clients can explicitly pass null for now.
Comment 12 Chris Dumez 2020-07-29 09:37:14 PDT
(In reply to youenn fablet from comment #10)
> Keeping it optional just reduces the size of the patch basically.

But makes it error prone so I am against it.
Comment 13 Chris Dumez 2020-07-29 09:53:19 PDT
(In reply to youenn fablet from comment #10)
> Keeping it optional just reduces the size of the patch basically.

There are not that many call sites and it is just an extra parameter. If you want to keep the patch small, then we don't have to do the refactoring at all and we can keep setClient().
Comment 14 Chris Dumez 2020-07-30 10:24:10 PDT
I uploaded a refactoring proposal at Bug 214976 because I don't like the Client interface. If you land this fix first, I will rebase my patch.
Comment 15 Chris Dumez 2020-07-30 10:28:28 PDT
(In reply to Chris Dumez from comment #14)
> I uploaded a refactoring proposal at Bug 214976 because I don't like the
> Client interface. If you land this fix first, I will rebase my patch.

My personal preference would be you landing the 2 line change to fix the bug here (moving setClient from didConnectToProcess to setAssertionType) and then doing the refactoring in Bug 214976.
Comment 16 youenn fablet 2020-08-03 00:53:31 PDT
Fixed by https://trac.webkit.org/r265162