Need a method to close all idle localstorage databases immediately.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 2 Dec 2012 10:31:42 +0000 (10:31 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 2 Dec 2012 10:31:42 +0000 (10:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=103469

Patch by Yongjun Zhang <yongjun_zhang@apple.com> on 2012-12-02
Reviewed by David Kilzer.

Source/WebCore:

Add a new PageGroup method closeIdleLocalStorageDatabases, which walks through
all local storage areas that don't have document referencing to them and closes
their underlying databases.

Test: storage/domstorage/localstorage/close-idle-localstorage-databases-immediately.html

* WebCore.exp.in:
* page/PageGroup.cpp:
(WebCore::PageGroup::clearLocalStorageForOrigin):
(WebCore):
(WebCore::PageGroup::closeIdleLocalStorageDatabases): walking through all idle local storages and
    closing their databases.
* page/PageGroup.h:
(PageGroup):
* storage/StorageArea.h:
(WebCore::StorageArea::closeDatabaseIfIdle):
* storage/StorageAreaImpl.cpp:
(WebCore::StorageAreaImpl::closeDatabaseIfIdle): close the database if it is idle.
(WebCore):
* storage/StorageAreaImpl.h:
(StorageAreaImpl):
* storage/StorageNamespace.h:
(StorageNamespace):
* storage/StorageNamespaceImpl.cpp:
(WebCore::StorageNamespaceImpl::closeIdleLocalStorageDatabases):
(WebCore):
* storage/StorageNamespaceImpl.h:
(StorageNamespaceImpl):

Source/WebKit/mac:

Add a new method to WebStorageManager that we can call to close all
idle local storage databases.

* Storage/WebStorageManager.mm:
(+[WebStorageManager closeIdleLocalStorageDatabases]):
* Storage/WebStorageManagerPrivate.h:

Tools:

Add an JS method to TestRunner, to enable testing closing idle local storage databases in
DumpRenderTree layout tests.

* DumpRenderTree/TestRunner.cpp:
(closeIdleLocalStorageDatabasesCallback):
(TestRunner::staticFunctions):
* DumpRenderTree/TestRunner.h:
(TestRunner):
* DumpRenderTree/blackberry/TestRunnerBlackBerry.cpp:
(TestRunner::closeIdleLocalStorageDatabases):
* DumpRenderTree/efl/TestRunnerEfl.cpp:
(TestRunner::closeIdleLocalStorageDatabases):
* DumpRenderTree/gtk/TestRunnerGtk.cpp:
(TestRunner::closeIdleLocalStorageDatabases):
* DumpRenderTree/mac/TestRunnerMac.mm:
(TestRunner::closeIdleLocalStorageDatabases):
* DumpRenderTree/win/TestRunnerWin.cpp:
(TestRunner::closeIdleLocalStorageDatabases):
* DumpRenderTree/wx/TestRunnerWx.cpp:
(TestRunner::closeIdleLocalStorageDatabases):

LayoutTests:

* storage/domstorage/localstorage/close-idle-localstorage-databases-immediately-expected.txt: Added.
* storage/domstorage/localstorage/close-idle-localstorage-databases-immediately.html: Added.
* storage/resources/storage-close-idle-localstorage-databases-immediately.html: Added.

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

27 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/chromium/TestExpectations
LayoutTests/storage/domstorage/localstorage/close-idle-localstorage-databases-immediately-expected.txt [new file with mode: 0644]
LayoutTests/storage/domstorage/localstorage/close-idle-localstorage-databases-immediately.html [new file with mode: 0644]
LayoutTests/storage/resources/storage-close-idle-localstorage-databases-immediately.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/page/PageGroup.cpp
Source/WebCore/page/PageGroup.h
Source/WebCore/storage/StorageArea.h
Source/WebCore/storage/StorageAreaImpl.cpp
Source/WebCore/storage/StorageAreaImpl.h
Source/WebCore/storage/StorageNamespace.h
Source/WebCore/storage/StorageNamespaceImpl.cpp
Source/WebCore/storage/StorageNamespaceImpl.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Storage/WebStorageManager.mm
Source/WebKit/mac/Storage/WebStorageManagerPrivate.h
Tools/ChangeLog
Tools/DumpRenderTree/TestRunner.cpp
Tools/DumpRenderTree/TestRunner.h
Tools/DumpRenderTree/blackberry/TestRunnerBlackBerry.cpp
Tools/DumpRenderTree/efl/TestRunnerEfl.cpp
Tools/DumpRenderTree/gtk/TestRunnerGtk.cpp
Tools/DumpRenderTree/mac/TestRunnerMac.mm
Tools/DumpRenderTree/win/TestRunnerWin.cpp
Tools/DumpRenderTree/wx/TestRunnerWx.cpp

index a54c098..76c3b07 100644 (file)
@@ -1,3 +1,14 @@
+2012-12-02  Yongjun Zhang  <yongjun_zhang@apple.com>
+
+        Need a method to close all idle localstorage databases immediately.
+        https://bugs.webkit.org/show_bug.cgi?id=103469
+
+        Reviewed by David Kilzer.
+
+        * storage/domstorage/localstorage/close-idle-localstorage-databases-immediately-expected.txt: Added.
+        * storage/domstorage/localstorage/close-idle-localstorage-databases-immediately.html: Added.
+        * storage/resources/storage-close-idle-localstorage-databases-immediately.html: Added.
+
 2012-12-02  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r136236.
index 12678f9..f1c907d 100644 (file)
@@ -804,6 +804,7 @@ fast/forms/get-forms-to-about-blank.html [ WontFix ]
 # implement because we can't emulate the caching behaviors it expects.
 fast/dom/HTMLScriptElement/nested-execution.html [ WontFix ]
 storage/domstorage/storage-close-database-on-idle.html [ WontFix ]
+storage/domstorage/localstorage/close-idle-localstorage-databases-immediately.html [ WontFix ]
 
 # Deletion UI is a Mail-ism. We don't need to worry about this.
 editing/deleting/deletionUI-single-instance.html [ WontFix ]
diff --git a/LayoutTests/storage/domstorage/localstorage/close-idle-localstorage-databases-immediately-expected.txt b/LayoutTests/storage/domstorage/localstorage/close-idle-localstorage-databases-immediately-expected.txt
new file mode 100644 (file)
index 0000000..dfb83e4
--- /dev/null
@@ -0,0 +1,3 @@
+PASS foo
+PASS bar
+
diff --git a/LayoutTests/storage/domstorage/localstorage/close-idle-localstorage-databases-immediately.html b/LayoutTests/storage/domstorage/localstorage/close-idle-localstorage-databases-immediately.html
new file mode 100644 (file)
index 0000000..1a56c1f
--- /dev/null
@@ -0,0 +1,65 @@
+<html>
+<head>
+<script src="../../../fast/js/resources/js-test-pre.js"></script>
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+
+function loadNextPage()
+{
+    location.href = "../../resources/storage-close-idle-localstorage-databases-immediately.html";
+}
+
+function runTest()
+{
+    if (window.testRunner) {
+        testRunner.setCacheModel(0); // WebCacheModelDocumentViewer.
+    }
+
+    // Test to make sure the storage values don't change after the database is closed.
+    if ("localStorage" in window) {
+        var loadCount = window.sessionStorage['testPageLoadCount'];
+        if (loadCount !== undefined)
+            loadCount++;
+        else
+            loadCount = 1;
+
+        window.sessionStorage['testPageLoadCount'] = loadCount;
+
+        if (loadCount == 1) {
+            window.localStorage.clear();
+            window.localStorage['foo'] = 'FOO';
+            window.localStorage['bar'] = 'BAR';
+
+            setTimeout("loadNextPage()", 0);
+        } else {
+            // Test if we still have the right values.
+            if (window.localStorage['foo'] === 'FOO')
+                testPassed("foo");
+            else
+                testFailed("foo");
+
+            if (window.localStorage['bar'] === 'BAR')
+                testPassed("bar");
+            else
+                testFailed("bar");
+
+            window.sessionStorage.removeItem('testPageLoadCount');
+
+            if (window.testRunner) {
+                window.testRunner.notifyDone();
+            }
+        }
+    }
+}
+
+</script>
+</head>
+<body onload="runTest();">
+<p id="description"></p>
+<div id="console"></div>
+</body>
+</html>
+
diff --git a/LayoutTests/storage/resources/storage-close-idle-localstorage-databases-immediately.html b/LayoutTests/storage/resources/storage-close-idle-localstorage-databases-immediately.html
new file mode 100644 (file)
index 0000000..4e0a446
--- /dev/null
@@ -0,0 +1,13 @@
+<html>
+<script>
+    function swingBack() 
+    {
+        if (window.testRunner) {
+            window.testRunner.closeIdleLocalStorageDatabases();
+        }
+        location.href='../domstorage/localstorage/close-idle-localstorage-databases-immediately.html';
+    }
+</script>
+<body onload='setTimeout(swingBack(), 100);'>
+</body>
+</html>
index 5e8a00b..e58e1cf 100644 (file)
@@ -1,3 +1,39 @@
+2012-12-02  Yongjun Zhang  <yongjun_zhang@apple.com>
+
+        Need a method to close all idle localstorage databases immediately.
+        https://bugs.webkit.org/show_bug.cgi?id=103469
+
+        Reviewed by David Kilzer.
+
+        Add a new PageGroup method closeIdleLocalStorageDatabases, which walks through
+        all local storage areas that don't have document referencing to them and closes
+        their underlying databases.
+
+        Test: storage/domstorage/localstorage/close-idle-localstorage-databases-immediately.html
+
+        * WebCore.exp.in:
+        * page/PageGroup.cpp:
+        (WebCore::PageGroup::clearLocalStorageForOrigin):
+        (WebCore):
+        (WebCore::PageGroup::closeIdleLocalStorageDatabases): walking through all idle local storages and
+            closing their databases.
+        * page/PageGroup.h:
+        (PageGroup):
+        * storage/StorageArea.h:
+        (WebCore::StorageArea::closeDatabaseIfIdle):
+        * storage/StorageAreaImpl.cpp:
+        (WebCore::StorageAreaImpl::closeDatabaseIfIdle): close the database if it is idle.
+        (WebCore):
+        * storage/StorageAreaImpl.h:
+        (StorageAreaImpl):
+        * storage/StorageNamespace.h:
+        (StorageNamespace):
+        * storage/StorageNamespaceImpl.cpp:
+        (WebCore::StorageNamespaceImpl::closeIdleLocalStorageDatabases):
+        (WebCore):
+        * storage/StorageNamespaceImpl.h:
+        (StorageNamespaceImpl):
+
 2012-12-02  Otto Derek Cheung  <otcheung@rim.com>
 
         [BlackBerry] Adding checks for null when checking cookie status in CookieJarBlackBerry
index ba60877..53c7c83 100644 (file)
@@ -1089,6 +1089,7 @@ __ZN7WebCore9PageGroup26setShouldTrackVisitedLinksEb
 __ZN7WebCore9PageGroup29removeUserStyleSheetFromWorldEPNS_15DOMWrapperWorldERKNS_4KURLE
 __ZN7WebCore9PageGroup30removeUserStyleSheetsFromWorldEPNS_15DOMWrapperWorldE
 __ZN7WebCore9PageGroup9pageGroupERKN3WTF6StringE
+__ZN7WebCore9PageGroup30closeIdleLocalStorageDatabasesEv
 __ZN7WebCore9Scrollbar10mouseMovedERKNS_18PlatformMouseEventE
 __ZN7WebCore9Scrollbar11mouseExitedEv
 __ZN7WebCore9Scrollbar12mouseEnteredEv
index f93c0b7..518aa19 100644 (file)
@@ -144,9 +144,21 @@ void PageGroup::clearLocalStorageForOrigin(SecurityOrigin* origin)
     for (PageGroupMap::iterator it = pageGroups->begin(); it != end; ++it) {
         if (it->value->hasLocalStorage())
             it->value->localStorage()->clearOriginForDeletion(origin);
-    }    
+    }
 }
