Changeset 272376 in webkit


Ignore:
Timestamp:
Feb 4, 2021 10:10:39 AM (3 years ago)
Author:
achristensen@apple.com
Message:

REGRESSION(r267763) Network process launches earlier than before
https://bugs.webkit.org/show_bug.cgi?id=221384
<rdar://problem/73507706>

Patch by Alex Christensen <achristensen@apple.com> on 2021-02-04
Reviewed by Chris Dumez.

Source/WebKit:

Before r267763 we could have an app launch, allocate a WKWebView, and set _resourceLoadStatisticsEnabled
all without having a network process launch.

When setting _resourceLoadStatisticsEnabled, we don't need to launch a network process if we haven't already
because when we do, WebsiteDataStore::parameters will send the correct value. I added a test that verifies this doesn't
launch the network process if it hasn't already been launched.

We also don't need to update the process assertion or the process suspension state if there is no network process.

sendNetworkProcessXPCEndpointToWebProcess is also called when opening Safari on iOS and would be the next thing to
unnecessarily launch the network process during app initialization. I manually verified that if we add an early return
if there is no network process yet, we do send the XPC endpoint to the web process when the network process does launch
through the call site in sendNetworkProcessXPCEndpointToAllWebProcesses.

I verified on my phone that this is the minimal change needed for Safari on iOS to not launch the network process before
application:didFinishLaunchingWithOptions: is called as it did before r267763.

  • UIProcess/Cocoa/WebProcessPoolCocoa.mm:

(WebKit::WebProcessPool::updateProcessSuppressionState):

  • UIProcess/WebProcessPool.cpp:

(WebKit::WebProcessPool::updateProcessAssertions):

  • UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:

(WebKit::WebsiteDataStore::sendNetworkProcessXPCEndpointToWebProcess):

  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::setResourceLoadStatisticsEnabled):

  • UIProcess/WebsiteData/WebsiteDataStore.h:

(WebKit::WebsiteDataStore::networkProcessIfExists):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/NetworkProcess.mm:

(TEST):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r272368 r272376  
     12021-02-04  Alex Christensen  <achristensen@apple.com>
     2
     3        REGRESSION(r267763) Network process launches earlier than before
     4        https://bugs.webkit.org/show_bug.cgi?id=221384
     5        <rdar://problem/73507706>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Before r267763 we could have an app launch, allocate a WKWebView, and set _resourceLoadStatisticsEnabled
     10        all without having a network process launch.
     11
     12        When setting _resourceLoadStatisticsEnabled, we don't need to launch a network process if we haven't already
     13        because when we do, WebsiteDataStore::parameters will send the correct value.  I added a test that verifies this doesn't
     14        launch the network process if it hasn't already been launched.
     15
     16        We also don't need to update the process assertion or the process suspension state if there is no network process.
     17
     18        sendNetworkProcessXPCEndpointToWebProcess is also called when opening Safari on iOS and would be the next thing to
     19        unnecessarily launch the network process during app initialization.  I manually verified that if we add an early return
     20        if there is no network process yet, we do send the XPC endpoint to the web process when the network process does launch
     21        through the call site in sendNetworkProcessXPCEndpointToAllWebProcesses.
     22
     23        I verified on my phone that this is the minimal change needed for Safari on iOS to not launch the network process before
     24        application:didFinishLaunchingWithOptions: is called as it did before r267763.
     25
     26        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
     27        (WebKit::WebProcessPool::updateProcessSuppressionState):
     28        * UIProcess/WebProcessPool.cpp:
     29        (WebKit::WebProcessPool::updateProcessAssertions):
     30        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     31        (WebKit::WebsiteDataStore::sendNetworkProcessXPCEndpointToWebProcess):
     32        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     33        (WebKit::WebsiteDataStore::setResourceLoadStatisticsEnabled):
     34        * UIProcess/WebsiteData/WebsiteDataStore.h:
     35        (WebKit::WebsiteDataStore::networkProcessIfExists):
     36
    1372021-02-04  Aditya Keerthi  <akeerthi@apple.com>
    238
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r269712 r272376  
    701701}
    702702
     703- (BOOL)_networkProcessExists
     704{
     705    return !!_websiteDataStore->networkProcessIfExists();
     706}
     707
    703708@end
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h

    r271813 r272376  
    9797- (pid_t)_networkProcessIdentifier WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    9898+ (void)_makeNextNetworkProcessLaunchFailForTesting WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
     99- (BOOL)_networkProcessExists WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    99100
    100101@end
  • trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm

    r272335 r272376  
    142142{
    143143    WebsiteDataStore::forEachWebsiteDataStore([enabled = processSuppressionEnabled()] (WebsiteDataStore& dataStore) {
    144         dataStore.networkProcess().setProcessSuppressionEnabled(enabled);
     144        if (auto* networkProcess = dataStore.networkProcessIfExists())
     145            networkProcess->setProcessSuppressionEnabled(enabled);
    145146    });
    146147
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r272209 r272376  
    17191719{
    17201720    WebsiteDataStore::forEachWebsiteDataStore([] (WebsiteDataStore& dataStore) {
    1721         dataStore.networkProcess().updateProcessAssertion();
     1721        if (auto* networkProcess = dataStore.networkProcessIfExists())
     1722            networkProcess->updateProcessAssertion();
    17221723    });
    17231724#if ENABLE(GPU_PROCESS)
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r271714 r272376  
    19911991        resolveDirectoriesIfNecessary();
    19921992       
    1993         networkProcess().send(Messages::NetworkProcess::SetResourceLoadStatisticsEnabled(m_sessionID, true), 0);
     1993        if (m_networkProcess)
     1994            m_networkProcess->send(Messages::NetworkProcess::SetResourceLoadStatisticsEnabled(m_sessionID, true), 0);
    19941995        for (auto& processPool : processPools())
    19951996            processPool->sendToAllProcessesForSession(Messages::WebProcess::SetResourceLoadStatisticsEnabled(true), m_sessionID);
     
    19971998    }
    19981999
    1999     networkProcess().send(Messages::NetworkProcess::SetResourceLoadStatisticsEnabled(m_sessionID, false), 0);
     2000    if (m_networkProcess)
     2001        m_networkProcess->send(Messages::NetworkProcess::SetResourceLoadStatisticsEnabled(m_sessionID, false), 0);
    20002002    for (auto& processPool : processPools())
    20012003        processPool->sendToAllProcessesForSession(Messages::WebProcess::SetResourceLoadStatisticsEnabled(false), m_sessionID);
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

    r271714 r272376  
    123123    NetworkProcessProxy& networkProcess() const;
    124124    NetworkProcessProxy& networkProcess();
     125    NetworkProcessProxy* networkProcessIfExists() { return m_networkProcess.get(); }
    125126
    126127    static WebsiteDataStore* existingDataStoreForSessionID(PAL::SessionID);
  • trunk/Tools/ChangeLog

    r272369 r272376  
     12021-02-04  Alex Christensen  <achristensen@apple.com>
     2
     3        REGRESSION(r267763) Network process launches earlier than before
     4        https://bugs.webkit.org/show_bug.cgi?id=221384
     5        <rdar://problem/73507706>
     6
     7        Reviewed by Chris Dumez.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/NetworkProcess.mm:
     10        (TEST):
     11
    1122021-02-04  Philippe Normand  <pnormand@igalia.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/NetworkProcess.mm

    r267763 r272376  
    7979    checkReferer([NSURL URLWithString:shorterHost], shorterHost.UTF8String);
    8080}
     81
     82TEST(WebKit, NetworkProcessLaunchOnlyWhenNecessary)
     83{
     84    auto webView = [[WKWebView new] autorelease];
     85    webView.configuration.websiteDataStore._resourceLoadStatisticsEnabled = YES;
     86    EXPECT_FALSE([webView.configuration.websiteDataStore _networkProcessExists]);
     87}
Note: See TracChangeset for help on using the changeset viewer.