| 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" | |
| 34 #include "storage/browser/quota/special_storage_policy.h" | 33 #include "storage/browser/quota/special_storage_policy.h" |
| 34 #include "url/gurl.h" |
| 35 #include "url/origin.h" |
| 35 | 36 |
| 36 namespace content { | 37 namespace content { |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 // Limits on the cache size and number of areas in memory, over which the areas | 40 // Limits on the cache size and number of areas in memory, over which the areas |
| 40 // are purged. | 41 // are purged. |
| 41 #if defined(OS_ANDROID) | 42 #if defined(OS_ANDROID) |
| 42 const unsigned kMaxStorageAreaCount = 20; | 43 const unsigned kMaxStorageAreaCount = 20; |
| 43 const size_t kMaxCacheSize = 2 * 1024 * 1024; | 44 const size_t kMaxCacheSize = 2 * 1024 * 1024; |
| 44 #else | 45 #else |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 for (std::vector<GURL>::const_iterator origin_it = it->second.begin(); | 195 for (std::vector<GURL>::const_iterator origin_it = it->second.begin(); |
| 195 origin_it != it->second.end(); ++origin_it) { | 196 origin_it != it->second.end(); ++origin_it) { |
| 196 SessionStorageUsageInfo info; | 197 SessionStorageUsageInfo info; |
| 197 info.persistent_namespace_id = it->first; | 198 info.persistent_namespace_id = it->first; |
| 198 info.origin = *origin_it; | 199 info.origin = *origin_it; |
| 199 infos->push_back(info); | 200 infos->push_back(info); |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 } | 203 } |
| 203 | 204 |
| 204 void DOMStorageContextImpl::DeleteLocalStorage(const GURL& origin) { | 205 void DOMStorageContextImpl::DeleteLocalStorageForPhysicalOrigin( |
| 206 const GURL& origin_url) { |
| 205 DCHECK(!is_shutdown_); | 207 DCHECK(!is_shutdown_); |
| 208 url::Origin origin(origin_url); |
| 206 DOMStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); | 209 DOMStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); |
| 207 std::vector<GURL> origins; | 210 std::vector<GURL> origins; |
| 208 local->GetOriginsWithAreas(&origins); | 211 local->GetOriginsWithAreas(&origins); |
| 209 // Suborigin storage should be deleted in tandem with the physical origin's | 212 // Suborigin at the physical origin of |origin_url| should have their storage |
| 210 // storage. https://w3c.github.io/webappsec-suborigins/ | 213 // deleted as well. |
| 211 for (auto origin_candidate : origins) { | 214 // https://w3c.github.io/webappsec-suborigins/ |
| 215 for (const auto& origin_candidate_url : origins) { |
| 216 url::Origin origin_candidate(origin_candidate_url); |
| 212 // |origin| is guaranteed to be deleted below, so don't delete it until | 217 // |origin| is guaranteed to be deleted below, so don't delete it until |
| 213 // then. | 218 // then. That is, only suborigins at the same physical origin as |origin| |
| 214 if (origin_candidate == origin || | 219 // should be deleted at this point. |
| 215 StripSuboriginFromUrl(origin_candidate) != origin) { | 220 if (!origin_candidate.IsSameOriginWith(origin) && |
| 216 continue; | 221 origin_candidate.IsSamePhysicalOriginWith(origin)) { |
| 222 DeleteLocalStorage(origin_candidate_url); |
| 217 } | 223 } |
| 218 DeleteAndClearStorageNamespaceForOrigin(origin_candidate, local); | |
| 219 } | 224 } |
| 220 // It is important to always explicitly delete |origin|. If it does not appear | 225 // 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 | 226 // 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 | 227 // preparation for this storage, and this call will make sure that the |
| 223 // directory is deleted. | 228 // directory is deleted. |
| 224 DeleteAndClearStorageNamespaceForOrigin(origin, local); | 229 DeleteLocalStorage(origin_url); |
| 230 } |
| 231 |
| 232 void DOMStorageContextImpl::DeleteLocalStorage(const GURL& origin_url) { |
| 233 DOMStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); |
| 234 local->DeleteLocalStorageOrigin(origin_url); |
| 235 // Synthesize a 'cleared' event if the area is open so CachedAreas in |
| 236 // renderers get emptied out too. |
| 237 DOMStorageArea* area = local->GetOpenStorageArea(origin_url); |
| 238 if (area) |
| 239 NotifyAreaCleared(area, origin_url); |
| 225 } | 240 } |
| 226 | 241 |
| 227 void DOMStorageContextImpl::DeleteSessionStorage( | 242 void DOMStorageContextImpl::DeleteSessionStorage( |
| 228 const SessionStorageUsageInfo& usage_info) { | 243 const SessionStorageUsageInfo& usage_info) { |
| 229 DCHECK(!is_shutdown_); | 244 DCHECK(!is_shutdown_); |
| 230 DOMStorageNamespace* dom_storage_namespace = NULL; | 245 DOMStorageNamespace* dom_storage_namespace = NULL; |
| 231 std::map<std::string, int64_t>::const_iterator it = | 246 std::map<std::string, int64_t>::const_iterator it = |
| 232 persistent_namespace_id_to_namespace_id_.find( | 247 persistent_namespace_id_to_namespace_id_.find( |
| 233 usage_info.persistent_namespace_id); | 248 usage_info.persistent_namespace_id); |
| 234 if (it != persistent_namespace_id_to_namespace_id_.end()) { | 249 if (it != persistent_namespace_id_to_namespace_id_.end()) { |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 deletable_persistent_namespace_ids_.pop_back(); | 628 deletable_persistent_namespace_ids_.pop_back(); |
| 614 if (!deletable_persistent_namespace_ids_.empty()) { | 629 if (!deletable_persistent_namespace_ids_.empty()) { |
| 615 task_runner_->PostDelayedTask( | 630 task_runner_->PostDelayedTask( |
| 616 FROM_HERE, base::Bind( | 631 FROM_HERE, base::Bind( |
| 617 &DOMStorageContextImpl::DeleteNextUnusedNamespace, | 632 &DOMStorageContextImpl::DeleteNextUnusedNamespace, |
| 618 this), | 633 this), |
| 619 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 634 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
| 620 } | 635 } |
| 621 } | 636 } |
| 622 | 637 |
| 623 void DOMStorageContextImpl::DeleteAndClearStorageNamespaceForOrigin( | |
| 624 const GURL& origin, | |
| 625 DOMStorageNamespace* local) { | |
| 626 local->DeleteLocalStorageOrigin(origin); | |
| 627 // Synthesize a 'cleared' event if the area is open so CachedAreas in | |
| 628 // renderers get emptied out too. | |
| 629 DOMStorageArea* area = local->GetOpenStorageArea(origin); | |
| 630 if (area) | |
| 631 NotifyAreaCleared(area, origin); | |
| 632 } | |
| 633 | |
| 634 } // namespace content | 638 } // namespace content |
| OLD | NEW |