Skip to content

Commit

Permalink
Deploy smart pointers in GPUConnectionToWebProcess.cpp
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=273600

Reviewed by Chris Dumez.

Deployed smart pointers in GPUConnectionToWebProcess.cpp as warned by the clang static analyzer.

* Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp:
(WebKit::m_preferences):
(WebKit::GPUConnectionToWebProcess::~GPUConnectionToWebProcess):
(WebKit::GPUConnectionToWebProcess::protectedGPUProcess const):
(WebKit::GPUConnectionToWebProcess::protectedLibWebRTCCodecsProxy const):
(WebKit::GPUConnectionToWebProcess::didClose):
(WebKit::GPUConnectionToWebProcess::allowsExitUnderMemoryPressure const):
(WebKit::GPUConnectionToWebProcess::terminateWebProcess):
(WebKit::GPUConnectionToWebProcess::lowMemoryHandler):
(WebKit::GPUConnectionToWebProcess::remoteMediaResourceManager):
(WebKit::GPUConnectionToWebProcess::protectedRemoteMediaResourceManager):
(WebKit::GPUConnectionToWebProcess::protectedSampleBufferDisplayLayerManager const):
(WebKit::GPUConnectionToWebProcess::audioSessionProxy):
(WebKit::GPUConnectionToWebProcess::releaseRenderingBackend):
(WebKit::GPUConnectionToWebProcess::createGraphicsContextGL):
(WebKit::GPUConnectionToWebProcess::releaseGraphicsContextGL):
(WebKit::GPUConnectionToWebProcess::protectedVideoFrameObjectHeap):
(WebKit::GPUConnectionToWebProcess::clearNowPlayingInfo):
(WebKit::GPUConnectionToWebProcess::setNowPlayingInfo):
(WebKit::GPUConnectionToWebProcess::updateSupportedRemoteCommands):
(WebKit::GPUConnectionToWebProcess::didReceiveRemoteControlCommand):
(WebKit::GPUConnectionToWebProcess::dispatchMessage):
(WebKit::GPUConnectionToWebProcess::mediaCacheDirectory const):
(WebKit::GPUConnectionToWebProcess::mediaKeysStorageDirectory const):
(WebKit::GPUConnectionToWebProcess::startCapturingAudio):
(WebKit::GPUConnectionToWebProcess::updateSampleBufferDisplayLayerBoundsAndPosition):
* Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h:
(WebKit::GPUConnectionToWebProcess::protectedConnection const):

Canonical link: https://commits.webkit.org/278250@main
  • Loading branch information
rniwa committed May 2, 2024
1 parent cdf0e8a commit 4365e51
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 33 deletions.
97 changes: 64 additions & 33 deletions Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
#include "RemoteVideoFrameObjectHeap.h"
#endif

#define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, (&connection()))
#define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, (protectedConnection().ptr()))

