Title: [149647] trunk/Source
Revision
149647
Author
[email protected]
Date
2013-05-06 16:06:18 -0700 (Mon, 06 May 2013)

Log Message

More work on LocalStorageDatabaseTracker
https://bugs.webkit.org/show_bug.cgi?id=115680

Reviewed by Andreas Kling.

Source/WebCore:

Export symbols needed by WebKit2.

* WebCore.exp.in:

Source/WebKit2:

* UIProcess/Storage/LocalStorageDatabaseTracker.cpp:
(WebKit::LocalStorageDatabaseTracker::databaseFilename):
Call the new databaseFilename that takes a string.

(WebKit::LocalStorageDatabaseTracker::setLocalStorageDirectoryInternal):
Assert that we don't call this more than once. Dispatch a call to import origin identifiers.

(WebKit::LocalStorageDatabaseTracker::trackerDatabasePath):
New helper function that returns the tracker database path.

(WebKit::LocalStorageDatabaseTracker::openTrackerDatabase):
Open the database and create the Origins table if needed.

(WebKit::LocalStorageDatabaseTracker::importOriginIdentifiers):
Open the database and import the origin identifiers from it, then synchronize it with whatever files are on disk.

(WebKit::LocalStorageDatabaseTracker::updateTrackerDatabaseFromLocalStorageDatabaseFiles):
Bring the tracker database up to date from the database files on disk.

* UIProcess/Storage/LocalStorageDatabaseTracker.h:
(LocalStorageDatabaseTracker):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149646 => 149647)


--- trunk/Source/WebCore/ChangeLog	2013-05-06 22:49:17 UTC (rev 149646)
+++ trunk/Source/WebCore/ChangeLog	2013-05-06 23:06:18 UTC (rev 149647)
@@ -1,3 +1,14 @@
+2013-05-06  Anders Carlsson  <[email protected]>
+
+        More work on LocalStorageDatabaseTracker
+        https://bugs.webkit.org/show_bug.cgi?id=115680
+
+        Reviewed by Andreas Kling.
+
+        Export symbols needed by WebKit2.
+
+        * WebCore.exp.in:
+
 2013-05-06  Manuel Rego Casasnovas  <[email protected]>
 
         [GTK] Add webkit_uri_scheme_request_finish_error

Modified: trunk/Source/WebCore/WebCore.exp.in (149646 => 149647)


--- trunk/Source/WebCore/WebCore.exp.in	2013-05-06 22:49:17 UTC (rev 149646)
+++ trunk/Source/WebCore/WebCore.exp.in	2013-05-06 23:06:18 UTC (rev 149647)
@@ -280,6 +280,7 @@
 __ZN7WebCore13cookiesForDOMERKNS_21NetworkStorageSessionERKNS_4KURLES5_
 __ZN7WebCore13createWrapperEPN3JSC9ExecStateEPNS_17JSDOMGlobalObjectEPNS_4NodeE
 __ZN7WebCore13directoryNameERKN3WTF6StringE
+__ZN7WebCore13listDirectoryERKN3WTF6StringES3_
 __ZN7WebCore13pointerCursorEv
 __ZN7WebCore13toArrayBufferEN3JSC7JSValueE
 __ZN7WebCore13toHTMLElementEPNS_21FormAssociatedElementE

Modified: trunk/Source/WebKit2/ChangeLog (149646 => 149647)


--- trunk/Source/WebKit2/ChangeLog	2013-05-06 22:49:17 UTC (rev 149646)
+++ trunk/Source/WebKit2/ChangeLog	2013-05-06 23:06:18 UTC (rev 149647)
@@ -1,3 +1,32 @@
+2013-05-06  Anders Carlsson  <[email protected]>
+
+        More work on LocalStorageDatabaseTracker
+        https://bugs.webkit.org/show_bug.cgi?id=115680
+
+        Reviewed by Andreas Kling.
+
+        * UIProcess/Storage/LocalStorageDatabaseTracker.cpp:
+        (WebKit::LocalStorageDatabaseTracker::databaseFilename):
+        Call the new databaseFilename that takes a string.
+
+        (WebKit::LocalStorageDatabaseTracker::setLocalStorageDirectoryInternal):
+        Assert that we don't call this more than once. Dispatch a call to import origin identifiers.
+
+        (WebKit::LocalStorageDatabaseTracker::trackerDatabasePath):
+        New helper function that returns the tracker database path.
+
+        (WebKit::LocalStorageDatabaseTracker::openTrackerDatabase):
+        Open the database and create the Origins table if needed.
+
+        (WebKit::LocalStorageDatabaseTracker::importOriginIdentifiers):
+        Open the database and import the origin identifiers from it, then synchronize it with whatever files are on disk.
+
+        (WebKit::LocalStorageDatabaseTracker::updateTrackerDatabaseFromLocalStorageDatabaseFiles):
+        Bring the tracker database up to date from the database files on disk.
+
+        * UIProcess/Storage/LocalStorageDatabaseTracker.h:
+        (LocalStorageDatabaseTracker):
+
 2013-05-06  Alexey Proskuryakov  <[email protected]>
 
         <rdar://problem/13479806> [Mac] Pass information about open pages to LaunchServices

Modified: trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp (149646 => 149647)


--- trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp	2013-05-06 22:49:17 UTC (rev 149646)
+++ trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp	2013-05-06 23:06:18 UTC (rev 149647)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,6 +28,7 @@
 
 #include "WorkQueue.h"
 #include <WebCore/FileSystem.h>
