From 6882a04fb36642862b11efe514251d32070c3d65 Mon Sep 17 00:00:00 2001 From: Konstantin Tokarev Date: Thu, 25 Aug 2016 19:20:41 +0300 Subject: Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443) Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f Reviewed-by: Konstantin Tokarev --- .../UIProcess/Storage/LocalStorageDatabase.cpp | 59 ++++++++++++---------- 1 file changed, 33 insertions(+), 26 deletions(-) (limited to 'Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp') diff --git a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp index 4dbb9eab1..1367438af 100644 --- a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp +++ b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp @@ -27,34 +27,35 @@ #include "LocalStorageDatabase.h" #include "LocalStorageDatabaseTracker.h" -#include "WorkQueue.h" #include #include #include #include #include +#include #include +#include #include #include using namespace WebCore; -static const double databaseUpdateIntervalInSeconds = 1.0; +static const auto databaseUpdateInterval = std::chrono::seconds(1); static const int maximumItemsToUpdate = 100; namespace WebKit { -PassRefPtr LocalStorageDatabase::create(PassRefPtr queue, PassRefPtr tracker, PassRefPtr securityOrigin) +PassRefPtr LocalStorageDatabase::create(PassRefPtr queue, PassRefPtr tracker, Ref&& securityOrigin) { - return adoptRef(new LocalStorageDatabase(queue, tracker, securityOrigin)); + return adoptRef(new LocalStorageDatabase(queue, tracker, WTFMove(securityOrigin))); } -LocalStorageDatabase::LocalStorageDatabase(PassRefPtr queue, PassRefPtr tracker, PassRefPtr securityOrigin) +LocalStorageDatabase::LocalStorageDatabase(PassRefPtr queue, PassRefPtr tracker, Ref&& securityOrigin) : m_queue(queue) , m_tracker(tracker) - , m_securityOrigin(securityOrigin) - , m_databasePath(m_tracker->databasePath(m_securityOrigin.get())) + , m_securityOrigin(WTFMove(securityOrigin)) + , m_databasePath(m_tracker->databasePath(m_securityOrigin.ptr())) , m_failedToOpenDatabase(false) , m_didImportItems(false) , m_isClosed(false) @@ -79,7 +80,7 @@ void LocalStorageDatabase::openDatabase(DatabaseOpeningStrategy openingStrategy) } if (m_database.isOpen()) - m_tracker->didOpenDatabaseWithOrigin(m_securityOrigin.get()); + m_tracker->didOpenDatabaseWithOrigin(m_securityOrigin.ptr()); } bool LocalStorageDatabase::tryToOpenDatabase(DatabaseOpeningStrategy openingStrategy) @@ -171,7 +172,7 @@ void LocalStorageDatabase::importItems(StorageMap& storageMap) return; SQLiteStatement query(m_database, "SELECT key, value FROM ItemTable"); - if (query.prepare() != SQLResultOk) { + if (query.prepare() != SQLITE_OK) { LOG_ERROR("Unable to select items from ItemTable for local storage"); return; } @@ -179,12 +180,12 @@ void LocalStorageDatabase::importItems(StorageMap& storageMap) HashMap items; int result = query.step(); - while (result == SQLResultRow) { + while (result == SQLITE_ROW) { items.set(query.getColumnText(0), query.getColumnBlobAsString(1)); result = query.step(); } - if (result != SQLResultDone) { + if (result != SQLITE_DONE) { LOG_ERROR("Error reading items from ItemTable for local storage"); return; } @@ -226,7 +227,7 @@ void LocalStorageDatabase::close() m_database.close(); if (isEmpty) - m_tracker->deleteDatabaseWithOrigin(m_securityOrigin.get()); + m_tracker->deleteDatabaseWithOrigin(m_securityOrigin.ptr()); } void LocalStorageDatabase::itemDidChange(const String& key, const String& value) @@ -240,8 +241,15 @@ void LocalStorageDatabase::scheduleDatabaseUpdate() if (m_didScheduleDatabaseUpdate) return; + if (!m_disableSuddenTerminationWhileWritingToLocalStorage) + m_disableSuddenTerminationWhileWritingToLocalStorage = std::make_unique(); + m_didScheduleDatabaseUpdate = true; - m_queue->dispatchAfterDelay(bind(&LocalStorageDatabase::updateDatabase, this), databaseUpdateIntervalInSeconds); + + RefPtr localStorageDatabase(this); + m_queue->dispatchAfter(databaseUpdateInterval, [localStorageDatabase] { + localStorageDatabase->updateDatabase(); + }); } void LocalStorageDatabase::updateDatabase() @@ -256,9 +264,11 @@ void LocalStorageDatabase::updateDatabase() if (m_changedItems.size() <= maximumItemsToUpdate) { // There are few enough changed items that we can just always write all of them. m_changedItems.swap(changedItems); + updateDatabaseWithChangedItems(changedItems); + m_disableSuddenTerminationWhileWritingToLocalStorage = nullptr; } else { for (int i = 0; i < maximumItemsToUpdate; ++i) { - HashMap::iterator it = m_changedItems.begin(); + auto it = m_changedItems.begin(); changedItems.add(it->key, it->value); m_changedItems.remove(it); @@ -268,9 +278,8 @@ void LocalStorageDatabase::updateDatabase() // Reschedule the update for the remaining items. scheduleDatabaseUpdate(); + updateDatabaseWithChangedItems(changedItems); } - - updateDatabaseWithChangedItems(changedItems); } void LocalStorageDatabase::updateDatabaseWithChangedItems(const HashMap& changedItems) @@ -284,26 +293,26 @@ void LocalStorageDatabase::updateDatabaseWithChangedItems(const HashMap::const_iterator it = changedItems.begin(); - const HashMap::const_iterator end = changedItems.end(); - for (; it != end; ++it) { + for (auto it = changedItems.begin(), end = changedItems.end(); it != end; ++it) { // A null value means that the key/value pair should be deleted. SQLiteStatement& statement = it->value.isNull() ? deleteStatement : insertStatement; @@ -324,7 +331,7 @@ void LocalStorageDatabase::updateDatabaseWithChangedItems(const HashMapvalue); int result = statement.step(); - if (result != SQLResultDone) { + if (result != SQLITE_DONE) { LOG_ERROR("Failed to update item in the local storage database - %i", result); break; } @@ -341,13 +348,13 @@ bool LocalStorageDatabase::databaseIsEmpty() return false; SQLiteStatement query(m_database, "SELECT COUNT(*) FROM ItemTable"); - if (query.prepare() != SQLResultOk) { + if (query.prepare() != SQLITE_OK) { LOG_ERROR("Unable to count number of rows in ItemTable for local storage"); return false; } int result = query.step(); - if (result != SQLResultRow) { + if (result != SQLITE_ROW) { LOG_ERROR("No results when counting number of rows in ItemTable for local storage"); return false; } -- cgit v1.2.1 From 9daf1655d7e4eaaa6ed5f44055a4b4fd399fd25c Mon Sep 17 00:00:00 2001 From: Konstantin Tokarev Date: Wed, 28 Sep 2016 16:39:37 +0300 Subject: Imported WebKit commit eb954cdcf58f9b915b2fcb6f8e4cb3a60650a4f3 Change-Id: I8dda875c38075d43b76fe3a21acb0ffa102bb82d Reviewed-by: Konstantin Tokarev --- Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp') diff --git a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp index 1367438af..3468b5df6 100644 --- a/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp +++ b/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp @@ -181,7 +181,10 @@ void LocalStorageDatabase::importItems(StorageMap& storageMap) int result = query.step(); while (result == SQLITE_ROW) { - items.set(query.getColumnText(0), query.getColumnBlobAsString(1)); + String key = query.getColumnText(0); + String value = query.getColumnBlobAsString(1); + if (!key.isNull() && !value.isNull()) + items.set(key, value); result = query.step(); } -- cgit v1.2.1