Changeset 248372 in webkit


Ignore:
Timestamp:
Aug 7, 2019 10:22:38 AM (5 years ago)
Author:
Chris Dumez
Message:

Add more threading assertions to ITP code
https://bugs.webkit.org/show_bug.cgi?id=200505

Reviewed by Brent Fulgham.

Add more threading assertions to ITP code to help catch bugs and protect against future bad usage.

  • NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp:

(WebKit::ResourceLoadStatisticsMemoryStore::isEmpty const):
(WebKit::ResourceLoadStatisticsMemoryStore::setPersistentStorage):
(WebKit::ResourceLoadStatisticsMemoryStore::incrementRecordsDeletedCountForDomains):
(WebKit::ResourceLoadStatisticsMemoryStore::classifyPrevalentResources):
(WebKit::ResourceLoadStatisticsMemoryStore::syncStorageIfNeeded):
(WebKit::ResourceLoadStatisticsMemoryStore::syncStorageImmediately):
(WebKit::ResourceLoadStatisticsMemoryStore::grandfatherDataForDomains):
(WebKit::ResourceLoadStatisticsMemoryStore::ensurePrevalentResourcesForDebugMode):

  • NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp:

(WebKit::ResourceLoadStatisticsStore::statisticsEpirationTime const):
(WebKit::ResourceLoadStatisticsStore::mergeOperatingDates):

  • NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:

