Title: [207218] trunk
Revision
207218
Author
pvol...@apple.com
Date
2016-10-12 09:36:11 -0700 (Wed, 12 Oct 2016)

Log Message

[Win] Parallel DRTs are sharing preferences and cache.
https://bugs.webkit.org/show_bug.cgi?id=163013

Reviewed by Brent Fulgham.

Source/WebKit/win:

Make it possible for a WebKit client to use separate preferences and cache.

* Interfaces/IWebPreferencesPrivate.idl:
* WebApplicationCache.cpp:
(applicationCachePath):
* WebCache.cpp:
(WebCache::cacheFolder):
(WebCache::setCacheFolder):
* WebDatabaseManager.cpp:
(databasesDirectory):
* WebPreferences.cpp:
(WebPreferences::applicationId):
(WebPreferences::valueForKey):
(WebPreferences::setValueForKey):
(WebPreferences::save):
(WebPreferences::QueryInterface):
(WebPreferences::modernMediaControlsEnabled):
(WebPreferences::setApplicationId):
* WebPreferences.h:
* WebView.cpp:
(WebView::setCacheModel):

Tools:

Use separate cache and preferences for each DRT instance.

* DumpRenderTree/win/DumpRenderTree.cpp:
(applicationId):
(setApplicationId):
(setCacheFolder):
(setDefaultsToConsistentValuesForTesting):
* Scripts/webkitpy/port/win.py:
(WinPort.setup_test_run):

Modified Paths

Diff

Modified: trunk/Source/WebKit/win/ChangeLog (207217 => 207218)


--- trunk/Source/WebKit/win/ChangeLog	2016-10-12 16:32:20 UTC (rev 207217)
+++ trunk/Source/WebKit/win/ChangeLog	2016-10-12 16:36:11 UTC (rev 207218)
@@ -1,3 +1,32 @@
+2016-10-12  Per Arne Vollan  <pvol...@apple.com>
+
+        [Win] Parallel DRTs are sharing preferences and cache.
+        https://bugs.webkit.org/show_bug.cgi?id=163013
+
+        Reviewed by Brent Fulgham.
+
+        Make it possible for a WebKit client to use separate preferences and cache.
+
+        * Interfaces/IWebPreferencesPrivate.idl:
+        * WebApplicationCache.cpp:
+        (applicationCachePath):
+        * WebCache.cpp:
+        (WebCache::cacheFolder):
+        (WebCache::setCacheFolder):
+        * WebDatabaseManager.cpp:
+        (databasesDirectory):
+        * WebPreferences.cpp:
+        (WebPreferences::applicationId):
+        (WebPreferences::valueForKey):
+        (WebPreferences::setValueForKey):
+        (WebPreferences::save):
+        (WebPreferences::QueryInterface):
+        (WebPreferences::modernMediaControlsEnabled):
+        (WebPreferences::setApplicationId):
+        * WebPreferences.h:
+        * WebView.cpp:
+        (WebView::setCacheModel):
+
 2016-10-11  Alex Christensen  <achristen...@webkit.org>
 
         Remove dead networking code

Modified: trunk/Source/WebKit/win/Interfaces/IWebPreferencesPrivate.idl (207217 => 207218)


--- trunk/Source/WebKit/win/Interfaces/IWebPreferencesPrivate.idl	2016-10-12 16:32:20 UTC (rev 207217)
+++ trunk/Source/WebKit/win/Interfaces/IWebPreferencesPrivate.idl	2016-10-12 16:36:11 UTC (rev 207218)
@@ -187,3 +187,8 @@
     HRESULT setModernMediaControlsEnabled([in] BOOL enabled);
 }
 
+[uuid(F9582D72-6348-45B1-AB09-39E33459B5B9)]
+interface IWebPreferencesPrivate4 : IWebPreferencesPrivate3
+{
+    HRESULT setApplicationId([in] BSTR applicationId);
+}
\ No newline at end of file

Modified: trunk/Source/WebKit/win/WebApplicationCache.cpp (207217 => 207218)


--- trunk/Source/WebKit/win/WebApplicationCache.cpp	2016-10-12 16:32:20 UTC (rev 207217)
+++ trunk/Source/WebKit/win/WebApplicationCache.cpp	2016-10-12 16:36:11 UTC (rev 207218)
@@ -28,6 +28,7 @@
 
 #include "CFDictionaryPropertyBag.h"
 #include "MarshallingHelpers.h"