-    
+
+void PageGroup::closeIdleLocalStorageDatabases()
+{
+    if (!pageGroups)
+        return;
+
+    PageGroupMap::iterator end = pageGroups->end();
+    for (PageGroupMap::iterator it = pageGroups->begin(); it != end; ++it) {
+        if (it->value->hasLocalStorage())
+            it->value->localStorage()->closeIdleLocalStorageDatabases();
+    }
+}
+
 void PageGroup::syncLocalStorage()
 {
     if (!pageGroups)
index 6284fa8..4bb00ac 100644 (file)
@@ -60,6 +60,7 @@ namespace WebCore {
 
         static void clearLocalStorageForAllOrigins();
         static void clearLocalStorageForOrigin(SecurityOrigin*);
+        static void closeIdleLocalStorageDatabases();
         // DumpRenderTree helper that triggers a StorageArea sync.
         static void syncLocalStorage();
 
index 97034c8..87349a6 100644 (file)
@@ -60,6 +60,7 @@ namespace WebCore {
 
         virtual void incrementAccessCount() { }
         virtual void decrementAccessCount() { }
+        virtual void closeDatabaseIfIdle() { }
     };
 
 } // namespace WebCore
index 8f57db7..8d85cc5 100644 (file)
@@ -349,4 +349,14 @@ void StorageAreaImpl::closeDatabaseTimerFired(Timer<StorageAreaImpl> *)
         m_storageAreaSync->scheduleCloseDatabase();
 }
 