(WebKit::WebResourceLoadStatisticsStore::hasStorageAccessForFrame):
(WebKit::WebResourceLoadStatisticsStore::requestStorageAccess):
(WebKit::WebResourceLoadStatisticsStore::grantStorageAccess):
(WebKit::WebResourceLoadStatisticsStore::applicationWillTerminate):
(WebKit::WebResourceLoadStatisticsStore::logFrameNavigation):
(WebKit::WebResourceLoadStatisticsStore::logWebSocketLoading):
(WebKit::WebResourceLoadStatisticsStore::logSubresourceLoading):
(WebKit::WebResourceLoadStatisticsStore::logSubresourceRedirect):
(WebKit::WebResourceLoadStatisticsStore::hasHadUserInteraction):
(WebKit::WebResourceLoadStatisticsStore::removePrevalentDomains):
(WebKit::WebResourceLoadStatisticsStore::networkSession):
(WebKit::WebResourceLoadStatisticsStore::invalidateAndCancel):
(WebKit::WebResourceLoadStatisticsStore::sendDiagnosticMessageWithValue const):
(WebKit::WebResourceLoadStatisticsStore::notifyPageStatisticsTelemetryFinished const):

Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r248371 r248372  
     12019-08-07  Chris Dumez  <cdumez@apple.com>
     2
     3        Add more threading assertions to ITP code
     4        https://bugs.webkit.org/show_bug.cgi?id=200505
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Add more threading assertions to ITP code to help catch bugs and protect against future bad usage.
     9
     10        * NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp:
     11        (WebKit::ResourceLoadStatisticsMemoryStore::isEmpty const):
     12        (WebKit::ResourceLoadStatisticsMemoryStore::setPersistentStorage):
     13        (WebKit::ResourceLoadStatisticsMemoryStore::incrementRecordsDeletedCountForDomains):
     14        (WebKit::ResourceLoadStatisticsMemoryStore::classifyPrevalentResources):
     15        (WebKit::ResourceLoadStatisticsMemoryStore::syncStorageIfNeeded):
     16        (WebKit::ResourceLoadStatisticsMemoryStore::syncStorageImmediately):
     17        (WebKit::ResourceLoadStatisticsMemoryStore::grandfatherDataForDomains):
     18        (WebKit::ResourceLoadStatisticsMemoryStore::ensurePrevalentResourcesForDebugMode):
     19        * NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp:
     20        (WebKit::ResourceLoadStatisticsStore::statisticsEpirationTime const):
     21        (WebKit::ResourceLoadStatisticsStore::mergeOperatingDates):
     22        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
     23        (WebKit::WebResourceLoadStatisticsStore::hasStorageAccessForFrame):
     24        (WebKit::WebResourceLoadStatisticsStore::requestStorageAccess):
     25        (WebKit::WebResourceLoadStatisticsStore::grantStorageAccess):
     26        (WebKit::WebResourceLoadStatisticsStore::applicationWillTerminate):
     27        (WebKit::WebResourceLoadStatisticsStore::logFrameNavigation):
     28        (WebKit::WebResourceLoadStatisticsStore::logWebSocketLoading):
     29        (WebKit::WebResourceLoadStatisticsStore::logSubresourceLoading):
     30        (WebKit::WebResourceLoadStatisticsStore::logSubresourceRedirect):
     31        (WebKit::WebResourceLoadStatisticsStore::hasHadUserInteraction):
     32        (WebKit::WebResourceLoadStatisticsStore::removePrevalentDomains):
     33        (WebKit::WebResourceLoadStatisticsStore::networkSession):
     34        (WebKit::WebResourceLoadStatisticsStore::invalidateAndCancel):
     35        (WebKit::WebResourceLoadStatisticsStore::sendDiagnosticMessageWithValue const):
     36        (WebKit::WebResourceLoadStatisticsStore::notifyPageStatisticsTelemetryFinished const):
     37
    1382019-08-07  Ryan Haddad  <ryanhaddad@apple.com>
    239
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp

    r247119 r248372  
    8383bool ResourceLoadStatisticsMemoryStore::isEmpty() const
    8484{
     85    ASSERT(!RunLoop::isMain());
     86
    8587    return m_resourceStatisticsMap.isEmpty();
    8688}
     
    8890void ResourceLoadStatisticsMemoryStore::setPersistentStorage(ResourceLoadStatisticsPersistentStorage& persistentStorage)
    8991{
     92    ASSERT(!RunLoop::isMain());
     93
    9094    m_persistentStorage = makeWeakPtr(persistentStorage);
    9195}
     
    101105void ResourceLoadStatisticsMemoryStore::incrementRecordsDeletedCountForDomains(HashSet<RegistrableDomain>&& domainsWithDeletedWebsiteData)
    102106{
     107    ASSERT(!RunLoop::isMain());
     108
    103109    for (auto& domain : domainsWithDeletedWebsiteData) {
    104110        auto& statistic = ensureResourceStatisticsForRegistrableDomain(domain);
     
    173179void ResourceLoadStatisticsMemoryStore::classifyPrevalentResources()
    174180{
     181    ASSERT(!RunLoop::isMain());
     182
    175183    for (auto& resourceStatistic : m_resourceStatisticsMap.values()) {
    176184        if (shouldSkip(resourceStatistic.registrableDomain))
     
    190198void ResourceLoadStatisticsMemoryStore::syncStorageIfNeeded()
    191199{
     200    ASSERT(!RunLoop::isMain());
     201
    192202    if (m_persistentStorage)
    193203        m_persistentStorage->scheduleOrWriteMemoryStore(ResourceLoadStatisticsPersistentStorage::ForceImmediateWrite::No);
     
    196206void ResourceLoadStatisticsMemoryStore::syncStorageImmediately()
    197207{
     208    ASSERT(!RunLoop::isMain());
     209
    198210    if (m_persistentStorage)
    199211        m_persistentStorage->scheduleOrWriteMemoryStore(ResourceLoadStatisticsPersistentStorage::ForceImmediateWrite::Yes);
     
    316328void ResourceLoadStatisticsMemoryStore::grandfatherDataForDomains(const HashSet<RegistrableDomain>& domains)
    317329{
     330    ASSERT(!RunLoop::isMain());
     331
    318332    for (auto& domain : domains) {
    319333        auto& statistic = ensureResourceStatisticsForRegistrableDomain(domain);
     
    324338Vector<RegistrableDomain> ResourceLoadStatisticsMemoryStore::ensurePrevalentResourcesForDebugMode()
    325339{
     340    ASSERT(!RunLoop::isMain());
     341
    326342    if (!debugModeEnabled())
    327343        return { };
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsStore.cpp

    r247119 r248372  
    446446Optional<Seconds> ResourceLoadStatisticsStore::statisticsEpirationTime() const
    447447{
     448    ASSERT(!RunLoop::isMain());
     449
    448450    if (m_parameters.timeToLiveUserInteraction)
    449451        return WallTime::now().secondsSinceEpoch() - m_parameters.timeToLiveUserInteraction.value();
     
    476478void ResourceLoadStatisticsStore::mergeOperatingDates(Vector<OperatingDate>&& newDates)
    477479{
     480    ASSERT(!RunLoop::isMain());
     481
    478482    m_operatingDates = mergeOperatingDates(m_operatingDates, WTFMove(newDates));
    479483}
  • trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp

    r248144 r248372  
    307307bool WebResourceLoadStatisticsStore::hasStorageAccessForFrame(const RegistrableDomain& resourceDomain, const RegistrableDomain& firstPartyDomain, uint64_t frameID, PageIdentifier pageID)
    308308{
    309     if (m_networkSession) {
    310         if (auto* storageSession = m_networkSession->networkStorageSession())
    311             return storageSession->hasStorageAccess(resourceDomain, firstPartyDomain, frameID, pageID);
    312     }
     309    ASSERT(RunLoop::isMain());
     310
     311    if (!m_networkSession)
     312        return false;
     313
     314    if (auto* storageSession = m_networkSession->networkStorageSession())
     315        return storageSession->hasStorageAccess(resourceDomain, firstPartyDomain, frameID, pageID);
     316
    313317    return false;
    314318}
     
    330334void WebResourceLoadStatisticsStore::requestStorageAccess(const RegistrableDomain& subFrameDomain, const RegistrableDomain& topFrameDomain, uint64_t frameID, PageIdentifier pageID, CompletionHandler<void(StorageAccessWasGranted, StorageAccessPromptWasShown)>&& completionHandler)
    331335{
     336    ASSERT(RunLoop::isMain());
     337
    332338    if (subFrameDomain == topFrameDomain) {
    333339        completionHandler(StorageAccessWasGranted::Yes, StorageAccessPromptWasShown::No);
     
    410416StorageAccessWasGranted WebResourceLoadStatisticsStore::grantStorageAccess(const RegistrableDomain& resourceDomain, const RegistrableDomain& firstPartyDomain, Optional<uint64_t> frameID, PageIdentifier pageID)
    411417{
     418    ASSERT(RunLoop::isMain());
     419
    412420    bool isStorageGranted = false;
    413421
     
    455463void WebResourceLoadStatisticsStore::applicationWillTerminate()
    456464{
     465    ASSERT(RunLoop::isMain());
    457466    flushAndDestroyPersistentStore();
    458467}
     
    514523void WebResourceLoadStatisticsStore::logFrameNavigation(const RegistrableDomain& targetDomain, const RegistrableDomain& topFrameDomain, const RegistrableDomain& sourceDomain, bool isRedirect, bool isMainFrame)
    515524{
     525    ASSERT(RunLoop::isMain());
     526
    516527    postTask([this, targetDomain = targetDomain.isolatedCopy(), topFrameDomain = topFrameDomain.isolatedCopy(), sourceDomain = sourceDomain.isolatedCopy(), isRedirect, isMainFrame] {
    517528        if (m_statisticsStore)
     
    522533void WebResourceLoadStatisticsStore::logWebSocketLoading(const RegistrableDomain& targetDomain, const RegistrableDomain& topFrameDomain, WallTime lastSeen, CompletionHandler<void()>&& completionHandler)
    523534{
     535    ASSERT(RunLoop::isMain());
     536
    524537    postTask([this, targetDomain = targetDomain.isolatedCopy(), topFrameDomain = topFrameDomain.isolatedCopy(), lastSeen, completionHandler = WTFMove(completionHandler)]() mutable {
    525538        if (m_statisticsStore)
     
    532545void WebResourceLoadStatisticsStore::logSubresourceLoading(const SubResourceDomain& targetDomain, const TopFrameDomain& topFrameDomain, WallTime lastSeen, CompletionHandler<void()>&& completionHandler)
    533546{
     547    ASSERT(RunLoop::isMain());
     548
    534549    postTask([this, targetDomain = targetDomain.isolatedCopy(), topFrameDomain = topFrameDomain.isolatedCopy(), lastSeen, completionHandler = WTFMove(completionHandler)]() mutable {
    535550        if (m_statisticsStore)
     
    542557void WebResourceLoadStatisticsStore::logSubresourceRedirect(const RegistrableDomain& sourceDomain, const RegistrableDomain& targetDomain, CompletionHandler<void()>&& completionHandler)
    543558{
     559    ASSERT(RunLoop::isMain());
     560
    544561    postTask([this, sourceDomain = sourceDomain.isolatedCopy(), targetDomain = targetDomain.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
    545562        if (m_statisticsStore)
     
    585602void WebResourceLoadStatisticsStore::hasHadUserInteraction(const RegistrableDomain& domain, CompletionHandler<void(bool)>&& completionHandler)
    586603{
     604    ASSERT(RunLoop::isMain());
     605
    587606    postTask([this, domain, completionHandler = WTFMove(completionHandler)]() mutable {
    588607        bool hadUserInteraction = m_statisticsStore ? m_statisticsStore->hasHadUserInteraction(domain, OperatingDatesWindow::Long) : false;
     
    955974void WebResourceLoadStatisticsStore::removePrevalentDomains(const Vector<RegistrableDomain>& domains)
    956975{
    957     if (m_networkSession) {
    958         if (auto* storageSession = m_networkSession->networkStorageSession())
    959             storageSession->removePrevalentDomains(domains);
    960     }
     976    ASSERT(RunLoop::isMain());
     977    if (!m_networkSession)
     978        return;
     979
     980    if (auto* storageSession = m_networkSession->networkStorageSession())
     981        storageSession->removePrevalentDomains(domains);
    961982}
    962983
     
    10211042NetworkSession* WebResourceLoadStatisticsStore::networkSession()
    10221043{
     1044    ASSERT(RunLoop::isMain());
    10231045    return m_networkSession.get();
    10241046}
     
    10261048void WebResourceLoadStatisticsStore::invalidateAndCancel()
    10271049{
     1050    ASSERT(RunLoop::isMain());
    10281051    m_networkSession = nullptr;
    10291052}
     
    10551078void WebResourceLoadStatisticsStore::sendDiagnosticMessageWithValue(const String& message, const String& description, unsigned value, unsigned sigDigits, WebCore::ShouldSample shouldSample) const
    10561079{
     1080    ASSERT(RunLoop::isMain());
    10571081    if (m_networkSession)
    10581082        const_cast<WebResourceLoadStatisticsStore*>(this)->networkSession()->logDiagnosticMessageWithValue(message, description, value, sigDigits, shouldSample);
     
    10611085void WebResourceLoadStatisticsStore::notifyPageStatisticsTelemetryFinished(unsigned totalPrevalentResources, unsigned totalPrevalentResourcesWithUserInteraction, unsigned top3SubframeUnderTopFrameOrigins) const
    10621086{
     1087    ASSERT(RunLoop::isMain());
    10631088    if (m_networkSession)
    10641089        const_cast<WebResourceLoadStatisticsStore*>(this)->networkSession()->notifyPageStatisticsTelemetryFinished(totalPrevalentResources, totalPrevalentResourcesWithUserInteraction, top3SubframeUnderTopFrameOrigins);
Note: See TracChangeset for help on using the changeset viewer.