+#include "WebPreferences.h"
 #include "WebSecurityOrigin.h"
 #include <wtf/RetainPtr.h>
 #include <WebCore/ApplicationCache.h>
@@ -68,7 +69,7 @@
     String path = localUserSpecificStorageDirectory();
 
 #if USE(CF)
-    auto cacheDirectoryPreference = adoptCF(CFPreferencesCopyAppValue(WebKitLocalCacheDefaultsKey, kCFPreferencesCurrentApplication));
+    auto cacheDirectoryPreference = adoptCF(CFPreferencesCopyAppValue(WebKitLocalCacheDefaultsKey, WebPreferences::applicationId()));
     if (cacheDirectoryPreference && CFStringGetTypeID() == CFGetTypeID(cacheDirectoryPreference.get()))
         path = static_cast<CFStringRef>(cacheDirectoryPreference.get());
 #endif

Modified: trunk/Source/WebKit/win/WebCache.cpp (207217 => 207218)


--- trunk/Source/WebKit/win/WebCache.cpp	2016-10-12 16:32:20 UTC (rev 207217)
+++ trunk/Source/WebKit/win/WebCache.cpp	2016-10-12 16:36:11 UTC (rev 207218)
@@ -35,8 +35,13 @@
 
 #if USE(CURL)
 #include <WebCore/CurlCacheManager.h>
+#elif USE(CFNETWORK)
+#include <CFNetwork/CFURLCachePriv.h>
+#include <WebKitSystemInterface/WebKitSystemInterface.h>
 #endif
 
+using namespace WebCore;
+
 // WebCache ---------------------------------------------------------------------------
 
 WebCache::WebCache()
@@ -243,8 +248,10 @@
     String cacheFolder = WebCore::CurlCacheManager::getInstance().cacheDirectory();
     *location = WebCore::BString(cacheFolder).release();
     return S_OK;
-#else
-    return E_NOTIMPL;
+#elif USE(CFNETWORK)
+    RetainPtr<CFStringRef> cfurlCacheDirectory = adoptCF(wkCopyFoundationCacheDirectory(0));
+    *location = BString(cfurlCacheDirectory.get()).release();
+    return S_OK;
 #endif
 }
 
@@ -254,7 +261,12 @@
     String cacheFolder(location, SysStringLen(location));
     WebCore::CurlCacheManager::getInstance().setCacheDirectory(cacheFolder);
     return S_OK;
-#else
-    return E_NOTIMPL;
+#elif USE(CFNETWORK)
+    RetainPtr<CFURLCacheRef> cache = adoptCF(CFURLCacheCopySharedURLCache());
+    CFIndex memoryCapacity = CFURLCacheMemoryCapacity(cache.get());
+    CFIndex diskCapacity = CFURLCacheDiskCapacity(cache.get());
+    RetainPtr<CFURLCacheRef> newCache = adoptCF(CFURLCacheCreate(kCFAllocatorDefault, memoryCapacity, diskCapacity, String(location).createCFString().get()));
+    CFURLCacheSetSharedURLCache(newCache.get());
+    return S_OK;
 #endif
 }

Modified: trunk/Source/WebKit/win/WebDatabaseManager.cpp (207217 => 207218)


--- trunk/Source/WebKit/win/WebDatabaseManager.cpp	2016-10-12 16:32:20 UTC (rev 207217)
+++ trunk/Source/WebKit/win/WebDatabaseManager.cpp	2016-10-12 16:36:11 UTC (rev 207218)
@@ -33,6 +33,7 @@
 #include "COMPropertyBag.h"
 #include "MarshallingHelpers.h"
 #include "WebNotificationCenter.h"
+#include "WebPreferences.h"
 #include "WebSecurityOrigin.h"
 
 #include <WebCore/BString.h>
