| 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/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // remove it from our cache if we haven't already changed it and are waiting | 200 // remove it from our cache if we haven't already changed it and are waiting |
| 201 // for the confirmation callback. In the latter case, we won't do anything | 201 // for the confirmation callback. In the latter case, we won't do anything |
| 202 // because ignore_key_mutations_ won't be updated until the callback runs. | 202 // because ignore_key_mutations_ won't be updated until the callback runs. |
| 203 if (ignore_key_mutations_.find(key_string) != ignore_key_mutations_.end()) { | 203 if (ignore_key_mutations_.find(key_string) != ignore_key_mutations_.end()) { |
| 204 base::string16 unused; | 204 base::string16 unused; |
| 205 map_->RemoveItem(key_string, &unused); | 205 map_->RemoveItem(key_string, &unused); |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 | 208 |
| 209 blink::WebStorageEventDispatcher::dispatchLocalStorageEvent( | 209 blink::WebStorageEventDispatcher::dispatchLocalStorageEvent( |
| 210 key_string, Uint8VectorToString16(old_value), base::NullableString16(), | 210 blink::WebString::fromUTF16(key_string), |
| 211 origin_.GetURL(), page_url, originating_area); | 211 blink::WebString::fromUTF16(Uint8VectorToString16(old_value)), |
| 212 blink::WebString(), origin_.GetURL(), page_url, originating_area); |
| 212 } | 213 } |
| 213 | 214 |
| 214 void LocalStorageCachedArea::AllDeleted(const std::string& source) { | 215 void LocalStorageCachedArea::AllDeleted(const std::string& source) { |
| 215 GURL page_url; | 216 GURL page_url; |
| 216 std::string storage_area_id; | 217 std::string storage_area_id; |
| 217 UnpackSource(source, &page_url, &storage_area_id); | 218 UnpackSource(source, &page_url, &storage_area_id); |
| 218 | 219 |
| 219 blink::WebStorageArea* originating_area = nullptr; | 220 blink::WebStorageArea* originating_area = nullptr; |
| 220 if (areas_.find(storage_area_id) != areas_.end()) { | 221 if (areas_.find(storage_area_id) != areas_.end()) { |
| 221 // The source storage area is in this process. | 222 // The source storage area is in this process. |
| 222 originating_area = areas_[storage_area_id]; | 223 originating_area = areas_[storage_area_id]; |
| 223 } else if (map_ && !ignore_all_mutations_) { | 224 } else if (map_ && !ignore_all_mutations_) { |
| 224 scoped_refptr<DOMStorageMap> old = map_; | 225 scoped_refptr<DOMStorageMap> old = map_; |
| 225 map_ = new DOMStorageMap(kPerStorageAreaQuota); | 226 map_ = new DOMStorageMap(kPerStorageAreaQuota); |
| 226 | 227 |
| 227 // We have to retain local additions which happened after this clear | 228 // We have to retain local additions which happened after this clear |
| 228 // operation from another process. | 229 // operation from another process. |
| 229 auto iter = ignore_key_mutations_.begin(); | 230 auto iter = ignore_key_mutations_.begin(); |
| 230 while (iter != ignore_key_mutations_.end()) { | 231 while (iter != ignore_key_mutations_.end()) { |
| 231 base::NullableString16 value = old->GetItem(iter->first); | 232 base::NullableString16 value = old->GetItem(iter->first); |
| 232 if (!value.is_null()) { | 233 if (!value.is_null()) { |
| 233 base::NullableString16 unused; | 234 base::NullableString16 unused; |
| 234 map_->SetItem(iter->first, value.string(), &unused); | 235 map_->SetItem(iter->first, value.string(), &unused); |
| 235 } | 236 } |
| 236 ++iter; | 237 ++iter; |
| 237 } | 238 } |
| 238 } | 239 } |
| 239 | 240 |
| 240 blink::WebStorageEventDispatcher::dispatchLocalStorageEvent( | 241 blink::WebStorageEventDispatcher::dispatchLocalStorageEvent( |
| 241 base::NullableString16(), base::NullableString16(), | 242 blink::WebString(), blink::WebString(), blink::WebString(), |
| 242 base::NullableString16(), origin_.GetURL(), page_url, originating_area); | 243 origin_.GetURL(), page_url, originating_area); |
| 243 } | 244 } |
| 244 | 245 |
| 245 void LocalStorageCachedArea::KeyAddedOrChanged( | 246 void LocalStorageCachedArea::KeyAddedOrChanged( |
| 246 const std::vector<uint8_t>& key, | 247 const std::vector<uint8_t>& key, |
| 247 const std::vector<uint8_t>& new_value, | 248 const std::vector<uint8_t>& new_value, |
| 248 const base::NullableString16& old_value, | 249 const base::NullableString16& old_value, |
| 249 const std::string& source) { | 250 const std::string& source) { |
| 250 GURL page_url; | 251 GURL page_url; |
| 251 std::string storage_area_id; | 252 std::string storage_area_id; |
| 252 UnpackSource(source, &page_url, &storage_area_id); | 253 UnpackSource(source, &page_url, &storage_area_id); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 267 // We turn off quota checking here to accomodate the over budget allowance | 268 // We turn off quota checking here to accomodate the over budget allowance |
| 268 // that's provided in the browser process. | 269 // that's provided in the browser process. |
| 269 base::NullableString16 unused; | 270 base::NullableString16 unused; |
| 270 map_->set_quota(std::numeric_limits<int32_t>::max()); | 271 map_->set_quota(std::numeric_limits<int32_t>::max()); |
| 271 map_->SetItem(key_string, new_value_string, &unused); | 272 map_->SetItem(key_string, new_value_string, &unused); |
| 272 map_->set_quota(kPerStorageAreaQuota); | 273 map_->set_quota(kPerStorageAreaQuota); |
| 273 } | 274 } |
| 274 } | 275 } |
| 275 | 276 |
| 276 blink::WebStorageEventDispatcher::dispatchLocalStorageEvent( | 277 blink::WebStorageEventDispatcher::dispatchLocalStorageEvent( |
| 277 key_string, old_value, new_value_string, origin_.GetURL(), page_url, | 278 blink::WebString::fromUTF16(key_string), |
| 279 blink::WebString::fromUTF16(old_value), |
| 280 blink::WebString::fromUTF16(new_value_string), origin_.GetURL(), page_url, |
| 278 originating_area); | 281 originating_area); |
| 279 } | 282 } |
| 280 | 283 |
| 281 void LocalStorageCachedArea::EnsureLoaded() { | 284 void LocalStorageCachedArea::EnsureLoaded() { |
| 282 if (map_) | 285 if (map_) |
| 283 return; | 286 return; |
| 284 | 287 |
| 285 base::TimeTicks before = base::TimeTicks::Now(); | 288 base::TimeTicks before = base::TimeTicks::Now(); |
| 286 ignore_all_mutations_ = true; | 289 ignore_all_mutations_ = true; |
| 287 leveldb::mojom::DatabaseError status = leveldb::mojom::DatabaseError::OK; | 290 leveldb::mojom::DatabaseError status = leveldb::mojom::DatabaseError::OK; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 364 } |
| 362 | 365 |
| 363 void LocalStorageCachedArea::Reset() { | 366 void LocalStorageCachedArea::Reset() { |
| 364 map_ = NULL; | 367 map_ = NULL; |
| 365 ignore_key_mutations_.clear(); | 368 ignore_key_mutations_.clear(); |
| 366 ignore_all_mutations_ = false; | 369 ignore_all_mutations_ = false; |
| 367 weak_factory_.InvalidateWeakPtrs(); | 370 weak_factory_.InvalidateWeakPtrs(); |
| 368 } | 371 } |
| 369 | 372 |
| 370 } // namespace content | 373 } // namespace content |
| OLD | NEW |