+#include <WebCore/SQLiteStatement.h>
 #include <WebCore/SecurityOrigin.h>
 #include <wtf/text/CString.h>
 
@@ -56,17 +57,109 @@
 
 String LocalStorageDatabaseTracker::databaseFilename(SecurityOrigin* securityOrigin) const
 {
+    return databaseFilename(securityOrigin->databaseIdentifier());
+}
+
+void LocalStorageDatabaseTracker::setLocalStorageDirectoryInternal(const String& localStorageDirectory)
+{
+    ASSERT(!m_localStorageDirectory);
+    m_localStorageDirectory = localStorageDirectory;
+
+    m_queue->dispatch(bind(&LocalStorageDatabaseTracker::importOriginIdentifiers, this));
+}
+
+String LocalStorageDatabaseTracker::databaseFilename(const String& filename) const
+{
     if (!makeAllDirectories(m_localStorageDirectory)) {
         LOG_ERROR("Unabled to create LocalStorage database path %s", m_localStorageDirectory.utf8().data());
         return String();
     }
 
-    return pathByAppendingComponent(m_localStorageDirectory, securityOrigin->databaseIdentifier() + ".localstorage");
+    return pathByAppendingComponent(m_localStorageDirectory, filename);
 }
 
-void LocalStorageDatabaseTracker::setLocalStorageDirectoryInternal(const String& localStorageDirectory)
+String LocalStorageDatabaseTracker::trackerDatabasePath() const
 {
-    m_localStorageDirectory = localStorageDirectory;
+    return databaseFilename("StorageTracker.db");
 }
 
+void LocalStorageDatabaseTracker::openTrackerDatabase(DatabaseOpeningStrategy openingStrategy)
+{
+    String databasePath = trackerDatabasePath();
+
+    if (!fileExists(databasePath) && openingStrategy == SkipIfNonExistent)
+        return;
+
+    if (!m_database.open(databasePath)) {
+        LOG_ERROR("Failed to open databasePath %s.", databasePath.ascii().data());
+        return;
+    }
+
+    // Since a WorkQueue isn't bound to a specific thread, we have to disable threading checks
+    // even though we never access the database from different threads simultaneously.
+    m_database.disableThreadingChecks();
+
+    if (m_database.tableExists("Origins"))
+        return;
+
+    if (!m_database.executeCommand("CREATE TABLE Origins (origin TEXT UNIQUE ON CONFLICT REPLACE, path TEXT);"))
+        LOG_ERROR("Failed to create Origins table.");
+}
+
+void LocalStorageDatabaseTracker::importOriginIdentifiers()
+{
+    openTrackerDatabase(SkipIfNonExistent);
+
+    if (m_database.isOpen()) {
+        SQLiteStatement statement(m_database, "SELECT origin FROM Origins");
+        if (statement.prepare() != SQLResultOk) {
+            LOG_ERROR("Failed to prepare statement.");
+            return;
+        }
+
+        int result;
+
+        while ((result = statement.step()) == SQLResultRow)
+            m_origins.add(statement.getColumnText(0));
+
+        if (result != SQLResultDone) {
+            LOG_ERROR("Failed to read in all origins from the database.");
+            return;
+        }
+    }
+
+    updateTrackerDatabaseFromLocalStorageDatabaseFiles();
+}
+
+void LocalStorageDatabaseTracker::updateTrackerDatabaseFromLocalStorageDatabaseFiles()
+{
+    Vector<String> paths = listDirectory(m_localStorageDirectory, "*.localstorage");
+
+    HashSet<String> origins(m_origins);
+    HashSet<String> originsFromLocalStorageDatabaseFiles;
+
+    for (size_t i = 0; i < paths.size(); ++i) {
+        const String& path = paths[i];
+
+        if (!path.endsWith(".localstorage"))
+            continue;
+
+        String filename = pathGetFileName(path);
+
+        String originIdentifier = filename.substring(0, filename.length() - strlen(".localstorage"));
+
+        // FIXME: Insert the origin and database pair.
+        originsFromLocalStorageDatabaseFiles.add(originIdentifier);
+    }
+
+    for (auto it = origins.begin(), end = origins.end(); it != end; ++it) {
+        const String& originIdentifier = *it;
+        if (origins.contains(originIdentifier))
+            continue;
+
+        // This origin doesn't have a database file, delete it from the database.
+        // FIXME: Do this.
+    }
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.h (149646 => 149647)


--- trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.h	2013-05-06 22:49:17 UTC (rev 149646)
+++ trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.h	2013-05-06 23:06:18 UTC (rev 149647)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,9 +26,12 @@
 #ifndef LocalStorageDatabaseTracker_h
 #define LocalStorageDatabaseTracker_h
 
+#include <WebCore/SQLiteDatabase.h>
+#include <wtf/HashSet.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 #include <wtf/ThreadSafeRefCounted.h>
+#include <wtf/text/StringHash.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -52,9 +55,23 @@
 
     void setLocalStorageDirectoryInternal(const String&);
 
+    String databaseFilename(const String&) const;
+    String trackerDatabasePath() const;
+
+    enum DatabaseOpeningStrategy {
+        CreateIfNonExistent,
+        SkipIfNonExistent
+    };
+    void openTrackerDatabase(DatabaseOpeningStrategy);
+
+    void importOriginIdentifiers();
+    void updateTrackerDatabaseFromLocalStorageDatabaseFiles();
+
     RefPtr<WorkQueue> m_queue;
+    String m_localStorageDirectory;
 
-    String m_localStorageDirectory;
+    WebCore::SQLiteDatabase m_database;
+    HashSet<String> m_origins;
 };
 
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to