Resource Load Statistics: Enable configuration through preferences
authorwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 May 2017 20:04:03 +0000 (20:04 +0000)
committerwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 May 2017 20:04:03 +0000 (20:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171949
<rdar://problem/31894518>

Reviewed by Alex Christensen.

Source/WebCore:

No new tests. Just an added setter.

* loader/ResourceLoadObserver.cpp:
(WebCore::ResourceLoadObserver::setReducedTimestampResolution):

Source/WebKit2:

* Shared/WebPreferencesDefinitions.h:
    Added ResourceLoadStatisticsTimeToLiveUserInteraction,
    ResourceLoadStatisticsTimeToLiveCookiePartitionFree, and
    ResourceLoadStatisticsReducedTimestampResolution.
* UIProcess/Cocoa/WebResourceLoadStatisticsManagerCocoa.mm: Added.
(WebKit::WebResourceLoadStatisticsManager::registerUserDefaultsIfNeeded):
* UIProcess/WebResourceLoadStatisticsManager.h:
* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver):
    Now calls WebResourceLoadStatisticsManager::registerUserDefaultsIfNeeded().
* WebKit2.xcodeproj/project.pbxproj:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@216690 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/loader/ResourceLoadObserver.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPreferencesDefinitions.h
Source/WebKit2/UIProcess/Cocoa/WebResourceLoadStatisticsManagerCocoa.mm [new file with mode: 0644]
Source/WebKit2/UIProcess/WebResourceLoadStatisticsManager.h
Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

index 990ad54..f0c8ff1 100644 (file)
@@ -1,3 +1,16 @@
+2017-05-11  John Wilander  <wilander@apple.com>
+
+        Resource Load Statistics: Enable configuration through preferences
+        https://bugs.webkit.org/show_bug.cgi?id=171949
+        <rdar://problem/31894518>
+
+        Reviewed by Alex Christensen.
+
+        No new tests. Just an added setter.
+
+        * loader/ResourceLoadObserver.cpp:
+        (WebCore::ResourceLoadObserver::setReducedTimestampResolution):
+
 2017-05-11  Frederic Wang  <fwang@igalia.com>
 
         Unify hasTouchScrollableOverflow/needsCompositedScrolling concepts
index 89d292b..f0d9937 100644 (file)
@@ -432,6 +432,12 @@ void ResourceLoadObserver::setTimeToLiveCookiePartitionFree(double seconds)
     m_store->setTimeToLiveCookiePartitionFree(seconds);
 }
 
+void ResourceLoadObserver::setReducedTimestampResolution(double seconds)
+{
+    if (seconds > 0)
+        timestampResolution = seconds;
+}
+
 void ResourceLoadObserver::fireDataModificationHandler()
 {
     m_store->fireDataModificationHandler();
index 34f2f4f..c6ea3db 100644 (file)
@@ -1,3 +1,23 @@
+2017-05-11  John Wilander  <wilander@apple.com>
+
+        Resource Load Statistics: Enable configuration through preferences
+        https://bugs.webkit.org/show_bug.cgi?id=171949
+        <rdar://problem/31894518>
+
+        Reviewed by Alex Christensen.
+
+        * Shared/WebPreferencesDefinitions.h:
+            Added ResourceLoadStatisticsTimeToLiveUserInteraction,
+            ResourceLoadStatisticsTimeToLiveCookiePartitionFree, and
+            ResourceLoadStatisticsReducedTimestampResolution.
+        * UIProcess/Cocoa/WebResourceLoadStatisticsManagerCocoa.mm: Added.
+        (WebKit::WebResourceLoadStatisticsManager::registerUserDefaultsIfNeeded):
+        * UIProcess/WebResourceLoadStatisticsManager.h:
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver):
+            Now calls WebResourceLoadStatisticsManager::registerUserDefaultsIfNeeded().
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2017-05-11  Claudio Saavedra  <csaavedra@igalia.com>
 
         [GTK] Remove notifications guards from GTK API layer
index c18d5db..87d4cd9 100644 (file)
     macro(LayoutInterval, layoutInterval, Double, double, -1, "", "") \
     macro(MaxParseDuration, maxParseDuration, Double, double, -1, "", "") \
     macro(PasswordEchoDuration, passwordEchoDuration, Double, double, 2, "", "") \
