Title: [219207] trunk/Source
Revision
219207
Author
[email protected]
Date
2017-07-06 11:28:40 -0700 (Thu, 06 Jul 2017)

Log 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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (219206 => 219207)


--- trunk/Source/WebCore/ChangeLog	2017-07-06 18:24:12 UTC (rev 219206)
+++ trunk/Source/WebCore/ChangeLog	2017-07-06 18:28:40 UTC (rev 219207)
@@ -1,3 +1,25 @@
+2017-07-06  Chris Dumez  <[email protected]>
+
+        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.
+
+        * 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:
+
 2017-07-06  Said Abou-Hallawa  <[email protected]>
 
         REGRESSION(r208511): RenderImageResourceStyleImage should not assume image() won't return null if its m_cachedImage is valid

Modified: trunk/Source/WebCore/loader/ResourceLoadObserver.cpp (219206 => 219207)


--- trunk/Source/WebCore/loader/ResourceLoadObserver.cpp	2017-07-06 18:24:12 UTC (rev 219206)
+++ trunk/Source/WebCore/loader/ResourceLoadObserver.cpp	2017-07-06 18:28:40 UTC (rev 219207)
@@ -37,7 +37,6 @@
 #include "SecurityOrigin.h"
 #include "Settings.h"
 #include "URL.h"
-#include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
 
@@ -47,6 +46,7 @@
 }
 
 static Seconds timestampResolution { 1_h };
+static const Seconds minimumNotificationInterval { 5_s };
 
 ResourceLoadObserver& ResourceLoadObserver::shared()
 {
@@ -54,12 +54,17 @@
     return resourceLoadObserver;
 }
 
-void ResourceLoadObserver::setNotificationCallback(WTF::Function<void()>&& notificationCallback)
+void ResourceLoadObserver::setNotificationCallback(WTF::Function<void (Vector<ResourceLoadStatistics>&&)>&& notificationCallback)
 {
     ASSERT(!m_notificationCallback);
     m_notificationCallback = WTFMove(notificationCallback);
 }
 
+ResourceLoadObserver::ResourceLoadObserver()
+    : m_notificationTimer(*this, &ResourceLoadObserver::notificationTimerFired)
+{
+}
+
 static inline bool is3xxRedirect(const ResourceResponse& response)
 {
     return response.httpStatusCode() >= 300 && response.httpStatusCode() <= 399;
@@ -158,7 +163,7 @@
     m_resourceStatisticsMap.set(targetPrimaryDomain, WTFMove(targetStatistics));
 
     if (shouldCallNotificationCallback)
-        m_notificationCallback();
+        scheduleNotificationIfNeeded();
 }
     
 void ResourceLoadObserver::logSubresourceLoading(const Frame* frame, const ResourceRequest& newRequest, const ResourceResponse& redirectResponse)
@@ -224,7 +229,7 @@
     m_resourceStatisticsMap.set(targetPrimaryDomain, WTFMove(targetStatistics));
 
     if (shouldCallNotificationCallback)
-        m_notificationCallback();
+        scheduleNotificationIfNeeded();
 }
 
 void ResourceLoadObserver::logWebSocketLoading(const Frame* frame, const URL& targetURL)
@@ -267,7 +272,7 @@
     targetStatistics.subresourceHasBeenSubresourceCountDividedByTotalNumberOfOriginsVisited = static_cast<double>(targetStatistics.subresourceHasBeenSubresourceCount) / totalVisited;
 
     if (shouldCallNotificationCallback)
-        m_notificationCallback();
+        scheduleNotificationIfNeeded();
 }
 
 static WallTime reduceTimeResolution(WallTime time)
@@ -294,7 +299,7 @@
     statistics.hadUserInteraction = true;
     statistics.mostRecentUserInteractionTime = newTime;
 
-    m_notificationCallback();
+    scheduleNotificationIfNeeded();
 }
 
 ResourceLoadStatistics& ResourceLoadObserver::ensureResourceStatisticsForPrimaryDomain(const String& primaryDomain)
@@ -322,6 +327,24 @@
     return mapEntry->value.isPrevalentResource;
 }
 
