Changeset 219207 in webkit


Ignore:
Timestamp:
Jul 6, 2017 11:28:40 AM (7 years ago)
Author:
Chris Dumez
Message:

Move ResourceLoadObserver notification throttling logic from WebProcess class to ResourceLoadObserver
https://bugs.webkit.org/show_bug.cgi?id=174194

Reviewed by Brent Fulgham.

Move ResourceLoadObserver notification throttling logic from WebProcess class to
ResourceLoadObserver. This makes more sense and decreases the complexity of the
WebProcess class.

Source/WebCore:

  • loader/ResourceLoadObserver.cpp:

(WebCore::ResourceLoadObserver::setNotificationCallback):
(WebCore::ResourceLoadObserver::ResourceLoadObserver):
(WebCore::ResourceLoadObserver::logFrameNavigation):
(WebCore::ResourceLoadObserver::logSubresourceLoading):
(WebCore::ResourceLoadObserver::logWebSocketLoading):
(WebCore::ResourceLoadObserver::logUserInteractionWithReducedTimeResolution):
(WebCore::ResourceLoadObserver::scheduleNotificationIfNeeded):
(WebCore::ResourceLoadObserver::notificationTimerFired):

  • loader/ResourceLoadObserver.h:

Source/WebKit2:

  • WebProcess/WebProcess.cpp:

(WebKit::m_webSQLiteDatabaseTracker):
(WebKit::WebProcess::statisticsChangedTimerFired): Deleted.

  • WebProcess/WebProcess.h:
Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r219205 r219207  
     12017-07-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Move ResourceLoadObserver notification throttling logic from WebProcess class to ResourceLoadObserver
     4        https://bugs.webkit.org/show_bug.cgi?id=174194
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Move ResourceLoadObserver notification throttling logic from WebProcess class to
     9        ResourceLoadObserver. This makes more sense and decreases the complexity of the
     10        WebProcess class.
     11
     12        * loader/ResourceLoadObserver.cpp:
     13        (WebCore::ResourceLoadObserver::setNotificationCallback):
     14        (WebCore::ResourceLoadObserver::ResourceLoadObserver):
     15        (WebCore::ResourceLoadObserver::logFrameNavigation):
     16        (WebCore::ResourceLoadObserver::logSubresourceLoading):
     17        (WebCore::ResourceLoadObserver::logWebSocketLoading):
     18        (WebCore::ResourceLoadObserver::logUserInteractionWithReducedTimeResolution):
     19        (WebCore::ResourceLoadObserver::scheduleNotificationIfNeeded):
     20        (WebCore::ResourceLoadObserver::notificationTimerFired):
     21        * loader/ResourceLoadObserver.h:
     22
    1232017-07-06  Said Abou-Hallawa  <sabouhallawa@apple.com>
    224
  • trunk/Source/WebCore/loader/ResourceLoadObserver.cpp

    r219010 r219207  
    3838#include "Settings.h"
    3939#include "URL.h"
    40 #include <wtf/NeverDestroyed.h>
    4140
    4241namespace WebCore {
     
    4847
    4948static Seconds timestampResolution { 1_h };
     49static const Seconds minimumNotificationInterval { 5_s };
    5050
    5151ResourceLoadObserver& ResourceLoadObserver::shared()
     
    5555}
    5656
    57 void ResourceLoadObserver::setNotificationCallback(WTF::Function<void()>&& notificationCallback)
     57void ResourceLoadObserver::setNotificationCallback(WTF::Function<void (Vector<ResourceLoadStatistics>&&)>&& notificationCallback)
    5858{
    5959    ASSERT(!m_notificationCallback);
    6060    m_notificationCallback = WTFMove(notificationCallback);
     61}
     62
     63ResourceLoadObserver::ResourceLoadObserver()
     64    : m_notificationTimer(*this, &ResourceLoadObserver::notificationTimerFired)
     65{
    6166}
    6267
     
    159164
    160165    if (shouldCallNotificationCallback)
    161         m_notificationCallback();
     166        scheduleNotificationIfNeeded();
    162167}
    163168   
     
    225230
    226231    if (shouldCallNotificationCallback)
    227         m_notificationCallback();
     232        scheduleNotificationIfNeeded();
    228233}
    229234
     
    268273
    269274    if (shouldCallNotificationCallback)
    270         m_notificationCallback();
     275        scheduleNotificationIfNeeded();
    271276}
    272277
     
    295300    statistics.mostRecentUserInteractionTime = newTime;
    296301
    297     m_notificationCallback();
     302    scheduleNotificationIfNeeded();
    298303}
    299304
     
    323328}
    324329
     330void ResourceLoadObserver::scheduleNotificationIfNeeded()
     331{
     332    ASSERT(m_notificationCallback);
     333    if (m_resourceStatisticsMap.isEmpty()) {
     334        m_notificationTimer.stop();
     335        return;
     336    }
     337
     338    if (!m_notificationTimer.isActive())
     339        m_notificationTimer.startOneShot(minimumNotificationInterval);
     340}
     341
     342void ResourceLoadObserver::notificationTimerFired()
     343{
     344    ASSERT(m_notificationCallback);
     345    m_notificationCallback(takeStatistics());
     346}
     347
    325348String ResourceLoadObserver::statisticsForOrigin(const String& origin)
    326349{
  • trunk/Source/WebCore/loader/ResourceLoadObserver.h

    r219005 r219207  
    2626#pragma once
    2727
     28#include "Timer.h"
    2829#include <wtf/HashMap.h>
     30#include <wtf/NeverDestroyed.h>
    2931#include <wtf/text/WTFString.h>
    3032
     
    4648
    4749class ResourceLoadObserver {
    48     friend class NeverDestroyed<ResourceLoadObserver>;
     50    friend class WTF::NeverDestroyed<ResourceLoadObserver>;
    4951public:
    5052    WEBCORE_EXPORT static ResourceLoadObserver& shared();
     
    5759    WEBCORE_EXPORT String statisticsForOrigin(const String&);
    5860
    59     WEBCORE_EXPORT void setNotificationCallback(WTF::Function<void()>&&);
    60     WEBCORE_EXPORT Vector<ResourceLoadStatistics> takeStatistics();
     61    WEBCORE_EXPORT void setNotificationCallback(WTF::Function<void (Vector<ResourceLoadStatistics>&&)>&&);
    6162
    6263private:
     64    ResourceLoadObserver();
     65
    6366    bool shouldLog(Page*) const;
    6467    ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
     
    6669    bool isPrevalentResource(const String& primaryDomain) const;
    6770
     71    void scheduleNotificationIfNeeded();
     72    void notificationTimerFired();
     73    Vector<ResourceLoadStatistics> takeStatistics();
     74
    6875    HashMap<String, ResourceLoadStatistics> m_resourceStatisticsMap;
    69     WTF::Function<void()> m_notificationCallback;
     76    WTF::Function<void (Vector<ResourceLoadStatistics>&&)> m_notificationCallback;
     77    Timer m_notificationTimer;
    7078    HashMap<String, size_t> m_originsVisitedMap;
    7179};
  • trunk/Source/WebKit2/ChangeLog

    r219203 r219207  
     12017-07-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Move ResourceLoadObserver notification throttling logic from WebProcess class to ResourceLoadObserver
     4        https://bugs.webkit.org/show_bug.cgi?id=174194
     5
     6        Reviewed by Brent Fulgham.
     7
     8        Move ResourceLoadObserver notification throttling logic from WebProcess class to
     9        ResourceLoadObserver. This makes more sense and decreases the complexity of the
     10        WebProcess class.
     11
     12        * WebProcess/WebProcess.cpp:
     13        (WebKit::m_webSQLiteDatabaseTracker):
     14        (WebKit::WebProcess::statisticsChangedTimerFired): Deleted.
     15        * WebProcess/WebProcess.h:
     16
    1172017-07-06  Chris Dumez  <cdumez@apple.com>
    218
  • trunk/Source/WebKit2/WebProcess/WebProcess.cpp

    r219005 r219207  
    171171#endif
    172172    , m_nonVisibleProcessCleanupTimer(*this, &WebProcess::nonVisibleProcessCleanupTimerFired)
    173     , m_statisticsChangedTimer(*this, &WebProcess::statisticsChangedTimerFired)
    174173#if PLATFORM(IOS)
    175174    , m_webSQLiteDatabaseTracker(*this)
     
    200199    m_plugInAutoStartOriginHashes.add(SessionID::defaultSessionID(), HashMap<unsigned, double>());
    201200
    202     ResourceLoadObserver::shared().setNotificationCallback([this] {
    203         if (m_statisticsChangedTimer.isActive())
    204             return;
    205         m_statisticsChangedTimer.startOneShot(5_s);
     201    ResourceLoadObserver::shared().setNotificationCallback([this] (Vector<ResourceLoadStatistics>&& statistics) {
     202        ASSERT(!statistics.isEmpty());
     203        parentProcessConnection()->send(Messages::WebResourceLoadStatisticsStore::ResourceLoadStatisticsUpdated(WTFMove(statistics)), 0);
    206204    });
    207205}
     
    14581456}
    14591457
    1460 void WebProcess::statisticsChangedTimerFired()
    1461 {
    1462     auto statistics = ResourceLoadObserver::shared().takeStatistics();
    1463     if (statistics.isEmpty())
    1464         return;
    1465 
    1466     parentProcessConnection()->send(Messages::WebResourceLoadStatisticsStore::ResourceLoadStatisticsUpdated(WTFMove(statistics)), 0);
    1467 }
    1468 
    14691458void WebProcess::setResourceLoadStatisticsEnabled(bool enabled)
    14701459{
  • trunk/Source/WebKit2/WebProcess/WebProcess.h

    r219005 r219207  
    185185
    186186    void nonVisibleProcessCleanupTimerFired();
    187     void statisticsChangedTimerFired();
    188187
    189188#if PLATFORM(COCOA)
     
    410409    HashSet<uint64_t> m_pagesInWindows;
    411410    WebCore::Timer m_nonVisibleProcessCleanupTimer;
    412     WebCore::Timer m_statisticsChangedTimer;
    413411
    414412    RefPtr<WebCore::ApplicationCacheStorage> m_applicationCacheStorage;
Note: See TracChangeset for help on using the changeset viewer.