Changeset 149631 in webkit


Ignore:
Timestamp:
May 6, 2013, 1:13:08 PM (12 years ago)
Author:
andersca@apple.com
Message:

Handle closing the local storage database
https://bugs.webkit.org/show_bug.cgi?id=115669

Reviewed by Beth Dakin.

  • UIProcess/Storage/LocalStorageDatabase.cpp:

(WebKit::LocalStorageDatabase::LocalStorageDatabase):
Initialize m_isClosed.

(WebKit::LocalStorageDatabase::~LocalStorageDatabase):
Assert that m_isClosed is false.

(WebKit::LocalStorageDatabase::close):
Set m_isClosed to true and write any pending changes to disk.

(WebKit::LocalStorageDatabase::updateDatabase):
Compute the changed items and pass them to updateDatabaseWithChangedItems.

(WebKit::LocalStorageDatabase::updateDatabaseWithChangedItems):
Split out the code that actually writes to the database from updateDatabase and into this function.

  • UIProcess/Storage/LocalStorageDatabase.h:
  • UIProcess/Storage/StorageManager.cpp:

(WebKit::StorageManager::StorageArea::~StorageArea):
Call close().

Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r149620 r149631  
     12013-05-06  Anders Carlsson  <andersca@apple.com>
     2
     3        Handle closing the local storage database
     4        https://bugs.webkit.org/show_bug.cgi?id=115669
     5
     6        Reviewed by Beth Dakin.
     7
     8        * UIProcess/Storage/LocalStorageDatabase.cpp:
     9        (WebKit::LocalStorageDatabase::LocalStorageDatabase):
     10        Initialize m_isClosed.
     11   
     12        (WebKit::LocalStorageDatabase::~LocalStorageDatabase):
     13        Assert that m_isClosed is false.
     14
     15        (WebKit::LocalStorageDatabase::close):
     16        Set m_isClosed to true and write any pending changes to disk.
     17
     18        (WebKit::LocalStorageDatabase::updateDatabase):
     19        Compute the changed items and pass them to updateDatabaseWithChangedItems.
     20
     21        (WebKit::LocalStorageDatabase::updateDatabaseWithChangedItems):
     22        Split out the code that actually writes to the database from updateDatabase and into this function.
     23
     24        * UIProcess/Storage/LocalStorageDatabase.h:
     25        * UIProcess/Storage/StorageManager.cpp:
     26        (WebKit::StorageManager::StorageArea::~StorageArea):
     27        Call close().
     28
    1292013-05-06  Zan Dobersek  <zdobersek@igalia.com>
    230
  • trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp

    r149618 r149631  
    5454    , m_failedToOpenDatabase(false)
    5555    , m_didImportItems(false)
     56    , m_isClosed(false)
    5657    , m_didScheduleDatabaseUpdate(false)
    5758    , m_shouldClearItems(false)
     
    6162LocalStorageDatabase::~LocalStorageDatabase()
    6263{
     64    ASSERT(m_isClosed);
    6365}
    6466
     
    204206}
    205207
     208void LocalStorageDatabase::close()
     209{
     210    ASSERT(!m_isClosed);
     211    m_isClosed = true;
     212
     213    if (m_didScheduleDatabaseUpdate) {
     214        updateDatabaseWithChangedItems(m_changedItems);
     215        m_changedItems.clear();
     216    }
     217
     218    // FIXME: Delete the database if it's empty.
     219}
     220
    206221void LocalStorageDatabase::itemDidChange(const String& key, const String& value)
    207222{
     
    221236void LocalStorageDatabase::updateDatabase()
    222237{
     238    if (m_isClosed)
     239        return;
     240
    223241    ASSERT(m_didScheduleDatabaseUpdate);
    224 
    225242    m_didScheduleDatabaseUpdate = false;
    226243
     244    HashMap<String, String> changedItems;
     245    if (m_changedItems.size() <= maximumItemsToUpdate) {
     246        // There are few enough changed items that we can just always write all of them.
     247        m_changedItems.swap(changedItems);
     248    } else {
     249        for (int i = 0; i < maximumItemsToUpdate; ++i) {
     250            auto it = m_changedItems.begin();
     251            changedItems.add(it->key, it->value);
     252
     253            m_changedItems.remove(it);
     254        }
     255
     256        ASSERT(changedItems.size() <= maximumItemsToUpdate);
     257
     258        // Reschedule the update for the remaining items.
     259        scheduleDatabaseUpdate();
     260    }
     261
     262    updateDatabaseWithChangedItems(changedItems);
     263}
     264
     265void LocalStorageDatabase::updateDatabaseWithChangedItems(const HashMap<String, String>& changedItems)
     266{
    227267    if (m_shouldClearItems) {
    228268        m_shouldClearItems = false;
     
    241281    }
    242282
    243     HashMap<String, String> changedItems;
    244     if (m_changedItems.size() > maximumItemsToUpdate) {
    245         for (int i = 0; i < maximumItemsToUpdate; ++i) {
    246             auto it = m_changedItems.begin();
    247             changedItems.add(it->key, it->value);
    248 
    249             m_changedItems.remove(it);
    250         }
    251 
    252         // Reschedule the update for the remaining items.
    253         scheduleDatabaseUpdate();
    254     } else {
    255         // There are few enough changed items that we can just always write all of them.
    256         m_changedItems.swap(changedItems);
    257     }
    258 
    259     ASSERT(changedItems.size() <= maximumItemsToUpdate);
    260 
    261283    SQLiteStatement insertStatement(m_database, "INSERT INTO ItemTable VALUES (?, ?)");
    262284    if (insertStatement.prepare() != SQLResultOk) {
  • trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h

    r149618 r149631  
    5353    void clear();
    5454
     55    // Will block until all pending changes have been written to disk.
     56    void close();
     57
    5558private:
    5659    LocalStorageDatabase(const String& databaseFilename, PassRefPtr<WorkQueue>);
     
    6972    void scheduleDatabaseUpdate();
    7073    void updateDatabase();
     74    void updateDatabaseWithChangedItems(const HashMap<String, String>&);
    7175
    7276    String m_databaseFilename;
     
    7680    bool m_failedToOpenDatabase;
    7781    bool m_didImportItems;
     82    bool m_isClosed;
    7883
    7984    bool m_didScheduleDatabaseUpdate;
  • trunk/Source/WebKit2/UIProcess/Storage/StorageManager.cpp

    r149618 r149631  
    118118    ASSERT(m_eventListeners.isEmpty());
    119119
     120    if (m_localStorageDatabase)
     121        m_localStorageDatabase->close();
     122
    120123    if (m_localStorageNamespace)
    121124        m_localStorageNamespace->didDestroyStorageArea(this);
Note: See TracChangeset for help on using the changeset viewer.