⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 278651 in webkit


Ignore:
Timestamp:
Jun 9, 2021, 12:02:40 AM (5 years ago)
Author:
Chris Dumez
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:
Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r278649 r278651  
     12021-06-09  Chris Dumez  <cdumez@apple.com>
     2
     3        Rely on SQLiteDatabase::setMaximumSize() for quota management in LocalStorageDatabase
     4        https://bugs.webkit.org/show_bug.cgi?id=226788
     5
     6        Reviewed by Sihui Liu.
     7
     8        Export SQLiteDatabase::setMaximumSize() so it can be used from WebKit2.
     9
     10        * platform/sql/SQLiteDatabase.h:
     11
    1122021-06-08  Alex Christensen  <achristensen@webkit.org>
    213
  • trunk/Source/WebCore/platform/sql/SQLiteDatabase.h

    r278150 r278651  
    104104    // setMaximumSize() will round the size down to the next smallest chunk if the passed size doesn't align.
    105105    int64_t maximumSize();
    106     void setMaximumSize(int64_t);
     106    WEBCORE_EXPORT void setMaximumSize(int64_t);
    107107   
    108108    // Gets the number of unused bytes in the database file.
  • trunk/Source/WebKit/ChangeLog

    r278649 r278651  
     12021-06-09  Chris Dumez  <cdumez@apple.com>
     2
     3        Rely on SQLiteDatabase::setMaximumSize() for quota management in LocalStorageDatabase
     4        https://bugs.webkit.org/show_bug.cgi?id=226788
     5
     6        Reviewed by Sihui Liu.
     7
     8        Rely on SQLiteDatabase::setMaximumSize() for quota management in LocalStorageDatabase.
     9        It simplifies the code a bit.
     10
     11        No new test, covered by storage/domstorage/quota.html that is still passing.
     12
     13        * NetworkProcess/WebStorage/LocalStorageDatabase.cpp:
     14        (WebKit::LocalStorageDatabase::openDatabase):
     15        (WebKit::LocalStorageDatabase::removeItem):
     16        (WebKit::LocalStorageDatabase::setItem):
     17        (WebKit::LocalStorageDatabase::clear):
     18        * NetworkProcess/WebStorage/LocalStorageDatabase.h:
     19
    1202021-06-08  Alex Christensen  <achristensen@webkit.org>
    221
  • trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.cpp

    r278338 r278651  
    9191    }
    9292
     93    if (m_quotaInBytes != WebCore::StorageMap::noQuota)
     94        m_database.setMaximumSize(m_quotaInBytes);
     95
    9396    return true;
    9497}
     
    182185        return;
    183186    }
    184 
    185     if (m_databaseSize) {
    186         auto sizeDecrease = key.sizeInBytes() + oldValue.sizeInBytes();
    187         if (sizeDecrease >= *m_databaseSize)
    188             *m_databaseSize = 0;
    189         else
    190             *m_databaseSize -= sizeDecrease;
    191     }
    192187}
    193188
     
    223218    oldValue = item(key);
    224219
    225     if (m_quotaInBytes != WebCore::StorageMap::noQuota) {
    226         if (!m_databaseSize)
    227             m_databaseSize = SQLiteFileSystem::databaseFileSize(m_databasePath);
    228         CheckedUint64 newDatabaseSize = *m_databaseSize;
    229         newDatabaseSize -= oldValue.sizeInBytes();
    230         newDatabaseSize += value.sizeInBytes();
    231         if (oldValue.isNull())
    232             newDatabaseSize += key.sizeInBytes();
    233         if (newDatabaseSize.hasOverflowed() || newDatabaseSize > m_quotaInBytes) {
    234             quotaException = true;
    235             return;
    236         }
    237         m_databaseSize = newDatabaseSize;
    238     }
    239 
    240220    auto insertStatement = scopedStatement(m_insertStatement, "INSERT INTO ItemTable VALUES (?, ?)"_s);
    241221    if (!insertStatement) {
     
    248228
    249229    int result = insertStatement->step();
    250     if (result != SQLITE_DONE)
     230    if (result != SQLITE_DONE) {
    251231        LOG_ERROR("Failed to update item in the local storage database - %i", result);
     232        if (result == SQLITE_FULL)
     233            quotaException = true;
     234    }
    252235}
    253236
     
    269252        return false;
    270253    }
    271 
    272     m_databaseSize = 0;
    273254
    274255    return m_database.lastChanges() > 0;
  • trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.h

    r278253 r278651  
    6969    const unsigned m_quotaInBytes { 0 };
    7070    bool m_isClosed { false };
    71     std::optional<uint64_t> m_databaseSize;
    7271
    7372    mutable std::unique_ptr<WebCore::SQLiteStatement> m_clearStatement;
Note: See TracChangeset for help on using the changeset viewer.