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

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
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_impl.h ('k') | content/common/origin_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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. https://w3c.github.io/webappsec-suborigins/
211 for (auto origin_candidate : origins) { 213 for (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.IsSameOriginWith(origin) ||
michaeln 2016/10/17 20:06:59 What is the desired behavior if an "origin_url" ex
jww 2016/10/18 06:44:19 Great point, Michael! In short, yes, you can yet a
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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 if (!deletable_persistent_namespace_ids_.empty()) { 621 if (!deletable_persistent_namespace_ids_.empty()) {
618 task_runner_->PostDelayedTask( 622 task_runner_->PostDelayedTask(
619 FROM_HERE, base::Bind( 623 FROM_HERE, base::Bind(
620 &DOMStorageContextImpl::DeleteNextUnusedNamespace, 624 &DOMStorageContextImpl::DeleteNextUnusedNamespace,
621 this), 625 this),
622 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); 626 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds));
623 } 627 }
624 } 628 }
625 629
626 void DOMStorageContextImpl::DeleteAndClearStorageNamespaceForOrigin( 630 void DOMStorageContextImpl::DeleteAndClearStorageNamespaceForOrigin(
627 const GURL& origin, 631 const GURL& origin_url,
628 DOMStorageNamespace* local) { 632 DOMStorageNamespace* local) {
629 local->DeleteLocalStorageOrigin(origin); 633 local->DeleteLocalStorageOrigin(origin_url);
630 // Synthesize a 'cleared' event if the area is open so CachedAreas in 634 // Synthesize a 'cleared' event if the area is open so CachedAreas in
631 // renderers get emptied out too. 635 // renderers get emptied out too.
632 DOMStorageArea* area = local->GetOpenStorageArea(origin); 636 DOMStorageArea* area = local->GetOpenStorageArea(origin_url);
633 if (area) 637 if (area)
634 NotifyAreaCleared(area, origin); 638 NotifyAreaCleared(area, origin_url);
635 } 639 }
636 640
637 } // namespace content 641 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_impl.h ('k') | content/common/origin_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698