Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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):

Canonical link: https://commits.webkit.org/134110@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@149647 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Anders Carlsson committed May 6, 2013
1 parent a4623f0 commit 775063e
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 6 deletions.
11 changes: 11 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,14 @@
2013-05-06 Anders Carlsson <andersca@apple.com>

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 <rego@igalia.com>

[GTK] Add webkit_uri_scheme_request_finish_error
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/WebCore.exp.in
Expand Up @@ -280,6 +280,7 @@ __ZN7WebCore13StyledElement22setInlineStylePropertyENS_13CSSPropertyIDEdNS_17CSS
__ZN7WebCore13cookiesForDOMERKNS_21NetworkStorageSessionERKNS_4KURLES5_
__ZN7WebCore13createWrapperEPN3JSC9ExecStateEPNS_17JSDOMGlobalObjectEPNS_4NodeE
__ZN7WebCore13directoryNameERKN3WTF6StringE
__ZN7WebCore13listDirectoryERKN3WTF6StringES3_
__ZN7WebCore13pointerCursorEv
__ZN7WebCore13toArrayBufferEN3JSC7JSValueE
__ZN7WebCore13toHTMLElementEPNS_21FormAssociatedElementE
Expand Down
29 changes: 29 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -1,3 +1,32 @@
2013-05-06 Anders Carlsson <andersca@apple.com>

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 <ap@apple.com>

<rdar://problem/13479806> [Mac] Pass information about open pages to LaunchServices
Expand Down
101 changes: 97 additions & 4 deletions Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp
@@ -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
Expand Down Expand Up @@ -28,6 +28,7 @@

#include "WorkQueue.h"
#include <WebCore/FileSystem.h>
#include <WebCore/SQLiteStatement.h>
#include <WebCore/SecurityOrigin.h>
#include <wtf/text/CString.h>

Expand Down Expand Up @@ -55,18 +56,110 @@ void LocalStorageDatabaseTracker::setLocalStorageDirectory(const String& localSt
}

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
21 changes: 19 additions & 2 deletions Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.h
@@ -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
Expand All @@ -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 {
Expand All @@ -52,9 +55,23 @@ class LocalStorageDatabaseTracker : public ThreadSafeRefCounted<LocalStorageData

void setLocalStorageDirectoryInternal(const String&);

RefPtr<WorkQueue> m_queue;
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;

WebCore::SQLiteDatabase m_database;
HashSet<String> m_origins;
};

} // namespace WebKit
Expand Down

0 comments on commit 775063e

Please sign in to comment.