+    macro(ResourceLoadStatisticsTimeToLiveUserInteraction, resourceLoadStatisticsTimeToLiveUserInteraction, Double, double, 2592000, "", "") \
+    macro(ResourceLoadStatisticsTimeToLiveCookiePartitionFree, resourceLoadStatisticsTimeToLiveCookiePartitionFree, Double, double, 86400, "", "") \
+    macro(ResourceLoadStatisticsReducedTimestampResolution, resourceLoadStatisticsReducedTimestampResolution, Double, double, 3600, "", "") \
     \
 
 #define FOR_EACH_WEBKIT_UINT32_PREFERENCE(macro) \
diff --git a/Source/WebKit2/UIProcess/Cocoa/WebResourceLoadStatisticsManagerCocoa.mm b/Source/WebKit2/UIProcess/Cocoa/WebResourceLoadStatisticsManagerCocoa.mm
new file mode 100644 (file)
index 0000000..402cf0d
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebResourceLoadStatisticsManager.h"
+
+#import "WebPreferencesKeys.h"
+#import <WebCore/ResourceLoadObserver.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+    
+void WebResourceLoadStatisticsManager::registerUserDefaultsIfNeeded()
+{
+    static dispatch_once_t initOnce;
+    
+    dispatch_once(&initOnce, ^ {
+        const size_t hourInSeconds = 3600;
+        const size_t dayInSeconds = 24 * hourInSeconds;
+        
+        double timeToLiveUserInteraction = [[NSUserDefaults standardUserDefaults] doubleForKey: WebPreferencesKey::resourceLoadStatisticsTimeToLiveUserInteractionKey()];
+        if (timeToLiveUserInteraction > 0 && timeToLiveUserInteraction <= 30 * dayInSeconds)
+            ResourceLoadObserver::sharedObserver().setTimeToLiveUserInteraction(timeToLiveUserInteraction);
+        
+        double timeToLiveCookiePartitionFree = [[NSUserDefaults standardUserDefaults] doubleForKey: WebPreferencesKey::resourceLoadStatisticsTimeToLiveCookiePartitionFreeKey()];
+        if (timeToLiveCookiePartitionFree > 0 && timeToLiveCookiePartitionFree <= dayInSeconds)
+            ResourceLoadObserver::sharedObserver().setTimeToLiveCookiePartitionFree(timeToLiveCookiePartitionFree);
+        
+        double reducedTimestampResolution = [[NSUserDefaults standardUserDefaults] doubleForKey: WebPreferencesKey::resourceLoadStatisticsReducedTimestampResolutionKey()];
+        if (reducedTimestampResolution > 0 && reducedTimestampResolution <= hourInSeconds)
+            ResourceLoadObserver::sharedObserver().setReducedTimestampResolution(reducedTimestampResolution);
+    });
+}
+
+};
index 685a13f..ddbb277 100644 (file)
@@ -57,6 +57,9 @@ public:
     static void clearInMemoryAndPersistentStore();
     static void clearInMemoryAndPersistentStoreModifiedSinceHours(unsigned);
     static void resetToConsistentState();
+#if PLATFORM(COCOA)
+    static void registerUserDefaultsIfNeeded();
+#endif
 
 private:
 };
index 58bb6e5..12c6df3 100644 (file)
@@ -29,6 +29,7 @@
 #include "WebProcessMessages.h"
 #include "WebProcessPool.h"
 #include "WebProcessProxy.h"
+#include "WebResourceLoadStatisticsManager.h"
 #include "WebResourceLoadStatisticsStoreMessages.h"
 #include "WebsiteDataFetchOption.h"
 #include "WebsiteDataType.h"
