Changeset 248144 in webkit


Ignore:
Timestamp:
Aug 1, 2019 6:59:08 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Do not send NetworkProcessProxy::LogTestingEvent message if we are not testing
https://bugs.webkit.org/show_bug.cgi?id=200360

Patch by Alex Christensen <achristensen@webkit.org> on 2019-08-01
Reviewed by Tim Horton.

Source/WebKit:

Sending this message causes instantiation of the default WebsiteDataStore in the UIProcess,
which causes more memory to be used than is needed if we are browsing without the default WebsiteDataStore.

Covered by an API test.

  • NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:

(WebKit::WebResourceLoadStatisticsStore::logTestingEvent):

  • NetworkProcess/NetworkSession.cpp:

(WebKit::NetworkSession::NetworkSession):

  • NetworkProcess/NetworkSession.h:

(WebKit::NetworkSession::enableResourceLoadStatisticsLogTestingEvent const):

  • NetworkProcess/NetworkSessionCreationParameters.cpp:

(WebKit::NetworkSessionCreationParameters::encode const):
(WebKit::NetworkSessionCreationParameters::decode):

  • NetworkProcess/NetworkSessionCreationParameters.h:
  • UIProcess/WebProcessPool.cpp:

(WebKit::WebProcessPool::ensureNetworkProcess):

  • UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:

(WebKit::WebsiteDataStore::parameters):

  • UIProcess/WebsiteData/WebsiteDataStore.h:

(WebKit::WebsiteDataStore::hasStatisticsTestingCallback const):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm:

