Changeset 219277 in webkit


Ignore:
Timestamp:
Jul 8, 2017 4:11:16 PM (7 years ago)
Author:
Chris Dumez
Message:

Simplify WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore
https://bugs.webkit.org/show_bug.cgi?id=174290

Reviewed by Brent Fulgham.

Source/WebKit2:

  • UIProcess/API/Cocoa/WKWebsiteDataStore.mm:

(-[WKWebsiteDataStore _resourceLoadStatisticsProcessStatisticsAndDataRecords]):
(-[WKWebsiteDataStore _resourceLoadStatisticsSubmitTelemetry]):

  • UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:

Rename a couple of functions in the Cocoa SPI for clarity and to match the name
of their internal implementation.

  • UIProcess/Storage/ResourceLoadStatisticsStore.cpp:

(WebKit::ResourceLoadStatisticsStore::create):
(WebKit::ResourceLoadStatisticsStore::ensureResourceStatisticsForPrimaryDomain):
Stylistic changes.

(WebKit::ResourceLoadStatisticsStore::createEncoderFromData):
Make const.

(WebKit::ResourceLoadStatisticsStore::readDataFromDecoder):
Use HashMap::add() instead of HashMap::set(). There is not supposed to have any duplicate
keys so add() is sufficient and more efficient.

(WebKit::ResourceLoadStatisticsStore::clearInMemoryAndPersistent): Removed.
clearInMemoryAndPersistent() was only called from WebResourceLoadStatisticsStore and
the m_deletePersistentStoreHandler / m_grandfatherExistingWebsiteDataHandler were both
set by the WebResourceLoadStatisticsStore as well. Therefore, we don't really need this
function, WebResourceLoadStatisticsStore now calls ResourceLoadStatisticsStore::clearInMemory()
instead and takes care of doing what the m_deletePersistentStoreHandler /
m_grandfatherExistingWebsiteDataHandler handlers were doing on its side.

(WebKit::ResourceLoadStatisticsStore::mergeStatistics):
Pass Vector as rvalue reference, as a preparation for a future optimization. Added FIXME
comment about the optimization.

(WebKit::ResourceLoadStatisticsStore::setNotificationCallback): Removed.
(WebKit::ResourceLoadStatisticsStore::setGrandfatherExistingWebsiteDataCallback): Removed.
(WebKit::ResourceLoadStatisticsStore::setDeletePersistentStoreCallback): Removed.
(WebKit::ResourceLoadStatisticsStore::setFireTelemetryCallback): Removed.
Drop those callback setters. WebResourceLoadStatisticsStore is the only client of
ResourceLoadStatisticsStore and those callbacks were always called as a result of
an operation requested by the WebResourceLoadStatisticsStore. Therefore, those are
not needed. WebResourceLoadStatisticsStore can take care of doing what those
callbacks were doing on its side.

(WebKit::ResourceLoadStatisticsStore::processStatistics):
Pass parameter by const reference since we clearly do not intend to transfer ownership of it.

(WebKit::ResourceLoadStatisticsStore::topPrivatelyControlledDomainsToRemoveWebsiteDataFor):
(WebKit::ResourceLoadStatisticsStore::updateStatisticsForRemovedDataRecords):
(WebKit::ResourceLoadStatisticsStore::handleFreshStartWithEmptyOrNoStore):
Stylistic changes.

(WebKit::ResourceLoadStatisticsStore::shouldRemoveDataRecords): Removed.
(WebKit::ResourceLoadStatisticsStore::dataRecordsBeingRemoved): Removed.
(WebKit::ResourceLoadStatisticsStore::dataRecordsWereRemoved): Removed.
Those were moved to WebResourceLoadStatisticsStore since they do not require
any access to the statistics, and are only used by WebResourceLoadStatisticsStore.

  • UIProcess/Storage/ResourceLoadStatisticsStore.h:
  • UIProcess/WebResourceLoadStatisticsStore.cpp:

(WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
Store registering most callbacks on the coreStore. Instead, the logic of those
callbacks is now inlined in the few methods in WebResourceLoadStatisticsStore
that were causing these callbacks to be called.

(WebKit::WebResourceLoadStatisticsStore::removeDataRecords):
Access some methods on WebResourceLoadStatisticsStore instead of the coreStore
since those were moved.

(WebKit::WebResourceLoadStatisticsStore::processStatisticsAndDataRecords):
Drop unnecessary mutable for lambda.

(WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated):
Pass parameter as rvalue reference as a preparation for a future optimization.

(WebKit::WebResourceLoadStatisticsStore::hasStatisticsFileChangedSinceLastSync):
Make const.

(WebKit::WebResourceLoadStatisticsStore::submitTelemetry):
Add assertion to make sure this is called on the main thread.

(WebKit::WebResourceLoadStatisticsStore::fireDataModificationHandler): Removed.
This was dispatching to a background queue to call fireDataModificationHandler()
on the ResourceLoadStatisticsStore. The coreStore would then dispatch back on the
main thread to call the WebResourceLoadStatisticsStore's modification handler.
This modification handler was merely calling processStatisticsAndDataRecords().
Therefore, callers of WebResourceLoadStatisticsStore::fireDataModificationHandler()
can call WebResourceLoadStatisticsStore::processStatisticsAndDataRecords() directly
instead.

(WebKit::WebResourceLoadStatisticsStore::fireTelemetryHandler): Removed.
This was calling ResourceLoadStatisticsStore::fireTelemetryHandler(), which was
calling back WebResourceLoadStatisticsStore's fireTelemetryHandler. The handler
in question was merely calling submitTelemetry(). Therefore, callers of
WebResourceLoadStatisticsStore::fireTelemetryHandler() can call
WebResourceLoadStatisticsStore::submitTelemetry() directly instead.

(WebKit::WebResourceLoadStatisticsStore::clearInMemoryAndPersistent):
Call ResourceLoadStatisticsStore::clearInMemory() instead of clearInMemoryAndPersistent(),
which was removed. ResourceLoadStatisticsStore::clearInMemoryAndPersistent() was calling
clearInMemory() and then 2 of WebResourceLoadStatisticsStore's handlers. Instead, we now
call the functions that those handlers were calling directly, thus eliminating the need
for those handlers.

(WebKit::WebResourceLoadStatisticsStore::setMinimumTimeBetweenDataRecordsRemoval):
Set m_minimumTimeBetweenDataRecordsRemoval directly as it is now store on this class
instead of the coreStore.

(WebKit::WebResourceLoadStatisticsStore::shouldRemoveDataRecords):
(WebKit::WebResourceLoadStatisticsStore::dataRecordsBeingRemoved):
(WebKit::WebResourceLoadStatisticsStore::dataRecordsWereRemoved):
Those were merely moved from the ResourceLoadStatisticsStore.

  • UIProcess/WebResourceLoadStatisticsStore.h:
  • UIProcess/WebResourceLoadStatisticsTelemetry.cpp:

(WebKit::WebResourceLoadStatisticsTelemetry::calculateAndSubmit):
Check for sortedPrevalentResources.isEmpty() instead of checking if the size
if less than minimumPrevalentResourcesForTelemetry.
ResourceLoadStatisticsStore::sortedPrevalentResourceTelemetry() either returns
an empty vector or a vector with more than minimumPrevalentResourcesForTelemetry
items. Therefore, there is no need to expose minimumPrevalentResourcesForTelemetry.

Tools:

Rename testRunner API to match the new internal API names.

  • WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
  • WebKitTestRunner/InjectedBundle/TestRunner.cpp:

(WTR::TestRunner::statisticsProcessStatisticsAndDataRecords):
(WTR::TestRunner::statisticsSubmitTelemetry):

  • WebKitTestRunner/InjectedBundle/TestRunner.h:
  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::statisticsProcessStatisticsAndDataRecords):