@@ -182,6 +183,9 @@ void WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver()
 void WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver(std::function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&& shouldPartitionCookiesForDomainsHandler)
 {
     registerSharedResourceLoadObserver();
+#if PLATFORM(COCOA)
+    WebResourceLoadStatisticsManager::registerUserDefaultsIfNeeded();
+#endif
     m_resourceLoadStatisticsStore->setShouldPartitionCookiesCallback([this, shouldPartitionCookiesForDomainsHandler = WTFMove(shouldPartitionCookiesForDomainsHandler)] (const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst) {
         shouldPartitionCookiesForDomainsHandler(domainsToRemove, domainsToAdd, clearFirst);
     });
index d1cc9cd..350acff 100644 (file)
                6501BD1A12F1243400E9F248 /* WKBundleInspector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65B86F1712F11D7B00B7DD8A /* WKBundleInspector.cpp */; };
                659C551E130006410025C0C2 /* InjectedBundlePageResourceLoadClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6546A82913000164000CEB1C /* InjectedBundlePageResourceLoadClient.cpp */; };
                65B86F1E12F11DE300B7DD8A /* WKBundleInspector.h in Headers */ = {isa = PBXBuildFile; fileRef = 65B86F1812F11D7B00B7DD8A /* WKBundleInspector.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               6BBBAD381EC3E57800AD0A2A /* WebResourceLoadStatisticsManagerCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6BBBAD371EC3E56300AD0A2A /* WebResourceLoadStatisticsManagerCocoa.mm */; };
                6BE9699C1E43B3FF008B7483 /* WKResourceLoadStatisticsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BE9699B1E43B3FF008B7483 /* WKResourceLoadStatisticsManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
                6BE9699E1E43B41D008B7483 /* WKResourceLoadStatisticsManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BE9699D1E43B41D008B7483 /* WKResourceLoadStatisticsManager.cpp */; };
                6BE969A01E43B86E008B7483 /* WebResourceLoadStatisticsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BE9699F1E43B86E008B7483 /* WebResourceLoadStatisticsManager.h */; };
                6546A82A13000164000CEB1C /* InjectedBundlePageResourceLoadClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundlePageResourceLoadClient.h; sourceTree = "<group>"; };
                65B86F1712F11D7B00B7DD8A /* WKBundleInspector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKBundleInspector.cpp; sourceTree = "<group>"; };
                65B86F1812F11D7B00B7DD8A /* WKBundleInspector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBundleInspector.h; sourceTree = "<group>"; };
+               6BBBAD371EC3E56300AD0A2A /* WebResourceLoadStatisticsManagerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebResourceLoadStatisticsManagerCocoa.mm; sourceTree = "<group>"; };
                6BE9699B1E43B3FF008B7483 /* WKResourceLoadStatisticsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKResourceLoadStatisticsManager.h; sourceTree = "<group>"; };
                6BE9699D1E43B41D008B7483 /* WKResourceLoadStatisticsManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKResourceLoadStatisticsManager.cpp; sourceTree = "<group>"; };
                6BE9699F1E43B86E008B7483 /* WebResourceLoadStatisticsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebResourceLoadStatisticsManager.h; sourceTree = "<group>"; };
                                CDA29A1F1CBEB5FB00901CCF /* WebPlaybackSessionManagerProxy.mm */,
                                7CE4D2151A49148400C7F152 /* WebProcessPoolCocoa.mm */,
                                1A04F6171A4A3A7A00A21B6E /* WebProcessProxyCocoa.mm */,
+                               6BBBAD371EC3E56300AD0A2A /* WebResourceLoadStatisticsManagerCocoa.mm */,
                                7AAD175E1EA6AF37003B0894 /* WebResourceLoadStatisticsStoreCocoa.mm */,
                                51D124311E6DE521002B2820 /* WebURLSchemeHandlerCocoa.h */,
                                51D124321E6DE521002B2820 /* WebURLSchemeHandlerCocoa.mm */,
                                8372DB281A67562800C697C5 /* WebPageDiagnosticLoggingClient.cpp in Sources */,
                                BC7B6207129A0A6700D174A4 /* WebPageGroup.cpp in Sources */,
                                BC7B625312A43C9600D174A4 /* WebPageGroupData.cpp in Sources */,
+                               6BBBAD381EC3E57800AD0A2A /* WebResourceLoadStatisticsManagerCocoa.mm in Sources */,
                                BC7B621612A4219A00D174A4 /* WebPageGroupProxy.cpp in Sources */,
                                2D9EA3111A96D9EB002D2807 /* WebPageInjectedBundleClient.cpp in Sources */,
                                2DA944BA1884EA3C00ED86DB /* WebPageIOS.mm in Sources */,