OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/renderer/dom_storage/local_storage_cached_area.h" | 5 #include "content/renderer/dom_storage/local_storage_cached_area.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "content/common/dom_storage/dom_storage_map.h" | 14 #include "content/common/dom_storage/dom_storage_map.h" |
15 #include "content/common/storage_partition_service.mojom.h" | 15 #include "content/common/storage_partition_service.mojom.h" |
16 #include "content/renderer/dom_storage/local_storage_area.h" | 16 #include "content/renderer/dom_storage/local_storage_area.h" |
17 #include "content/renderer/dom_storage/local_storage_cached_areas.h" | 17 #include "content/renderer/dom_storage/local_storage_cached_areas.h" |
18 #include "third_party/WebKit/public/platform/WebURL.h" | 18 #include "third_party/WebKit/public/platform/WebURL.h" |
19 #include "third_party/WebKit/public/web/WebStorageEventDispatcher.h" | 19 #include "third_party/WebKit/public/web/WebStorageEventDispatcher.h" |
20 #include "url/gurl.h" | |
21 | 20 |
22 namespace { | 21 namespace { |
23 | 22 |
24 base::string16 Uint8VectorToString16(const std::vector<uint8_t>& input) { | 23 base::string16 Uint8VectorToString16(const std::vector<uint8_t>& input) { |
25 return base::string16(reinterpret_cast<const base::char16*>(input.data()), | 24 return base::string16(reinterpret_cast<const base::char16*>(input.data()), |
26 input.size() / sizeof(base::char16)); | 25 input.size() / sizeof(base::char16)); |
27 } | 26 } |
28 | 27 |
29 std::vector<uint8_t> String16ToUint8Vector(const base::string16& input) { | 28 std::vector<uint8_t> String16ToUint8Vector(const base::string16& input) { |
30 const uint8_t* data = reinterpret_cast<const uint8_t*>(input.data()); | 29 const uint8_t* data = reinterpret_cast<const uint8_t*>(input.data()); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // for the confirmation callback. In the latter case, we won't do anything | 174 // for the confirmation callback. In the latter case, we won't do anything |
176 // because ignore_key_mutations_ won't be updated until the callback runs. | 175 // because ignore_key_mutations_ won't be updated until the callback runs. |
177 if (ignore_key_mutations_.find(key_string) != ignore_key_mutations_.end()) { | 176 if (ignore_key_mutations_.find(key_string) != ignore_key_mutations_.end()) { |
178 base::string16 unused; | 177 base::string16 unused; |
179 map_->RemoveItem(key_string, &unused); | 178 map_->RemoveItem(key_string, &unused); |
180 } | 179 } |
181 } | 180 } |
182 | 181 |
183 blink::WebStorageEventDispatcher::dispatchLocalStorageEvent( | 182 blink::WebStorageEventDispatcher::dispatchLocalStorageEvent( |
184 key_string, Uint8VectorToString16(old_value), base::NullableString16(), | 183 key_string, Uint8VectorToString16(old_value), base::NullableString16(), |
185 GURL(origin_.Serialize()), page_url, originating_area); | 184 origin_.GetURL(), page_url, originating_area); |
186 } | 185 } |
187 | 186 |
188 void LocalStorageCachedArea::AllDeleted(const std::string& source) { | 187 void LocalStorageCachedArea::AllDeleted(const std::string& source) { |
189 GURL page_url; | 188 GURL page_url; |
190 std::string storage_area_id; | 189 std::string storage_area_id; |
191 UnpackSource(source, &page_url, &storage_area_id); | 190 UnpackSource(source, &page_url, &storage_area_id); |
192 | 191 |
193 blink::WebStorageArea* originating_area = nullptr; | 192 blink::WebStorageArea* originating_area = nullptr; |
194 if (areas_.find(storage_area_id) != areas_.end()) { | 193 if (areas_.find(storage_area_id) != areas_.end()) { |
195 // The source storage area is in this process. | 194 // The source storage area is in this process. |
(...skipping 10 matching lines...) Expand all Loading... |
206 if (!value.is_null()) { | 205 if (!value.is_null()) { |
207 base::NullableString16 unused; | 206 base::NullableString16 unused; |
208 map_->SetItem(iter->first, value.string(), &unused); | 207 map_->SetItem(iter->first, value.string(), &unused); |
209 } | 208 } |
210 ++iter; | 209 ++iter; |
211 } | 210 } |
212 } | 211 } |
213 | 212 |
214 blink::WebStorageEventDispatcher::dispatchLocalStorageEvent( | 213 blink::WebStorageEventDispatcher::dispatchLocalStorageEvent( |
215 base::NullableString16(), base::NullableString16(), | 214 base::NullableString16(), base::NullableString16(), |
216 base::NullableString16(), GURL(origin_.Serialize()), page_url, | 215 base::NullableString16(), origin_.GetURL(), page_url, originating_area); |
217 originating_area); | |
218 } | 216 } |
219 | 217 |
220 void LocalStorageCachedArea::GetAllComplete(const std::string& source) { | 218 void LocalStorageCachedArea::GetAllComplete(const std::string& source) { |
221 // Since the GetAll method is synchronous, we need this asynchronously | 219 // Since the GetAll method is synchronous, we need this asynchronously |
222 // delivered notification to avoid applying changes to the returned array | 220 // delivered notification to avoid applying changes to the returned array |
223 // that we already have. | 221 // that we already have. |
224 if (source == get_all_request_id_) { | 222 if (source == get_all_request_id_) { |
225 DCHECK(ignore_all_mutations_); | 223 DCHECK(ignore_all_mutations_); |
226 DCHECK(!get_all_request_id_.empty()); | 224 DCHECK(!get_all_request_id_.empty()); |
227 ignore_all_mutations_ = false; | 225 ignore_all_mutations_ = false; |
(...skipping 26 matching lines...) Expand all Loading... |
254 // We turn off quota checking here to accomodate the over budget allowance | 252 // We turn off quota checking here to accomodate the over budget allowance |
255 // that's provided in the browser process. | 253 // that's provided in the browser process. |
256 base::NullableString16 unused; | 254 base::NullableString16 unused; |
257 map_->set_quota(std::numeric_limits<int32_t>::max()); | 255 map_->set_quota(std::numeric_limits<int32_t>::max()); |
258 map_->SetItem(key_string, new_value_string, &unused); | 256 map_->SetItem(key_string, new_value_string, &unused); |
259 map_->set_quota(kPerStorageAreaQuota); | 257 map_->set_quota(kPerStorageAreaQuota); |
260 } | 258 } |
261 } | 259 } |
262 | 260 |
263 blink::WebStorageEventDispatcher::dispatchLocalStorageEvent( | 261 blink::WebStorageEventDispatcher::dispatchLocalStorageEvent( |
264 key_string, old_value, new_value_string, | 262 key_string, old_value, new_value_string, origin_.GetURL(), page_url, |
265 GURL(origin_.Serialize()), page_url, originating_area); | 263 originating_area); |
266 | |
267 } | 264 } |
268 | 265 |
269 void LocalStorageCachedArea::EnsureLoaded() { | 266 void LocalStorageCachedArea::EnsureLoaded() { |
270 if (map_) | 267 if (map_) |
271 return; | 268 return; |
272 | 269 |
273 base::TimeTicks before = base::TimeTicks::Now(); | 270 base::TimeTicks before = base::TimeTicks::Now(); |
274 ignore_all_mutations_ = true; | 271 ignore_all_mutations_ = true; |
275 get_all_request_id_ = base::Uint64ToString(base::RandUint64()); | 272 get_all_request_id_ = base::Uint64ToString(base::RandUint64()); |
276 leveldb::mojom::DatabaseError status = leveldb::mojom::DatabaseError::OK; | 273 leveldb::mojom::DatabaseError status = leveldb::mojom::DatabaseError::OK; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 } | 334 } |
338 | 335 |
339 void LocalStorageCachedArea::Reset() { | 336 void LocalStorageCachedArea::Reset() { |
340 map_ = NULL; | 337 map_ = NULL; |
341 ignore_key_mutations_.clear(); | 338 ignore_key_mutations_.clear(); |
342 ignore_all_mutations_ = false; | 339 ignore_all_mutations_ = false; |
343 weak_factory_.InvalidateWeakPtrs(); | 340 weak_factory_.InvalidateWeakPtrs(); |
344 } | 341 } |
345 | 342 |
346 } // namespace content | 343 } // namespace content |
OLD | NEW |