Skip to content
Permalink
Browse files
GPUProcess doesn't get notified of imminent process suspension
https://bugs.webkit.org/show_bug.cgi?id=239815

Reviewed by Tim Horton.

By defaults, ProcessThrottler in the UIProcess use a ProcessAndUIAssertion instance internally,
instead of a simple ProcessAssertion. This makes sure that a process assertion is taken on
behalf of the UIProcess as well, not just the child process. This also makes sure that when
the UIProcess has been in the background for too long and its assertion gets invalidated, we
release all ProcessAndUIAssertion instances as well.

The WebProcess and NetworkProcess were correctly using a ProcessAndUIAssertion. However, the
GPUProcess was passing `false` when constructing the ProcessThrottler, causing it to use a
simple ProcessAssertion. As a result, the GPUProcess would not get notified on imminent
suspension when the app has been running in the background for too long.

This patch aligns the behavior of the GPUProcess with the one of the NetworkProcess since
both processes are very similar.

* Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp:
(WebKit::GPUProcessProxy::GPUProcessProxy):
* Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::NetworkProcessProxy):
(WebKit::anyProcessPoolShouldTakeUIBackgroundAssertion): Deleted.
* Source/WebKit/UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::anyProcessPoolNeedsUIBackgroundAssertion):
* Source/WebKit/UIProcess/WebProcessPool.h:

Canonical link: https://commits.webkit.org/250076@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@293562 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Apr 28, 2022
1 parent 7e967ef commit d09a083b2e1f30ef825865340b536c78d09d423b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
@@ -130,7 +130,7 @@ static String gpuProcessCachesDirectory()

GPUProcessProxy::GPUProcessProxy()
: AuxiliaryProcessProxy()
, m_throttler(*this, false)
, m_throttler(*this, WebProcessPool::anyProcessPoolNeedsUIBackgroundAssertion())
#if ENABLE(MEDIA_STREAM)
, m_useMockCaptureDevices(MockRealtimeMediaSourceCenter::mockRealtimeMediaSourceCenterEnabled())
#endif
@@ -230,15 +230,6 @@ static bool anyProcessPoolAlwaysRunsAtBackgroundPriority()
return false;
}

static bool anyProcessPoolShouldTakeUIBackgroundAssertion()
{
for (auto& processPool : WebProcessPool::allProcessPools()) {
if (processPool->shouldTakeUIBackgroundAssertion())
return true;
}
return false;
}

NetworkProcessProxy::NetworkProcessProxy()
: AuxiliaryProcessProxy(anyProcessPoolAlwaysRunsAtBackgroundPriority(), networkProcessResponsivenessTimeout)
#if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
@@ -247,7 +238,7 @@ NetworkProcessProxy::NetworkProcessProxy()
#else
, m_customProtocolManagerClient(makeUniqueRef<API::CustomProtocolManagerClient>())
#endif
, m_throttler(*this, anyProcessPoolShouldTakeUIBackgroundAssertion())
, m_throttler(*this, WebProcessPool::anyProcessPoolNeedsUIBackgroundAssertion())
, m_cookieManager(makeUniqueRef<WebCookieManagerProxy>(*this))
{
connect();
@@ -2166,6 +2166,15 @@ void WebProcessPool::setUseSeparateServiceWorkerProcess(bool useSeparateServiceW
processPool->terminateServiceWorkers();
}

bool WebProcessPool::anyProcessPoolNeedsUIBackgroundAssertion()
{
for (auto& processPool : WebProcessPool::allProcessPools()) {
if (processPool->shouldTakeUIBackgroundAssertion())
return true;
}
return false;
}

#if ENABLE(SERVICE_WORKER)
size_t WebProcessPool::serviceWorkerProxiesCount() const
{
@@ -435,6 +435,7 @@ class WebProcessPool final

bool alwaysRunsAtBackgroundPriority() const { return m_alwaysRunsAtBackgroundPriority; }
bool shouldTakeUIBackgroundAssertion() const { return m_shouldTakeUIBackgroundAssertion; }
static bool anyProcessPoolNeedsUIBackgroundAssertion();

#if ENABLE(GAMEPAD)
void gamepadConnected(const UIGamepad&, WebCore::EventMakesGamepadsVisible);

0 comments on commit d09a083

Please sign in to comment.