(WTR::TestController::statisticsSubmitTelemetry):

  • WebKitTestRunner/TestController.h:
  • WebKitTestRunner/TestInvocation.cpp:

(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

  • WebKitTestRunner/cocoa/TestControllerCocoa.mm:

(WTR::TestController::statisticsProcessStatisticsAndDataRecords):
(WTR::TestController::statisticsSubmitTelemetry):

LayoutTests:

Update layout tests to reflect changes to the testRunner API naming.

  • http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics.html:
  • http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins.html:
  • http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins.html:
  • http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to.html:
  • http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics.html:
  • http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins.html:
  • http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins.html:
  • http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to.html:
  • http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html:
  • http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store.html:
  • http/tests/loading/resourceLoadStatistics/grandfathering.html:
  • http/tests/loading/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html:
  • http/tests/loading/resourceLoadStatistics/non-prevalent-resource-without-user-interaction.html:
  • http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html:
  • http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html:
  • http/tests/loading/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html:
  • http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout.html:
  • http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction.html:
  • http/tests/loading/resourceLoadStatistics/prevalent-resource-without-user-interaction.html:
  • http/tests/loading/resourceLoadStatistics/telemetry-generation.html:
Location:
trunk
Files:
35 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r219272 r219277  
     12017-07-08  Chris Dumez  <cdumez@apple.com>
     2
     3        Simplify WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore
     4        https://bugs.webkit.org/show_bug.cgi?id=174290
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Update layout tests to reflect changes to the testRunner API naming.
     9
     10        * http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics.html:
     11        * http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins.html:
     12        * http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins.html:
     13        * http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to.html:
     14        * http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics.html:
     15        * http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins.html:
     16        * http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins.html:
     17        * http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to.html:
     18        * http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html:
     19        * http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store.html:
     20        * http/tests/loading/resourceLoadStatistics/grandfathering.html:
     21        * http/tests/loading/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html:
     22        * http/tests/loading/resourceLoadStatistics/non-prevalent-resource-without-user-interaction.html:
     23        * http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html:
     24        * http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-with-partitioning-timeout.html:
     25        * http/tests/loading/resourceLoadStatistics/partitioned-cookies-with-and-without-user-interaction.html:
     26        * http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout.html:
     27        * http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction.html:
     28        * http/tests/loading/resourceLoadStatistics/prevalent-resource-without-user-interaction.html:
     29        * http/tests/loading/resourceLoadStatistics/telemetry-generation.html:
     30
    1312017-07-07  Daniel Bates  <dabates@apple.com>
    232
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-mixed-statistics.html

    r217606 r219277  
    3737        testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
    3838
    39         testRunner.statisticsFireDataModificationHandler();
     39        testRunner.statisticsProcessStatisticsAndDataRecords();
    4040    }
    4141
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-sub-frame-under-top-frame-origins.html

    r217606 r219277  
    3838        testRunner.installStatisticsDidModifyDataRecordsCallback(completeTest);
    3939
    40         testRunner.statisticsFireDataModificationHandler();
     40        testRunner.statisticsProcessStatisticsAndDataRecords();
    4141    }
    4242
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-under-top-frame-origins.html

    r217606 r219277  
    3535        testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
    3636
    37         testRunner.statisticsFireDataModificationHandler();
     37        testRunner.statisticsProcessStatisticsAndDataRecords();
    3838    }
    3939
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-non-prevalent-based-on-subresource-unique-redirects-to.html

    r217606 r219277  
    3636        testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
    3737
    38         testRunner.statisticsFireDataModificationHandler();
     38        testRunner.statisticsProcessStatisticsAndDataRecords();
    3939    }
    4040
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-mixed-statistics.html

    r217606 r219277  
    4545        testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
    4646
    47         testRunner.statisticsFireDataModificationHandler();
     47        testRunner.statisticsProcessStatisticsAndDataRecords();
    4848    }
    4949
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-sub-frame-under-top-frame-origins.html

    r217606 r219277  
    4040        testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
    4141
    42         testRunner.statisticsFireDataModificationHandler();
     42        testRunner.statisticsProcessStatisticsAndDataRecords();
    4343    }
    4444
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-under-top-frame-origins.html

    r217606 r219277  
    4040        testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
    4141
    42         testRunner.statisticsFireDataModificationHandler();
     42        testRunner.statisticsProcessStatisticsAndDataRecords();
    4343    }
    4444
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/classify-as-prevalent-based-on-subresource-unique-redirects-to.html

    r217606 r219277  
    4040        testRunner.installStatisticsDidScanDataRecordsCallback(completeTest);
    4141
    42         testRunner.statisticsFireDataModificationHandler();
     42        testRunner.statisticsProcessStatisticsAndDataRecords();
    4343    }
    4444
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store-one-hour.html

    r217606 r219277  
    5656        testRunner.installStatisticsDidModifyDataRecordsCallback(testStep2);
    5757
    58         testRunner.statisticsFireDataModificationHandler();
     58        testRunner.statisticsProcessStatisticsAndDataRecords();
    5959    }
    6060
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/clear-in-memory-and-persistent-store.html

    r217606 r219277  
    5656        testRunner.installStatisticsDidModifyDataRecordsCallback(testStep2);
    5757
    58         testRunner.statisticsFireDataModificationHandler();
     58        testRunner.statisticsProcessStatisticsAndDataRecords();
    5959    }
    6060
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/grandfathering.html

    r219025 r219277  
    3737            runTest();
    3838        });
    39         testRunner.statisticsFireDataModificationHandler();
     39        testRunner.statisticsProcessStatisticsAndDataRecords();
    4040    }
    4141
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html

    r219025 r219277  
    4444        testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
    4545        testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
    46         testRunner.statisticsFireDataModificationHandler();
     46        testRunner.statisticsProcessStatisticsAndDataRecords();
    4747    }
    4848
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/non-prevalent-resource-without-user-interaction.html

    r219025 r219277  
    4444        testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
    4545        testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
    46         testRunner.statisticsFireDataModificationHandler();
     46        testRunner.statisticsProcessStatisticsAndDataRecords();
    4747    }
    4848
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/partitioned-and-unpartitioned-cookie-deletion.html

    r219025 r219277  
    4646            runTest();
    4747        });
    48         testRunner.statisticsFireDataModificationHandler();
     48        testRunner.statisticsProcessStatisticsAndDataRecords();
    4949    }
    5050
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction-timeout.html

    r219025 r219277  
    3838        testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
    3939        testRunner.setStatisticsTimeToLiveUserInteraction(0);
    40         setTimeout("testRunner.statisticsFireDataModificationHandler()", 1000);
     40        setTimeout("testRunner.statisticsProcessStatisticsAndDataRecords()", 1000);
    4141    }
    4242
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-with-user-interaction.html

    r219025 r219277  
    4444        testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
    4545        testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
    46         testRunner.statisticsFireDataModificationHandler();
     46        testRunner.statisticsProcessStatisticsAndDataRecords();
    4747    }
    4848
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/prevalent-resource-without-user-interaction.html

    r219025 r219277  
    3737        testRunner.setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(false);
    3838        testRunner.setStatisticsMinimumTimeBetweenDataRecordsRemoval(0);
    39         testRunner.statisticsFireDataModificationHandler();
     39        testRunner.statisticsProcessStatisticsAndDataRecords();
    4040    }
    4141
  • trunk/LayoutTests/http/tests/loading/resourceLoadStatistics/telemetry-generation.html

    r218841 r219277  
    7575        testRunner.installStatisticsDidScanDataRecordsCallback(checkInsufficientClassificationAndContinue);
    7676        testRunner.installStatisticsDidRunTelemetryCallback(checkInsufficientTelemetry);
    77         testRunner.statisticsFireDataModificationHandler();
     77        testRunner.statisticsProcessStatisticsAndDataRecords();
    7878    }
    7979
     
    8686        testRunner.installStatisticsDidScanDataRecordsCallback(checkSufficientClassificationAndContinue);
    8787        testRunner.installStatisticsDidRunTelemetryCallback(checkSufficientTelemetry);
    88         testRunner.statisticsFireDataModificationHandler();
     88        testRunner.statisticsProcessStatisticsAndDataRecords();
    8989    }
    9090
    9191    function runTelemetryAndContinue() {
    92         testRunner.statisticsFireTelemetryHandler();
     92        testRunner.statisticsSubmitTelemetry();
    9393    }
    9494
  • trunk/Source/WebKit2/ChangeLog

    r219276 r219277  
     12017-07-08  Chris Dumez  <cdumez@apple.com>
     2
     3        Simplify WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore
     4        https://bugs.webkit.org/show_bug.cgi?id=174290
     5
     6        Reviewed by Brent Fulgham.
     7
     8        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
     9        (-[WKWebsiteDataStore _resourceLoadStatisticsProcessStatisticsAndDataRecords]):
     10        (-[WKWebsiteDataStore _resourceLoadStatisticsSubmitTelemetry]):
     11        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
     12        Rename a couple of functions in the Cocoa SPI for clarity and to match the name
     13        of their internal implementation.
     14
     15        * UIProcess/Storage/ResourceLoadStatisticsStore.cpp:
     16        (WebKit::ResourceLoadStatisticsStore::create):
     17        (WebKit::ResourceLoadStatisticsStore::ensureResourceStatisticsForPrimaryDomain):
     18        Stylistic changes.
     19
     20        (WebKit::ResourceLoadStatisticsStore::createEncoderFromData):
     21        Make const.
     22
     23        (WebKit::ResourceLoadStatisticsStore::readDataFromDecoder):
     24        Use HashMap::add() instead of HashMap::set(). There is not supposed to have any duplicate
     25        keys so add() is sufficient and more efficient.
     26
     27        (WebKit::ResourceLoadStatisticsStore::clearInMemoryAndPersistent): Removed.
     28        clearInMemoryAndPersistent() was only called from WebResourceLoadStatisticsStore and
     29        the m_deletePersistentStoreHandler / m_grandfatherExistingWebsiteDataHandler were both
     30        set by the WebResourceLoadStatisticsStore as well. Therefore, we don't really need this
     31        function, WebResourceLoadStatisticsStore now calls ResourceLoadStatisticsStore::clearInMemory()
     32        instead and takes care of doing what the m_deletePersistentStoreHandler /
     33        m_grandfatherExistingWebsiteDataHandler handlers were doing on its side.
     34
     35        (WebKit::ResourceLoadStatisticsStore::mergeStatistics):
     36        Pass Vector as rvalue reference, as a preparation for a future optimization. Added FIXME
     37        comment about the optimization.
     38
     39        (WebKit::ResourceLoadStatisticsStore::setNotificationCallback): Removed.
     40        (WebKit::ResourceLoadStatisticsStore::setGrandfatherExistingWebsiteDataCallback): Removed.
     41        (WebKit::ResourceLoadStatisticsStore::setDeletePersistentStoreCallback): Removed.
     42        (WebKit::ResourceLoadStatisticsStore::setFireTelemetryCallback): Removed.
     43        Drop those callback setters. WebResourceLoadStatisticsStore is the only client of
     44        ResourceLoadStatisticsStore and those callbacks were always called as a result of
     45        an operation requested by the WebResourceLoadStatisticsStore. Therefore, those are
     46        not needed. WebResourceLoadStatisticsStore can take care of doing what those
     47        callbacks were doing on its side.
     48
     49        (WebKit::ResourceLoadStatisticsStore::processStatistics):
     50        Pass parameter by const reference since we clearly do not intend to transfer ownership of it.
     51
     52        (WebKit::ResourceLoadStatisticsStore::topPrivatelyControlledDomainsToRemoveWebsiteDataFor):
     53        (WebKit::ResourceLoadStatisticsStore::updateStatisticsForRemovedDataRecords):
     54        (WebKit::ResourceLoadStatisticsStore::handleFreshStartWithEmptyOrNoStore):
     55        Stylistic changes.
     56
     57        (WebKit::ResourceLoadStatisticsStore::shouldRemoveDataRecords): Removed.
     58        (WebKit::ResourceLoadStatisticsStore::dataRecordsBeingRemoved): Removed.
     59        (WebKit::ResourceLoadStatisticsStore::dataRecordsWereRemoved): Removed.
     60        Those were moved to WebResourceLoadStatisticsStore since they do not require
     61        any access to the statistics, and are only used by WebResourceLoadStatisticsStore.
     62
     63        * UIProcess/Storage/ResourceLoadStatisticsStore.h:
     64
     65        * UIProcess/WebResourceLoadStatisticsStore.cpp:
     66        (WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
     67        Store registering most callbacks on the coreStore. Instead, the logic of those
     68        callbacks is now inlined in the few methods in WebResourceLoadStatisticsStore
     69        that were causing these callbacks to be called.
     70
     71        (WebKit::WebResourceLoadStatisticsStore::removeDataRecords):
     72        Access some methods on WebResourceLoadStatisticsStore instead of the coreStore
     73        since those were moved.
     74
     75        (WebKit::WebResourceLoadStatisticsStore::processStatisticsAndDataRecords):
     76        Drop unnecessary mutable for lambda.
     77
     78        (WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated):
     79        Pass parameter as rvalue reference as a preparation for a future optimization.
     80
     81        (WebKit::WebResourceLoadStatisticsStore::hasStatisticsFileChangedSinceLastSync):
     82        Make const.
     83
     84        (WebKit::WebResourceLoadStatisticsStore::submitTelemetry):
     85        Add assertion to make sure this is called on the main thread.
     86
     87        (WebKit::WebResourceLoadStatisticsStore::fireDataModificationHandler): Removed.
     88        This was dispatching to a background queue to call fireDataModificationHandler()
     89        on the ResourceLoadStatisticsStore. The coreStore would then dispatch back on the
     90        main thread to call the WebResourceLoadStatisticsStore's modification handler.
     91        This modification handler was merely calling processStatisticsAndDataRecords().
     92        Therefore, callers of WebResourceLoadStatisticsStore::fireDataModificationHandler()
     93        can call WebResourceLoadStatisticsStore::processStatisticsAndDataRecords() directly
     94        instead.
     95
     96        (WebKit::WebResourceLoadStatisticsStore::fireTelemetryHandler): Removed.
     97        This was calling ResourceLoadStatisticsStore::fireTelemetryHandler(), which was
     98        calling back WebResourceLoadStatisticsStore's fireTelemetryHandler. The handler
     99        in question was merely calling submitTelemetry(). Therefore, callers of
     100        WebResourceLoadStatisticsStore::fireTelemetryHandler() can call
     101        WebResourceLoadStatisticsStore::submitTelemetry() directly instead.
     102
     103        (WebKit::WebResourceLoadStatisticsStore::clearInMemoryAndPersistent):
     104        Call ResourceLoadStatisticsStore::clearInMemory() instead of clearInMemoryAndPersistent(),
     105        which was removed. ResourceLoadStatisticsStore::clearInMemoryAndPersistent() was calling
     106        clearInMemory() and then 2 of WebResourceLoadStatisticsStore's handlers. Instead, we now
     107        call the functions that those handlers were calling directly, thus eliminating the need
     108        for those handlers.
     109
     110        (WebKit::WebResourceLoadStatisticsStore::setMinimumTimeBetweenDataRecordsRemoval):
     111        Set m_minimumTimeBetweenDataRecordsRemoval directly as it is now store on this class
     112        instead of the coreStore.
     113
     114        (WebKit::WebResourceLoadStatisticsStore::shouldRemoveDataRecords):
     115        (WebKit::WebResourceLoadStatisticsStore::dataRecordsBeingRemoved):
     116        (WebKit::WebResourceLoadStatisticsStore::dataRecordsWereRemoved):
     117        Those were merely moved from the ResourceLoadStatisticsStore.
     118
     119        * UIProcess/WebResourceLoadStatisticsStore.h:
     120
     121        * UIProcess/WebResourceLoadStatisticsTelemetry.cpp:
     122        (WebKit::WebResourceLoadStatisticsTelemetry::calculateAndSubmit):
     123        Check for sortedPrevalentResources.isEmpty() instead of checking if the size
     124        if less than minimumPrevalentResourcesForTelemetry.
     125        ResourceLoadStatisticsStore::sortedPrevalentResourceTelemetry() either returns
     126        an empty vector or a vector with more than minimumPrevalentResourcesForTelemetry
     127        items. Therefore, there is no need to expose minimumPrevalentResourcesForTelemetry.
     128
    11292017-07-08  Yusuke Suzuki  <utatane.tea@gmail.com>
    2130
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r219275 r219277  
    346346}
    347347
    348 - (void)_resourceLoadStatisticsFireDataModificationHandler
    349 {
    350     auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
    351     if (!store)
    352         return;
    353 
    354     store->fireDataModificationHandler();
     348- (void)_resourceLoadStatisticsProcessStatisticsAndDataRecords
     349{
     350    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
     351    if (!store)
     352        return;
     353
     354    store->processStatisticsAndDataRecords();
    355355}
    356356
     
    376376}
    377377
    378 - (void)_resourceLoadStatisticsFireTelemetryHandler
    379 {
    380     auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
    381     if (!store)
    382         return;
    383 
    384     store->fireTelemetryHandler();
     378- (void)_resourceLoadStatisticsSubmitTelemetry
     379{
     380    auto* store = _websiteDataStore->websiteDataStore().resourceLoadStatistics();
     381    if (!store)
     382        return;
     383
     384    store->submitTelemetry();
    385385}
    386386
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h

    r219071 r219277  
    5858- (void)_resourceLoadStatisticsSetMinimumTimeBetweenDataRecordsRemoval:(double)seconds WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    5959- (void)_resourceLoadStatisticsSetGrandfatheringTime:(double)seconds WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    60 - (void)_resourceLoadStatisticsFireDataModificationHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     60- (void)_resourceLoadStatisticsProcessStatisticsAndDataRecords WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    6161- (void)_resourceLoadStatisticsFireShouldPartitionCookiesHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    6262- (void)_resourceLoadStatisticsFireShouldPartitionCookiesHandlerForOneDomain:(BOOL)value forHost:(NSString *)host WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    63 - (void)_resourceLoadStatisticsFireTelemetryHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     63- (void)_resourceLoadStatisticsSubmitTelemetry WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    6464- (void)_resourceLoadStatisticsSetNotifyPagesWhenDataRecordsWereScanned:(BOOL)value WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    6565- (void)_resourceLoadStatisticsSetShouldClassifyResourcesBeforeDataRecordsRemoval:(BOOL)value WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
  • trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.cpp

    r219275 r219277  
    2727#include "ResourceLoadStatisticsStore.h"
    2828
    29 #include "Logging.h"
    3029#include <WebCore/KeyedCoding.h>
    3130#include <WebCore/ResourceLoadStatistics.h>
    32 #include <WebCore/SharedBuffer.h>
    33 #include <WebCore/URL.h>
    3431#include <wtf/CrossThreadCopier.h>
    35 #include <wtf/NeverDestroyed.h>
    3632#include <wtf/RunLoop.h>
    3733
     
    4036using namespace WebCore;
    4137
     38const unsigned minimumPrevalentResourcesForTelemetry = 3;
     39const unsigned operatingDatesWindow { 30 };
    4240const unsigned statisticsModelVersion { 6 };
    43 const unsigned operatingDatesWindow { 30 };
    44    
     41
    4542Ref<ResourceLoadStatisticsStore> ResourceLoadStatisticsStore::create()
    4643{
    47     return adoptRef(*new ResourceLoadStatisticsStore());
    48 }
    49    
     44    return adoptRef(*new ResourceLoadStatisticsStore);
     45}
     46
    5047bool ResourceLoadStatisticsStore::isPrevalentResource(const String& primaryDomain) const
    5148{
     
    7168{
    7269    ASSERT(!RunLoop::isMain());
    73     auto addResult = m_resourceStatisticsMap.ensure(primaryDomain, [&primaryDomain] {
     70    return m_resourceStatisticsMap.ensure(primaryDomain, [&primaryDomain] {
    7471        return ResourceLoadStatistics(primaryDomain);
    75     });
    76 
    77     return addResult.iterator->value;
     72    }).iterator->value;
    7873}
    7974
    8075typedef HashMap<String, ResourceLoadStatistics>::KeyValuePairType StatisticsValue;
    8176
    82 std::unique_ptr<KeyedEncoder> ResourceLoadStatisticsStore::createEncoderFromData()
     77std::unique_ptr<KeyedEncoder> ResourceLoadStatisticsStore::createEncoderFromData() const
    8378{
    8479    ASSERT(!RunLoop::isMain());
     
    10196{
    10297    ASSERT(!RunLoop::isMain());
    103     if (m_resourceStatisticsMap.size())
     98    if (!m_resourceStatisticsMap.isEmpty())
    10499        return;
    105100
     
    132127            statistics.isMarkedForCookiePartitioning = true;
    133128        }
    134         m_resourceStatisticsMap.set(statistics.highLevelDomain, WTFMove(statistics));
     129        m_resourceStatisticsMap.add(statistics.highLevelDomain, WTFMove(statistics));
    135130    }
    136131
     
    159154}
    160155
    161 void ResourceLoadStatisticsStore::clearInMemoryAndPersistent()
    162 {
    163     ASSERT(!RunLoop::isMain());
    164     clearInMemory();
    165     if (m_deletePersistentStoreHandler)
    166         m_deletePersistentStoreHandler();
    167     if (m_grandfatherExistingWebsiteDataHandler)
    168         m_grandfatherExistingWebsiteDataHandler();
    169 }
    170 
    171 void ResourceLoadStatisticsStore::mergeStatistics(const Vector<ResourceLoadStatistics>& statistics)
     156void ResourceLoadStatisticsStore::mergeStatistics(Vector<ResourceLoadStatistics>&& statistics)
    172157{
    173158    ASSERT(!RunLoop::isMain());
    174159    for (auto& statistic : statistics) {
     160        // FIXME: In the case where the statistics does not already exist, it seems inefficient to create
     161        // an empty one just to merge the new one into it.
    175162        auto result = m_resourceStatisticsMap.ensure(statistic.highLevelDomain, [&statistic] {
    176163            return ResourceLoadStatistics(statistic.highLevelDomain);
     
    181168}
    182169
    183 void ResourceLoadStatisticsStore::setNotificationCallback(WTF::Function<void()>&& handler)
    184 {
    185     m_dataAddedHandler = WTFMove(handler);
    186 }
    187 
    188170void ResourceLoadStatisticsStore::setShouldPartitionCookiesCallback(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&& handler)
    189171{
    190172    m_shouldPartitionCookiesForDomainsHandler = WTFMove(handler);
    191173}
    192    
    193 void ResourceLoadStatisticsStore::setGrandfatherExistingWebsiteDataCallback(WTF::Function<void()>&& handler)
    194 {
    195     m_grandfatherExistingWebsiteDataHandler = WTFMove(handler);
    196 }
    197 
    198 void ResourceLoadStatisticsStore::setDeletePersistentStoreCallback(WTF::Function<void()>&& handler)
    199 {
    200     m_deletePersistentStoreHandler = WTFMove(handler);
    201 }
    202 
    203 void ResourceLoadStatisticsStore::setFireTelemetryCallback(WTF::Function<void()>&& handler)
    204 {
    205     m_fireTelemetryHandler = WTFMove(handler);
    206 }
    207    
    208 void ResourceLoadStatisticsStore::fireDataModificationHandler()
    209 {
    210     ASSERT(!RunLoop::isMain());
    211     RunLoop::main().dispatch([this, protectedThis = makeRef(*this)] () {
    212         if (m_dataAddedHandler)
    213             m_dataAddedHandler();
    214     });
    215 }
    216 
    217 void ResourceLoadStatisticsStore::fireTelemetryHandler()
    218 {
    219     ASSERT(RunLoop::isMain());
    220     if (m_fireTelemetryHandler)
    221         m_fireTelemetryHandler();
    222 }
    223    
     174
    224175inline bool ResourceLoadStatisticsStore::shouldPartitionCookies(const ResourceLoadStatistics& statistic) const
    225176{
     
    288239}
    289240
    290 void ResourceLoadStatisticsStore::setMinimumTimeBetweenDataRecordsRemoval(Seconds seconds)
    291 {
    292     ASSERT(seconds >= 0_s);
    293     m_minimumTimeBetweenDataRecordsRemoval = seconds;
    294 }
    295 
    296241void ResourceLoadStatisticsStore::setGrandfatheringTime(Seconds seconds)
    297242{
     
    300245}
    301246
    302 void ResourceLoadStatisticsStore::processStatistics(WTF::Function<void(ResourceLoadStatistics&)>&& processFunction)
     247void ResourceLoadStatisticsStore::processStatistics(const WTF::Function<void(ResourceLoadStatistics&)>& processFunction)
    303248{
    304249    ASSERT(!RunLoop::isMain());
     
    337282    Vector<String> prevalentResources;
    338283    for (auto& statistic : m_resourceStatisticsMap.values()) {
    339         if (statistic.isPrevalentResource
    340             && !hasHadRecentUserInteraction(statistic)
    341             && (!shouldCheckForGrandfathering || !statistic.grandfathered))
     284        if (statistic.isPrevalentResource && !hasHadRecentUserInteraction(statistic) && (!shouldCheckForGrandfathering || !statistic.grandfathered))
    342285            prevalentResources.append(statistic.highLevelDomain);
    343286
     
    383326    ASSERT(!RunLoop::isMain());
    384327    for (auto& prevalentResourceDomain : prevalentResourceDomains) {
    385         ResourceLoadStatistics& statistic = ensureResourceStatisticsForPrimaryDomain(prevalentResourceDomain);
     328        auto& statistic = ensureResourceStatisticsForPrimaryDomain(prevalentResourceDomain);
    386329        ++statistic.dataRecordsRemoved;
    387330    }
     
    392335    ASSERT(!RunLoop::isMain());
    393336    for (auto& topPrivatelyControlledDomain : topPrivatelyControlledDomainsToGrandfather) {
    394         ResourceLoadStatistics& statistic = ensureResourceStatisticsForPrimaryDomain(topPrivatelyControlledDomain);
     337        auto& statistic = ensureResourceStatisticsForPrimaryDomain(topPrivatelyControlledDomain);
    395338        statistic.grandfathered = true;
    396339    }
    397340    m_endOfGrandfatheringTimestamp = WallTime::now() + m_grandfatheringTime;
    398 }
    399 
    400 bool ResourceLoadStatisticsStore::shouldRemoveDataRecords() const
    401 {
    402     ASSERT(!RunLoop::isMain());
    403     if (m_dataRecordsRemovalPending)
    404         return false;
    405 
    406     if (m_lastTimeDataRecordsWereRemoved && MonotonicTime::now() < (m_lastTimeDataRecordsWereRemoved + m_minimumTimeBetweenDataRecordsRemoval))
    407         return false;
    408 
    409     return true;
    410 }
    411 
    412 void ResourceLoadStatisticsStore::dataRecordsBeingRemoved()
    413 {
    414     ASSERT(!RunLoop::isMain());
    415     m_lastTimeDataRecordsWereRemoved = MonotonicTime::now();
    416     m_dataRecordsRemovalPending = true;
    417 }
    418 
    419 void ResourceLoadStatisticsStore::dataRecordsWereRemoved()
    420 {
    421     ASSERT(!RunLoop::isMain());
    422     m_dataRecordsRemovalPending = false;
    423341}
    424342
  • trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.h

    r219275 r219277  
    4242namespace WebKit {
    4343
    44 static const auto minimumPrevalentResourcesForTelemetry = 3;
    45 
    4644struct PrevalentResourceTelemetry {
    4745    unsigned numberOfTimesDataRecordsRemoved;
     
    5856    static Ref<ResourceLoadStatisticsStore> create();
    5957
    60     std::unique_ptr<WebCore::KeyedEncoder> createEncoderFromData();
     58    std::unique_ptr<WebCore::KeyedEncoder> createEncoderFromData() const;
    6159    void readDataFromDecoder(WebCore::KeyedDecoder&);
    6260
    6361    bool isEmpty() const { return m_resourceStatisticsMap.isEmpty(); }
    64     size_t size() const { return m_resourceStatisticsMap.size(); }
    6562    void clearInMemory();
    66     void clearInMemoryAndPersistent();
    6763
    6864    WebCore::ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
    69     void setResourceStatisticsForPrimaryDomain(const String&, WebCore::ResourceLoadStatistics&&);
    7065
    7166    bool isPrevalentResource(const String&) const;
    7267    bool isGrandFathered(const String&) const;
    7368   
    74     void mergeStatistics(const Vector<WebCore::ResourceLoadStatistics>&);
     69    void mergeStatistics(Vector<WebCore::ResourceLoadStatistics>&&);
    7570
    76     void setNotificationCallback(WTF::Function<void()>&&);
    7771    void setShouldPartitionCookiesCallback(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&&);
    78     void setDeletePersistentStoreCallback(WTF::Function<void()>&&);
    79     void setGrandfatherExistingWebsiteDataCallback(WTF::Function<void()>&&);
    80     void setFireTelemetryCallback(WTF::Function<void()>&& handler);
    8172
    82     void fireDataModificationHandler();
    83     void fireTelemetryHandler();
    8473    void setTimeToLiveUserInteraction(std::optional<Seconds>);
    8574    void setTimeToLiveCookiePartitionFree(Seconds);
    86     void setMinimumTimeBetweenDataRecordsRemoval(Seconds);
    8775    void setGrandfatheringTime(Seconds);
     76
    8877    void fireShouldPartitionCookiesHandler();
    8978    void fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst);
    9079
    91     void processStatistics(WTF::Function<void (WebCore::ResourceLoadStatistics&)>&&);
     80    void processStatistics(const WTF::Function<void (WebCore::ResourceLoadStatistics&)>&);
    9281
    9382    bool hasHadRecentUserInteraction(WebCore::ResourceLoadStatistics&) const;
     
    9786
    9887    void handleFreshStartWithEmptyOrNoStore(HashSet<String>&& topPrivatelyControlledDomainsToGrandfather);
    99     bool shouldRemoveDataRecords() const;
    100     void dataRecordsBeingRemoved();
    101     void dataRecordsWereRemoved();
    102 
    10388    void includeTodayAsOperatingDateIfNecessary();
    10489
     
    11297    Deque<WTF::WallTime> m_operatingDates;
    11398
    114     WTF::Function<void()> m_dataAddedHandler;
    11599    WTF::Function<void(const Vector<String>&, const Vector<String>&, bool clearFirst)> m_shouldPartitionCookiesForDomainsHandler;
    116     WTF::Function<void()> m_grandfatherExistingWebsiteDataHandler;
    117     WTF::Function<void()> m_deletePersistentStoreHandler;
    118     WTF::Function<void()> m_fireTelemetryHandler;
    119100
    120101    std::optional<Seconds> m_timeToLiveUserInteraction;
    121102    Seconds m_timeToLiveCookiePartitionFree { 24_h };
    122103    Seconds m_grandfatheringTime { 1_h };
    123     Seconds m_minimumTimeBetweenDataRecordsRemoval { 1_h };
    124104
    125105    WallTime m_endOfGrandfatheringTimestamp;
    126     MonotonicTime m_lastTimeDataRecordsWereRemoved;
    127     bool m_dataRecordsRemovalPending { false };
    128106};
    129107   
  • trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp

    r219275 r219277  
    2828
    2929#include "Logging.h"
     30#include "ResourceLoadStatisticsStore.h"
    3031#include "WebProcessMessages.h"
    31 #include "WebProcessPool.h"
    3232#include "WebProcessProxy.h"
    3333#include "WebResourceLoadStatisticsStoreMessages.h"
     34#include "WebResourceLoadStatisticsTelemetry.h"
    3435#include "WebsiteDataFetchOption.h"
    3536#include "WebsiteDataType.h"
     
    3839#include <WebCore/KeyedCoding.h>
    3940#include <WebCore/ResourceLoadStatistics.h>
     41#include <WebCore/SharedBuffer.h>
    4042#include <wtf/CrossThreadCopier.h>
    41 #include <wtf/MainThread.h>
    4243#include <wtf/MathExtras.h>
    43 #include <wtf/MonotonicTime.h>
    4444#include <wtf/NeverDestroyed.h>
    45 #include <wtf/RunLoop.h>
    46 #include <wtf/Seconds.h>
    47 #include <wtf/WallTime.h>
    4845#include <wtf/threads/BinarySemaphore.h>
    4946
     
    104101#endif
    105102
    106     m_resourceLoadStatisticsStore->setNotificationCallback([this, protectedThis = makeRef(*this)] {
    107         if (m_resourceLoadStatisticsStore->isEmpty())
    108             return;
    109         processStatisticsAndDataRecords();
    110     });
    111     m_resourceLoadStatisticsStore->setGrandfatherExistingWebsiteDataCallback([this, protectedThis = makeRef(*this)] {
    112         grandfatherExistingWebsiteData();
    113     });
    114     m_resourceLoadStatisticsStore->setDeletePersistentStoreCallback([this, protectedThis = makeRef(*this)] {
    115         m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] {
    116             deleteStoreFromDisk();
    117         });
    118     });
    119     m_resourceLoadStatisticsStore->setFireTelemetryCallback([this, protectedThis = makeRef(*this)] {
    120         submitTelemetry();
    121     });
    122 
    123103    if (updatePartitionCookiesForDomainsHandler) {
    124104        m_resourceLoadStatisticsStore->setShouldPartitionCookiesCallback([updatePartitionCookiesForDomainsHandler = WTFMove(updatePartitionCookiesForDomainsHandler)] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst) {
     
    165145    ASSERT(!RunLoop::isMain());
    166146   
    167     if (!coreStore().shouldRemoveDataRecords())
     147    if (!shouldRemoveDataRecords())
    168148        return;
    169149
     
    172152        return;
    173153   
    174     coreStore().dataRecordsBeingRemoved();
     154    dataRecordsBeingRemoved();
    175155
    176156    // Switch to the main thread to get the default website data store
     
    178158        WebProcessProxy::deleteWebsiteDataForTopPrivatelyControlledDomainsInAllPersistentDataStores(dataTypesToRemove(), WTFMove(prevalentResourceDomains), notifyPagesWhenDataRecordsWereScanned, [this, protectedThis = WTFMove(protectedThis)](const HashSet<String>& domainsWithDeletedWebsiteData) mutable {
    179159            // But always touch the ResourceLoadStatistics store on the worker queue.
    180             m_statisticsQueue->dispatch([protectedThis = WTFMove(protectedThis), topDomains = CrossThreadCopier<HashSet<String>>::copy(domainsWithDeletedWebsiteData)] () mutable {
    181                 protectedThis->coreStore().updateStatisticsForRemovedDataRecords(topDomains);
    182                 protectedThis->coreStore().dataRecordsWereRemoved();
     160            m_statisticsQueue->dispatch([this, protectedThis = WTFMove(protectedThis), topDomains = CrossThreadCopier<HashSet<String>>::copy(domainsWithDeletedWebsiteData)] () mutable {
     161                coreStore().updateStatisticsForRemovedDataRecords(topDomains);
     162                dataRecordsWereRemoved();
    183163            });
    184164        });
     
    197177       
    198178        if (notifyPagesWhenDataRecordsWereScanned) {
    199             RunLoop::main().dispatch([] () mutable {
     179            RunLoop::main().dispatch([] {
    200180                WebProcessProxy::notifyPageStatisticsAndDataRecordsProcessed();
    201181            });
     
    206186}
    207187
    208 void WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated(const Vector<WebCore::ResourceLoadStatistics>& origins)
    209 {
    210     coreStore().mergeStatistics(origins);
     188void WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated(Vector<WebCore::ResourceLoadStatistics>&& origins)
     189{
     190    ASSERT(!RunLoop::isMain());
     191
     192    coreStore().mergeStatistics(WTFMove(origins));
    211193    // Fire before processing statistics to propagate user
    212194    // interaction as fast as possible to the network process.
     
    238220}
    239221
    240 bool WebResourceLoadStatisticsStore::hasStatisticsFileChangedSinceLastSync(const String& path)
     222bool WebResourceLoadStatisticsStore::hasStatisticsFileChangedSinceLastSync(const String& path) const
    241223{
    242224    return statisticsFileModificationTime(path) > m_lastStatisticsFileSyncTime;
     
    550532void WebResourceLoadStatisticsStore::submitTelemetry()
    551533{
     534    ASSERT(RunLoop::isMain());
    552535    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
    553536        WebResourceLoadStatisticsTelemetry::calculateAndSubmit(coreStore());
     
    693676}
    694677
    695 void WebResourceLoadStatisticsStore::fireDataModificationHandler()
     678void WebResourceLoadStatisticsStore::fireShouldPartitionCookiesHandler()
    696679{
    697680    // Helper function used by testing system. Should only be called from the main thread.
    698681    ASSERT(RunLoop::isMain());
    699     m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
    700         coreStore().fireDataModificationHandler();
    701     });
    702 }
    703 
    704 void WebResourceLoadStatisticsStore::fireShouldPartitionCookiesHandler()
    705 {
    706     // Helper function used by testing system. Should only be called from the main thread.
    707     ASSERT(RunLoop::isMain());
     682
    708683    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
    709684        coreStore().fireShouldPartitionCookiesHandler();
     
    720695}
    721696
    722 void WebResourceLoadStatisticsStore::fireTelemetryHandler()
    723 {
    724     // Helper function used by testing system. Should only be called from the main thread.
    725     ASSERT(RunLoop::isMain());
    726     coreStore().fireTelemetryHandler();
    727 }
    728 
    729697void WebResourceLoadStatisticsStore::clearInMemory()
    730698{
     
    737705{
    738706    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this)] {
    739         coreStore().clearInMemoryAndPersistent();
     707        coreStore().clearInMemory();
     708        deleteStoreFromDisk();
     709        grandfatherExistingWebsiteData();
    740710    });
    741711}
     
    760730void WebResourceLoadStatisticsStore::setMinimumTimeBetweenDataRecordsRemoval(Seconds seconds)
    761731{
    762     coreStore().setMinimumTimeBetweenDataRecordsRemoval(seconds);
     732    ASSERT(seconds >= 0_s);
     733    m_minimumTimeBetweenDataRecordsRemoval = seconds;
    763734}
    764735
     
    767738    coreStore().setGrandfatheringTime(seconds);
    768739}
     740
     741bool WebResourceLoadStatisticsStore::shouldRemoveDataRecords() const
     742{
     743    ASSERT(!RunLoop::isMain());
     744    if (m_dataRecordsRemovalPending)
     745        return false;
     746
     747    if (m_lastTimeDataRecordsWereRemoved && MonotonicTime::now() < (m_lastTimeDataRecordsWereRemoved + m_minimumTimeBetweenDataRecordsRemoval))
     748        return false;
     749
     750    return true;
     751}
     752
     753void WebResourceLoadStatisticsStore::dataRecordsBeingRemoved()
     754{
     755    ASSERT(!RunLoop::isMain());
     756    m_lastTimeDataRecordsWereRemoved = MonotonicTime::now();
     757    m_dataRecordsRemovalPending = true;
     758}
     759
     760void WebResourceLoadStatisticsStore::dataRecordsWereRemoved()
     761{
     762    ASSERT(!RunLoop::isMain());
     763    m_dataRecordsRemovalPending = false;
     764}
    769765   
    770766} // namespace WebKit
  • trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h

    r219275 r219277  
    2626#pragma once
    2727
    28 #include "APIObject.h"
    2928#include "Connection.h"
    3029#include "ResourceLoadStatisticsClassifier.h"
    31 #include "ResourceLoadStatisticsStore.h"
    32 #include "WebResourceLoadStatisticsTelemetry.h"
    33 #include "WebsiteDataRecord.h"
     30#include <wtf/MonotonicTime.h>
    3431#include <wtf/RunLoop.h>
    3532#include <wtf/Vector.h>
     33#include <wtf/WallTime.h>
    3634#include <wtf/text/WTFString.h>
    3735
     
    4139
    4240namespace WTF {
    43 class MonotonicTime;
    44 class WallTime;
    4541class WorkQueue;
    4642}
     
    5046class KeyedDecoder;
    5147class KeyedEncoder;
     48class URL;
    5249struct ResourceLoadStatistics;
    5350}
     
    5552namespace WebKit {
    5653
     54class ResourceLoadStatisticsStore;
    5755class WebProcessProxy;
    5856
     
    6563    }
    6664
     65    ~WebResourceLoadStatisticsStore();
     66
    6767    static void setNotifyPagesWhenDataRecordsWereScanned(bool);
    6868    static void setShouldClassifyResourcesBeforeDataRecordsRemoval(bool);
    6969    static void setShouldSubmitTelemetry(bool);
    70     virtual ~WebResourceLoadStatisticsStore();
    7170
    72     void resourceLoadStatisticsUpdated(const Vector<WebCore::ResourceLoadStatistics>& origins);
     71    void resourceLoadStatisticsUpdated(Vector<WebCore::ResourceLoadStatistics>&& origins);
    7372
    7473    void processWillOpenConnection(WebProcessProxy&, IPC::Connection&);
     
    8786    void setSubresourceUnderTopFrameOrigin(const WebCore::URL& subresource, const WebCore::URL& topFrame);
    8887    void setSubresourceUniqueRedirectTo(const WebCore::URL& subresource, const WebCore::URL& hostNameRedirectedTo);
    89     void fireDataModificationHandler();
    9088    void fireShouldPartitionCookiesHandler();
    9189    void fireShouldPartitionCookiesHandler(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst);
     90    void processStatisticsAndDataRecords();
     91    void submitTelemetry();
    9292
    93     void fireTelemetryHandler();
    9493    void clearInMemory();
    9594    void clearInMemoryAndPersistent();
     
    107106    const ResourceLoadStatisticsStore& coreStore() const { return m_resourceLoadStatisticsStore.get(); }
    108107
    109     void processStatisticsAndDataRecords();
    110108    void readDataFromDiskIfNeeded();
    111109
     
    134132    void refreshFromDisk();
    135133    void submitTelemetryIfNecessary();
    136     void submitTelemetry();
    137     bool hasStatisticsFileChangedSinceLastSync(const String& path);
     134    bool hasStatisticsFileChangedSinceLastSync(const String& path) const;
    138135    void performDailyTasks();
     136    bool shouldRemoveDataRecords() const;
     137    void dataRecordsBeingRemoved();
     138    void dataRecordsWereRemoved();
    139139
    140140#if PLATFORM(COCOA)
     
    151151    std::unique_ptr<WebCore::FileMonitor> m_statisticsStorageMonitor;
    152152    const String m_statisticsStoragePath;
    153     WTF::WallTime m_lastStatisticsFileSyncTime;
    154     WTF::MonotonicTime m_lastStatisticsWriteTime;
     153    WallTime m_lastStatisticsFileSyncTime;
     154    MonotonicTime m_lastStatisticsWriteTime;
    155155    RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryOneShotTimer;
    156156    RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryRepeatedTimer;
     157    MonotonicTime m_lastTimeDataRecordsWereRemoved;
     158    Seconds m_minimumTimeBetweenDataRecordsRemoval { 1_h };
     159    bool m_dataRecordsRemovalPending { false };
    157160    bool m_didScheduleWrite { false };
    158161};
  • trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsTelemetry.cpp

    r219020 r219277  
    190190   
    191191    auto sortedPrevalentResources = resourceLoadStatisticsStore.sortedPrevalentResourceTelemetry();
    192     if (notifyPagesWhenTelemetryWasCaptured && sortedPrevalentResources.size() < minimumPrevalentResourcesForTelemetry) {
     192    if (notifyPagesWhenTelemetryWasCaptured && sortedPrevalentResources.isEmpty()) {
    193193        notifyPages(0, 0, 0);
    194194        return;
  • trunk/Tools/ChangeLog

    r219276 r219277  
     12017-07-08  Chris Dumez  <cdumez@apple.com>
     2
     3        Simplify WebResourceLoadStatisticsStore / ResourceLoadStatisticsStore
     4        https://bugs.webkit.org/show_bug.cgi?id=174290
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Rename testRunner API to match the new internal API names.
     9
     10        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
     11        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
     12        (WTR::TestRunner::statisticsProcessStatisticsAndDataRecords):
     13        (WTR::TestRunner::statisticsSubmitTelemetry):
     14        * WebKitTestRunner/InjectedBundle/TestRunner.h:
     15        * WebKitTestRunner/TestController.cpp:
     16        (WTR::TestController::statisticsProcessStatisticsAndDataRecords):
     17        (WTR::TestController::statisticsSubmitTelemetry):
     18        * WebKitTestRunner/TestController.h:
     19        * WebKitTestRunner/TestInvocation.cpp:
     20        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
     21        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
     22        (WTR::TestController::statisticsProcessStatisticsAndDataRecords):
     23        (WTR::TestController::statisticsSubmitTelemetry):
     24
    1252017-07-08  Yusuke Suzuki  <utatane.tea@gmail.com>
    226
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl

    r219025 r219277  
    266266    void setStatisticsTimeToLiveUserInteraction(double seconds);
    267267    void setStatisticsTimeToLiveCookiePartitionFree(double seconds);
    268     void statisticsFireDataModificationHandler();
     268    void statisticsProcessStatisticsAndDataRecords();
    269269    void statisticsFireShouldPartitionCookiesHandler();
    270270    void statisticsFireShouldPartitionCookiesHandlerForOneDomain(DOMString hostName, boolean value);
    271     void statisticsFireTelemetryHandler();
     271    void statisticsSubmitTelemetry();
    272272    void setStatisticsNotifyPagesWhenDataRecordsWereScanned(boolean value);
    273273    void setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(boolean value);
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

    r219049 r219277  
    14141414}
    14151415   
    1416 void TestRunner::statisticsFireDataModificationHandler()
    1417 {
    1418     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsFireDataModificationHandler"));
     1416void TestRunner::statisticsProcessStatisticsAndDataRecords()
     1417{
     1418    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsProcessStatisticsAndDataRecords"));
    14191419    WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), 0, nullptr);
    14201420}
     
    14511451}
    14521452
    1453 void TestRunner::statisticsFireTelemetryHandler()
    1454 {
    1455     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsFireTelemetryHandler"));
     1453void TestRunner::statisticsSubmitTelemetry()
     1454{
     1455    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("StatisticsSubmitTelemetry"));
    14561456    WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), 0, nullptr);
    14571457}
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

    r219025 r219277  
    354354    void statisticsDidScanDataRecordsCallback();
    355355    void statisticsDidRunTelemetryCallback(unsigned totalPrevalentResources, unsigned totalPrevalentResourcesWithUserInteraction, unsigned top3SubframeUnderTopFrameOrigins);
    356     void statisticsFireDataModificationHandler();
     356    void statisticsProcessStatisticsAndDataRecords();
    357357    void statisticsFireShouldPartitionCookiesHandler();
    358358    void statisticsFireShouldPartitionCookiesHandlerForOneDomain(JSStringRef hostName, bool value);
    359     void statisticsFireTelemetryHandler();
     359    void statisticsSubmitTelemetry();
    360360    void setStatisticsPrevalentResource(JSStringRef hostName, bool value);
    361361    bool isStatisticsPrevalentResource(JSStringRef hostName);
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r219049 r219277  
    22972297}
    22982298
    2299 void TestController::statisticsFireDataModificationHandler()
     2299void TestController::statisticsProcessStatisticsAndDataRecords()
    23002300{
    23012301}
     
    23092309}
    23102310
    2311 void TestController::statisticsFireTelemetryHandler()
     2311void TestController::statisticsSubmitTelemetry()
    23122312{
    23132313}
  • trunk/Tools/WebKitTestRunner/TestController.h

    r219025 r219277  
    162162    void setStatisticsTimeToLiveUserInteraction(double seconds);
    163163    void setStatisticsTimeToLiveCookiePartitionFree(double seconds);
    164     void statisticsFireDataModificationHandler();
     164    void statisticsProcessStatisticsAndDataRecords();
    165165    void statisticsFireShouldPartitionCookiesHandler();
    166166    void statisticsFireShouldPartitionCookiesHandlerForOneDomain(WKStringRef hostName, bool value);
    167     void statisticsFireTelemetryHandler();
     167    void statisticsSubmitTelemetry();
    168168    void setStatisticsNotifyPagesWhenDataRecordsWereScanned(bool);
    169169    void setStatisticsShouldClassifyResourcesBeforeDataRecordsRemoval(bool);
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r219025 r219277  
    10381038    }
    10391039
    1040     if (WKStringIsEqualToUTF8CString(messageName, "StatisticsFireDataModificationHandler")) {
    1041         TestController::singleton().statisticsFireDataModificationHandler();
     1040    if (WKStringIsEqualToUTF8CString(messageName, "StatisticsProcessStatisticsAndDataRecords")) {
     1041        TestController::singleton().statisticsProcessStatisticsAndDataRecords();
    10421042        return nullptr;
    10431043    }
     
    10621062    }
    10631063   
    1064     if (WKStringIsEqualToUTF8CString(messageName, "StatisticsFireTelemetryHandler")) {
    1065         TestController::singleton().statisticsFireTelemetryHandler();
     1064    if (WKStringIsEqualToUTF8CString(messageName, "StatisticsSubmitTelemetry")) {
     1065        TestController::singleton().statisticsSubmitTelemetry();
    10661066        return nullptr;
    10671067    }
  • trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm

    r219071 r219277  
    302302}
    303303
    304 void TestController::statisticsFireDataModificationHandler()
    305 {
    306     [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsFireDataModificationHandler];
     304void TestController::statisticsProcessStatisticsAndDataRecords()
     305{
     306    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsProcessStatisticsAndDataRecords];
    307307}
    308308
     
    317317}
    318318
    319 void TestController::statisticsFireTelemetryHandler()
    320 {
    321     [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsFireTelemetryHandler];
     319void TestController::statisticsSubmitTelemetry()
     320{
     321    [globalWebViewConfiguration.websiteDataStore _resourceLoadStatisticsSubmitTelemetry];
    322322}
    323323
Note: See TracChangeset for help on using the changeset viewer.