Changeset 219203 in webkit


Ignore:
Timestamp:
Jul 6, 2017 10:23:07 AM (7 years ago)
Author:
Chris Dumez
Message:

WebResourceLoadStatisticsStore should only be constructed when the feature is enabled
https://bugs.webkit.org/show_bug.cgi?id=174189

Reviewed by Brent Fulgham.

Delay the construction of the WebResourceLoadStatisticsStore until the feature gets
enabled via WebsiteDataStore::setResourceLoadStatisticsEnabled(). Previously, we would
always construct a store and then have a boolean on the store to indicate if it is
enabled or not.

Also simplify the initialization process of the WebResourceLoadStatisticsStore, we
used to have:

  1. WebResourceLoadStatisticsStore constructor
  2. WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver()
  3. WebResourceLoadStatisticsStore::setResourceLoadStatisticsEnabled(true)

All 3 steps are now taken care of by the WebResourceLoadStatisticsStore constructor.

  • UIProcess/Cocoa/WebProcessPoolCocoa.mm:

(WebKit::WebProcessPool::platformInitialize):

  • UIProcess/WebResourceLoadStatisticsStore.cpp:

(WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
(WebKit::WebResourceLoadStatisticsStore::readDataFromDiskIfNeeded):

  • UIProcess/WebResourceLoadStatisticsStore.h:
  • UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:

(WebKit::WebsiteDataStore::platformInitialize):

  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::WebsiteDataStore):
(WebKit::WebsiteDataStore::resourceLoadStatisticsEnabled):
(WebKit::WebsiteDataStore::setResourceLoadStatisticsEnabled):

  • UIProcess/WebsiteData/WebsiteDataStore.h:

(WebKit::WebsiteDataStore::resourceLoadStatistics):

  • UIProcess/wpe/WebProcessPoolWPE.cpp:

(WebKit::WebProcessPool::platformInitialize):

