Skip to content
Permalink
Browse files
Clean up / simplify ProcessAssertion code
https://bugs.webkit.org/show_bug.cgi?id=195394

Reviewed by Geoffrey Garen.

Clean up / simplify ProcessAssertion code to facilitate its maintenance and make it
less error-prone.

* Platform/IPC/mac/ConnectionMac.mm:
(IPC::ConnectionTerminationWatchdog::ConnectionTerminationWatchdog):
* UIProcess/ProcessAssertion.cpp:
(WebKit::ProcessAssertion::ProcessAssertion):
(WebKit::ProcessAssertion::setState):
* UIProcess/ProcessAssertion.h:
(WebKit::ProcessAssertion::Client::~Client):
(WebKit::ProcessAssertion::setClient):
(WebKit::ProcessAssertion::client):
* UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::didConnectToProcess):
* UIProcess/ProcessThrottler.h:
* UIProcess/ios/ProcessAssertionIOS.mm:
(-[WKProcessAssertionBackgroundTaskManager dealloc]):
(-[WKProcessAssertionBackgroundTaskManager addAssertionNeedingBackgroundTask:]):
(-[WKProcessAssertionBackgroundTaskManager removeAssertionNeedingBackgroundTask:]):
(-[WKProcessAssertionBackgroundTaskManager _notifyAssertionsOfImminentSuspension]):
(-[WKProcessAssertionBackgroundTaskManager _releaseBackgroundTask]):
(-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]):
(WebKit::ProcessAssertion::ProcessAssertion):
(WebKit::ProcessAssertion::processAssertionWasInvalidated):
(WebKit::ProcessAssertion::setState):
(WebKit::ProcessAndUIAssertion::updateRunInBackgroundCount):
(WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion):
(WebKit::ProcessAndUIAssertion::~ProcessAndUIAssertion):
(WebKit::ProcessAndUIAssertion::processAssertionWasInvalidated):
(WebKit::ProcessAndUIAssertion::setState):
(WebKit::ProcessAndUIAssertion::uiAssertionWillExpireImminently):

Canonical link: https://commits.webkit.org/209749@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242610 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Mar 7, 2019
1 parent 77b1bcf commit 91f7339477b3089587a1818c1ce79581696b715f
Showing 7 changed files with 135 additions and 195 deletions.
@@ -1,3 +1,42 @@
2019-03-07 Chris Dumez <cdumez@apple.com>

Clean up / simplify ProcessAssertion code
https://bugs.webkit.org/show_bug.cgi?id=195394

Reviewed by Geoffrey Garen.

Clean up / simplify ProcessAssertion code to facilitate its maintenance and make it
less error-prone.

* Platform/IPC/mac/ConnectionMac.mm:
(IPC::ConnectionTerminationWatchdog::ConnectionTerminationWatchdog):
* UIProcess/ProcessAssertion.cpp:
(WebKit::ProcessAssertion::ProcessAssertion):
(WebKit::ProcessAssertion::setState):
* UIProcess/ProcessAssertion.h:
(WebKit::ProcessAssertion::Client::~Client):
(WebKit::ProcessAssertion::setClient):
(WebKit::ProcessAssertion::client):
* UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::didConnectToProcess):
* UIProcess/ProcessThrottler.h:
* UIProcess/ios/ProcessAssertionIOS.mm:
(-[WKProcessAssertionBackgroundTaskManager dealloc]):
(-[WKProcessAssertionBackgroundTaskManager addAssertionNeedingBackgroundTask:]):
(-[WKProcessAssertionBackgroundTaskManager removeAssertionNeedingBackgroundTask:]):
(-[WKProcessAssertionBackgroundTaskManager _notifyAssertionsOfImminentSuspension]):
(-[WKProcessAssertionBackgroundTaskManager _releaseBackgroundTask]):
(-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]):
(WebKit::ProcessAssertion::ProcessAssertion):
(WebKit::ProcessAssertion::processAssertionWasInvalidated):
(WebKit::ProcessAssertion::setState):
(WebKit::ProcessAndUIAssertion::updateRunInBackgroundCount):
(WebKit::ProcessAndUIAssertion::ProcessAndUIAssertion):
(WebKit::ProcessAndUIAssertion::~ProcessAndUIAssertion):
(WebKit::ProcessAndUIAssertion::processAssertionWasInvalidated):
(WebKit::ProcessAndUIAssertion::setState):
(WebKit::ProcessAndUIAssertion::uiAssertionWillExpireImminently):

2019-03-07 Commit Queue <commit-queue@webkit.org>

