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

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

Issue 13219005: Replace string16 with base::string16 in src/webkit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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_cached_area.h" 5 #include "webkit/dom_storage/dom_storage_cached_area.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "webkit/dom_storage/dom_storage_map.h" 10 #include "webkit/dom_storage/dom_storage_map.h"
(...skipping 16 matching lines...) Expand all
27 return map_->Length(); 27 return map_->Length();
28 } 28 }
29 29
30 NullableString16 DomStorageCachedArea::GetKey( 30 NullableString16 DomStorageCachedArea::GetKey(
31 int connection_id, unsigned index) { 31 int connection_id, unsigned index) {
32 PrimeIfNeeded(connection_id); 32 PrimeIfNeeded(connection_id);
33 return map_->Key(index); 33 return map_->Key(index);
34 } 34 }
35 35
36 NullableString16 DomStorageCachedArea::GetItem( 36 NullableString16 DomStorageCachedArea::GetItem(
37 int connection_id, const string16& key) { 37 int connection_id, const base::string16& key) {
38 PrimeIfNeeded(connection_id); 38 PrimeIfNeeded(connection_id);
39 return map_->GetItem(key); 39 return map_->GetItem(key);
40 } 40 }
41 41
42 bool DomStorageCachedArea::SetItem( 42 bool DomStorageCachedArea::SetItem(
43 int connection_id, const string16& key, 43 int connection_id, const base::string16& key,
44 const string16& value, const GURL& page_url) { 44 const base::string16& value, const GURL& page_url) {
45 // A quick check to reject obviously overbudget items to avoid 45 // A quick check to reject obviously overbudget items to avoid
46 // the priming the cache. 46 // the priming the cache.
47 if (key.length() + value.length() > dom_storage::kPerAreaQuota) 47 if (key.length() + value.length() > dom_storage::kPerAreaQuota)
48 return false; 48 return false;
49 49
50 PrimeIfNeeded(connection_id); 50 PrimeIfNeeded(connection_id);
51 NullableString16 unused; 51 NullableString16 unused;
52 if (!map_->SetItem(key, value, &unused)) 52 if (!map_->SetItem(key, value, &unused))
53 return false; 53 return false;
54 54
55 // Ignore mutations to 'key' until OnSetItemComplete. 55 // Ignore mutations to 'key' until OnSetItemComplete.
56 ignore_key_mutations_[key]++; 56 ignore_key_mutations_[key]++;
57 proxy_->SetItem( 57 proxy_->SetItem(
58 connection_id, key, value, page_url, 58 connection_id, key, value, page_url,
59 base::Bind(&DomStorageCachedArea::OnSetItemComplete, 59 base::Bind(&DomStorageCachedArea::OnSetItemComplete,
60 weak_factory_.GetWeakPtr(), key)); 60 weak_factory_.GetWeakPtr(), key));
61 return true; 61 return true;
62 } 62 }
63 63
64 void DomStorageCachedArea::RemoveItem( 64 void DomStorageCachedArea::RemoveItem(
65 int connection_id, const string16& key, const GURL& page_url) { 65 int connection_id, const base::string16& key, const GURL& page_url) {
66 PrimeIfNeeded(connection_id); 66 PrimeIfNeeded(connection_id);
67 string16 unused; 67 base::string16 unused;
68 if (!map_->RemoveItem(key, &unused)) 68 if (!map_->RemoveItem(key, &unused))
69 return; 69 return;
70 70
71 // Ignore mutations to 'key' until OnRemoveItemComplete. 71 // Ignore mutations to 'key' until OnRemoveItemComplete.
72 ignore_key_mutations_[key]++; 72 ignore_key_mutations_[key]++;
73 proxy_->RemoveItem( 73 proxy_->RemoveItem(
74 connection_id, key, page_url, 74 connection_id, key, page_url,
75 base::Bind(&DomStorageCachedArea::OnRemoveItemComplete, 75 base::Bind(&DomStorageCachedArea::OnRemoveItemComplete,
76 weak_factory_.GetWeakPtr(), key)); 76 weak_factory_.GetWeakPtr(), key));
77 } 77 }
(...skipping 16 matching lines...) Expand all
94 if (!map_ || ignore_all_mutations_) 94 if (!map_ || ignore_all_mutations_)
95 return; 95 return;
96 96
97 if (key.is_null()) { 97 if (key.is_null()) {
98 // It's a clear event. 98 // It's a clear event.
99 scoped_refptr<DomStorageMap> old = map_; 99 scoped_refptr<DomStorageMap> old = map_;
100 map_ = new DomStorageMap(dom_storage::kPerAreaQuota); 100 map_ = new DomStorageMap(dom_storage::kPerAreaQuota);
101 101
102 // We have to retain local additions which happened after this 102 // We have to retain local additions which happened after this
103 // clear operation from another process. 103 // clear operation from another process.
104 std::map<string16, int>::iterator iter = ignore_key_mutations_.begin(); 104 std::map<base::string16, int>::iterator iter =
105 ignore_key_mutations_.begin();
105 while (iter != ignore_key_mutations_.end()) { 106 while (iter != ignore_key_mutations_.end()) {
106 NullableString16 value = old->GetItem(iter->first); 107 NullableString16 value = old->GetItem(iter->first);
107 if (!value.is_null()) { 108 if (!value.is_null()) {
108 NullableString16 unused; 109 NullableString16 unused;
109 map_->SetItem(iter->first, value.string(), &unused); 110 map_->SetItem(iter->first, value.string(), &unused);
110 } 111 }
111 ++iter; 112 ++iter;
112 } 113 }
113 return; 114 return;
114 } 115 }
115 116
116 // We have to retain local changes. 117 // We have to retain local changes.
117 if (should_ignore_key_mutation(key.string())) 118 if (should_ignore_key_mutation(key.string()))
118 return; 119 return;
119 120
120 if (new_value.is_null()) { 121 if (new_value.is_null()) {
121 // It's a remove item event. 122 // It's a remove item event.
122 string16 unused; 123 base::string16 unused;
123 map_->RemoveItem(key.string(), &unused); 124 map_->RemoveItem(key.string(), &unused);
124 return; 125 return;
125 } 126 }
126 127
127 // It's a set item event. 128 // It's a set item event.
128 // We turn off quota checking here to accomodate the over budget 129 // We turn off quota checking here to accomodate the over budget
129 // allowance that's provided in the browser process. 130 // allowance that's provided in the browser process.
130 NullableString16 unused; 131 NullableString16 unused;
131 map_->set_quota(kint32max); 132 map_->set_quota(kint32max);
132 map_->SetItem(key.string(), new_value.string(), &unused); 133 map_->SetItem(key.string(), new_value.string(), &unused);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 ignore_all_mutations_ = false; 192 ignore_all_mutations_ = false;
192 } 193 }
193 194
194 void DomStorageCachedArea::OnLoadComplete(bool success) { 195 void DomStorageCachedArea::OnLoadComplete(bool success) {
195 DCHECK(success); 196 DCHECK(success);
196 DCHECK(ignore_all_mutations_); 197 DCHECK(ignore_all_mutations_);
197 ignore_all_mutations_ = false; 198 ignore_all_mutations_ = false;
198 } 199 }
199 200
200 void DomStorageCachedArea::OnSetItemComplete( 201 void DomStorageCachedArea::OnSetItemComplete(
201 const string16& key, bool success) { 202 const base::string16& key, bool success) {
202 if (!success) { 203 if (!success) {
203 Reset(); 204 Reset();
204 return; 205 return;
205 } 206 }
206 std::map<string16, int>::iterator found = ignore_key_mutations_.find(key); 207 std::map<base::string16, int>::iterator found =
208 ignore_key_mutations_.find(key);
207 DCHECK(found != ignore_key_mutations_.end()); 209 DCHECK(found != ignore_key_mutations_.end());
208 if (--found->second == 0) 210 if (--found->second == 0)
209 ignore_key_mutations_.erase(found); 211 ignore_key_mutations_.erase(found);
210 } 212 }
211 213
212 void DomStorageCachedArea::OnRemoveItemComplete( 214 void DomStorageCachedArea::OnRemoveItemComplete(
213 const string16& key, bool success) { 215 const base::string16& key, bool success) {
214 DCHECK(success); 216 DCHECK(success);
215 std::map<string16, int>::iterator found = ignore_key_mutations_.find(key); 217 std::map<base::string16, int>::iterator found =
218 ignore_key_mutations_.find(key);
216 DCHECK(found != ignore_key_mutations_.end()); 219 DCHECK(found != ignore_key_mutations_.end());
217 if (--found->second == 0) 220 if (--found->second == 0)
218 ignore_key_mutations_.erase(found); 221 ignore_key_mutations_.erase(found);
219 } 222 }
220 223
221 void DomStorageCachedArea::OnClearComplete(bool success) { 224 void DomStorageCachedArea::OnClearComplete(bool success) {
222 DCHECK(success); 225 DCHECK(success);
223 DCHECK(ignore_all_mutations_); 226 DCHECK(ignore_all_mutations_);
224 ignore_all_mutations_ = false; 227 ignore_all_mutations_ = false;
225 } 228 }
226 229
227 } // namespace dom_storage 230 } // namespace dom_storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698