@@ -420,7 +421,7 @@
 static WTF::String databasesDirectory()
 {
 #if USE(CF)
-    RetainPtr<CFPropertyListRef> directoryPref = adoptCF(CFPreferencesCopyAppValue(WebDatabaseDirectoryDefaultsKey, kCFPreferencesCurrentApplication));
+    RetainPtr<CFPropertyListRef> directoryPref = adoptCF(CFPreferencesCopyAppValue(WebDatabaseDirectoryDefaultsKey, WebPreferences::applicationId()));
     if (directoryPref && (CFStringGetTypeID() == CFGetTypeID(directoryPref.get())))
         return static_cast<CFStringRef>(directoryPref.get());
 #endif

Modified: trunk/Source/WebKit/win/WebPreferences.cpp (207217 => 207218)


--- trunk/Source/WebKit/win/WebPreferences.cpp	2016-10-12 16:32:20 UTC (rev 207217)
+++ trunk/Source/WebKit/win/WebPreferences.cpp	2016-10-12 16:36:11 UTC (rev 207218)
@@ -101,6 +101,8 @@
 
 static CFDictionaryRef defaultSettings;
 
+RetainPtr<CFStringRef> WebPreferences::m_applicationId = kCFPreferencesCurrentApplication;
+
 static HashMap<WTF::String, COMPtr<WebPreferences>>& webPreferencesInstances()
 {
     static NeverDestroyed<HashMap<WTF::String, COMPtr<WebPreferences>>> webPreferencesInstances;
@@ -183,6 +185,11 @@
         webPreferencesInstances().remove(identifierString);
 }
 
+CFStringRef WebPreferences::applicationId()
+{
+    return m_applicationId.get();
+}
+
 void WebPreferences::initializeDefaultSettings()
 {
     if (defaultSettings)
@@ -306,7 +313,7 @@
     if (value)
         return value;
 
-    value = adoptCF(CFPreferencesCopyAppValue(key, kCFPreferencesCurrentApplication));
+    value = adoptCF(CFPreferencesCopyAppValue(key, applicationId()));
     if (value)
         return value;
 
@@ -317,7 +324,7 @@
 {
     CFDictionarySetValue(m_privatePrefs.get(), key, value);
     if (m_autoSaves) {
-        CFPreferencesSetAppValue(key, value, kCFPreferencesCurrentApplication);
+        CFPreferencesSetAppValue(key, value, applicationId());
         save();
     }
 }
@@ -448,7 +455,7 @@
 
 void WebPreferences::save()
 {
-    CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
+    CFPreferencesAppSynchronize(applicationId());
 }
 
 void WebPreferences::load()
@@ -540,6 +547,8 @@
         *ppvObject = static_cast<IWebPreferencesPrivate2*>(this);
     else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate3))
         *ppvObject = static_cast<IWebPreferencesPrivate3*>(this);
+    else if (IsEqualGUID(riid, IID_IWebPreferencesPrivate4))
+        *ppvObject = static_cast<IWebPreferencesPrivate4*>(this);
     else if (IsEqualGUID(riid, CLSID_WebPreferences))
         *ppvObject = this;
     else
@@ -1993,3 +2002,9 @@
     *enabled = boolValueForKey(WebKitModernMediaControlsEnabledPreferenceKey);
     return S_OK;
 }
+
+HRESULT WebPreferences::setApplicationId(BSTR applicationId)
+{
+    m_applicationId = String(applicationId).createCFString();
+    return S_OK;
+}

Modified: trunk/Source/WebKit/win/WebPreferences.h (207217 => 207218)


--- trunk/Source/WebKit/win/WebPreferences.h	2016-10-12 16:32:20 UTC (rev 207217)
+++ trunk/Source/WebKit/win/WebPreferences.h	2016-10-12 16:36:11 UTC (rev 207218)
@@ -23,8 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef WebPreferences_H
-#define WebPreferences_H
+#pragma once
 
 #include "WebKit.h"
 #include <CoreFoundation/CoreFoundation.h>
@@ -31,7 +30,7 @@
 #include <WebCore/BString.h>
 #include <wtf/RetainPtr.h>
 