+void StorageAreaImpl::closeDatabaseIfIdle()
+{
+    if (m_closeDatabaseTimer.isActive()) {
+        ASSERT(!m_accessCount);
+        m_closeDatabaseTimer.stop();
+
+        closeDatabaseTimerFired(&m_closeDatabaseTimer);
+    }
+}
+
 }
index 384af5f..e394556 100644 (file)
@@ -58,6 +58,7 @@ namespace WebCore {
 
         virtual void incrementAccessCount();
         virtual void decrementAccessCount();
+        virtual void closeDatabaseIfIdle();
 
         PassRefPtr<StorageAreaImpl> copy();
         void close();
index 5ceddc3..cbd8733 100644 (file)
@@ -49,6 +49,7 @@ public:
     virtual void clearOriginForDeletion(SecurityOrigin*) = 0;
     virtual void clearAllOriginsForDeletion() = 0;
     virtual void sync() = 0;
+    virtual void closeIdleLocalStorageDatabases()  { }
 };
 
 } // namespace WebCore
index 4501b11..6bd9f40 100644 (file)
@@ -165,4 +165,12 @@ void StorageNamespaceImpl::sync()
         it->value->sync();
 }
 
+void StorageNamespaceImpl::closeIdleLocalStorageDatabases()
+{
+    ASSERT(isMainThread());
+    StorageAreaMap::iterator end = m_storageAreaMap.end();
+    for (StorageAreaMap::iterator it = m_storageAreaMap.begin(); it != end; ++it)
+        it->value->closeDatabaseIfIdle();
+}
+
 } // namespace WebCore