Location:
trunk/Source/WebKit2
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r219195 r219203  
     12017-07-06  Chris Dumez  <cdumez@apple.com>
     2
     3        WebResourceLoadStatisticsStore should only be constructed when the feature is enabled
     4        https://bugs.webkit.org/show_bug.cgi?id=174189
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Delay the construction of the WebResourceLoadStatisticsStore until the feature gets
     9        enabled via WebsiteDataStore::setResourceLoadStatisticsEnabled(). Previously, we would
     10        always construct a store and then have a boolean on the store to indicate if it is
     11        enabled or not.
     12
     13        Also simplify the initialization process of the WebResourceLoadStatisticsStore, we
     14        used to have:
     15        1. WebResourceLoadStatisticsStore constructor
     16        2. WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver()
     17        3. WebResourceLoadStatisticsStore::setResourceLoadStatisticsEnabled(true)
     18
     19        All 3 steps are now taken care of by the WebResourceLoadStatisticsStore constructor.
     20
     21        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
     22        (WebKit::WebProcessPool::platformInitialize):
     23        * UIProcess/WebResourceLoadStatisticsStore.cpp:
     24        (WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
     25        (WebKit::WebResourceLoadStatisticsStore::readDataFromDiskIfNeeded):
     26        * UIProcess/WebResourceLoadStatisticsStore.h:
     27        * UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
     28        (WebKit::WebsiteDataStore::platformInitialize):
     29        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     30        (WebKit::WebsiteDataStore::WebsiteDataStore):
     31        (WebKit::WebsiteDataStore::resourceLoadStatisticsEnabled):
     32        (WebKit::WebsiteDataStore::setResourceLoadStatisticsEnabled):
     33        * UIProcess/WebsiteData/WebsiteDataStore.h:
     34        (WebKit::WebsiteDataStore::resourceLoadStatistics):
     35        * UIProcess/wpe/WebProcessPoolWPE.cpp:
     36        (WebKit::WebProcessPool::platformInitialize):
     37
    1382017-07-06  Claudio Saavedra  <csaavedra@igalia.com>
    239
  • trunk/Source/WebKit2/UIProcess/Cocoa/WebProcessPoolCocoa.mm

    r219050 r219203  
    149149
    150150    setLegacyCustomProtocolManagerClient(std::make_unique<LegacyCustomProtocolManagerClient>());
    151 
    152     m_websiteDataStore->websiteDataStore().registerSharedResourceLoadObserver();
    153151}
    154152
  • trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp

    r219144 r219203  
    8888}
    8989
    90 Ref<WebResourceLoadStatisticsStore> WebResourceLoadStatisticsStore::create(const String& resourceLoadStatisticsDirectory)
    91 {
    92     return adoptRef(*new WebResourceLoadStatisticsStore(resourceLoadStatisticsDirectory));
    93 }
    94 
    95 WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore(const String& resourceLoadStatisticsDirectory)
     90WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore(const String& resourceLoadStatisticsDirectory, UpdatePartitionCookiesForDomainsHandler&& updatePartitionCookiesForDomainsHandler)
    9691    : m_resourceLoadStatisticsStore(ResourceLoadStatisticsStore::create())
    9792    , m_statisticsQueue(WorkQueue::create("WebResourceLoadStatisticsStore Process Data Queue", WorkQueue::Type::Serial, WorkQueue::QOS::Utility))
     
    10095    , m_telemetryRepeatedTimer(RunLoop::main(), this, &WebResourceLoadStatisticsStore::telemetryTimerFired)
    10196{
     97    ASSERT(RunLoop::isMain());
     98
     99#if PLATFORM(COCOA)
     100    registerUserDefaultsIfNeeded();
     101#endif
     102
     103    m_resourceLoadStatisticsStore->setNotificationCallback([this, protectedThis = makeRef(*this)] {
     104        if (m_resourceLoadStatisticsStore->isEmpty())
     105            return;
     106        processStatisticsAndDataRecords();
     107    });
     108    m_resourceLoadStatisticsStore->setWritePersistentStoreCallback([this, protectedThis = makeRef(*this)] {
     109        m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] {
     110            stopMonitoringStatisticsStorage();
     111            writeStoreToDisk();
     112            startMonitoringStatisticsStorage();
     113        });
     114    });
     115    m_resourceLoadStatisticsStore->setGrandfatherExistingWebsiteDataCallback([this, protectedThis = makeRef(*this)] {
     116        grandfatherExistingWebsiteData();
     117    });
     118    m_resourceLoadStatisticsStore->setDeletePersistentStoreCallback([this, protectedThis = makeRef(*this)] {
     119        m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] {
     120            deleteStoreFromDisk();
     121        });
     122    });
     123    m_resourceLoadStatisticsStore->setFireTelemetryCallback([this, protectedThis = makeRef(*this)] {
     124        submitTelemetry();
     125    });
     126
     127    if (updatePartitionCookiesForDomainsHandler) {
     128        m_resourceLoadStatisticsStore->setShouldPartitionCookiesCallback([updatePartitionCookiesForDomainsHandler = WTFMove(updatePartitionCookiesForDomainsHandler)] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst) {
     129            updatePartitionCookiesForDomainsHandler(domainsToRemove, domainsToAdd, shouldClearFirst);
     130        });
     131    }
     132
     133    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
     134        readDataFromDiskIfNeeded();
     135        startMonitoringStatisticsStorage();
     136    });
     137
    102138    m_telemetryOneShotTimer.startOneShot(5_s);
    103139    m_telemetryRepeatedTimer.startRepeating(24_h);
     
    187223}
    188224
    189 void WebResourceLoadStatisticsStore::setResourceLoadStatisticsEnabled(bool enabled)
    190 {
    191     ASSERT(RunLoop::isMain());
    192 
    193     if (enabled == m_resourceLoadStatisticsEnabled)
    194         return;
    195 
    196     m_resourceLoadStatisticsEnabled = enabled;
    197 
    198     if (m_resourceLoadStatisticsEnabled) {
    199         readDataFromDiskIfNeeded();
    200         m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
    201             startMonitoringStatisticsStorage();
    202         });
    203     } else
    204         m_statisticsQueue->dispatch([statisticsStorageMonitor = WTFMove(m_statisticsStorageMonitor)]  { });
    205 }
    206 
    207 bool WebResourceLoadStatisticsStore::resourceLoadStatisticsEnabled() const
    208 {
    209     return m_resourceLoadStatisticsEnabled;
    210 }
    211 
    212 void WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver()
    213 {
    214     ASSERT(RunLoop::isMain());
    215    
    216     m_resourceLoadStatisticsStore->setNotificationCallback([this, protectedThis = makeRef(*this)] {
    217         if (m_resourceLoadStatisticsStore->isEmpty())
    218             return;
    219         processStatisticsAndDataRecords();
    220     });
    221     m_resourceLoadStatisticsStore->setWritePersistentStoreCallback([this, protectedThis = makeRef(*this)] {
    222         m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] {
    223             stopMonitoringStatisticsStorage();
    224             writeStoreToDisk();
    225             startMonitoringStatisticsStorage();
    226         });
    227     });
    228     m_resourceLoadStatisticsStore->setGrandfatherExistingWebsiteDataCallback([this, protectedThis = makeRef(*this)] {
    229         grandfatherExistingWebsiteData();
    230     });
    231     m_resourceLoadStatisticsStore->setDeletePersistentStoreCallback([this, protectedThis = makeRef(*this)] {
    232         m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] {
    233             deleteStoreFromDisk();
    234         });
    235     });
    236     m_resourceLoadStatisticsStore->setFireTelemetryCallback([this, protectedThis = makeRef(*this)] {
    237         submitTelemetry();
    238     });
    239 
    240 #if PLATFORM(COCOA)
    241     registerUserDefaultsIfNeeded();
    242 #endif
    243 }
    244 
    245 void WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&& shouldPartitionCookiesForDomainsHandler)
    246 {
    247     ASSERT(RunLoop::isMain());
    248    
    249     registerSharedResourceLoadObserver();
    250     m_resourceLoadStatisticsStore->setShouldPartitionCookiesCallback([shouldPartitionCookiesForDomainsHandler = WTFMove(shouldPartitionCookiesForDomainsHandler)] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst) {
    251         shouldPartitionCookiesForDomainsHandler(domainsToRemove, domainsToAdd, clearFirst);
    252     });
    253 }
    254 
    255225void WebResourceLoadStatisticsStore::grandfatherExistingWebsiteData()
    256226{
     
    283253void WebResourceLoadStatisticsStore::readDataFromDiskIfNeeded()
    284254{
    285     if (!m_resourceLoadStatisticsEnabled)
    286         return;
    287 
    288     m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
    289         String resourceLog = persistentStoragePath(ASCIILiteral("full_browsing_session"));
    290         if (resourceLog.isEmpty() || !fileExists(resourceLog)) {
    291             grandfatherExistingWebsiteData();
    292             return;
    293         }
    294 
    295         if (!hasStatisticsFileChangedSinceLastSync(resourceLog)) {
    296             // No need to grandfather in this case.
    297             return;
    298         }
    299 
    300         WallTime readTime = WallTime::now();
    301 
    302         auto decoder = createDecoderFromDisk(resourceLog);
    303         if (!decoder) {
    304             grandfatherExistingWebsiteData();
    305             return;
    306         }
    307        
    308         coreStore().clearInMemory();
    309         coreStore().readDataFromDecoder(*decoder);
    310 
    311         m_lastStatisticsFileSyncTime = readTime;
    312 
    313         if (coreStore().isEmpty())
    314             grandfatherExistingWebsiteData();
    315     });
     255    ASSERT(!RunLoop::isMain());
     256
     257    String resourceLog = persistentStoragePath(ASCIILiteral("full_browsing_session"));
     258    if (resourceLog.isEmpty() || !fileExists(resourceLog)) {
     259        grandfatherExistingWebsiteData();
     260        return;
     261    }
     262
     263    if (!hasStatisticsFileChangedSinceLastSync(resourceLog)) {
     264        // No need to grandfather in this case.
     265        return;
     266    }
     267
     268    WallTime readTime = WallTime::now();
     269
     270    auto decoder = createDecoderFromDisk(resourceLog);
     271    if (!decoder) {
     272        grandfatherExistingWebsiteData();
     273        return;
     274    }
     275
     276    coreStore().clearInMemory();
     277    coreStore().readDataFromDecoder(*decoder);
     278
     279    m_lastStatisticsFileSyncTime = readTime;
     280
     281    if (coreStore().isEmpty())
     282        grandfatherExistingWebsiteData();
    316283}
    317284   
  • trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h

    r219144 r219203  
    5858class WebResourceLoadStatisticsStore final : public IPC::Connection::WorkQueueMessageReceiver {
    5959public:
    60     static Ref<WebResourceLoadStatisticsStore> create(const String&);
     60    using UpdatePartitionCookiesForDomainsHandler = WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst)>;
     61    static Ref<WebResourceLoadStatisticsStore> create(const String& resourceLoadStatisticsDirectory, UpdatePartitionCookiesForDomainsHandler&& updatePartitionCookiesForDomainsHandler = { })
     62    {
     63        return adoptRef(*new WebResourceLoadStatisticsStore(resourceLoadStatisticsDirectory, WTFMove(updatePartitionCookiesForDomainsHandler)));
     64    }
     65
    6166    static void setNotifyPagesWhenDataRecordsWereScanned(bool);
    6267    static void setShouldClassifyResourcesBeforeDataRecordsRemoval(bool);
    6368    static void setShouldSubmitTelemetry(bool);
    6469    virtual ~WebResourceLoadStatisticsStore();
    65    
    66     void setResourceLoadStatisticsEnabled(bool);
    67     bool resourceLoadStatisticsEnabled() const;
    68     void registerSharedResourceLoadObserver();
    69     void registerSharedResourceLoadObserver(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&& shouldPartitionCookiesForDomainsHandler);
    70    
     70
    7171    void resourceLoadStatisticsUpdated(const Vector<WebCore::ResourceLoadStatistics>& origins);
    7272
     
    7474    void processDidCloseConnection(WebProcessProxy&, IPC::Connection&);
    7575    void applicationWillTerminate();
    76 
    77     void readDataFromDiskIfNeeded();
    7876
    7977    void logUserInteraction(const WebCore::URL&);
     
    103101
    104102private:
    105     explicit WebResourceLoadStatisticsStore(const String&);
     103    WebResourceLoadStatisticsStore(const String&, UpdatePartitionCookiesForDomainsHandler&&);
    106104
    107105    ResourceLoadStatisticsStore& coreStore() { return m_resourceLoadStatisticsStore.get(); }
     
    109107
    110108    void processStatisticsAndDataRecords();
     109    void readDataFromDiskIfNeeded();
    111110
    112111    void classifyResource(WebCore::ResourceLoadStatistics&);
     
    149148    String m_statisticsStoragePath;
    150149    WTF::WallTime m_lastStatisticsFileSyncTime;
    151     bool m_resourceLoadStatisticsEnabled { false };
    152150    RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryOneShotTimer;
    153151    RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryRepeatedTimer;
  • trunk/Source/WebKit2/UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm

    r219052 r219203  
    104104    ASSERT(!dataStoresWithStorageManagers().contains(this));
    105105    dataStoresWithStorageManagers().append(this);
    106     if (m_resourceLoadStatistics)
    107         m_resourceLoadStatistics->readDataFromDiskIfNeeded();
    108106}
    109107
  • trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r219161 r219203  
    7777    , m_configuration(WTFMove(configuration))
    7878    , m_storageManager(StorageManager::create(m_configuration.localStorageDirectory))
    79     , m_resourceLoadStatistics(WebResourceLoadStatisticsStore::create(m_configuration.resourceLoadStatisticsDirectory))
    8079    , m_queue(WorkQueue::create("com.apple.WebKit.WebsiteDataStore"))
    8180{
     
    12551254bool WebsiteDataStore::resourceLoadStatisticsEnabled() const
    12561255{
    1257     return m_resourceLoadStatistics ? m_resourceLoadStatistics->resourceLoadStatisticsEnabled() : false;
     1256    return !!m_resourceLoadStatistics;
    12581257}
    12591258
    12601259void WebsiteDataStore::setResourceLoadStatisticsEnabled(bool enabled)
    12611260{
    1262     if (!m_resourceLoadStatistics)
    1263         return;
    1264 
    12651261    if (enabled == resourceLoadStatisticsEnabled())
    12661262        return;
    12671263
    1268     // FIXME: We should probably only initialize m_resourceLoadStatistics when resource load statistics get enabled.
    1269     m_resourceLoadStatistics->setResourceLoadStatisticsEnabled(enabled);
     1264    if (enabled) {
     1265#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
     1266        m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(m_configuration.resourceLoadStatisticsDirectory, [this] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst) {
     1267            updateCookiePartitioningForTopPrivatelyOwnedDomains(domainsToRemove, domainsToAdd, shouldClearFirst);
     1268        });
     1269#else
     1270        m_resourceLoadStatistics = WebResourceLoadStatisticsStore::create(m_configuration.resourceLoadStatisticsDirectory);
     1271#endif
     1272    } else
     1273        m_resourceLoadStatistics = nullptr;
    12701274
    12711275    for (auto& processPool : processPools())
    12721276        processPool->setResourceLoadStatisticsEnabled(enabled);
    1273 }
    1274 
    1275 void WebsiteDataStore::registerSharedResourceLoadObserver()
    1276 {
    1277     if (!m_resourceLoadStatistics)
    1278         return;
    1279    
    1280 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
    1281     m_resourceLoadStatistics->registerSharedResourceLoadObserver([this] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst) {
    1282         updateCookiePartitioningForTopPrivatelyOwnedDomains(domainsToRemove, domainsToAdd, shouldClearFirst);
    1283     });
    1284 #else
    1285     m_resourceLoadStatistics->registerSharedResourceLoadObserver();
    1286 #endif
    12871277}
    12881278
  • trunk/Source/WebKit2/UIProcess/WebsiteData/WebsiteDataStore.h

    r219161 r219203  
    9191    void setResourceLoadStatisticsEnabled(bool);
    9292    WebResourceLoadStatisticsStore* resourceLoadStatistics() const { return m_resourceLoadStatistics.get(); }
    93     void registerSharedResourceLoadObserver();
    9493
    9594    static void cloneSessionData(WebPageProxy& sourcePage, WebPageProxy& newPage);
     
    162161
    163162    const RefPtr<StorageManager> m_storageManager;
    164     const RefPtr<WebResourceLoadStatisticsStore> m_resourceLoadStatistics;
     163    RefPtr<WebResourceLoadStatisticsStore> m_resourceLoadStatistics;
    165164
    166165    Ref<WorkQueue> m_queue;
  • trunk/Source/WebKit2/UIProcess/wpe/WebProcessPoolWPE.cpp

    r217924 r219203  
    7676    }
    7777#endif
    78     m_websiteDataStore->websiteDataStore().registerSharedResourceLoadObserver();
    7978}
    8079
Note: See TracChangeset for help on using the changeset viewer.