-class WebPreferences : public IWebPreferences, public IWebPreferencesPrivate3 {
+class WebPreferences : public IWebPreferences, public IWebPreferencesPrivate4 {
 public:
     static WebPreferences* createInstance();
 protected:
@@ -244,6 +243,9 @@
     virtual HRESULT STDMETHODCALLTYPE modernMediaControlsEnabled(_Out_ BOOL*);
     virtual HRESULT STDMETHODCALLTYPE setModernMediaControlsEnabled(BOOL);
 
+    // IWebPreferencesPrivate4
+    virtual HRESULT STDMETHODCALLTYPE setApplicationId(BSTR);
+
     // WebPreferences
 
     // This method accesses a different preference key than developerExtrasEnabled.
@@ -257,6 +259,8 @@
     static void removeReferenceForIdentifier(BSTR identifier);
     static WebPreferences* sharedStandardPreferences();
 
+    static CFStringRef applicationId();
+
     // From WebHistory.h
     HRESULT historyItemLimit(_Out_ int*);
     HRESULT setHistoryItemLimit(int);
@@ -263,8 +267,8 @@
     HRESULT historyAgeInDaysLimit(_Out_ int*);
     HRESULT setHistoryAgeInDaysLimit(int);
 
-     void willAddToWebView();
-     void didRemoveFromWebView();
+    void willAddToWebView();
+    void didRemoveFromWebView();
 
     HRESULT postPreferencesChangesNotification();
 
@@ -297,6 +301,5 @@
     bool m_autoSaves { false };
     bool m_automaticallyDetectsCacheModel { true };
     unsigned m_numWebViews { 0 };
+    static RetainPtr<CFStringRef> m_applicationId;
 };
-
-#endif

Modified: trunk/Source/WebKit/win/WebView.cpp (207217 => 207218)


--- trunk/Source/WebKit/win/WebView.cpp	2016-10-12 16:32:20 UTC (rev 207217)
+++ trunk/Source/WebKit/win/WebView.cpp	2016-10-12 16:36:11 UTC (rev 207218)
@@ -501,7 +501,7 @@
     RetainPtr<CFURLCacheRef> cfurlCache = adoptCF(CFURLCacheCopySharedURLCache());
     RetainPtr<CFStringRef> cfurlCacheDirectory = adoptCF(wkCopyFoundationCacheDirectory(0));
     if (!cfurlCacheDirectory) {
-        RetainPtr<CFPropertyListRef> preference = adoptCF(CFPreferencesCopyAppValue(WebKitLocalCacheDefaultsKey, kCFPreferencesCurrentApplication));
+        RetainPtr<CFPropertyListRef> preference = adoptCF(CFPreferencesCopyAppValue(WebKitLocalCacheDefaultsKey, WebPreferences::applicationId()));
         if (preference && (CFStringGetTypeID() == CFGetTypeID(preference.get())))
             cfurlCacheDirectory = adoptCF(static_cast<CFStringRef>(preference.leakRef()));
         else

Modified: trunk/Tools/ChangeLog (207217 => 207218)


--- trunk/Tools/ChangeLog	2016-10-12 16:32:20 UTC (rev 207217)
+++ trunk/Tools/ChangeLog	2016-10-12 16:36:11 UTC (rev 207218)
@@ -1,3 +1,20 @@
+2016-10-12  Per Arne Vollan  <pvol...@apple.com>
+
+        [Win] Parallel DRTs are sharing preferences and cache.
+        https://bugs.webkit.org/show_bug.cgi?id=163013
+
+        Reviewed by Brent Fulgham.
+
+        Use separate cache and preferences for each DRT instance.
+
+        * DumpRenderTree/win/DumpRenderTree.cpp:
+        (applicationId):
+        (setApplicationId):
+        (setCacheFolder):
+        (setDefaultsToConsistentValuesForTesting):
+        * Scripts/webkitpy/port/win.py:
+        (WinPort.setup_test_run):
+
 2016-10-11  Alex Christensen  <achristen...@webkit.org>
 
         Update API test expectation after r207162.

Modified: trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp (207217 => 207218)


--- trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp	2016-10-12 16:32:20 UTC (rev 207217)
+++ trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp	2016-10-12 16:36:11 UTC (rev 207218)
@@ -49,6 +49,7 @@
 #include <fstream>
 #include <io.h>
 #include <math.h>
+#include <shlobj.h>
 #include <shlwapi.h>
 #include <tchar.h>
 #include <wtf/NeverDestroyed.h>
@@ -859,16 +860,52 @@
     setAlwaysAcceptCookies(false);
 }
 
+static String applicationId()
+{
+    DWORD processId = ::GetCurrentProcessId();
+    return String::format("com.apple.DumpRenderTree.%d", processId);
+}
+
+static void setApplicationId()
+{
+    COMPtr<IWebPreferences> preferences;
+    if (SUCCEEDED(WebKitCreateInstance(CLSID_WebPreferences, 0, IID_IWebPreferences, (void**)&preferences))) {
+        COMPtr<IWebPreferencesPrivate4> prefsPrivate4(Query, preferences);
+        ASSERT(prefsPrivate4);
+        _bstr_t fileName = applicationId().charactersWithNullTermination().data();
+        prefsPrivate4->setApplicationId(fileName);
+    }
+}
+
+static void setCacheFolder()
+{
+    String libraryPath = libraryPathForDumpRenderTree();
+
+    COMPtr<IWebCache> webCache;
+    if (SUCCEEDED(WebKitCreateInstance(CLSID_WebCache, 0, IID_IWebCache, (void**)&webCache))) {
+        _bstr_t cacheFolder = WebCore::pathByAppendingComponent(libraryPath, "LocalCache").utf8().data();
+        webCache->setCacheFolder(cacheFolder);
+    }
+}
+
 // Called once on DumpRenderTree startup.
 static void setDefaultsToConsistentValuesForTesting()
 {
 #if USE(CF)
+    // Create separate preferences for each DRT instance
+    setApplicationId();
+
+    RetainPtr<CFStringRef> appId = applicationId().createCFString();
+
     String libraryPath = libraryPathForDumpRenderTree();
 
     // Set up these values before creating the WebView so that the various initializations will see these preferred values.
-    CFPreferencesSetAppValue(WebDatabaseDirectoryDefaultsKey, WebCore::pathByAppendingComponent(libraryPath, "Databases").createCFString().get(), kCFPreferencesCurrentApplication);
-    CFPreferencesSetAppValue(WebStorageDirectoryDefaultsKey, WebCore::pathByAppendingComponent(libraryPath, "LocalStorage").createCFString().get(), kCFPreferencesCurrentApplication);
-    CFPreferencesSetAppValue(WebKitLocalCacheDefaultsKey, WebCore::pathByAppendingComponent(libraryPath, "LocalCache").createCFString().get(), kCFPreferencesCurrentApplication);
+    CFPreferencesSetAppValue(WebDatabaseDirectoryDefaultsKey, WebCore::pathByAppendingComponent(libraryPath, "Databases").createCFString().get(), appId.get());
+    CFPreferencesSetAppValue(WebStorageDirectoryDefaultsKey, WebCore::pathByAppendingComponent(libraryPath, "LocalStorage").createCFString().get(), appId.get());
+    CFPreferencesSetAppValue(WebKitLocalCacheDefaultsKey, WebCore::pathByAppendingComponent(libraryPath, "LocalCache").createCFString().get(), appId.get());
+
+    // Create separate cache for each DRT instance
+    setCacheFolder();
 #endif
 }
 

Modified: trunk/Tools/Scripts/webkitpy/port/win.py (207217 => 207218)


--- trunk/Tools/Scripts/webkitpy/port/win.py	2016-10-12 16:32:20 UTC (rev 207217)
+++ trunk/Tools/Scripts/webkitpy/port/win.py	2016-10-12 16:36:11 UTC (rev 207218)
@@ -28,8 +28,9 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 import atexit
+import glob
+import logging
 import os
-import logging
 import re
 import sys
 import time
@@ -346,11 +347,21 @@
     def delete_sem_locks(self):
         os.system("rm -rf /dev/shm/sem.*")
 
+    def delete_preference_files(self):
+        try:
+            preferences_files = self._filesystem.join(os.environ['APPDATA'], "Apple Computer/Preferences", "com.apple.DumpRenderTree*")
+            filelist = glob.glob(preferences_files)
+            for file in filelist:
+                self._filesystem.remove(file)
+        except:
+            _log.warn("Failed to delete preference files.")
+
     def setup_test_run(self, device_class=None):
         atexit.register(self.restore_crash_log_saving)
         self.setup_crash_log_saving()
         self.prevent_error_dialogs()
         self.delete_sem_locks()
+        self.delete_preference_files()
         super(WinPort, self).setup_test_run(device_class)
 
     def clean_up_test_run(self):
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to