namespace WebKit {
using namespace WebCore;
Expand Down Expand Up @@ -325,7 +325,7 @@ GPUConnectionToWebProcess::GPUConnectionToWebProcess(GPUProcess& gpuProcess, Web

WebKit::GPUProcessConnectionInfo info {
#if HAVE(AUDIT_TOKEN)
gpuProcess.parentProcessConnection()->getAuditToken(),
gpuProcess.protectedParentProcessConnection()->getAuditToken(),
#endif
#if ENABLE(VP9)
hasVP9HardwareDecoder,
Expand All @@ -334,7 +334,7 @@ GPUConnectionToWebProcess::GPUConnectionToWebProcess(GPUProcess& gpuProcess, Web
hasAV1HardwareDecoder
#endif
};
m_connection->send(Messages::GPUProcessConnection::DidInitialize(info), 0);
protectedConnection()->send(Messages::GPUProcessConnection::DidInitialize(info), 0);
++gObjectCountForTesting;
}

Expand All @@ -345,12 +345,24 @@ GPUConnectionToWebProcess::~GPUConnectionToWebProcess()
m_connection->invalidate();

#if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
m_sampleBufferDisplayLayerManager->close();
protectedSampleBufferDisplayLayerManager()->close();
#endif

--gObjectCountForTesting;
}

Ref<GPUProcess> GPUConnectionToWebProcess::protectedGPUProcess() const
{
return m_gpuProcess.copyRef();
}

#if PLATFORM(COCOA) && USE(LIBWEBRTC)
Ref<LibWebRTCCodecsProxy> GPUConnectionToWebProcess::protectedLibWebRTCCodecsProxy() const
{
return *m_libWebRTCCodecsProxy.get();
}
#endif

Ref<RemoteSharedResourceCache> GPUConnectionToWebProcess::sharedResourceCache()
{
if (!m_sharedResourceCache)
Expand Down Expand Up @@ -379,7 +391,7 @@ void GPUConnectionToWebProcess::didClose(IPC::Connection& connection)
userMediaCaptureManagerProxy->close();
#endif
#if ENABLE(VIDEO)
m_videoFrameObjectHeap->close();
protectedVideoFrameObjectHeap()->close();
m_remoteMediaPlayerManagerProxy->clear();
#endif
// RemoteRenderingBackend objects ref their GPUConnectionToWebProcess so we need to make sure
Expand Down Expand Up @@ -409,11 +421,12 @@ void GPUConnectionToWebProcess::didClose(IPC::Connection& connection)
RemoteLegacyCDMFactoryProxy& legacyCdmFactoryProxy();
#endif

if (m_remoteMediaResourceManager)
m_remoteMediaResourceManager->stopListeningForIPC();
if (RefPtr remoteMediaResourceManager = m_remoteMediaResourceManager)
remoteMediaResourceManager->stopListeningForIPC();

gpuProcess().connectionToWebProcessClosed(connection);
gpuProcess().removeGPUConnectionToWebProcess(*this); // May destroy |this|.
Ref gpuProcess = this->gpuProcess();
gpuProcess->connectionToWebProcessClosed(connection);
gpuProcess->removeGPUConnectionToWebProcess(*this); // May destroy |this|.
}

#if HAVE(VISIBILITY_PROPAGATION_VIEW)
Expand Down Expand Up @@ -486,7 +499,7 @@ bool GPUConnectionToWebProcess::allowsExitUnderMemoryPressure() const
return false;
if (m_audioMediaStreamTrackRendererInternalUnitManager && m_audioMediaStreamTrackRendererInternalUnitManager->hasUnits())
return false;
if (!m_sampleBufferDisplayLayerManager->allowsExitUnderMemoryPressure())
if (!protectedSampleBufferDisplayLayerManager()->allowsExitUnderMemoryPressure())
return false;
#endif
#if PLATFORM(COCOA) && ENABLE(MEDIA_RECORDER)
Expand All @@ -506,7 +519,7 @@ bool GPUConnectionToWebProcess::allowsExitUnderMemoryPressure() const
return false;
#endif
#if PLATFORM(COCOA) && USE(LIBWEBRTC)
if (!m_libWebRTCCodecsProxy->allowsExitUnderMemoryPressure())
if (!protectedLibWebRTCCodecsProxy()->allowsExitUnderMemoryPressure())
return false;
#endif
return true;
Expand Down Expand Up @@ -534,15 +547,15 @@ void GPUConnectionToWebProcess::didReceiveInvalidMessage(IPC::Connection& connec

void GPUConnectionToWebProcess::terminateWebProcess()
{
gpuProcess().parentProcessConnection()->send(Messages::GPUProcessProxy::TerminateWebProcess(m_webProcessIdentifier), 0);
gpuProcess().protectedParentProcessConnection()->send(Messages::GPUProcessProxy::TerminateWebProcess(m_webProcessIdentifier), 0);
}

void GPUConnectionToWebProcess::lowMemoryHandler(Critical critical, Synchronous synchronous)
{
for (auto& remoteRenderingBackend : m_remoteRenderingBackendMap.values())
remoteRenderingBackend->lowMemoryHandler(critical, synchronous);
#if ENABLE(VIDEO)
m_videoFrameObjectHeap->lowMemoryHandler();
protectedVideoFrameObjectHeap()->lowMemoryHandler();
#endif
}

Expand All @@ -562,15 +575,26 @@ RemoteMediaResourceManager& GPUConnectionToWebProcess::remoteMediaResourceManage
assertIsMainThread();

if (!m_remoteMediaResourceManager) {
m_remoteMediaResourceManager = RemoteMediaResourceManager::create();
m_remoteMediaResourceManager->initializeConnection(&connection());
Ref manager = RemoteMediaResourceManager::create();
manager->initializeConnection(protectedConnection().ptr());
m_remoteMediaResourceManager = WTFMove(manager);
}

return *m_remoteMediaResourceManager;
}

Ref<RemoteMediaResourceManager> GPUConnectionToWebProcess::protectedRemoteMediaResourceManager()
{
return remoteMediaResourceManager();
}
#endif

#if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
Ref<RemoteSampleBufferDisplayLayerManager> GPUConnectionToWebProcess::protectedSampleBufferDisplayLayerManager() const
{
return m_sampleBufferDisplayLayerManager.copyRef();
}

UserMediaCaptureManagerProxy& GPUConnectionToWebProcess::userMediaCaptureManagerProxy()
{
if (!m_userMediaCaptureManagerProxy)
Expand Down Expand Up @@ -614,8 +638,8 @@ RemoteAudioSessionProxy& GPUConnectionToWebProcess::audioSessionProxy()
if (!m_audioSessionProxy) {
m_audioSessionProxy = RemoteAudioSessionProxy::create(*this).moveToUniquePtr();

auto auditToken = gpuProcess().parentProcessConnection()->getAuditToken();
gpuProcess().audioSessionManager().addProxy(*m_audioSessionProxy, auditToken);
auto auditToken = gpuProcess().protectedParentProcessConnection()->getAuditToken();
protectedGPUProcess()->audioSessionManager().addProxy(*m_audioSessionProxy, auditToken);
}
return *m_audioSessionProxy;
}
Expand Down Expand Up @@ -653,7 +677,7 @@ void GPUConnectionToWebProcess::releaseRenderingBackend(RenderingBackendIdentifi
{
bool found = m_remoteRenderingBackendMap.remove(renderingBackendIdentifier);
ASSERT_UNUSED(found, found);
gpuProcess().tryExitIfUnusedAndUnderMemoryPressure();
protectedGPUProcess()->tryExitIfUnusedAndUnderMemoryPressure();
}

#if ENABLE(WEBGL)
Expand All @@ -664,7 +688,7 @@ void GPUConnectionToWebProcess::createGraphicsContextGL(WebCore::GraphicsContext
auto it = m_remoteRenderingBackendMap.find(renderingBackendIdentifier);
if (it == m_remoteRenderingBackendMap.end())
return;
auto* renderingBackend = it->value.get();
RefPtr renderingBackend = it->value.get();

IPC::StreamServerConnectionParameters params;
#if ENABLE(IPC_TESTING_API)
Expand All @@ -685,7 +709,7 @@ void GPUConnectionToWebProcess::releaseGraphicsContextGL(GraphicsContextGLIdenti

m_remoteGraphicsContextGLMap.remove(graphicsContextGLIdentifier);
if (m_remoteGraphicsContextGLMap.isEmpty())
gpuProcess().tryExitIfUnusedAndUnderMemoryPressure();
protectedGPUProcess()->tryExitIfUnusedAndUnderMemoryPressure();
}

void GPUConnectionToWebProcess::releaseGraphicsContextGLForTesting(GraphicsContextGLIdentifier identifier)
Expand All @@ -703,6 +727,11 @@ RemoteRenderingBackend* GPUConnectionToWebProcess::remoteRenderingBackend(Render
}

#if ENABLE(VIDEO)
Ref<RemoteVideoFrameObjectHeap> GPUConnectionToWebProcess::protectedVideoFrameObjectHeap()
{
return *m_videoFrameObjectHeap.get();
}

void GPUConnectionToWebProcess::performWithMediaPlayerOnMainThread(MediaPlayerIdentifier identifier, Function<void(MediaPlayer&)>&& callback)
{
callOnMainRunLoopAndWait([&, gpuConnectionToWebProcess = Ref { *this }, identifier] {
Expand Down Expand Up @@ -748,14 +777,15 @@ void GPUConnectionToWebProcess::releaseRemoteGPU(WebGPUIdentifier identifier)
void GPUConnectionToWebProcess::clearNowPlayingInfo()
{
m_isActiveNowPlayingProcess = false;
gpuProcess().nowPlayingManager().removeClient(*this);
protectedGPUProcess()->nowPlayingManager().removeClient(*this);
}

void GPUConnectionToWebProcess::setNowPlayingInfo(NowPlayingInfo&& nowPlayingInfo)
{
m_isActiveNowPlayingProcess = true;
gpuProcess().nowPlayingManager().addClient(*this);
gpuProcess().nowPlayingManager().setNowPlayingInfo(WTFMove(nowPlayingInfo));
Ref gpuProcess = this->gpuProcess();
gpuProcess->nowPlayingManager().addClient(*this);
gpuProcess->nowPlayingManager().setNowPlayingInfo(WTFMove(nowPlayingInfo));
updateSupportedRemoteCommands();
}

Expand All @@ -764,13 +794,14 @@ void GPUConnectionToWebProcess::updateSupportedRemoteCommands()
if (!m_isActiveNowPlayingProcess || !m_remoteRemoteCommandListener)
return;

gpuProcess().nowPlayingManager().setSupportsSeeking(m_remoteRemoteCommandListener->supportsSeeking());
gpuProcess().nowPlayingManager().setSupportedRemoteCommands(m_remoteRemoteCommandListener->supportedCommands());
Ref gpuProcess = this->gpuProcess();
gpuProcess->nowPlayingManager().setSupportsSeeking(m_remoteRemoteCommandListener->supportsSeeking());
gpuProcess->nowPlayingManager().setSupportedRemoteCommands(m_remoteRemoteCommandListener->supportedCommands());
}

void GPUConnectionToWebProcess::didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType type, const PlatformMediaSession::RemoteCommandArgument& argument)
{
connection().send(Messages::GPUProcessConnection::DidReceiveRemoteCommand(type, argument), 0);
protectedConnection()->send(Messages::GPUProcessConnection::DidReceiveRemoteCommand(type, argument), 0);
}

#if USE(AUDIO_SESSION)
Expand Down Expand Up @@ -885,7 +916,7 @@ bool GPUConnectionToWebProcess::dispatchMessage(IPC::Connection& connection, IPC
return true;
}
if (decoder.messageReceiverName() == Messages::RemoteMediaResourceManager::messageReceiverName()) {
remoteMediaResourceManager().didReceiveMessage(connection, decoder);
protectedRemoteMediaResourceManager()->didReceiveMessage(connection, decoder);
return true;
}
#endif
Expand Down Expand Up @@ -975,8 +1006,8 @@ bool GPUConnectionToWebProcess::dispatchMessage(IPC::Connection& connection, IPC
}
#endif
if (decoder.messageReceiverName() == Messages::RemoteRemoteCommandListenerProxy::messageReceiverName()) {
if (m_remoteRemoteCommandListener)
m_remoteRemoteCommandListener->didReceiveMessage(connection, decoder);
if (RefPtr listener = m_remoteRemoteCommandListener)
listener->didReceiveMessage(connection, decoder);
return true;
}
if (decoder.messageReceiverName() == Messages::RemoteSharedResourceCache::messageReceiverName()) {
Expand Down Expand Up @@ -1058,13 +1089,13 @@ bool GPUConnectionToWebProcess::dispatchSyncMessage(IPC::Connection& connection,

const String& GPUConnectionToWebProcess::mediaCacheDirectory() const
{
return m_gpuProcess->mediaCacheDirectory(m_sessionID);
return protectedGPUProcess()->mediaCacheDirectory(m_sessionID);
}

#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
const String& GPUConnectionToWebProcess::mediaKeysStorageDirectory() const
{
return m_gpuProcess->mediaKeysStorageDirectory(m_sessionID);
return protectedGPUProcess()->mediaKeysStorageDirectory(m_sessionID);
}
#endif

Expand Down Expand Up @@ -1092,7 +1123,7 @@ void GPUConnectionToWebProcess::updateCaptureOrigin(const WebCore::SecurityOrigi
#if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
void GPUConnectionToWebProcess::startCapturingAudio()
{
gpuProcess().processIsStartingToCaptureAudio(*this);
protectedGPUProcess()->processIsStartingToCaptureAudio(*this);
}

void GPUConnectionToWebProcess::processIsStartingToCaptureAudio(GPUConnectionToWebProcess& process)
Expand Down Expand Up @@ -1151,7 +1182,7 @@ void GPUConnectionToWebProcess::enableMockMediaSource()
#if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
void GPUConnectionToWebProcess::updateSampleBufferDisplayLayerBoundsAndPosition(SampleBufferDisplayLayerIdentifier identifier, WebCore::FloatRect bounds, std::optional<MachSendRight>&& fence)
{
m_sampleBufferDisplayLayerManager->updateSampleBufferDisplayLayerBoundsAndPosition(identifier, bounds, WTFMove(fence));
protectedSampleBufferDisplayLayerManager()->updateSampleBufferDisplayLayerBoundsAndPosition(identifier, bounds, WTFMove(fence));
}
#endif

Expand Down
10 changes: 10 additions & 0 deletions Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,13 @@ class GPUConnectionToWebProcess
Ref<IPC::Connection> protectedConnection() { return m_connection; }
IPC::MessageReceiverMap& messageReceiverMap() { return m_messageReceiverMap; }
GPUProcess& gpuProcess() { return m_gpuProcess.get(); }
Ref<GPUProcess> protectedGPUProcess() const;
WebCore::ProcessIdentifier webProcessIdentifier() const { return m_webProcessIdentifier; }
Ref<RemoteSharedResourceCache> sharedResourceCache();

#if ENABLE(VIDEO)
RemoteMediaResourceManager& remoteMediaResourceManager();
Ref<RemoteMediaResourceManager> protectedRemoteMediaResourceManager();
#endif

PAL::SessionID sessionID() const { return m_sessionID; }
Expand Down Expand Up @@ -246,6 +248,7 @@ class GPUConnectionToWebProcess
#endif

#if ENABLE(VIDEO)
Ref<RemoteVideoFrameObjectHeap> protectedVideoFrameObjectHeap();
void performWithMediaPlayerOnMainThread(WebCore::MediaPlayerIdentifier, Function<void(WebCore::MediaPlayer&)>&&);
#endif

Expand All @@ -261,10 +264,17 @@ class GPUConnectionToWebProcess
private:
GPUConnectionToWebProcess(GPUProcess&, WebCore::ProcessIdentifier, PAL::SessionID, IPC::Connection::Handle&&, GPUProcessConnectionParameters&&);

Ref<IPC::Connection> protectedConnection() const { return m_connection.copyRef(); }

#if PLATFORM(COCOA) && USE(LIBWEBRTC)
Ref<LibWebRTCCodecsProxy> protectedLibWebRTCCodecsProxy() const;
#endif

#if ENABLE(WEB_AUDIO)
RemoteAudioDestinationManager& remoteAudioDestinationManager();
#endif
#if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
Ref<RemoteSampleBufferDisplayLayerManager> protectedSampleBufferDisplayLayerManager() const;
UserMediaCaptureManagerProxy& userMediaCaptureManagerProxy();
RemoteAudioMediaStreamTrackRendererInternalUnitManager& audioMediaStreamTrackRendererInternalUnitManager();
#endif
Expand Down

0 comments on commit 4365e51

Please sign in to comment.