Bug 231679

Summary: Drop makeWeakPtr() and use WeakPtr { } directly
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: Web Template FrameworkAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, achristensen, andresg_22, apinheiro, benjamin, berto, cfleizach, cgarcia, changseok, cmarcelo, darin, dmazzoni, eric.carlson, esprehn+autocc, ews-watchlist, ggaren, glenn, gustavo, gyuyoung.kim, hi, japhet, jbedard, jcraig, jdiggs, jer.noble, jiewen_tan, joepeck, kangil.han, mifenton, mkwst, pangle, philipj, samuel_white, sam, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 231580    
Bug Blocks:    
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
none
Patch none

Description Chris Dumez 2021-10-13 09:11:32 PDT
Drop makeWeakPtr() and use WeakPtr { } directly.
Comment 1 Chris Dumez 2021-10-13 09:48:10 PDT
Created attachment 441093 [details]
Patch
Comment 2 EWS Watchlist 2021-10-13 09:49:00 PDT
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See https://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
Comment 3 Chris Dumez 2021-10-13 10:08:08 PDT
Created attachment 441095 [details]
Patch
Comment 4 Chris Dumez 2021-10-13 10:27:18 PDT
Created attachment 441096 [details]
Patch
Comment 5 Chris Dumez 2021-10-13 13:37:14 PDT
Created attachment 441128 [details]
Patch
Comment 6 Darin Adler 2021-10-13 15:17:57 PDT
Comment on attachment 441128 [details]
Patch

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

> Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp:233
> +    gpuProcess.audioSessionManager().session().setRoutingArbitrationClient(WeakPtr { m_routingArbitrator.get() });

Can we leave out the explicit conversion to WeakPtr? I saw many other cases where it seems we were able to do that.

> Source/WebKit/GPUProcess/media/RemoteCDMInstanceProxy.cpp:56
> +    m_instance->setClient(static_cast<CDMInstanceClient&>(*this));

Why is the static_cast needed? What compilation failure do we get without the cast?
Comment 7 Chris Dumez 2021-10-13 15:20:55 PDT
Comment on attachment 441128 [details]
Patch

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

>> Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp:233
>> +    gpuProcess.audioSessionManager().session().setRoutingArbitrationClient(WeakPtr { m_routingArbitrator.get() });
> 
> Can we leave out the explicit conversion to WeakPtr? I saw many other cases where it seems we were able to do that.

I had initially tried to drop the explicit conversion but it failed to build so I put it back.

The issue is that setRoutingArbitrationClient() takes in a `WeakPtr<AudioSessionRoutingArbitrationClient>&&`, but AudioSessionRoutingArbitrationClient doesn't subclass CanMakeWeakPtr (its subclasses do). It is a bit weird it was implemented this way. I tried not to refactor the code too much in this patch.
Comment 8 Chris Dumez 2021-10-13 15:23:29 PDT
Comment on attachment 441128 [details]
Patch

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

>> Source/WebKit/GPUProcess/media/RemoteCDMInstanceProxy.cpp:56
>> +    m_instance->setClient(static_cast<CDMInstanceClient&>(*this));
> 
> Why is the static_cast needed? What compilation failure do we get without the cast?

The issue is that RemoteCDMInstanceProxy inherits CanMakeWeakPtr<> from 2 base classes, this cast resolves the ambiguity. We could also resolve the ambiguity with a couple of `using` statements in the RemoteCDMInstanceProxy header too though.
Comment 9 Darin Adler 2021-10-13 15:34:07 PDT
Comment on attachment 441128 [details]
Patch

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

>>> Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp:233
>>> +    gpuProcess.audioSessionManager().session().setRoutingArbitrationClient(WeakPtr { m_routingArbitrator.get() });
>> 
>> Can we leave out the explicit conversion to WeakPtr? I saw many other cases where it seems we were able to do that.
> 
> I had initially tried to drop the explicit conversion but it failed to build so I put it back.
> 
> The issue is that setRoutingArbitrationClient() takes in a `WeakPtr<AudioSessionRoutingArbitrationClient>&&`, but AudioSessionRoutingArbitrationClient doesn't subclass CanMakeWeakPtr (its subclasses do). It is a bit weird it was implemented this way. I tried not to refactor the code too much in this patch.

I am kind of surprised that works; can’t really figure out how it does. How can WeakPtr<AudioSessionRoutingArbitrationClient> member functions successfully compile? I guess it’s down to the implementation internals of WeakPtr.

After landing this, it seems like we should streamline this code by moving CanMakeWeakPtr into AudioSessionRoutingArbitrationClient unless that would lead to derived classes that inherit from two different CanMakeWeakPtr bases.

>>> Source/WebKit/GPUProcess/media/RemoteCDMInstanceProxy.cpp:56
>>> +    m_instance->setClient(static_cast<CDMInstanceClient&>(*this));
>> 
>> Why is the static_cast needed? What compilation failure do we get without the cast?
> 
> The issue is that RemoteCDMInstanceProxy inherits CanMakeWeakPtr<> from 2 base classes, this cast resolves the ambiguity. We could also resolve the ambiguity with a couple of `using` statements in the RemoteCDMInstanceProxy header too though.

I wouldn’t block landing the patch over this; on the other hand, I think the using statements would be a more elegant solution.
Comment 10 Chris Dumez 2021-10-13 16:05:21 PDT
Created attachment 441155 [details]
Patch
Comment 11 Chris Dumez 2021-10-13 16:09:26 PDT
(In reply to Chris Dumez from comment #10)
> Created attachment 441155 [details]
> Patch

I made the 2 suggested changes as they were painless.
Comment 12 EWS 2021-10-13 18:46:33 PDT
Committed r284142 (242962@main): <https://commits.webkit.org/242962@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 441155 [details].
Comment 13 Radar WebKit Bug Importer 2021-10-13 18:47:20 PDT
<rdar://problem/84227975>
Comment 14 Chris Dumez 2021-10-14 07:49:13 PDT
Follow-up fix in https://commits.webkit.org/r284160 to address some assertions on Mac-wk1 debug bots.