Title: [278651] trunk/Source
Revision
278651
Author
[email protected]
Date
2021-06-09 00:02:40 -0700 (Wed, 09 Jun 2021)

Log Message

Rely on SQLiteDatabase::setMaximumSize() for quota management in LocalStorageDatabase
https://bugs.webkit.org/show_bug.cgi?id=226788

Reviewed by Sihui Liu.

Source/WebCore:

Export SQLiteDatabase::setMaximumSize() so it can be used from WebKit2.

* platform/sql/SQLiteDatabase.h:

Source/WebKit:

Rely on SQLiteDatabase::setMaximumSize() for quota management in LocalStorageDatabase.
It simplifies the code a bit.

No new test, covered by storage/domstorage/quota.html that is still passing.

* NetworkProcess/WebStorage/LocalStorageDatabase.cpp:
(WebKit::LocalStorageDatabase::openDatabase):
(WebKit::LocalStorageDatabase::removeItem):
(WebKit::LocalStorageDatabase::setItem):
(WebKit::LocalStorageDatabase::clear):
* NetworkProcess/WebStorage/LocalStorageDatabase.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (278650 => 278651)


--- trunk/Source/WebCore/ChangeLog	2021-06-09 05:48:08 UTC (rev 278650)
+++ trunk/Source/WebCore/ChangeLog	2021-06-09 07:02:40 UTC (rev 278651)
@@ -1,3 +1,14 @@
+2021-06-09  Chris Dumez  <[email protected]>
+
+        Rely on SQLiteDatabase::setMaximumSize() for quota management in LocalStorageDatabase
+        https://bugs.webkit.org/show_bug.cgi?id=226788
+
+        Reviewed by Sihui Liu.
+
+        Export SQLiteDatabase::setMaximumSize() so it can be used from WebKit2.
+
+        * platform/sql/SQLiteDatabase.h:
+
 2021-06-08  Alex Christensen  <[email protected]>
 
         Move PrivacyStance code from WebKitAdditions

Modified: trunk/Source/WebCore/platform/sql/SQLiteDatabase.h (278650 => 278651)


--- trunk/Source/WebCore/platform/sql/SQLiteDatabase.h	2021-06-09 05:48:08 UTC (rev 278650)
+++ trunk/Source/WebCore/platform/sql/SQLiteDatabase.h	2021-06-09 07:02:40 UTC (rev 278651)
@@ -103,7 +103,7 @@
     // These chunks will never be anything other than 512, 1024, 2048, 4096, 8192, 16384, or 32768 bytes in size.
     // setMaximumSize() will round the size down to the next smallest chunk if the passed size doesn't align.
     int64_t maximumSize();
-    void setMaximumSize(int64_t);
+    WEBCORE_EXPORT void setMaximumSize(int64_t);
     
     // Gets the number of unused bytes in the database file.
     int64_t freeSpaceSize();

Modified: trunk/Source/WebKit/ChangeLog (278650 => 278651)


--- trunk/Source/WebKit/ChangeLog	2021-06-09 05:48:08 UTC (rev 278650)
+++ trunk/Source/WebKit/ChangeLog	2021-06-09 07:02:40 UTC (rev 278651)
@@ -1,3 +1,22 @@
+2021-06-09  Chris Dumez  <[email protected]>
+
+        Rely on SQLiteDatabase::setMaximumSize() for quota management in LocalStorageDatabase
+        https://bugs.webkit.org/show_bug.cgi?id=226788
+
+        Reviewed by Sihui Liu.
+
+        Rely on SQLiteDatabase::setMaximumSize() for quota management in LocalStorageDatabase.
+        It simplifies the code a bit.
+
+        No new test, covered by storage/domstorage/quota.html that is still passing.
+
+        * NetworkProcess/WebStorage/LocalStorageDatabase.cpp:
+        (WebKit::LocalStorageDatabase::openDatabase):
+        (WebKit::LocalStorageDatabase::removeItem):
+        (WebKit::LocalStorageDatabase::setItem):
+        (WebKit::LocalStorageDatabase::clear):
+        * NetworkProcess/WebStorage/LocalStorageDatabase.h:
+
 2021-06-08  Alex Christensen  <[email protected]>
 
         Move PrivacyStance code from WebKitAdditions

Modified: trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.cpp (278650 => 278651)


--- trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.cpp	2021-06-09 05:48:08 UTC (rev 278650)
+++ trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.cpp	2021-06-09 07:02:40 UTC (rev 278651)
@@ -90,6 +90,9 @@
         return false;
     }
 
+    if (m_quotaInBytes != WebCore::StorageMap::noQuota)
+        m_database.setMaximumSize(m_quotaInBytes);
+
     return true;
 }
 
@@ -181,14 +184,6 @@
         LOG_ERROR("Failed to delete item in the local storage database - %i", result);
         return;
     }
-
-    if (m_databaseSize) {
-        auto sizeDecrease = key.sizeInBytes() + oldValue.sizeInBytes();
-        if (sizeDecrease >= *m_databaseSize)
-            *m_databaseSize = 0;
-        else
-            *m_databaseSize -= sizeDecrease;
-    }
 }
 
 String LocalStorageDatabase::item(const String& key) const
@@ -222,21 +217,6 @@
 
     oldValue = item(key);
 
-    if (m_quotaInBytes != WebCore::StorageMap::noQuota) {
-        if (!m_databaseSize)
-            m_databaseSize = SQLiteFileSystem::databaseFileSize(m_databasePath);
-        CheckedUint64 newDatabaseSize = *m_databaseSize;
-        newDatabaseSize -= oldValue.sizeInBytes();
-        newDatabaseSize += value.sizeInBytes();
-        if (oldValue.isNull())
-            newDatabaseSize += key.sizeInBytes();
-        if (newDatabaseSize.hasOverflowed() || newDatabaseSize > m_quotaInBytes) {
-            quotaException = true;
-            return;
-        }
-        m_databaseSize = newDatabaseSize;
-    }
-
     auto insertStatement = scopedStatement(m_insertStatement, "INSERT INTO ItemTable VALUES (?, ?)"_s);
     if (!insertStatement) {
         LOG_ERROR("Failed to prepare insert statement - cannot write to local storage database");
@@ -247,8 +227,11 @@
     insertStatement->bindBlob(2, value);
 
     int result = insertStatement->step();
-    if (result != SQLITE_DONE)
+    if (result != SQLITE_DONE) {
         LOG_ERROR("Failed to update item in the local storage database - %i", result);
+        if (result == SQLITE_FULL)
+            quotaException = true;
+    }
 }
 
 bool LocalStorageDatabase::clear()
@@ -269,8 +252,6 @@
         return false;
     }
 
-    m_databaseSize = 0;
-
     return m_database.lastChanges() > 0;
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.h (278650 => 278651)


--- trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.h	2021-06-09 05:48:08 UTC (rev 278650)
+++ trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.h	2021-06-09 07:02:40 UTC (rev 278651)
@@ -68,7 +68,6 @@
     mutable WebCore::SQLiteDatabase m_database;
     const unsigned m_quotaInBytes { 0 };
     bool m_isClosed { false };
-    std::optional<uint64_t> m_databaseSize;
 
     mutable std::unique_ptr<WebCore::SQLiteStatement> m_clearStatement;
     mutable std::unique_ptr<WebCore::SQLiteStatement> m_insertStatement;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to