| OLD | NEW |
| 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" |
| 11 #include "webkit/dom_storage/dom_storage_proxy.h" | 11 #include "webkit/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 int64 storage_size) |
| 17 : ignore_all_mutations_(false), | 18 : ignore_all_mutations_(false), |
| 18 namespace_id_(namespace_id), origin_(origin), | 19 namespace_id_(namespace_id), origin_(origin), |
| 19 proxy_(proxy), weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 20 proxy_(proxy), weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 21 global_storage_size_(storage_size) { |
| 20 } | 22 } |
| 21 | 23 |
| 22 DomStorageCachedArea::~DomStorageCachedArea() { | 24 DomStorageCachedArea::~DomStorageCachedArea() { |
| 23 } | 25 } |
| 24 | 26 |
| 25 unsigned DomStorageCachedArea::GetLength(int connection_id) { | 27 unsigned DomStorageCachedArea::GetLength(int connection_id) { |
| 26 PrimeIfNeeded(connection_id); | 28 PrimeIfNeeded(connection_id); |
| 27 return map_->Length(); | 29 return map_->Length(); |
| 28 } | 30 } |
| 29 | 31 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 40 } | 42 } |
| 41 | 43 |
| 42 bool DomStorageCachedArea::SetItem( | 44 bool DomStorageCachedArea::SetItem( |
| 43 int connection_id, const string16& key, | 45 int connection_id, const string16& key, |
| 44 const string16& value, const GURL& page_url) { | 46 const string16& value, const GURL& page_url) { |
| 45 // A quick check to reject obviously overbudget items to avoid | 47 // A quick check to reject obviously overbudget items to avoid |
| 46 // the priming the cache. | 48 // the priming the cache. |
| 47 if (key.length() + value.length() > dom_storage::kPerAreaQuota) | 49 if (key.length() + value.length() > dom_storage::kPerAreaQuota) |
| 48 return false; | 50 return false; |
| 49 | 51 |
| 52 // TENTATIVE: Limit the global data to 512MB. |
| 53 if (key.length() + value.length() + global_storage_size_ |
| 54 > 512 * 1024 * 1024) { |
| 55 return false; |
| 56 } |
| 57 |
| 50 PrimeIfNeeded(connection_id); | 58 PrimeIfNeeded(connection_id); |
| 51 NullableString16 unused; | 59 NullableString16 unused; |
| 52 if (!map_->SetItem(key, value, &unused)) | 60 if (!map_->SetItem(key, value, &unused)) |
| 53 return false; | 61 return false; |
| 54 | 62 |
| 55 // Ignore mutations to 'key' until OnSetItemComplete. | 63 // Ignore mutations to 'key' until OnSetItemComplete. |
| 56 ignore_key_mutations_[key]++; | 64 ignore_key_mutations_[key]++; |
| 57 proxy_->SetItem( | 65 proxy_->SetItem( |
| 58 connection_id, key, value, page_url, | 66 connection_id, key, value, page_url, |
| 59 base::Bind(&DomStorageCachedArea::OnSetItemComplete, | 67 base::Bind(&DomStorageCachedArea::OnSetItemComplete, |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 ignore_key_mutations_.erase(found); | 226 ignore_key_mutations_.erase(found); |
| 219 } | 227 } |
| 220 | 228 |
| 221 void DomStorageCachedArea::OnClearComplete(bool success) { | 229 void DomStorageCachedArea::OnClearComplete(bool success) { |
| 222 DCHECK(success); | 230 DCHECK(success); |
| 223 DCHECK(ignore_all_mutations_); | 231 DCHECK(ignore_all_mutations_); |
| 224 ignore_all_mutations_ = false; | 232 ignore_all_mutations_ = false; |
| 225 } | 233 } |
| 226 | 234 |
| 227 } // namespace dom_storage | 235 } // namespace dom_storage |
| OLD | NEW |