diff options
| author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
|---|---|---|
| committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-05-20 09:56:07 +0000 |
| commit | 41386e9cb918eed93b3f13648cbef387e371e451 (patch) | |
| tree | a97f9d7bd1d9d091833286085f72da9d83fd0606 /Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp | |
| parent | e15dd966d523731101f70ccf768bba12435a0208 (diff) | |
| download | WebKitGtk-tarball-41386e9cb918eed93b3f13648cbef387e371e451.tar.gz | |
webkitgtk-2.4.9webkitgtk-2.4.9
Diffstat (limited to 'Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp')
| -rw-r--r-- | Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp | 126 |
1 files changed, 38 insertions, 88 deletions
diff --git a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp index ad81e146d..d0f771e7c 100644 --- a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp +++ b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp @@ -26,41 +26,40 @@ #include "config.h" #include "LocalStorageDatabaseTracker.h" +#include "WorkQueue.h" #include <WebCore/FileSystem.h> #include <WebCore/SQLiteStatement.h> #include <WebCore/SecurityOrigin.h> -#include <WebCore/TextEncoding.h> -#include <wtf/WorkQueue.h> #include <wtf/text/CString.h> using namespace WebCore; namespace WebKit { -PassRefPtr<LocalStorageDatabaseTracker> LocalStorageDatabaseTracker::create(PassRefPtr<WorkQueue> queue, const String& localStorageDirectory) +PassRefPtr<LocalStorageDatabaseTracker> LocalStorageDatabaseTracker::create(PassRefPtr<WorkQueue> queue) { - return adoptRef(new LocalStorageDatabaseTracker(queue, localStorageDirectory)); + return adoptRef(new LocalStorageDatabaseTracker(queue)); } -LocalStorageDatabaseTracker::LocalStorageDatabaseTracker(PassRefPtr<WorkQueue> queue, const String& localStorageDirectory) +LocalStorageDatabaseTracker::LocalStorageDatabaseTracker(PassRefPtr<WorkQueue> queue) : m_queue(queue) - , m_localStorageDirectory(localStorageDirectory.isolatedCopy()) { - ASSERT(!m_localStorageDirectory.isEmpty()); - - // Make sure the encoding is initialized before we start dispatching things to the queue. - UTF8Encoding(); - - RefPtr<LocalStorageDatabaseTracker> localStorageDatabaseTracker(this); - m_queue->dispatch([localStorageDatabaseTracker] { - localStorageDatabaseTracker->importOriginIdentifiers(); - }); } LocalStorageDatabaseTracker::~LocalStorageDatabaseTracker() { } +void LocalStorageDatabaseTracker::setLocalStorageDirectory(const String& localStorageDirectory) +{ + // FIXME: We should come up with a better idiom for safely copying strings across threads. + RefPtr<StringImpl> copiedLocalStorageDirectory; + if (localStorageDirectory.impl()) + copiedLocalStorageDirectory = localStorageDirectory.impl()->isolatedCopy(); + + m_queue->dispatch(bind(&LocalStorageDatabaseTracker::setLocalStorageDirectoryInternal, this, copiedLocalStorageDirectory.release())); +} + String LocalStorageDatabaseTracker::databasePath(SecurityOrigin* securityOrigin) const { return databasePath(securityOrigin->databaseIdentifier() + ".localstorage"); @@ -85,19 +84,19 @@ void LocalStorageDatabaseTracker::deleteAllDatabases() return; SQLiteStatement statement(m_database, "SELECT origin, path FROM Origins"); - if (statement.prepare() != SQLITE_OK) { + if (statement.prepare() != SQLResultOk) { LOG_ERROR("Failed to prepare statement."); return; } int result; - while ((result = statement.step()) == SQLITE_ROW) { + while ((result = statement.step()) == SQLResultRow) { deleteFile(statement.getColumnText(1)); // FIXME: Call out to the client. } - if (result != SQLITE_DONE) + if (result != SQLResultDone) LOG_ERROR("Failed to read in all origins from the database."); if (m_database.isOpen()) @@ -111,7 +110,7 @@ void LocalStorageDatabaseTracker::deleteAllDatabases() return; SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins"); - if (deleteStatement.prepare() != SQLITE_OK) { + if (deleteStatement.prepare() != SQLResultOk) { LOG_ERROR("Unable to prepare deletion of all origins"); return; } @@ -124,81 +123,32 @@ void LocalStorageDatabaseTracker::deleteAllDatabases() deleteEmptyDirectory(m_localStorageDirectory); } -static Optional<time_t> fileCreationTime(const String& filePath) -{ - time_t time; - return getFileCreationTime(filePath, time) ? time : Optional<time_t>(Nullopt); -} - -static Optional<time_t> fileModificationTime(const String& filePath) -{ - time_t time; - if (!getFileModificationTime(filePath, time)) - return Nullopt; - - return time; -} - -Vector<Ref<SecurityOrigin>> LocalStorageDatabaseTracker::deleteDatabasesModifiedSince(std::chrono::system_clock::time_point time) -{ - Vector<String> originIdentifiersToDelete; - - for (const String& origin : m_origins) { - String filePath = pathForDatabaseWithOriginIdentifier(origin); - - auto modificationTime = fileModificationTime(filePath); - if (!modificationTime) - continue; - - if (modificationTime.value() >= std::chrono::system_clock::to_time_t(time)) - originIdentifiersToDelete.append(origin); - } - - Vector<Ref<SecurityOrigin>> deletedDatabaseOrigins; - deletedDatabaseOrigins.reserveInitialCapacity(originIdentifiersToDelete.size()); - - for (const auto& originIdentifier : originIdentifiersToDelete) { - removeDatabaseWithOriginIdentifier(originIdentifier); - - deletedDatabaseOrigins.uncheckedAppend(SecurityOrigin::createFromDatabaseIdentifier(originIdentifier)); - } - - return deletedDatabaseOrigins; -} - -Vector<Ref<WebCore::SecurityOrigin>> LocalStorageDatabaseTracker::origins() const +Vector<RefPtr<WebCore::SecurityOrigin>> LocalStorageDatabaseTracker::origins() const { - Vector<Ref<SecurityOrigin>> origins; + Vector<RefPtr<SecurityOrigin>> origins; origins.reserveInitialCapacity(m_origins.size()); - for (const String& origin : m_origins) - origins.uncheckedAppend(SecurityOrigin::createFromDatabaseIdentifier(origin)); + for (HashSet<String>::const_iterator it = m_origins.begin(), end = m_origins.end(); it != end; ++it) + origins.uncheckedAppend(SecurityOrigin::createFromDatabaseIdentifier(*it)); return origins; } -Vector<LocalStorageDatabaseTracker::OriginDetails> LocalStorageDatabaseTracker::originDetails() +void LocalStorageDatabaseTracker::setLocalStorageDirectoryInternal(StringImpl* localStorageDirectory) { - Vector<OriginDetails> result; - result.reserveInitialCapacity(m_origins.size()); - - for (const String& origin : m_origins) { - String filePath = pathForDatabaseWithOriginIdentifier(origin); + if (m_database.isOpen()) + m_database.close(); - OriginDetails details; - details.originIdentifier = origin.isolatedCopy(); - details.creationTime = fileCreationTime(filePath); - details.modificationTime = fileModificationTime(filePath); - result.uncheckedAppend(details); - } + m_localStorageDirectory = localStorageDirectory; + m_origins.clear(); - return result; + m_queue->dispatch(bind(&LocalStorageDatabaseTracker::importOriginIdentifiers, this)); } String LocalStorageDatabaseTracker::databasePath(const String& filename) const { if (!makeAllDirectories(m_localStorageDirectory)) { - LOG_ERROR("Unable to create LocalStorage database path %s", m_localStorageDirectory.utf8().data()); + LOG_ERROR("Unabled to create LocalStorage database path %s", m_localStorageDirectory.utf8().data()); return String(); } @@ -242,17 +192,17 @@ void LocalStorageDatabaseTracker::importOriginIdentifiers() if (m_database.isOpen()) { SQLiteStatement statement(m_database, "SELECT origin FROM Origins"); - if (statement.prepare() != SQLITE_OK) { + if (statement.prepare() != SQLResultOk) { LOG_ERROR("Failed to prepare statement."); return; } int result; - while ((result = statement.step()) == SQLITE_ROW) + while ((result = statement.step()) == SQLResultRow) m_origins.add(statement.getColumnText(0)); - if (result != SQLITE_DONE) { + if (result != SQLResultDone) { LOG_ERROR("Failed to read in all origins from the database."); return; } @@ -300,7 +250,7 @@ void LocalStorageDatabaseTracker::addDatabaseWithOriginIdentifier(const String& return; SQLiteStatement statement(m_database, "INSERT INTO Origins VALUES (?, ?)"); - if (statement.prepare() != SQLITE_OK) { + if (statement.prepare() != SQLResultOk) { LOG_ERROR("Unable to establish origin '%s' in the tracker", originIdentifier.utf8().data()); return; } @@ -308,7 +258,7 @@ void LocalStorageDatabaseTracker::addDatabaseWithOriginIdentifier(const String& statement.bindText(1, originIdentifier); statement.bindText(2, databasePath); - if (statement.step() != SQLITE_DONE) + if (statement.step() != SQLResultDone) LOG_ERROR("Unable to establish origin '%s' in the tracker", originIdentifier.utf8().data()); m_origins.add(originIdentifier); @@ -327,7 +277,7 @@ void LocalStorageDatabaseTracker::removeDatabaseWithOriginIdentifier(const Strin return; SQLiteStatement deleteStatement(m_database, "DELETE FROM Origins where origin=?"); - if (deleteStatement.prepare() != SQLITE_OK) { + if (deleteStatement.prepare() != SQLResultOk) { LOG_ERROR("Unable to prepare deletion of origin '%s'", originIdentifier.ascii().data()); return; } @@ -341,7 +291,7 @@ void LocalStorageDatabaseTracker::removeDatabaseWithOriginIdentifier(const Strin m_origins.remove(originIdentifier); if (m_origins.isEmpty()) { - // There are no origins left; delete the tracker database. + // There are no origins left, go ahead and delete the tracker database. m_database.close(); deleteFile(trackerDatabasePath()); deleteEmptyDirectory(m_localStorageDirectory); @@ -356,7 +306,7 @@ String LocalStorageDatabaseTracker::pathForDatabaseWithOriginIdentifier(const St return String(); SQLiteStatement pathStatement(m_database, "SELECT path FROM Origins WHERE origin=?"); - if (pathStatement.prepare() != SQLITE_OK) { + if (pathStatement.prepare() != SQLResultOk) { LOG_ERROR("Unable to prepare selection of path for origin '%s'", originIdentifier.utf8().data()); return String(); } @@ -364,7 +314,7 @@ String LocalStorageDatabaseTracker::pathForDatabaseWithOriginIdentifier(const St pathStatement.bindText(1, originIdentifier); int result = pathStatement.step(); - if (result != SQLITE_ROW) + if (result != SQLResultRow) return String(); return pathStatement.getColumnText(0); |