+void ResourceLoadObserver::scheduleNotificationIfNeeded()
+{
+    ASSERT(m_notificationCallback);
+    if (m_resourceStatisticsMap.isEmpty()) {
+        m_notificationTimer.stop();
+        return;
+    }
+
+    if (!m_notificationTimer.isActive())
+        m_notificationTimer.startOneShot(minimumNotificationInterval);
+}
+
+void ResourceLoadObserver::notificationTimerFired()
+{
+    ASSERT(m_notificationCallback);
+    m_notificationCallback(takeStatistics());
+}
+
 String ResourceLoadObserver::statisticsForOrigin(const String& origin)
 {
     auto iter = m_resourceStatisticsMap.find(origin);

Modified: trunk/Source/WebCore/loader/ResourceLoadObserver.h (219206 => 219207)


--- trunk/Source/WebCore/loader/ResourceLoadObserver.h	2017-07-06 18:24:12 UTC (rev 219206)
+++ trunk/Source/WebCore/loader/ResourceLoadObserver.h	2017-07-06 18:28:40 UTC (rev 219207)
@@ -25,7 +25,9 @@
 
 #pragma once
 
+#include "Timer.h"
 #include <wtf/HashMap.h>
+#include <wtf/NeverDestroyed.h>
 #include <wtf/text/WTFString.h>
 
 namespace WTF {
@@ -45,7 +47,7 @@
 struct ResourceLoadStatistics;
 
 class ResourceLoadObserver {
-    friend class NeverDestroyed<ResourceLoadObserver>;
+    friend class WTF::NeverDestroyed<ResourceLoadObserver>;
 public:
     WEBCORE_EXPORT static ResourceLoadObserver& shared();
     
@@ -56,17 +58,23 @@
 
     WEBCORE_EXPORT String statisticsForOrigin(const String&);
 
-    WEBCORE_EXPORT void setNotificationCallback(WTF::Function<void()>&&);
-    WEBCORE_EXPORT Vector<ResourceLoadStatistics> takeStatistics();
+    WEBCORE_EXPORT void setNotificationCallback(WTF::Function<void (Vector<ResourceLoadStatistics>&&)>&&);
 
 private:
+    ResourceLoadObserver();
+
     bool shouldLog(Page*) const;
     ResourceLoadStatistics& ensureResourceStatisticsForPrimaryDomain(const String&);
     ResourceLoadStatistics takeResourceStatisticsForPrimaryDomain(const String& primaryDomain);
     bool isPrevalentResource(const String& primaryDomain) const;
 
+    void scheduleNotificationIfNeeded();
+    void notificationTimerFired();
+    Vector<ResourceLoadStatistics> takeStatistics();
+
     HashMap<String, ResourceLoadStatistics> m_resourceStatisticsMap;
-    WTF::Function<void()> m_notificationCallback;
+    WTF::Function<void (Vector<ResourceLoadStatistics>&&)> m_notificationCallback;
+    Timer m_notificationTimer;
     HashMap<String, size_t> m_originsVisitedMap;
 };
     

Modified: trunk/Source/WebKit2/ChangeLog (219206 => 219207)


--- trunk/Source/WebKit2/ChangeLog	2017-07-06 18:24:12 UTC (rev 219206)
+++ trunk/Source/WebKit2/ChangeLog	2017-07-06 18:28:40 UTC (rev 219207)
@@ -1,5 +1,21 @@
 2017-07-06  Chris Dumez  <[email protected]>
 
+        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.
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::m_webSQLiteDatabaseTracker):
+        (WebKit::WebProcess::statisticsChangedTimerFired): Deleted.
+        * WebProcess/WebProcess.h:
+
+2017-07-06  Chris Dumez  <[email protected]>
+
         WebResourceLoadStatisticsStore should only be constructed when the feature is enabled
         https://bugs.webkit.org/show_bug.cgi?id=174189
 

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (219206 => 219207)


--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2017-07-06 18:24:12 UTC (rev 219206)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp	2017-07-06 18:28:40 UTC (rev 219207)
@@ -170,7 +170,6 @@
     , m_pluginProcessConnectionManager(PluginProcessConnectionManager::create())
 #endif
     , m_nonVisibleProcessCleanupTimer(*this, &WebProcess::nonVisibleProcessCleanupTimerFired)
-    , m_statisticsChangedTimer(*this, &WebProcess::statisticsChangedTimerFired)
 #if PLATFORM(IOS)
     , m_webSQLiteDatabaseTracker(*this)
 #endif
@@ -199,10 +198,9 @@
 
     m_plugInAutoStartOriginHashes.add(SessionID::defaultSessionID(), HashMap<unsigned, double>());
 
-    ResourceLoadObserver::shared().setNotificationCallback([this] {
-        if (m_statisticsChangedTimer.isActive())
-            return;
-        m_statisticsChangedTimer.startOneShot(5_s);
+    ResourceLoadObserver::shared().setNotificationCallback([this] (Vector<ResourceLoadStatistics>&& statistics) {
+        ASSERT(!statistics.isEmpty());
+        parentProcessConnection()->send(Messages::WebResourceLoadStatisticsStore::ResourceLoadStatisticsUpdated(WTFMove(statistics)), 0);
     });
 }
 
@@ -1457,15 +1455,6 @@
 #endif
 }
 
-void WebProcess::statisticsChangedTimerFired()
-{
-    auto statistics = ResourceLoadObserver::shared().takeStatistics();
-    if (statistics.isEmpty())
-        return;
-
-    parentProcessConnection()->send(Messages::WebResourceLoadStatisticsStore::ResourceLoadStatisticsUpdated(WTFMove(statistics)), 0);
-}
-
 void WebProcess::setResourceLoadStatisticsEnabled(bool enabled)
 {
     WebCore::Settings::setResourceLoadStatisticsEnabled(enabled);

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.h (219206 => 219207)


--- trunk/Source/WebKit2/WebProcess/WebProcess.h	2017-07-06 18:24:12 UTC (rev 219206)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.h	2017-07-06 18:28:40 UTC (rev 219207)
@@ -184,7 +184,6 @@
     void pageWillLeaveWindow(uint64_t pageID);
 
     void nonVisibleProcessCleanupTimerFired();
-    void statisticsChangedTimerFired();
 
 #if PLATFORM(COCOA)
     RetainPtr<CFDataRef> sourceApplicationAuditData() const;
@@ -409,7 +408,6 @@
 
     HashSet<uint64_t> m_pagesInWindows;
     WebCore::Timer m_nonVisibleProcessCleanupTimer;
-    WebCore::Timer m_statisticsChangedTimer;
 
     RefPtr<WebCore::ApplicationCacheStorage> m_applicationCacheStorage;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to