Skip to content

Commit

Permalink
Provide private relay information via the didExceedMemoryFootprintThr…
Browse files Browse the repository at this point in the history
…eshold callback

https://bugs.webkit.org/show_bug.cgi?id=270304
rdar://123799163

Reviewed by Chris Dumez.

In 274733@main we added a callback which helps us observe when WebContent processes exceed certain
key memory thresholds in the field. After further discussion, we decided that we need that event to
carry state about whether any of the page loads in the process were private relayed or not, so we're
adding that here.

* Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
* Source/WebKit/UIProcess/API/Cocoa/_WKWebsiteDataStoreDelegate.h:
* Source/WebKit/UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didExceedMemoryFootprintThreshold):
* Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreClient.h:
(WebKit::WebsiteDataStoreClient::didExceedMemoryFootprintThreshold):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/MemoryFootprintThreshold.mm:
(-[MemoryFootprintDelegate websiteDataStore:domain:didExceedMemoryFootprintThreshold:withPageCount:processLifetime:inForeground:wasPrivateRelayed:]):
(-[MemoryFootprintDelegate websiteDataStore:domain:didExceedMemoryFootprintThreshold:withPageCount:processLifetime:inForeground:]): Deleted.

Canonical link: https://commits.webkit.org/275586@main
  • Loading branch information
bnham committed Mar 2, 2024
1 parent 9146216 commit 48ca65b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,4 @@ static const WKNavigationResponsePolicy _WKNavigationResponsePolicyBecomeDownloa
- (void)_webView:(WKWebView *)webView willGoToBackForwardListItem:(WKBackForwardListItem *)item inPageCache:(BOOL)inPageCache WK_API_AVAILABLE(macos(10.13.4), ios(14.0));
- (void)_webView:(WKWebView *)webView decidePolicyForSOAuthorizationLoadWithCurrentPolicy:(_WKSOAuthorizationLoadPolicy)policy forExtension:(NSString *)extension completionHandler:(void (^)(_WKSOAuthorizationLoadPolicy policy))completionHandler WK_API_AVAILABLE(macos(10.15), ios(13.0));

- (void)_webView:(WKWebView *)webView didExceedMemoryFootprintThresholdWithFootprint:(size_t)footprint WK_API_AVAILABLE(macos(WK_MAC_TBA));

@end
7 changes: 4 additions & 3 deletions Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#import "_WKWebsiteDataStoreDelegate.h"
#import <WebCore/Credential.h>
#import <WebCore/RegistrableDomain.h>
#import <WebCore/ResourceResponse.h>
#import <WebCore/ServiceWorkerClientData.h>
#import <WebCore/WebCoreObjCExtras.h>
#import <wtf/BlockPtr.h>
Expand Down Expand Up @@ -81,7 +82,7 @@
, m_hasNotifyBackgroundFetchChangeSelector([m_delegate.get() respondsToSelector:@selector(notifyBackgroundFetchChange:change:)])
, m_hasWindowProxyPropertyAccessSelector([m_delegate.get() respondsToSelector:@selector(websiteDataStore:domain:didOpenDomainViaWindowOpen:withProperty:directly:)])
, m_hasDidAllowPrivateTokenUsageByThirdPartyForTestingSelector([m_delegate.get() respondsToSelector:@selector(websiteDataStore:didAllowPrivateTokenUsageByThirdPartyForTesting:forResourceURL:)])
, m_hasDidExceedMemoryFootprintThresholdSelector([m_delegate.get() respondsToSelector:@selector(websiteDataStore:domain:didExceedMemoryFootprintThreshold:withPageCount:processLifetime:inForeground:)])
, m_hasDidExceedMemoryFootprintThresholdSelector([m_delegate.get() respondsToSelector:@selector(websiteDataStore:domain:didExceedMemoryFootprintThreshold:withPageCount:processLifetime:inForeground:wasPrivateRelayed:)])
{
}

Expand Down Expand Up @@ -301,12 +302,12 @@ void didAllowPrivateTokenUsageByThirdPartyForTesting(bool wasAllowed, WTF::URL&&
[m_delegate.getAutoreleased() websiteDataStore:m_dataStore.getAutoreleased() didAllowPrivateTokenUsageByThirdPartyForTesting:wasAllowed forResourceURL:resourceURL];
}

void didExceedMemoryFootprintThreshold(size_t footprint, const String& domain, unsigned pageCount, Seconds processLifetime, bool inForeground)
void didExceedMemoryFootprintThreshold(size_t footprint, const String& domain, unsigned pageCount, Seconds processLifetime, bool inForeground, WebCore::WasPrivateRelayed wasPrivateRelayed)
{
if (!m_hasDidExceedMemoryFootprintThresholdSelector)
return;

[m_delegate.getAutoreleased() websiteDataStore:m_dataStore.getAutoreleased() domain:(NSString *)domain didExceedMemoryFootprintThreshold:footprint withPageCount:pageCount processLifetime:processLifetime.seconds() inForeground:inForeground];
[m_delegate.getAutoreleased() websiteDataStore:m_dataStore.getAutoreleased() domain:(NSString *)domain didExceedMemoryFootprintThreshold:footprint withPageCount:pageCount processLifetime:processLifetime.seconds() inForeground:inForeground wasPrivateRelayed:wasPrivateRelayed == WebCore::WasPrivateRelayed::Yes];
}