index 4f40dba..ca415ab 100644 (file)
@@ -54,7 +54,8 @@ namespace WebCore {
         virtual void clearOriginForDeletion(SecurityOrigin*);
         virtual void clearAllOriginsForDeletion();
         virtual void sync();
-        
+        virtual void closeIdleLocalStorageDatabases();
+
     private:
         StorageNamespaceImpl(StorageType, const String& path, unsigned quota);
 
index 9e6ce64..d4d98ef 100644 (file)
@@ -1,3 +1,17 @@
+2012-12-02  Yongjun Zhang  <yongjun_zhang@apple.com>
+
+        Need a method to close all idle localstorage databases immediately.
+        https://bugs.webkit.org/show_bug.cgi?id=103469
+
+        Reviewed by David Kilzer.
+
+        Add a new method to WebStorageManager that we can call to close all
+        idle local storage databases.
+
+        * Storage/WebStorageManager.mm:
+        (+[WebStorageManager closeIdleLocalStorageDatabases]):
+        * Storage/WebStorageManagerPrivate.h:
+
 2012-11-30  Mihai Maerean  <mmaerean@adobe.com>
 
         [CSSRegions] when WebKit uses V8, there should be a single variable to store if the CSS Regions feature is enabled
index eea21fd..776345d 100644 (file)
@@ -28,6 +28,7 @@
 #import "WebStorageManagerInternal.h"
 #import "WebStorageTrackerClient.h"
 
+#import <WebCore/PageGroup.h>
 #import <WebCore/SecurityOrigin.h>
 #import <WebCore/StorageTracker.h>
 #import <pthread.h>
@@ -102,6 +103,11 @@ static pthread_once_t registerLocalStoragePath = PTHREAD_ONCE_INIT;
     StorageTracker::tracker().setStorageDatabaseIdleInterval(interval);
 }
 
