Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: content/browser/dom_storage/dom_storage_context_impl.cc

Issue 2403713002: Add suborigin logic to url::Origin (Closed)
Patch Set: Rebase on ToT Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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::DeleteLocalStorage(const GURL& origin_url) {
205 DCHECK(!is_shutdown_); 206 DCHECK(!is_shutdown_);
207 url::Origin origin(origin_url);
206 DOMStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); 208 DOMStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId);
207 std::vector<GURL> origins; 209 std::vector<GURL> origins;
208 local->GetOriginsWithAreas(&origins); 210 local->GetOriginsWithAreas(&origins);
209 // Suborigin storage should be deleted in tandem with the physical origin's 211 // Suborigin storage should be deleted in tandem with the physical origin's
210 // storage. https://w3c.github.io/webappsec-suborigins/ 212 // storage and vice versa. https://w3c.github.io/webappsec-suborigins/
211 for (auto origin_candidate : origins) { 213 for (const auto& origin_candidate_url : origins) {
214 url::Origin origin_candidate(origin_candidate_url);
212 // |origin| is guaranteed to be deleted below, so don't delete it until 215 // |origin| is guaranteed to be deleted below, so don't delete it until
213 // then. 216 // then. That is, only suborigins at the same physical origin as |origin|
214 if (origin_candidate == origin || 217 // should be deleted at this point.
215 StripSuboriginFromUrl(origin_candidate) != origin) { 218 if (origin_candidate.IsSameOriginWith(origin) ||
219 !origin_candidate.IsSamePhysicalOriginWith(origin)) {
216 continue; 220 continue;
217 } 221 }
218 DeleteAndClearStorageNamespaceForOrigin(origin_candidate, local); 222 DeleteAndClearStorageNamespaceForOrigin(origin_candidate_url, local);
219 } 223 }
220 // It is important to always explicitly delete |origin|. If it does not appear 224 // 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 225 // 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 226 // preparation for this storage, and this call will make sure that the
223 // directory is deleted. 227 // directory is deleted.
224 DeleteAndClearStorageNamespaceForOrigin(origin, local); 228 DeleteAndClearStorageNamespaceForOrigin(origin_url, local);
225 } 229 }
226 230
227 void DOMStorageContextImpl::DeleteSessionStorage( 231 void DOMStorageContextImpl::DeleteSessionStorage(
228 const SessionStorageUsageInfo& usage_info) { 232 const SessionStorageUsageInfo& usage_info) {
229 DCHECK(!is_shutdown_); 233 DCHECK(!is_shutdown_);
230 DOMStorageNamespace* dom_storage_namespace = NULL; 234 DOMStorageNamespace* dom_storage_namespace = NULL;
231 std::map<std::string, int64_t>::const_iterator it = 235 std::map<std::string, int64_t>::const_iterator it =
232 persistent_namespace_id_to_namespace_id_.find( 236 persistent_namespace_id_to_namespace_id_.find(
233 usage_info.persistent_namespace_id); 237 usage_info.persistent_namespace_id);
234 if (it != persistent_namespace_id_to_namespace_id_.end()) { 238 if (it != persistent_namespace_id_to_namespace_id_.end()) {
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 if (!deletable_persistent_namespace_ids_.empty()) { 618 if (!deletable_persistent_namespace_ids_.empty()) {
615 task_runner_->PostDelayedTask( 619 task_runner_->PostDelayedTask(
616 FROM_HERE, base::Bind( 620 FROM_HERE, base::Bind(
617 &DOMStorageContextImpl::DeleteNextUnusedNamespace, 621 &DOMStorageContextImpl::DeleteNextUnusedNamespace,
618 this), 622 this),
619 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); 623 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds));
620 } 624 }
621 } 625 }
622 626
623 void DOMStorageContextImpl::DeleteAndClearStorageNamespaceForOrigin( 627 void DOMStorageContextImpl::DeleteAndClearStorageNamespaceForOrigin(
624 const GURL& origin, 628 const GURL& origin_url,
625 DOMStorageNamespace* local) { 629 DOMStorageNamespace* local) {
626 local->DeleteLocalStorageOrigin(origin); 630 local->DeleteLocalStorageOrigin(origin_url);
627 // Synthesize a 'cleared' event if the area is open so CachedAreas in 631 // Synthesize a 'cleared' event if the area is open so CachedAreas in
628 // renderers get emptied out too. 632 // renderers get emptied out too.
629 DOMStorageArea* area = local->GetOpenStorageArea(origin); 633 DOMStorageArea* area = local->GetOpenStorageArea(origin_url);
630 if (area) 634 if (area)
631 NotifyAreaCleared(area, origin); 635 NotifyAreaCleared(area, origin_url);
632 } 636 }
633 637
634 } // namespace content 638 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698