WeakObjCPtr<WKWebsiteDataStore> m_dataStore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ WK_API_AVAILABLE(macos(10.15), ios(13.0))
- (void)notifyBackgroundFetchChange:(NSString *)backgroundFetchIdentifier change:(WKBackgroundFetchChange)change;
- (void)websiteDataStore:(WKWebsiteDataStore *)dataStore domain:(NSString *)registrableDomain didOpenDomainViaWindowOpen:(NSString *)openedRegistrableDomain withProperty:(WKWindowProxyProperty)property directly:(BOOL)directly;
- (void)websiteDataStore:(WKWebsiteDataStore *)dataStore didAllowPrivateTokenUsageByThirdPartyForTesting:(BOOL)wasAllowed forResourceURL:(NSURL *)resourceURL;
- (void)websiteDataStore:(WKWebsiteDataStore *)dataStore domain:(NSString *)registrableDomain didExceedMemoryFootprintThreshold:(size_t)footprint withPageCount:(NSUInteger)pageCount processLifetime:(NSTimeInterval)processLifetime inForeground:(BOOL)inForeground;
- (void)websiteDataStore:(WKWebsiteDataStore *)dataStore domain:(NSString *)registrableDomain didExceedMemoryFootprintThreshold:(size_t)footprint withPageCount:(NSUInteger)pageCount processLifetime:(NSTimeInterval)processLifetime inForeground:(BOOL)inForeground wasPrivateRelayed:(BOOL)wasPrivateRelayed;
@end
7 changes: 6 additions & 1 deletion Source/WebKit/UIProcess/WebProcessProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#include <WebCore/PrewarmInformation.h>
#include <WebCore/PublicSuffix.h>
#include <WebCore/RealtimeMediaSourceCenter.h>
#include <WebCore/ResourceResponse.h>
#include <WebCore/SecurityOriginData.h>
#include <WebCore/SuddenTermination.h>
#include <pal/system/Sound.h>
Expand Down Expand Up @@ -1999,21 +2000,25 @@ void WebProcessProxy::didExceedMemoryFootprintThreshold(size_t footprint)
return;

String domain;
bool wasPrivateRelayed = false;

for (auto& page : this->pages()) {
#if ENABLE(PUBLIC_SUFFIX_LIST)
String pageDomain = topPrivatelyControlledDomain(URL({ }, page->currentURL()).host().toString());
if (domain.isEmpty())
domain = WTFMove(pageDomain);
else if (domain != pageDomain)
domain = "multiple"_s;

wasPrivateRelayed = wasPrivateRelayed || page->pageLoadState().wasPrivateRelayed();
#endif
}

if (domain.isEmpty())
domain = "unknown"_s;

auto activeTime = totalForegroundTime() + totalBackgroundTime() + totalSuspendedTime();
dataStore->client().didExceedMemoryFootprintThreshold(footprint, domain, pageCount(), activeTime, throttler().currentState() == ProcessThrottleState::Foreground);
dataStore->client().didExceedMemoryFootprintThreshold(footprint, domain, pageCount(), activeTime, throttler().currentState() == ProcessThrottleState::Foreground, wasPrivateRelayed ? WebCore::WasPrivateRelayed::Yes : WebCore::WasPrivateRelayed::No);
}

void WebProcessProxy::didExceedCPULimit()
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <wtf/Seconds.h>

namespace WebCore {
enum class WasPrivateRelayed : bool;
enum class WindowProxyProperty : uint8_t;
struct NotificationData;
class RegistrableDomain;
Expand Down Expand Up @@ -117,7 +118,7 @@ class WebsiteDataStoreClient {
{
}

virtual void didExceedMemoryFootprintThreshold(size_t, const String&, unsigned, Seconds, bool)
virtual void didExceedMemoryFootprintThreshold(size_t, const String&, unsigned, Seconds, bool inForeground, WebCore::WasPrivateRelayed)
{
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ @interface MemoryFootprintDelegate : NSObject<_WKWebsiteDataStoreDelegate> {

@implementation MemoryFootprintDelegate

- (void)websiteDataStore:(WKWebsiteDataStore *)dataStore domain:(NSString *)registrableDomain didExceedMemoryFootprintThreshold:(size_t)footprint withPageCount:(NSUInteger)pageCount processLifetime:(NSTimeInterval)processLifetime inForeground:(BOOL)inForeground
- (void)websiteDataStore:(WKWebsiteDataStore *)dataStore domain:(NSString *)registrableDomain didExceedMemoryFootprintThreshold:(size_t)footprint withPageCount:(NSUInteger)pageCount processLifetime:(NSTimeInterval)processLifetime inForeground:(BOOL)inForeground wasPrivateRelayed:(BOOL)wasPrivateRelayed
{
_footprints.append(footprint);

Expand Down

0 comments on commit 48ca65b

Please sign in to comment.