| 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 "content/browser/dom_storage/dom_storage_context_impl.h" | 5 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
| 6 | 6 |
| 7 #include <inttypes.h> | 7 #include <inttypes.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "base/trace_event/process_memory_dump.h" | 23 #include "base/trace_event/process_memory_dump.h" |
| 24 #include "content/browser/dom_storage/dom_storage_area.h" | 24 #include "content/browser/dom_storage/dom_storage_area.h" |
| 25 #include "content/browser/dom_storage/dom_storage_database.h" | 25 #include "content/browser/dom_storage/dom_storage_database.h" |
| 26 #include "content/browser/dom_storage/dom_storage_namespace.h" | 26 #include "content/browser/dom_storage/dom_storage_namespace.h" |
| 27 #include "content/browser/dom_storage/dom_storage_task_runner.h" | 27 #include "content/browser/dom_storage/dom_storage_task_runner.h" |
| 28 #include "content/browser/dom_storage/session_storage_database.h" | 28 #include "content/browser/dom_storage/session_storage_database.h" |
| 29 #include "content/common/dom_storage/dom_storage_types.h" | 29 #include "content/common/dom_storage/dom_storage_types.h" |
| 30 #include "content/public/browser/dom_storage_context.h" | 30 #include "content/public/browser/dom_storage_context.h" |
| 31 #include "content/public/browser/local_storage_usage_info.h" | 31 #include "content/public/browser/local_storage_usage_info.h" |
| 32 #include "content/public/browser/session_storage_usage_info.h" | 32 #include "content/public/browser/session_storage_usage_info.h" |
| 33 #include "content/public/common/origin_util.h" |
| 33 #include "storage/browser/quota/special_storage_policy.h" | 34 #include "storage/browser/quota/special_storage_policy.h" |
| 34 | 35 |
| 35 namespace content { | 36 namespace content { |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 // Limits on the cache size and number of areas in memory, over which the areas | 39 // Limits on the cache size and number of areas in memory, over which the areas |
| 39 // are purged. | 40 // are purged. |
| 40 #if defined(OS_ANDROID) | 41 #if defined(OS_ANDROID) |
| 41 const unsigned kMaxStorageAreaCount = 20; | 42 const unsigned kMaxStorageAreaCount = 20; |
| 42 const size_t kMaxCacheSize = 2 * 1024 * 1024; | 43 const size_t kMaxCacheSize = 2 * 1024 * 1024; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 info.persistent_namespace_id = it->first; | 197 info.persistent_namespace_id = it->first; |
| 197 info.origin = *origin_it; | 198 info.origin = *origin_it; |
| 198 infos->push_back(info); | 199 infos->push_back(info); |
| 199 } | 200 } |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 | 203 |
| 203 void DOMStorageContextImpl::DeleteLocalStorage(const GURL& origin) { | 204 void DOMStorageContextImpl::DeleteLocalStorage(const GURL& origin) { |
| 204 DCHECK(!is_shutdown_); | 205 DCHECK(!is_shutdown_); |
| 205 DOMStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); | 206 DOMStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); |
| 206 local->DeleteLocalStorageOrigin(origin); | 207 std::vector<GURL> origins; |
| 207 // Synthesize a 'cleared' event if the area is open so CachedAreas in | 208 local->GetOriginsWithAreas(&origins); |
| 208 // renderers get emptied out too. | 209 // Suborigin storage should be deleted in tandem with the physical origin's |
| 209 DOMStorageArea* area = local->GetOpenStorageArea(origin); | 210 // storage. https://w3c.github.io/webappsec-suborigins/ |
| 210 if (area) | 211 for (auto origin_candidate : origins) { |
| 211 NotifyAreaCleared(area, origin); | 212 // |origin| is guaranteed to be deleted below, so don't delete it until |
| 213 // then. |
| 214 if (origin_candidate == origin || |
| 215 StripSuboriginFromUrl(origin_candidate) != origin) { |
| 216 continue; |
| 217 } |
| 218 DeleteAndClearStorageNamespaceForOrigin(origin_candidate, local); |
| 219 } |
| 220 // It is important to always explicitly delete |origin|. If it does not appear |
| 221 // it |origins| above, there still may be a directory open in the namespace in |
| 222 // preparation for this storage, and this call will make sure that the |
| 223 // directory is deleted. |
| 224 DeleteAndClearStorageNamespaceForOrigin(origin, local); |
| 212 } | 225 } |
| 213 | 226 |
| 214 void DOMStorageContextImpl::DeleteSessionStorage( | 227 void DOMStorageContextImpl::DeleteSessionStorage( |
| 215 const SessionStorageUsageInfo& usage_info) { | 228 const SessionStorageUsageInfo& usage_info) { |
| 216 DCHECK(!is_shutdown_); | 229 DCHECK(!is_shutdown_); |
| 217 DOMStorageNamespace* dom_storage_namespace = NULL; | 230 DOMStorageNamespace* dom_storage_namespace = NULL; |
| 218 std::map<std::string, int64_t>::const_iterator it = | 231 std::map<std::string, int64_t>::const_iterator it = |
| 219 persistent_namespace_id_to_namespace_id_.find( | 232 persistent_namespace_id_to_namespace_id_.find( |
| 220 usage_info.persistent_namespace_id); | 233 usage_info.persistent_namespace_id); |
| 221 if (it != persistent_namespace_id_to_namespace_id_.end()) { | 234 if (it != persistent_namespace_id_to_namespace_id_.end()) { |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 deletable_persistent_namespace_ids_.pop_back(); | 616 deletable_persistent_namespace_ids_.pop_back(); |
| 604 if (!deletable_persistent_namespace_ids_.empty()) { | 617 if (!deletable_persistent_namespace_ids_.empty()) { |
| 605 task_runner_->PostDelayedTask( | 618 task_runner_->PostDelayedTask( |
| 606 FROM_HERE, base::Bind( | 619 FROM_HERE, base::Bind( |
| 607 &DOMStorageContextImpl::DeleteNextUnusedNamespace, | 620 &DOMStorageContextImpl::DeleteNextUnusedNamespace, |
| 608 this), | 621 this), |
| 609 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 622 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
| 610 } | 623 } |
| 611 } | 624 } |
| 612 | 625 |
| 626 void DOMStorageContextImpl::DeleteAndClearStorageNamespaceForOrigin( |
| 627 const GURL& origin, |
| 628 DOMStorageNamespace* local) { |
| 629 local->DeleteLocalStorageOrigin(origin); |
| 630 // Synthesize a 'cleared' event if the area is open so CachedAreas in |
| 631 // renderers get emptied out too. |
| 632 DOMStorageArea* area = local->GetOpenStorageArea(origin); |
| 633 if (area) |
| 634 NotifyAreaCleared(area, origin); |
| 635 } |
| 636 |
| 613 } // namespace content | 637 } // namespace content |
| OLD | NEW |