(cleanupITPDatabase):
(TEST):

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r248139 r248144  
     12019-08-01  Alex Christensen  <achristensen@webkit.org>
     2
     3        Do not send NetworkProcessProxy::LogTestingEvent message if we are not testing
     4        https://bugs.webkit.org/show_bug.cgi?id=200360
     5
     6        Reviewed by Tim Horton.
     7
     8        Sending this message causes instantiation of the default WebsiteDataStore in the UIProcess,
     9        which causes more memory to be used than is needed if we are browsing without the default WebsiteDataStore.
     10
     11        Covered by an API test.
     12
     13        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
     14        (WebKit::WebResourceLoadStatisticsStore::logTestingEvent):
     15        * NetworkProcess/NetworkSession.cpp:
     16        (WebKit::NetworkSession::NetworkSession):
     17        * NetworkProcess/NetworkSession.h:
     18        (WebKit::NetworkSession::enableResourceLoadStatisticsLogTestingEvent const):
     19        * NetworkProcess/NetworkSessionCreationParameters.cpp:
     20        (WebKit::NetworkSessionCreationParameters::encode const):
     21        (WebKit::NetworkSessionCreationParameters::decode):
     22        * NetworkProcess/NetworkSessionCreationParameters.h:
     23        * UIProcess/WebProcessPool.cpp:
     24        (WebKit::WebProcessPool::ensureNetworkProcess):
     25        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     26        (WebKit::WebsiteDataStore::parameters):
     27        * UIProcess/WebsiteData/WebsiteDataStore.h:
     28        (WebKit::WebsiteDataStore::hasStatisticsTestingCallback const):
     29
    1302019-08-01  Alex Christensen  <achristensen@webkit.org>
    231
  • trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp

    r247918 r248144  
    10071007    ASSERT(RunLoop::isMain());
    10081008
    1009     if (m_networkSession)
     1009    if (m_networkSession && m_networkSession->enableResourceLoadStatisticsLogTestingEvent())
    10101010        m_networkSession->networkProcess().parentProcessConnection()->send(Messages::NetworkProcessProxy::LogTestingEvent(m_networkSession->sessionID(), event), 0);
    10111011}
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r248047 r248144  
    11601160}
    11611161
     1162void NetworkProcess::setResourceLoadStatisticsLogTestingEvent(bool enabled)
     1163{
     1164    forEachNetworkSession([enabled](auto& networkSession) {
     1165        networkSession.setResourceLoadStatisticsLogTestingEvent(enabled);
     1166    });
     1167}
     1168
    11621169void NetworkProcess::setResourceLoadStatisticsDebugMode(PAL::SessionID sessionID, bool debugMode, CompletionHandler<void()>&& completionHandler)
    11631170{
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r248047 r248144  
    247247    void setNotifyPagesWhenTelemetryWasCaptured(PAL::SessionID, bool value, CompletionHandler<void()>&&);
    248248    void setResourceLoadStatisticsEnabled(bool);
     249    void setResourceLoadStatisticsLogTestingEvent(bool);
    249250    void setResourceLoadStatisticsDebugMode(PAL::SessionID, bool debugMode, CompletionHandler<void()>&&d);
    250251    void setShouldClassifyResourcesBeforeDataRecordsRemoval(PAL::SessionID, bool value, CompletionHandler<void()>&&);
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in

    r248047 r248144  
    9292    DumpResourceLoadStatistics(PAL::SessionID sessionID) -> (String dumpedStatistics) Async
    9393    SetResourceLoadStatisticsEnabled(bool enabled)
     94    SetResourceLoadStatisticsLogTestingEvent(bool enabled)
    9495    UpdatePrevalentDomainsToBlockCookiesFor(PAL::SessionID sessionID, Vector<WebCore::RegistrableDomain> domainsToBlock) -> () Async
    9596    IsGrandfathered(PAL::SessionID sessionID, WebCore::RegistrableDomain targetDomain) -> (bool isGrandfathered) Async
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp

    r247831 r248144  
    8282    : m_sessionID(parameters.sessionID)
    8383    , m_networkProcess(networkProcess)
     84#if ENABLE(RESOURCE_LOAD_STATISTICS)
     85    , m_enableResourceLoadStatisticsLogTestingEvent(parameters.enableResourceLoadStatisticsLogTestingEvent)
     86#endif
    8487    , m_adClickAttribution(makeUniqueRef<AdClickAttributionManager>(parameters.sessionID))
    8588    , m_storageManager(StorageManager::create(String(parameters.localStorageDirectory)))
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.h

    r247831 r248144  
    9191    void logDiagnosticMessageWithValue(const String& message, const String& description, unsigned value, unsigned significantFigures, WebCore::ShouldSample);
    9292    void notifyPageStatisticsTelemetryFinished(unsigned totalPrevalentResources, unsigned totalPrevalentResourcesWithUserInteraction, unsigned top3SubframeUnderTopFrameOrigins);
     93    bool enableResourceLoadStatisticsLogTestingEvent() const { return m_enableResourceLoadStatisticsLogTestingEvent; }
     94    void setResourceLoadStatisticsLogTestingEvent(bool log) { m_enableResourceLoadStatisticsLogTestingEvent = log; }
    9395#endif
    9496    void storeAdClickAttribution(WebCore::AdClickAttribution&&);
     
    129131    EnableResourceLoadStatisticsDebugMode m_enableResourceLoadStatisticsDebugMode { EnableResourceLoadStatisticsDebugMode::No };
    130132    WebCore::RegistrableDomain m_resourceLoadStatisticsManualPrevalentResource;
     133    bool m_enableResourceLoadStatisticsLogTestingEvent;
    131134#endif
    132135    UniqueRef<AdClickAttributionManager> m_adClickAttribution;
  • trunk/Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.cpp

    r247567 r248144  
    5151        , { }, { }
    5252#endif
    53         , { }, { }, false, { }, { }, { }, { }, { }, { }, { }, { }, { }
     53        , { }, { }, false, false, { }, { }, { }, { }, { }, { }, { }, { }, { }
    5454    };
    5555}
     
    8181    encoder << resourceLoadStatisticsDirectoryExtensionHandle;
    8282    encoder << enableResourceLoadStatistics;
     83    encoder << enableResourceLoadStatisticsLogTestingEvent;
    8384    encoder << shouldIncludeLocalhostInResourceLoadStatistics;
    8485    encoder << enableResourceLoadStatisticsDebugMode;
     
    186187    decoder >> enableResourceLoadStatistics;
    187188    if (!enableResourceLoadStatistics)
     189        return WTF::nullopt;
     190
     191    Optional<bool> enableResourceLoadStatisticsLogTestingEvent;
     192    decoder >> enableResourceLoadStatisticsLogTestingEvent;
     193    if (!enableResourceLoadStatisticsLogTestingEvent)
    188194        return WTF::nullopt;
    189195
     
    258264        , WTFMove(*resourceLoadStatisticsDirectoryExtensionHandle)
    259265        , WTFMove(*enableResourceLoadStatistics)
     266        , WTFMove(*enableResourceLoadStatisticsLogTestingEvent)
    260267        , WTFMove(*shouldIncludeLocalhostInResourceLoadStatistics)
    261268        , WTFMove(*enableResourceLoadStatisticsDebugMode)
  • trunk/Source/WebKit/NetworkProcess/NetworkSessionCreationParameters.h

    r247567 r248144  
    8585    SandboxExtension::Handle resourceLoadStatisticsDirectoryExtensionHandle;
    8686    bool enableResourceLoadStatistics { false };
     87    bool enableResourceLoadStatisticsLogTestingEvent { false };
    8788    bool shouldIncludeLocalhostInResourceLoadStatistics { true };
    8889    bool enableResourceLoadStatisticsDebugMode { false };
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r247733 r248144  
    457457
    458458    if (callback) {
    459         _websiteDataStore->websiteDataStore().enableResourceLoadStatisticsAndSetTestingCallback([callback = makeBlockPtr(callback), self](const String& event) {
    460             callback(self, (NSString *)event);
     459        _websiteDataStore->websiteDataStore().setStatisticsTestingCallback([callback = makeBlockPtr(callback), self](const String& event) {
     460            callback(self, event);
    461461        });
    462462        return;
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r248047 r248144  
    595595
    596596    bool enableResourceLoadStatistics = m_shouldEnableITPForDefaultSessions;
     597    bool enableResourceLoadStatisticsLogTestingEvent = false;
    597598    bool shouldIncludeLocalhost = true;
    598599    bool enableResourceLoadStatisticsDebugMode = false;
     
    600601    if (withWebsiteDataStore) {
    601602        enableResourceLoadStatistics = withWebsiteDataStore->resourceLoadStatisticsEnabled();
     603#if ENABLE(RESOURCE_LOAD_STATISTICS)
     604        enableResourceLoadStatisticsLogTestingEvent = withWebsiteDataStore->hasStatisticsTestingCallback();
     605#endif
    602606        if (enableResourceLoadStatistics) {
    603607            auto networkSessionParameters = withWebsiteDataStore->parameters().networkSessionParameters;
     
    611615    } else if (m_websiteDataStore) {
    612616        enableResourceLoadStatistics = m_websiteDataStore->resourceLoadStatisticsEnabled();
     617#if ENABLE(RESOURCE_LOAD_STATISTICS)
     618        enableResourceLoadStatisticsLogTestingEvent = m_websiteDataStore->websiteDataStore().hasStatisticsTestingCallback();
     619#endif
    613620        if (enableResourceLoadStatistics) {
    614621            auto networkSessionParameters = m_websiteDataStore->websiteDataStore().parameters().networkSessionParameters;
     
    623630
    624631    parameters.defaultDataStoreParameters.networkSessionParameters.enableResourceLoadStatistics = enableResourceLoadStatistics;
     632    parameters.defaultDataStoreParameters.networkSessionParameters.enableResourceLoadStatisticsLogTestingEvent = enableResourceLoadStatisticsLogTestingEvent;
    625633    parameters.defaultDataStoreParameters.networkSessionParameters.shouldIncludeLocalhostInResourceLoadStatistics = shouldIncludeLocalhost;
    626634    parameters.defaultDataStoreParameters.networkSessionParameters.enableResourceLoadStatisticsDebugMode = enableResourceLoadStatisticsDebugMode;
  • trunk/Source/WebKit/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm

    r247567 r248144  
    135135        WTFMove(resourceLoadStatisticsDirectoryHandle),
    136136        false,
     137        false,
    137138        shouldIncludeLocalhostInResourceLoadStatistics,
    138139        enableResourceLoadStatisticsDebugMode,
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r247567 r248144  
    18461846
    18471847    if (enabled) {
    1848         enableResourceLoadStatisticsAndSetTestingCallback(nullptr);
     1848        m_resourceLoadStatisticsEnabled = true;
     1849       
     1850        resolveDirectoriesIfNecessary();
     1851       
     1852        for (auto& processPool : processPools(std::numeric_limits<size_t>::max(), false)) {
     1853            processPool->setResourceLoadStatisticsEnabled(true);
     1854            processPool->sendToNetworkingProcess(Messages::NetworkProcess::SetResourceLoadStatisticsEnabled(true));
     1855        }
    18491856        return;
    18501857    }
     
    18601867#endif
    18611868}
     1869
     1870#if ENABLE(RESOURCE_LOAD_STATISTICS)
     1871void WebsiteDataStore::setStatisticsTestingCallback(Function<void(const String&)>&& callback)
     1872{
     1873    if (callback) {
     1874        for (auto& processPool : processPools(std::numeric_limits<size_t>::max(), false))
     1875            processPool->sendToNetworkingProcess(Messages::NetworkProcess::SetResourceLoadStatisticsLogTestingEvent(true));
     1876    }
     1877   
     1878    m_statisticsTestingCallback = WTFMove(callback);
     1879}
     1880#endif
    18621881
    18631882void WebsiteDataStore::setResourceLoadStatisticsDebugMode(bool enabled)
     
    18821901
    18831902#if ENABLE(RESOURCE_LOAD_STATISTICS)
    1884 void WebsiteDataStore::enableResourceLoadStatisticsAndSetTestingCallback(Function<void (const String&)>&& callback)
    1885 {
    1886     ASSERT(!m_sessionID.isEphemeral());
    1887 
    1888     m_resourceLoadStatisticsEnabled = true;
    1889     setStatisticsTestingCallback(WTFMove(callback));
    1890 
    1891     resolveDirectoriesIfNecessary();
    1892 
    1893     for (auto& processPool : processPools(std::numeric_limits<size_t>::max(), false)) {
    1894         processPool->setResourceLoadStatisticsEnabled(true);
    1895         processPool->sendToNetworkingProcess(Messages::NetworkProcess::SetResourceLoadStatisticsEnabled(true));
    1896     }
    1897 }
    1898 
    18991903void WebsiteDataStore::logTestingEvent(const String& event)
    19001904{
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

    r247686 r248144  
    172172    void setPrevalentResourceForDebugMode(const URL&, CompletionHandler<void()>&&);
    173173    void setShouldClassifyResourcesBeforeDataRecordsRemoval(bool, CompletionHandler<void()>&&);
    174     void setStatisticsTestingCallback(WTF::Function<void(const String&)>&& callback) { m_statisticsTestingCallback = WTFMove(callback); }
     174    void setStatisticsTestingCallback(Function<void(const String&)>&&);
     175    bool hasStatisticsTestingCallback() const { return !!m_statisticsTestingCallback; }
    175176    void setVeryPrevalentResource(const URL&, CompletionHandler<void()>&&);
    176177    void setSubframeUnderTopFrameDomain(const URL& subframe, const URL& topFrame);
     
    208209    void clearPendingCookies();
    209210
    210     void enableResourceLoadStatisticsAndSetTestingCallback(Function<void (const String&)>&& callback);
    211 
    212211    void setBoundInterfaceIdentifier(String&& identifier) { m_boundInterfaceIdentifier = WTFMove(identifier); }
    213212    const String& boundInterfaceIdentifier() { return m_boundInterfaceIdentifier; }
  • trunk/Tools/ChangeLog

    r248139 r248144  
     12019-08-01  Alex Christensen  <achristensen@webkit.org>
     2
     3        Do not send NetworkProcessProxy::LogTestingEvent message if we are not testing
     4        https://bugs.webkit.org/show_bug.cgi?id=200360
     5
     6        Reviewed by Tim Horton.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm:
     9        (cleanupITPDatabase):
     10        (TEST):
     11
    1122019-08-01  Alex Christensen  <achristensen@webkit.org>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm

    r246500 r248144  
    2828#import "PlatformUtilities.h"
    2929#import "TestNavigationDelegate.h"
     30#import "TestWKWebView.h"
    3031#import <WebKit/WKFoundation.h>
    3132#import <WebKit/WKPreferencesPrivate.h>
     
    215216    // Make sure 'evil.com' is not in our data set.
    216217    static bool doneFlag;
    217     [dataStore _clearPrevalentDomain:[NSURL URLWithString:@"http://evil.com"] completionHandler: ^(void) {
    218         doneFlag = true;
    219     }];
    220    
    221218    static bool dataSyncCompleted;
    222219    [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) {
     
    225222
    226223        dataSyncCompleted = true;
     224    }];
     225    [dataStore _clearPrevalentDomain:[NSURL URLWithString:@"http://evil.com"] completionHandler: ^(void) {
     226        doneFlag = true;
    227227    }];
    228228
     
    474474    TestWebKitAPI::Util::run(&doneFlag);
    475475}
     476
     477TEST(ResourceLoadStatistics, NoMessagesWhenNotTesting)
     478{
     479    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     480    WKWebsiteDataStore *dataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:[[[_WKWebsiteDataStoreConfiguration alloc] init] autorelease]] autorelease];
     481    [configuration setWebsiteDataStore:dataStore];
     482    [dataStore _setResourceLoadStatisticsEnabled:YES];
     483    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:configuration.get()]);
     484    [webView synchronouslyLoadTestPageNamed:@"simple"];
     485    EXPECT_FALSE([WKWebsiteDataStore _defaultDataStoreExists]);
     486}
Note: See TracChangeset for help on using the changeset viewer.