Changeset 50979 in webkit


Ignore:
Timestamp:
Nov 13, 2009 4:27:25 PM (15 years ago)
Author:
jorlow@chromium.org
Message:

2009-11-12 Jeremy Orlow <jorlow@chromium.org>

Reviewed by Dmitry Titov.

LocalStorage quota should include key sizes in its count
https://bugs.webkit.org/show_bug.cgi?id=31451

  • storage/StorageMap.cpp: (WebCore::StorageMap::setItem):

Count keys in the quota when adding a new item.

(WebCore::StorageMap::removeItem):

Remove the key's length from the quota if we're removing the item.

(WebCore::StorageMap::importItem):

Assume that we're adding things for the first time.
Count keys in the quota.

2009-11-12 Jeremy Orlow <jorlow@chromium.org>

Reviewed by Dmitry Titov.

Now that we're tracking key size in the quota, we can't fit as much in.
https://bugs.webkit.org/show_bug.cgi?id=31451

  • storage/domstorage/quota-expected.txt:
  • storage/domstorage/script-tests/quota.js: (testQuota):
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r50976 r50979  
     12009-11-12  Jeremy Orlow  <jorlow@chromium.org>
     2
     3        Reviewed by Dmitry Titov.
     4
     5        Now that we're tracking key size in the quota, we can't fit as much in.
     6        https://bugs.webkit.org/show_bug.cgi?id=31451
     7
     8        * storage/domstorage/quota-expected.txt:
     9        * storage/domstorage/script-tests/quota.js:
     10        (testQuota):
     11
    1122009-11-13  Shinichiro Hamaji  <hamaji@chromium.org>
    213
  • trunk/LayoutTests/storage/domstorage/quota-expected.txt

    r49928 r50979  
    1919Creating 'data' which contains 64K of data
    2020PASS data.length is 65536
    21 Putting 'data' into 40 localStorage buckets.
     21Putting 'data' into 39 localStorage buckets.
    2222Putting 'data' into another bucket.h
    2323PASS Hit exception as expected
    2424Verify that data was never inserted.
    25 PASS storage.getItem(40) is null
    26 Removing bucket 39.
     25PASS storage.getItem(39) is null
     26Removing bucket 38.
    2727Adding 'Hello!' into a new bucket.
    2828PASS Insertion worked.
  • trunk/LayoutTests/storage/domstorage/script-tests/quota.js

    r49928 r50979  
    2020    shouldBe("data.length", "65536");
    2121
    22     debug("Putting 'data' into 40 " + storageString + " buckets.");
    23     for (var i=0; i<40; i++)
     22    debug("Putting 'data' into 39 " + storageString + " buckets.");
     23    for (var i=0; i<39; i++)
    2424        storage[i] = data;
    2525
    2626    debug("Putting 'data' into another bucket.h");
    2727    try {
    28         storage[40] = data;
     28        storage[39] = data;
    2929        testFailed("Did not hit quota error.");
    3030    } catch (e) {
     
    3333
    3434    debug("Verify that data was never inserted.");
    35     shouldBeNull("storage.getItem(40)");
     35    shouldBeNull("storage.getItem(39)");
    3636
    37     debug("Removing bucket 39.");
    38     storage.removeItem('39');
     37    debug("Removing bucket 38.");
     38    storage.removeItem('38');
    3939
    4040    debug("Adding 'Hello!' into a new bucket.");
  • trunk/WebCore/ChangeLog

    r50977 r50979  
     12009-11-12  Jeremy Orlow  <jorlow@chromium.org>
     2
     3        Reviewed by Dmitry Titov.
     4
     5        LocalStorage quota should include key sizes in its count
     6        https://bugs.webkit.org/show_bug.cgi?id=31451
     7
     8        * storage/StorageMap.cpp:
     9        (WebCore::StorageMap::setItem):
     10            Count keys in the quota when adding a new item.
     11        (WebCore::StorageMap::removeItem):
     12            Remove the key's length from the quota if we're removing the item.
     13        (WebCore::StorageMap::importItem):
     14            Assume that we're adding things for the first time.
     15            Count keys in the quota.
     16
    1172009-11-13  Dominik Röttsches  <dominik.roettsches@access-company.com>
    218
  • trunk/WebCore/storage/StorageMap.cpp

    r49160 r50979  
    112112    }
    113113
    114     // Quota tracking.  If the quota is enabled and this would go over it, bail.
     114    // Quota tracking.  This is done in a couple of steps to keep the overflow tracking simple.
     115    unsigned newLength = m_currentLength;
     116    bool overflow = newLength + value.length() < newLength;
     117    newLength += value.length();
     118
    115119    oldValue = m_map.get(key);
    116     unsigned newLength = m_currentLength + value.length() - oldValue.length();
     120    overflow |= newLength - oldValue.length() > newLength;
     121    newLength -= oldValue.length();
     122
     123    unsigned adjustedKeyLength = oldValue.isNull() ? key.length() : 0;
     124    overflow |= newLength + adjustedKeyLength < newLength;
     125    newLength += adjustedKeyLength;
     126
     127    ASSERT(!overflow);  // Overflow is bad...even if quotas are off.
    117128    bool overQuota = newLength > m_quotaSize / sizeof(UChar);
    118     bool overflow = (newLength > m_currentLength) != (value.length() > oldValue.length());
    119     ASSERT(!overflow);  // If we're debugging, make a fuss.  But it's still worth checking this in the following if statement.
    120129    if (m_quotaSize != noQuota && (overflow || overQuota)) {
    121130        quotaException = true;
     
    144153
    145154    oldValue = m_map.take(key);
    146     if (!oldValue.isNull())
     155    if (!oldValue.isNull()) {
    147156        invalidateIterator();
    148 
    149     // Update quota.
     157        ASSERT(m_currentLength - key.length() <= m_currentLength);
     158        m_currentLength -= key.length();
     159    }
    150160    ASSERT(m_currentLength - oldValue.length() <= m_currentLength);
    151161    m_currentLength -= oldValue.length();
     
    163173    // Be sure to copy the keys/values as items imported on a background thread are destined
    164174    // to cross a thread boundary
    165     pair<HashMap<String, String>::iterator, bool> result = m_map.add(key.threadsafeCopy(), String());
     175    pair<HashMap<String, String>::iterator, bool> result = m_map.add(key.threadsafeCopy(), value.threadsafeCopy());
     176    ASSERT(result.second);  // True if the key didn't exist previously.
    166177
    167     if (result.second)
    168         result.first->second = value.threadsafeCopy();
    169 
    170     // Update quota.
     178    ASSERT(m_currentLength + key.length() >= m_currentLength);
     179    m_currentLength += key.length();
    171180    ASSERT(m_currentLength + value.length() >= m_currentLength);
    172181    m_currentLength += value.length();
Note: See TracChangeset for help on using the changeset viewer.