| 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/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 std::vector<std::string> result = base::SplitString( | 32 std::vector<std::string> result = base::SplitString( |
| 33 source.To<std::string>(), "\n", base::KEEP_WHITESPACE, | 33 source.To<std::string>(), "\n", base::KEEP_WHITESPACE, |
| 34 base::SPLIT_WANT_ALL); | 34 base::SPLIT_WANT_ALL); |
| 35 DCHECK_EQ(result.size(), 2u); | 35 DCHECK_EQ(result.size(), 2u); |
| 36 *page_url = GURL(result[0]); | 36 *page_url = GURL(result[0]); |
| 37 *storage_area_id = result[1]; | 37 *storage_area_id = result[1]; |
| 38 } | 38 } |
| 39 | 39 |
| 40 LocalStorageCachedArea::LocalStorageCachedArea( | 40 LocalStorageCachedArea::LocalStorageCachedArea( |
| 41 const url::Origin& origin, | 41 const url::Origin& origin, |
| 42 StoragePartitionService* storage_partition_service, | 42 mojom::StoragePartitionService* storage_partition_service, |
| 43 LocalStorageCachedAreas* cached_areas) | 43 LocalStorageCachedAreas* cached_areas) |
| 44 : origin_(origin), binding_(this), | 44 : origin_(origin), binding_(this), cached_areas_(cached_areas) { |
| 45 cached_areas_(cached_areas) { | |
| 46 storage_partition_service->OpenLocalStorage( | 45 storage_partition_service->OpenLocalStorage( |
| 47 origin_, mojo::GetProxy(&leveldb_)); | 46 origin_, mojo::GetProxy(&leveldb_)); |
| 48 } | 47 } |
| 49 | 48 |
| 50 LocalStorageCachedArea::~LocalStorageCachedArea() { | 49 LocalStorageCachedArea::~LocalStorageCachedArea() { |
| 51 cached_areas_->CacheAreaClosed(this); | 50 cached_areas_->CacheAreaClosed(this); |
| 52 } | 51 } |
| 53 | 52 |
| 54 unsigned LocalStorageCachedArea::GetLength() { | 53 unsigned LocalStorageCachedArea::GetLength() { |
| 55 EnsureLoaded(); | 54 EnsureLoaded(); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 base::NullableString16(), GURL(origin_.Serialize()), page_url, | 222 base::NullableString16(), GURL(origin_.Serialize()), page_url, |
| 224 originating_area); | 223 originating_area); |
| 225 } | 224 } |
| 226 | 225 |
| 227 void LocalStorageCachedArea::EnsureLoaded() { | 226 void LocalStorageCachedArea::EnsureLoaded() { |
| 228 if (map_) | 227 if (map_) |
| 229 return; | 228 return; |
| 230 | 229 |
| 231 base::TimeTicks before = base::TimeTicks::Now(); | 230 base::TimeTicks before = base::TimeTicks::Now(); |
| 232 leveldb::DatabaseError status = leveldb::DatabaseError::OK; | 231 leveldb::DatabaseError status = leveldb::DatabaseError::OK; |
| 233 mojo::Array<content::KeyValuePtr> data; | 232 mojo::Array<content::mojom::KeyValuePtr> data; |
| 234 leveldb_->GetAll(binding_.CreateInterfacePtrAndBind(), &status, &data); | 233 leveldb_->GetAll(binding_.CreateInterfacePtrAndBind(), &status, &data); |
| 235 | 234 |
| 236 DOMStorageValuesMap values; | 235 DOMStorageValuesMap values; |
| 237 for (size_t i = 0; i < data.size(); ++i) { | 236 for (size_t i = 0; i < data.size(); ++i) { |
| 238 values[data[i]->key.To<base::string16>()] = | 237 values[data[i]->key.To<base::string16>()] = |
| 239 base::NullableString16(data[i]->value.To<base::string16>(), false); | 238 base::NullableString16(data[i]->value.To<base::string16>(), false); |
| 240 } | 239 } |
| 241 | 240 |
| 242 map_ = new DOMStorageMap(kPerStorageAreaQuota); | 241 map_ = new DOMStorageMap(kPerStorageAreaQuota); |
| 243 map_->SwapValues(&values); | 242 map_->SwapValues(&values); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 DCHECK_EQ(result, leveldb::DatabaseError::OK); | 289 DCHECK_EQ(result, leveldb::DatabaseError::OK); |
| 291 } | 290 } |
| 292 | 291 |
| 293 void LocalStorageCachedArea::Reset() { | 292 void LocalStorageCachedArea::Reset() { |
| 294 binding_.Close(); | 293 binding_.Close(); |
| 295 map_ = NULL; | 294 map_ = NULL; |
| 296 ignore_key_mutations_.clear(); | 295 ignore_key_mutations_.clear(); |
| 297 } | 296 } |
| 298 | 297 |
| 299 } // namespace content | 298 } // namespace content |
| OLD | NEW |