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

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

Issue 16415016: Move nullable_string16.h to the string subdirectory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar Created 7 years, 6 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/renderer/dom_storage/dom_storage_cached_area.h" 5 #include "webkit/renderer/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/common/dom_storage/dom_storage_map.h" 10 #include "webkit/common/dom_storage/dom_storage_map.h"
11 #include "webkit/renderer/dom_storage/dom_storage_proxy.h" 11 #include "webkit/renderer/dom_storage/dom_storage_proxy.h"
12 12
13 namespace dom_storage { 13 namespace dom_storage {
14 14
15 DomStorageCachedArea::DomStorageCachedArea( 15 DomStorageCachedArea::DomStorageCachedArea(
16 int64 namespace_id, const GURL& origin, DomStorageProxy* proxy) 16 int64 namespace_id, const GURL& origin, DomStorageProxy* proxy)
17 : ignore_all_mutations_(false), 17 : ignore_all_mutations_(false),
18 namespace_id_(namespace_id), origin_(origin), 18 namespace_id_(namespace_id), origin_(origin),
19 proxy_(proxy), weak_factory_(this) { 19 proxy_(proxy), weak_factory_(this) {
20 } 20 }
21 21
22 DomStorageCachedArea::~DomStorageCachedArea() { 22 DomStorageCachedArea::~DomStorageCachedArea() {
23 } 23 }
24 24
25 unsigned DomStorageCachedArea::GetLength(int connection_id) { 25 unsigned DomStorageCachedArea::GetLength(int connection_id) {
26 PrimeIfNeeded(connection_id); 26 PrimeIfNeeded(connection_id);
27 return map_->Length(); 27 return map_->Length();
28 } 28 }
29 29
30 NullableString16 DomStorageCachedArea::GetKey( 30 base::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 base::NullableString16 DomStorageCachedArea::GetItem(
37 int connection_id, const base::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 base::string16& key, 43 int connection_id, const base::string16& key,
44 const base::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 base::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;
(...skipping 21 matching lines...) Expand all
83 83
84 // Ignore all mutations until OnClearComplete time. 84 // Ignore all mutations until OnClearComplete time.
85 ignore_all_mutations_ = true; 85 ignore_all_mutations_ = true;
86 proxy_->ClearArea( 86 proxy_->ClearArea(
87 connection_id, page_url, 87 connection_id, page_url,
88 base::Bind(&DomStorageCachedArea::OnClearComplete, 88 base::Bind(&DomStorageCachedArea::OnClearComplete,
89 weak_factory_.GetWeakPtr())); 89 weak_factory_.GetWeakPtr()));
90 } 90 }
91 91
92 void DomStorageCachedArea::ApplyMutation( 92 void DomStorageCachedArea::ApplyMutation(
93 const NullableString16& key, const NullableString16& new_value) { 93 const base::NullableString16& key,
94 const base::NullableString16& new_value) {
94 if (!map_.get() || ignore_all_mutations_) 95 if (!map_.get() || ignore_all_mutations_)
95 return; 96 return;
96 97
97 if (key.is_null()) { 98 if (key.is_null()) {
98 // It's a clear event. 99 // It's a clear event.
99 scoped_refptr<DomStorageMap> old = map_; 100 scoped_refptr<DomStorageMap> old = map_;
100 map_ = new DomStorageMap(dom_storage::kPerAreaQuota); 101 map_ = new DomStorageMap(dom_storage::kPerAreaQuota);
101 102
102 // We have to retain local additions which happened after this 103 // We have to retain local additions which happened after this
103 // clear operation from another process. 104 // clear operation from another process.
104 std::map<base::string16, int>::iterator iter = 105 std::map<base::string16, int>::iterator iter =
105 ignore_key_mutations_.begin(); 106 ignore_key_mutations_.begin();
106 while (iter != ignore_key_mutations_.end()) { 107 while (iter != ignore_key_mutations_.end()) {
107 NullableString16 value = old->GetItem(iter->first); 108 base::NullableString16 value = old->GetItem(iter->first);
108 if (!value.is_null()) { 109 if (!value.is_null()) {
109 NullableString16 unused; 110 base::NullableString16 unused;
110 map_->SetItem(iter->first, value.string(), &unused); 111 map_->SetItem(iter->first, value.string(), &unused);
111 } 112 }
112 ++iter; 113 ++iter;
113 } 114 }
114 return; 115 return;
115 } 116 }
116 117
117 // We have to retain local changes. 118 // We have to retain local changes.
118 if (should_ignore_key_mutation(key.string())) 119 if (should_ignore_key_mutation(key.string()))
119 return; 120 return;
120 121
121 if (new_value.is_null()) { 122 if (new_value.is_null()) {
122 // It's a remove item event. 123 // It's a remove item event.
123 base::string16 unused; 124 base::string16 unused;
124 map_->RemoveItem(key.string(), &unused); 125 map_->RemoveItem(key.string(), &unused);
125 return; 126 return;
126 } 127 }
127 128
128 // It's a set item event. 129 // It's a set item event.
129 // We turn off quota checking here to accomodate the over budget 130 // We turn off quota checking here to accomodate the over budget
130 // allowance that's provided in the browser process. 131 // allowance that's provided in the browser process.
131 NullableString16 unused; 132 base::NullableString16 unused;
132 map_->set_quota(kint32max); 133 map_->set_quota(kint32max);
133 map_->SetItem(key.string(), new_value.string(), &unused); 134 map_->SetItem(key.string(), new_value.string(), &unused);
134 map_->set_quota(dom_storage::kPerAreaQuota); 135 map_->set_quota(dom_storage::kPerAreaQuota);
135 } 136 }
136 137
137 size_t DomStorageCachedArea::MemoryBytesUsedByCache() const { 138 size_t DomStorageCachedArea::MemoryBytesUsedByCache() const {
138 return map_.get() ? map_->bytes_used() : 0; 139 return map_.get() ? map_->bytes_used() : 0;
139 } 140 }
140 141
141 void DomStorageCachedArea::Prime(int connection_id) { 142 void DomStorageCachedArea::Prime(int connection_id) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 ignore_key_mutations_.erase(found); 222 ignore_key_mutations_.erase(found);
222 } 223 }
223 224
224 void DomStorageCachedArea::OnClearComplete(bool success) { 225 void DomStorageCachedArea::OnClearComplete(bool success) {
225 DCHECK(success); 226 DCHECK(success);
226 DCHECK(ignore_all_mutations_); 227 DCHECK(ignore_all_mutations_);
227 ignore_all_mutations_ = false; 228 ignore_all_mutations_ = false;
228 } 229 }
229 230
230 } // namespace dom_storage 231 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/renderer/dom_storage/dom_storage_cached_area.h ('k') | webkit/renderer/dom_storage/dom_storage_cached_area_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698