diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-08 01:35:05 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-08 01:35:05 +0000 |
commit | d2a6636936cb5ed04041028b2e7ca188620411ce (patch) | |
tree | 88bc323ce959b2dc180a66a60c6fbabea038044c /webkit/dom_storage/dom_storage_map.cc | |
parent | d8d97c2224367396e57bc69294beaea7002f1f14 (diff) | |
download | chromium_src-d2a6636936cb5ed04041028b2e7ca188620411ce.zip chromium_src-d2a6636936cb5ed04041028b2e7ca188620411ce.tar.gz chromium_src-d2a6636936cb5ed04041028b2e7ca188620411ce.tar.bz2 |
Relax strict quota limit checks when reading pre-existing DomStorage database files. The other checks will disallow increases that exceed the limit, but when it comes to existing files its not clear that the checks on open will pass. So we'll grandfather in the existing files.
Review URL: https://chromiumcodereview.appspot.com/9594038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125524 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/dom_storage/dom_storage_map.cc')
-rw-r--r-- | webkit/dom_storage/dom_storage_map.cc | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/webkit/dom_storage/dom_storage_map.cc b/webkit/dom_storage/dom_storage_map.cc index aa34752..6c086b6 100644 --- a/webkit/dom_storage/dom_storage_map.cc +++ b/webkit/dom_storage/dom_storage_map.cc @@ -72,14 +72,17 @@ bool DomStorageMap::SetItem( size_t old_item_size = old_value->is_null() ? 0 : size_of_item(key, old_value->string()); - size_t new_size = bytes_used_ - old_item_size + size_of_item(key, value); - if (new_size > quota_) + size_t new_item_size = size_of_item(key, value); + size_t new_bytes_used = bytes_used_ - old_item_size + new_item_size; + + // Only check quota if the size is increasing, this allows + // shrinking changes to pre-existing files that are over budget. + if (new_item_size > old_item_size && new_bytes_used > quota_) return false; values_[key] = NullableString16(value, false); ResetKeyIterator(); - bytes_used_ -= old_item_size; - bytes_used_ += size_of_item(key, value); + bytes_used_ = new_bytes_used; return true; } @@ -96,18 +99,14 @@ bool DomStorageMap::RemoveItem( return true; } -bool DomStorageMap::SwapValues(ValuesMap* values) { - size_t new_size = CountBytes(*values); - if (new_size > quota_) - return false; +void DomStorageMap::SwapValues(ValuesMap* values) { + // Note: A pre-existing file may be over the quota budget. values_.swap(*values); - bytes_used_ = new_size; + bytes_used_ = CountBytes(values_); ResetKeyIterator(); - return true; } DomStorageMap* DomStorageMap::DeepCopy() const { - DCHECK(CountBytes(values_) <= quota_); DomStorageMap* copy = new DomStorageMap(quota_); copy->values_ = values_; copy->bytes_used_ = bytes_used_; |