Changeset 61023 in webkit


Ignore:
Timestamp:
Jun 11, 2010 9:17:05 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-06-11 Hans Wennborg <hans@chromium.org>

Reviewed by Jeremy Orlow.

DOM storage should only create databases when needed
https://bugs.webkit.org/show_bug.cgi?id=40301

As soon as a page attempts to use localstorage, StorageAreaSync will
create an empty database if one doesn't already exist. This can lead to
lots of unnecessary database files. In particular, they are created
even when the privacy settings or private browsing mode disallow
localstorage data, which may seem odd to the user.

Database creation should be put off in StorageAreaSync until it is time
to actually write something to the database.

Tests:

manual-tests/localstorage-empty-database.html

  • manual-tests/localstorage-empty-database.html: Added.
  • storage/StorageAreaSync.cpp: (WebCore::StorageAreaSync::StorageAreaSync): (WebCore::StorageAreaSync::openDatabase): (WebCore::StorageAreaSync::performImport): (WebCore::StorageAreaSync::sync):
  • storage/StorageAreaSync.h: (WebCore::StorageAreaSync::):
Location:
trunk/WebCore
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r61022 r61023  
     12010-06-11  Hans Wennborg  <hans@chromium.org>
     2
     3        Reviewed by Jeremy Orlow.
     4
     5        DOM storage should only create databases when needed
     6        https://bugs.webkit.org/show_bug.cgi?id=40301
     7
     8        As soon as a page attempts to use localstorage, StorageAreaSync will
     9        create an empty database if one doesn't already exist. This can lead to
     10        lots of unnecessary database files. In particular, they are created
     11        even when the privacy settings or private browsing mode disallow
     12        localstorage data, which may seem odd to the user.
     13
     14        Database creation should be put off in StorageAreaSync until it is time
     15        to actually write something to the database.
     16
     17        Tests:
     18         manual-tests/localstorage-empty-database.html
     19
     20        * manual-tests/localstorage-empty-database.html: Added.
     21        * storage/StorageAreaSync.cpp:
     22        (WebCore::StorageAreaSync::StorageAreaSync):
     23        (WebCore::StorageAreaSync::openDatabase):
     24        (WebCore::StorageAreaSync::performImport):
     25        (WebCore::StorageAreaSync::sync):
     26        * storage/StorageAreaSync.h:
     27        (WebCore::StorageAreaSync::):
     28
    1292010-06-11  Ilya Tikhonovsky  <loislo@chromium.org>
    230
  • trunk/WebCore/storage/StorageAreaSync.cpp

    r56825 r61023  
    3030
    3131#include "EventNames.h"
     32#include "FileSystem.h"
    3233#include "HTMLElement.h"
    3334#include "SecurityOrigin.h"
     
    6364    , m_syncScheduled(false)
    6465    , m_syncInProgress(false)
     66    , m_databaseOpenFailed(false)
    6567    , m_importComplete(false)
    6668{
     
    199201}
    200202
    201 void StorageAreaSync::performImport()
     203void StorageAreaSync::openDatabase(OpenDatabaseParamType openingStrategy)
    202204{
    203205    ASSERT(!isMainThread());
    204206    ASSERT(!m_database.isOpen());
     207    ASSERT(!m_databaseOpenFailed);
    205208
    206209    String databaseFilename = m_syncManager->fullDatabaseFilename(m_databaseIdentifier);
     210
     211    if (!fileExists(databaseFilename) && openingStrategy == SkipIfNonExistent)
     212        return;
    207213
    208214    if (databaseFilename.isEmpty()) {
    209215        LOG_ERROR("Filename for local storage database is empty - cannot open for persistent storage");
    210216        markImported();
     217        m_databaseOpenFailed = true;
    211218        return;
    212219    }
     
    215222        LOG_ERROR("Failed to open database file %s for local storage", databaseFilename.utf8().data());
    216223        markImported();
     224        m_databaseOpenFailed = true;
    217225        return;
    218226    }
     
    220228    if (!m_database.executeCommand("CREATE TABLE IF NOT EXISTS ItemTable (key TEXT UNIQUE ON CONFLICT REPLACE, value TEXT NOT NULL ON CONFLICT FAIL)")) {
    221229        LOG_ERROR("Failed to create table ItemTable for local storage");
     230        markImported();
     231        m_databaseOpenFailed = true;
     232        return;
     233    }
     234}
     235
     236void StorageAreaSync::performImport()
     237{
     238    ASSERT(!isMainThread());
     239    ASSERT(!m_database.isOpen());
     240
     241    openDatabase(SkipIfNonExistent);
     242    if (!m_database.isOpen()) {
    222243        markImported();
    223244        return;
     
    286307    ASSERT(!isMainThread());
    287308
     309    if (m_databaseOpenFailed)
     310        return;
     311    if (!m_database.isOpen())
     312        openDatabase(CreateIfNonExistent);
    288313    if (!m_database.isOpen())
    289314        return;
  • trunk/WebCore/storage/StorageAreaSync.h

    r55523 r61023  
    7676
    7777    private:
     78        enum OpenDatabaseParamType {
     79          CreateIfNonExistent,
     80          SkipIfNonExistent
     81        };
     82
    7883        void syncTimerFired(Timer<StorageAreaSync>*);
     84        void openDatabase(OpenDatabaseParamType openingStrategy);
    7985        void sync(bool clearItems, const HashMap<String, String>& items);
    8086
     
    8692        bool m_syncScheduled;
    8793        bool m_syncInProgress;
     94        bool m_databaseOpenFailed;
    8895
    8996        mutable Mutex m_importLock;
Note: See TracChangeset for help on using the changeset viewer.