Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: webkit/dom_storage/dom_storage_map.cc

Issue 9594038: Relax strict quota limit checks when reading pre-existing DomStorage database files. The other chec… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/dom_storage/dom_storage_map.h" 5 #include "webkit/dom_storage/dom_storage_map.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace { 9 namespace {
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const string16& key, const string16& value, 65 const string16& key, const string16& value,
66 NullableString16* old_value) { 66 NullableString16* old_value) {
67 ValuesMap::const_iterator found = values_.find(key); 67 ValuesMap::const_iterator found = values_.find(key);
68 if (found == values_.end()) 68 if (found == values_.end())
69 *old_value = NullableString16(true); 69 *old_value = NullableString16(true);
70 else 70 else
71 *old_value = found->second; 71 *old_value = found->second;
72 72
73 size_t old_item_size = old_value->is_null() ? 73 size_t old_item_size = old_value->is_null() ?
74 0 : size_of_item(key, old_value->string()); 74 0 : size_of_item(key, old_value->string());
75 size_t new_size = bytes_used_ - old_item_size + size_of_item(key, value); 75 size_t new_item_size = size_of_item(key, value);
76 if (new_size > quota_) 76 size_t new_bytes_used = bytes_used_ - old_item_size + new_item_size;
77
78 // Only check quota if the size is increasing since a descrese is
benm (inactive) 2012/03/06 11:31:15 s/descrease/decrease/
michaeln 2012/03/06 20:37:51 Done.
79 // always allowed.
80 if ((new_item_size > old_item_size) && (new_bytes_used > quota_))
benm (inactive) 2012/03/06 11:31:15 should this be new_item_size >= old_item_size? Tha
michaeln 2012/03/06 20:37:51 Seems cruel to reject a change where the size is n
77 return false; 81 return false;
78 82
79 values_[key] = NullableString16(value, false); 83 values_[key] = NullableString16(value, false);
80 ResetKeyIterator(); 84 ResetKeyIterator();
81 bytes_used_ -= old_item_size; 85 bytes_used_ = new_bytes_used;
82 bytes_used_ += size_of_item(key, value);
83 return true; 86 return true;
84 } 87 }
85 88
86 bool DomStorageMap::RemoveItem( 89 bool DomStorageMap::RemoveItem(
87 const string16& key, 90 const string16& key,
88 string16* old_value) { 91 string16* old_value) {
89 ValuesMap::iterator found = values_.find(key); 92 ValuesMap::iterator found = values_.find(key);
90 if (found == values_.end()) 93 if (found == values_.end())
91 return false; 94 return false;
92 *old_value = found->second.string(); 95 *old_value = found->second.string();
93 values_.erase(found); 96 values_.erase(found);
94 ResetKeyIterator(); 97 ResetKeyIterator();
95 bytes_used_ -= size_of_item(key, *old_value); 98 bytes_used_ -= size_of_item(key, *old_value);
96 return true; 99 return true;
97 } 100 }
98 101
99 bool DomStorageMap::SwapValues(ValuesMap* values) { 102 void DomStorageMap::SwapValues(ValuesMap* values) {
100 size_t new_size = CountBytes(*values);
101 if (new_size > quota_)
102 return false;
103 values_.swap(*values); 103 values_.swap(*values);
104 bytes_used_ = new_size; 104 bytes_used_ = CountBytes(values_);
105 ResetKeyIterator(); 105 ResetKeyIterator();
106 return true;
107 } 106 }
108 107
109 DomStorageMap* DomStorageMap::DeepCopy() const { 108 DomStorageMap* DomStorageMap::DeepCopy() const {
110 DCHECK(CountBytes(values_) <= quota_);
111 DomStorageMap* copy = new DomStorageMap(quota_); 109 DomStorageMap* copy = new DomStorageMap(quota_);
112 copy->values_ = values_; 110 copy->values_ = values_;
113 copy->bytes_used_ = bytes_used_; 111 copy->bytes_used_ = bytes_used_;
114 copy->ResetKeyIterator(); 112 copy->ResetKeyIterator();
115 return copy; 113 return copy;
116 } 114 }
117 115
118 void DomStorageMap::ResetKeyIterator() { 116 void DomStorageMap::ResetKeyIterator() {
119 key_iterator_ = values_.begin(); 117 key_iterator_ = values_.begin();
120 last_key_index_ = 0; 118 last_key_index_ = 0;
121 } 119 }
122 120
123 } // namespace dom_storage 121 } // namespace dom_storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698