Unreviewed, rolling out r242297.
@@ -92,7 +92,7 @@ static void createConnectionTerminationWatchdog(OSObjectPtr<xpc_connection_t>& x
: m_xpcConnection(xpcConnection)
, m_watchdogTimer(RunLoop::main(), this, &ConnectionTerminationWatchdog::watchdogTimerFired)
#if PLATFORM(IOS_FAMILY)
, m_assertion(std::make_unique<WebKit::ProcessAndUIAssertion>(xpc_connection_get_pid(m_xpcConnection.get()), WebKit::AssertionState::Background))
, m_assertion(std::make_unique<WebKit::ProcessAndUIAssertion>(xpc_connection_get_pid(m_xpcConnection.get()), "ConnectionTerminationWatchdog"_s, WebKit::AssertionState::Background))
#endif
{
m_watchdogTimer.startOneShot(interval);
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Apple Inc. All rights reserved.
* Copyright (C) 2014-2019 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,51 +26,22 @@
#include "config.h"
#include "ProcessAssertion.h"

#if !PLATFORM(IOS_FAMILY)
#if !PLATFORM(IOS_FAMILY) || PLATFORM(IOS_FAMILY_SIMULATOR)

namespace WebKit {

ProcessAssertion::ProcessAssertion(ProcessID, AssertionState assertionState, Function<void()>&&)
ProcessAssertion::ProcessAssertion(ProcessID, const String&, AssertionState assertionState)
: m_assertionState(assertionState)
{
}

ProcessAssertion::ProcessAssertion(ProcessID, const String&, AssertionState assertionState, Function<void()>&&)
: m_assertionState(assertionState)
{
}

ProcessAssertion::~ProcessAssertion()
{
}
ProcessAssertion::~ProcessAssertion() = default;

void ProcessAssertion::setState(AssertionState assertionState)
{
if (m_assertionState == assertionState)
return;

m_assertionState = assertionState;
}

ProcessAndUIAssertion::ProcessAndUIAssertion(ProcessID pid, AssertionState assertionState)
: ProcessAssertion(pid, assertionState)
{
}

ProcessAndUIAssertion::~ProcessAndUIAssertion()
{
}

void ProcessAndUIAssertion::setState(AssertionState assertionState)
{
ProcessAssertion::setState(assertionState);
}

void ProcessAndUIAssertion::setClient(ProcessAssertionClient& client)
{
ProcessAssertion::setClient(client);
}

}
} // namespace WebKit

#endif // !PLATFORM(IOS_FAMILY)
#endif // !PLATFORM(IOS_FAMILY) || PLATFORM(IOS_FAMILY_SIMULATOR)
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Apple Inc. All rights reserved.
* Copyright (C) 2014-2019 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -23,11 +23,11 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef ProcessAssertion_h
#define ProcessAssertion_h
#pragma once

#include <wtf/Function.h>
#include <wtf/ProcessID.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>

#if !OS(WINDOWS)
@@ -36,7 +36,6 @@

#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
#include <wtf/RetainPtr.h>
#include <wtf/WeakPtr.h>
OBJC_CLASS BKSProcessAssertion;
#endif

@@ -49,25 +48,20 @@ enum class AssertionState {
Foreground
};

class ProcessAssertionClient {
public:
virtual ~ProcessAssertionClient() { }
virtual void uiAssertionWillExpireImminently() = 0;
};

class ProcessAssertion
#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
: public CanMakeWeakPtr<ProcessAssertion>
#endif
{
class ProcessAssertion : public CanMakeWeakPtr<ProcessAssertion> {
WTF_MAKE_FAST_ALLOCATED;
public:
ProcessAssertion(ProcessID, AssertionState, Function<void()>&& invalidationCallback = { });
ProcessAssertion(ProcessID, const String& reason, AssertionState, Function<void()>&& invalidationCallback = { });
class Client {
public:
virtual ~Client() { }
virtual void uiAssertionWillExpireImminently() = 0;
};

ProcessAssertion(ProcessID, const String& reason, AssertionState);
virtual ~ProcessAssertion();

virtual void setClient(ProcessAssertionClient& client) { m_client = &client; }
ProcessAssertionClient* client() { return m_client; }
void setClient(Client& client) { m_client = &client; }
Client* client() { return m_client; }

AssertionState state() const { return m_assertionState; }
virtual void setState(AssertionState);
@@ -76,37 +70,40 @@ class ProcessAssertion
protected:
enum class Validity { No, Yes, Unset };
Validity validity() const { return m_validity; }

virtual void processAssertionWasInvalidated();
#endif

private:
#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
void markAsInvalidated();

RetainPtr<BKSProcessAssertion> m_assertion;
Validity m_validity { Validity::Unset };
Function<void()> m_invalidationCallback;
#endif
AssertionState m_assertionState;
ProcessAssertionClient* m_client { nullptr };
Client* m_client { nullptr };
};


#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)

class ProcessAndUIAssertion final : public ProcessAssertion {
public:
ProcessAndUIAssertion(ProcessID, AssertionState);
ProcessAndUIAssertion(ProcessID, const String& reason, AssertionState);
~ProcessAndUIAssertion();

void setClient(ProcessAssertionClient&) final;

void setState(AssertionState) final;
void uiAssertionWillExpireImminently();

#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
private:
void processAssertionWasInvalidated() final;
void updateRunInBackgroundCount();

bool m_isHoldingBackgroundAssertion { false };
#endif
bool m_isHoldingBackgroundTask { false };
};

}

#endif // ProcessAssertion_h
#else

using ProcessAndUIAssertion = ProcessAssertion;

#endif // PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)

} // namespace WebKit
@@ -103,9 +103,9 @@ void ProcessThrottler::didConnectToProcess(ProcessID pid)

m_suspendTimer.stop();
if (m_shouldTakeUIBackgroundAssertion)
m_assertion = std::make_unique<ProcessAndUIAssertion>(pid, assertionState());
m_assertion = std::make_unique<ProcessAndUIAssertion>(pid, "Web content visibility"_s, assertionState());
else
m_assertion = std::make_unique<ProcessAssertion>(pid, assertionState());
m_assertion = std::make_unique<ProcessAssertion>(pid, "Web content visibility"_s, assertionState());
m_process.didSetAssertionState(assertionState());
m_assertion->setClient(*this);
}
@@ -43,7 +43,7 @@ typedef ProcessSuppressionDisabledCounter::Token ProcessSuppressionDisabledToken

class ProcessThrottlerClient;

class ProcessThrottler : private ProcessAssertionClient {
class ProcessThrottler : private ProcessAssertion::Client {
public:
enum ForegroundActivityCounterType { };
typedef RefCounter<ForegroundActivityCounterType> ForegroundActivityCounter;

0 comments on commit 91f7339

Please sign in to comment.