++ (void)closeIdleLocalStorageDatabases
+{
+    PageGroup::closeIdleLocalStorageDatabases();
+}
+
 static void initializeLocalStoragePath()
 {
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
index 79fe005..e7ca4e8 100644 (file)
@@ -44,5 +44,6 @@ extern NSString * const WebStorageDidModifyOriginNotification;
 
 + (NSString *)_storageDirectoryPath;
 + (void)setStorageDatabaseIdleInterval:(double)interval;
++ (void)closeIdleLocalStorageDatabases;
 @end
 
index d0525c0..d07a32a 100644 (file)
@@ -1,3 +1,31 @@
+2012-12-02  Yongjun Zhang  <yongjun_zhang@apple.com>
+
+        Need a method to close all idle localstorage databases immediately.
+        https://bugs.webkit.org/show_bug.cgi?id=103469
+
+        Reviewed by David Kilzer.
+
+        Add an JS method to TestRunner, to enable testing closing idle local storage databases in
+        DumpRenderTree layout tests.
+
+        * DumpRenderTree/TestRunner.cpp:
+        (closeIdleLocalStorageDatabasesCallback):
+        (TestRunner::staticFunctions):
+        * DumpRenderTree/TestRunner.h:
+        (TestRunner):
+        * DumpRenderTree/blackberry/TestRunnerBlackBerry.cpp:
+        (TestRunner::closeIdleLocalStorageDatabases):
+        * DumpRenderTree/efl/TestRunnerEfl.cpp:
+        (TestRunner::closeIdleLocalStorageDatabases):
+        * DumpRenderTree/gtk/TestRunnerGtk.cpp:
+        (TestRunner::closeIdleLocalStorageDatabases):
+        * DumpRenderTree/mac/TestRunnerMac.mm:
+        (TestRunner::closeIdleLocalStorageDatabases):
+        * DumpRenderTree/win/TestRunnerWin.cpp:
+        (TestRunner::closeIdleLocalStorageDatabases):
+        * DumpRenderTree/wx/TestRunnerWx.cpp:
+        (TestRunner::closeIdleLocalStorageDatabases):
+
 2012-12-02  Yael Aharon  <yael.aharon@intel.com>
 
         [EFL][WK2] MiniBrowser should have a legacy mode
index fe28a29..046f76b 100644 (file)
@@ -2079,6 +2079,14 @@ static JSValueRef setStorageDatabaseIdleIntervalCallback(JSContextRef context, J
     return JSValueMakeUndefined(context);
 }
 
+static JSValueRef closeIdleLocalStorageDatabasesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    TestRunner* controller = static_cast<TestRunner*>(JSObjectGetPrivate(thisObject));
+    controller->closeIdleLocalStorageDatabases();
+
+    return JSValueMakeUndefined(context);
+}
+
 static JSValueRef grantWebNotificationPermissionCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     if (argumentCount < 1)
@@ -2344,6 +2352,7 @@ JSStaticFunction* TestRunner::staticFunctions()
         { "preciseTime", preciseTimeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setHasCustomFullScreenBehavior", setHasCustomFullScreenBehaviorCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setStorageDatabaseIdleInterval", setStorageDatabaseIdleIntervalCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "closeIdleLocalStorageDatabases", closeIdleLocalStorageDatabasesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "grantWebNotificationPermission", grantWebNotificationPermissionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "denyWebNotificationPermission", denyWebNotificationPermissionCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "removeAllWebNotificationPermissions", removeAllWebNotificationPermissionsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
index fa76c76..a952781 100644 (file)
@@ -362,6 +362,7 @@ public:
     bool hasCustomFullScreenBehavior() const { return m_customFullScreenBehavior; }
 
     void setStorageDatabaseIdleInterval(double);
+    void closeIdleLocalStorageDatabases();
 
     bool hasPendingWebNotificationClick() const { return m_hasPendingWebNotificationClick; }
 
index f06f4a8..ea9b4e7 100644 (file)
@@ -856,3 +856,8 @@ void TestRunner::setStorageDatabaseIdleInterval(double)
     // FIXME: Implement this.
     notImplemented();
 }
+
+void TestRunner::closeIdleLocalStorageDatabases()
+{
+    notImplemented();
+}
index cd78b10..de40034 100644 (file)
@@ -924,3 +924,8 @@ void TestRunner::setStorageDatabaseIdleInterval(double)
 {
     notImplemented();
 }
+
+void TestRunner::closeIdleLocalStorageDatabases()
+{
+    notImplemented();
+}
index 32d3dd5..e887ca1 100644 (file)
@@ -997,3 +997,7 @@ void TestRunner::setStorageDatabaseIdleInterval(double)
 {
     // FIXME: Implement this.
 }
+
+void TestRunner::closeIdleLocalStorageDatabases()
+{
+}
index b520e09..7ab216b 100644 (file)
@@ -213,6 +213,11 @@ void TestRunner::setStorageDatabaseIdleInterval(double interval)
     [WebStorageManager setStorageDatabaseIdleInterval:interval];
 }
 
+void TestRunner::closeIdleLocalStorageDatabases()
+{
+    [WebStorageManager closeIdleLocalStorageDatabases];
+}
+
 JSValueRef TestRunner::originsWithLocalStorage(JSContextRef context)
 {
     return originsArrayToJS(context, [[WebStorageManager sharedWebStorageManager] origins]);
index 3e48ade..1728465 100644 (file)
@@ -1445,3 +1445,8 @@ void TestRunner::setStorageDatabaseIdleInterval(double)
 {
     // FIXME: Implement this.
 }
+
+void TestRunner::closeIdleLocalStorageDatabases()
+{
+    // FIXME: Implement this.
+}
index 35a9137..978b87e 100644 (file)
@@ -617,3 +617,8 @@ void TestRunner::setStorageDatabaseIdleInterval(double)
 {
     // FIXME: Implement this.
 }
+
+void TestRunner::closeIdleLocalStorageDatabases()
+{
+    // FIXME: Implement this.
+}