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); | |
209 DCHECK(origin.suborigin().empty()); | |
michaeln
2016/10/21 23:07:12
if we redefine the semantics as described i the .h
jww
2016/10/22 00:43:12
Done.
| |
206 DOMStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); | 210 DOMStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); |
207 std::vector<GURL> origins; | 211 std::vector<GURL> origins; |
208 local->GetOriginsWithAreas(&origins); | 212 local->GetOriginsWithAreas(&origins); |
209 // Suborigin storage should be deleted in tandem with the physical origin's | 213 // Suborigin at the physical origin of |origin_url| should have their storage |
210 // storage. https://w3c.github.io/webappsec-suborigins/ | 214 // deleted as well. Since suborigins are not allowed to be sent to the method, |
211 for (auto origin_candidate : origins) { | 215 // there is no need to be concerned with the inverse case. |
216 // https://w3c.github.io/webappsec-suborigins/ | |
217 for (const auto& origin_candidate_url : origins) { | |
218 url::Origin origin_candidate(origin_candidate_url); | |
212 // |origin| is guaranteed to be deleted below, so don't delete it until | 219 // |origin| is guaranteed to be deleted below, so don't delete it until |
213 // then. | 220 // then. That is, only suborigins at the same physical origin as |origin| |
214 if (origin_candidate == origin || | 221 // should be deleted at this point. |
215 StripSuboriginFromUrl(origin_candidate) != origin) { | 222 if (origin_candidate.IsSameOriginWith(origin) || |
223 !origin_candidate.IsSamePhysicalOriginWith(origin)) { | |
216 continue; | 224 continue; |
217 } | 225 } |
218 DeleteAndClearStorageNamespaceForOrigin(origin_candidate, local); | 226 DeleteAndClearStorageNamespaceForOrigin(origin_candidate_url, local); |
michaeln
2016/10/21 23:07:12
call DeleteLocalStorage here and on line 232
jww
2016/10/22 00:43:12
Done.
| |
219 } | 227 } |
220 // It is important to always explicitly delete |origin|. If it does not appear | 228 // 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 | 229 // 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 | 230 // preparation for this storage, and this call will make sure that the |
223 // directory is deleted. | 231 // directory is deleted. |
224 DeleteAndClearStorageNamespaceForOrigin(origin, local); | 232 DeleteAndClearStorageNamespaceForOrigin(origin_url, local); |
233 } | |
234 | |
235 void DOMStorageContextImpl::DeleteLocalStorage(const GURL& origin_url) { | |
michaeln
2016/10/21 23:07:12
make this method do what DeleteAndClearStorageName
jww
2016/10/22 00:43:12
Done.
| |
236 url::Origin origin(origin_url); | |
237 DeleteLocalStorageForPhysicalOrigin(origin.GetPhysicalOrigin().GetURL()); | |
225 } | 238 } |
226 | 239 |
227 void DOMStorageContextImpl::DeleteSessionStorage( | 240 void DOMStorageContextImpl::DeleteSessionStorage( |
228 const SessionStorageUsageInfo& usage_info) { | 241 const SessionStorageUsageInfo& usage_info) { |
229 DCHECK(!is_shutdown_); | 242 DCHECK(!is_shutdown_); |
230 DOMStorageNamespace* dom_storage_namespace = NULL; | 243 DOMStorageNamespace* dom_storage_namespace = NULL; |
231 std::map<std::string, int64_t>::const_iterator it = | 244 std::map<std::string, int64_t>::const_iterator it = |
232 persistent_namespace_id_to_namespace_id_.find( | 245 persistent_namespace_id_to_namespace_id_.find( |
233 usage_info.persistent_namespace_id); | 246 usage_info.persistent_namespace_id); |
234 if (it != persistent_namespace_id_to_namespace_id_.end()) { | 247 if (it != persistent_namespace_id_to_namespace_id_.end()) { |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 if (!deletable_persistent_namespace_ids_.empty()) { | 627 if (!deletable_persistent_namespace_ids_.empty()) { |
615 task_runner_->PostDelayedTask( | 628 task_runner_->PostDelayedTask( |
616 FROM_HERE, base::Bind( | 629 FROM_HERE, base::Bind( |
617 &DOMStorageContextImpl::DeleteNextUnusedNamespace, | 630 &DOMStorageContextImpl::DeleteNextUnusedNamespace, |
618 this), | 631 this), |
619 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 632 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
620 } | 633 } |
621 } | 634 } |
622 | 635 |
623 void DOMStorageContextImpl::DeleteAndClearStorageNamespaceForOrigin( | 636 void DOMStorageContextImpl::DeleteAndClearStorageNamespaceForOrigin( |
624 const GURL& origin, | 637 const GURL& origin_url, |
625 DOMStorageNamespace* local) { | 638 DOMStorageNamespace* local) { |
626 local->DeleteLocalStorageOrigin(origin); | 639 local->DeleteLocalStorageOrigin(origin_url); |
627 // Synthesize a 'cleared' event if the area is open so CachedAreas in | 640 // Synthesize a 'cleared' event if the area is open so CachedAreas in |
628 // renderers get emptied out too. | 641 // renderers get emptied out too. |
629 DOMStorageArea* area = local->GetOpenStorageArea(origin); | 642 DOMStorageArea* area = local->GetOpenStorageArea(origin_url); |
630 if (area) | 643 if (area) |
631 NotifyAreaCleared(area, origin); | 644 NotifyAreaCleared(area, origin_url); |
632 } | 645 } |
633 | 646 |
634 } // namespace content | 647 } // namespace content |
OLD | NEW |