If deleting the StorageTracker.db file fails, local storage is left in a strange...
authorjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Apr 2011 23:34:25 +0000 (23:34 +0000)
committerjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Apr 2011 23:34:25 +0000 (23:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=58805

Reviewed by Steve Falkenburg.

* storage/StorageTracker.cpp:
(WebCore::StorageTracker::syncFileSystemAndTrackerDatabase):
When cleaning up the StorageTracker.db file, is not enough to call syncDeleteOrigin.
deleteOrigin itself must be called to update the data structures that syncDeleteOrigin
depends on and to prevent clashes between a theoretical web page editing local storage
at the same time this method is called.
(WebCore::StorageTracker::syncDeleteAllOrigins):
If it is not possible to delete the StorageTracker.db file, empty it.
(WebCore::StorageTracker::deleteOriginOnMainThread):
Wrapper for deleteOrigin.
* storage/StorageTracker.h:

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

Source/WebCore/ChangeLog
Source/WebCore/storage/StorageTracker.cpp
Source/WebCore/storage/StorageTracker.h

index 2c27dd7..23ac47a 100644 (file)
@@ -1,3 +1,22 @@
+2011-04-18  Jessie Berlin  <jberlin@apple.com>
+
+        Reviewed by Steve Falkenburg.
+
+        If deleting the StorageTracker.db file fails, local storage is left in a strange state.
+        https://bugs.webkit.org/show_bug.cgi?id=58805
+
+        * storage/StorageTracker.cpp:
+        (WebCore::StorageTracker::syncFileSystemAndTrackerDatabase):
+        When cleaning up the StorageTracker.db file, is not enough to call syncDeleteOrigin.
+        deleteOrigin itself must be called to update the data structures that syncDeleteOrigin
+        depends on and to prevent clashes between a theoretical web page editing local storage
+        at the same time this method is called.
+        (WebCore::StorageTracker::syncDeleteAllOrigins):
+        If it is not possible to delete the StorageTracker.db file, empty it.
+        (WebCore::StorageTracker::deleteOriginOnMainThread):
+        Wrapper for deleteOrigin.
+        * storage/StorageTracker.h:
+
 2011-04-18  Geoffrey Garen  <ggaren@apple.com>
 
         Build fix.
index e18b4b8..b9ce65f 100644 (file)
@@ -232,8 +232,10 @@ void StorageTracker::syncFileSystemAndTrackerDatabase()
     // Delete stale StorageTracker records.
     OriginSet::const_iterator setEnd = originSetCopy.end();
     for (OriginSet::const_iterator it = originSetCopy.begin(); it != setEnd; ++it) {
-        if (!foundOrigins.contains(*it))
-            syncDeleteOrigin(*it);
+        if (!foundOrigins.contains(*it)) {
+            RefPtr<StringImpl> originIdentifier = (*it).threadsafeCopy().impl();
+            callOnMainThread(deleteOriginOnMainThread, originIdentifier.release().leakRef());
+        }
     }
 }
 
@@ -376,10 +378,33 @@ void StorageTracker::syncDeleteAllOrigins()
     if (m_database.isOpen())
         m_database.close();
     
-    SQLiteFileSystem::deleteDatabaseFile(trackerDatabasePath());
+    if (!SQLiteFileSystem::deleteDatabaseFile(trackerDatabasePath())) {
+        // In the case where it is not possible to delete the database file (e.g some other program
+        // like a virus scanner is accessing it), make sure to remove all entries.
+        openTrackerDatabase(false);
+        if (!m_database.isOpen())
+            return;
+        SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins");
+        if (deleteStatement.prepare() != SQLResultOk) {
+            LOG_ERROR("Unable to prepare deletion of all origins");
+            return;
+        }
+        if (!deleteStatement.executeCommand()) {
+            LOG_ERROR("Unable to execute deletion of all origins");
+            return;
+        }
+    }
     SQLiteFileSystem::deleteEmptyDatabaseDirectory(m_storageDirectoryPath);
 }
 
+void StorageTracker::deleteOriginOnMainThread(void* originIdentifier)
+{
+    ASSERT(isMainThread());
+
+    String identifier = adoptRef(reinterpret_cast<StringImpl*>(originIdentifier));
+    tracker().deleteOrigin(identifier);
+}
+
 void StorageTracker::deleteOrigin(const String& originIdentifier)
 {
     deleteOrigin(SecurityOrigin::createFromDatabaseIdentifier(originIdentifier).get());
index 04a821b..714576d 100644 (file)
@@ -86,6 +86,7 @@ private:
     bool canDeleteOrigin(const String& originIdentifier);
     void willDeleteOrigin(const String& originIdentifier);
     void willDeleteAllOrigins();
+    static void deleteOriginOnMainThread(void* originIdentifier);
 
     void originFilePaths(Vector<String>& paths);