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

Side by Side Diff: chrome/browser/browsing_data/browsing_data_local_storage_helper.cc

Issue 2005783005: Re-enable storage for Suborigins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
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 "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" 5 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "chrome/browser/browsing_data/browsing_data_helper.h" 11 #include "chrome/browser/browsing_data/browsing_data_helper.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/local_storage_usage_info.h" 14 #include "content/public/browser/local_storage_usage_info.h"
15 #include "content/public/browser/storage_partition.h" 15 #include "content/public/browser/storage_partition.h"
16 #include "content/public/common/origin_util.h"
17 #include "content/public/common/url_constants.h"
16 18
17 using content::BrowserContext; 19 using content::BrowserContext;
18 using content::BrowserThread; 20 using content::BrowserThread;
19 using content::DOMStorageContext; 21 using content::DOMStorageContext;
20 22
21 namespace { 23 namespace {
22 24
25 // Only websafe state and suborigins are considered browsing data.
26 bool HasStorageScheme(const GURL& origin) {
27 return BrowsingDataHelper::HasWebScheme(origin) ||
28 origin.scheme() == content::kHttpSuboriginScheme ||
29 origin.scheme() == content::kHttpsSuboriginScheme;
30 }
31
23 void GetUsageInfoCallback( 32 void GetUsageInfoCallback(
24 const BrowsingDataLocalStorageHelper::FetchCallback& callback, 33 const BrowsingDataLocalStorageHelper::FetchCallback& callback,
25 const std::vector<content::LocalStorageUsageInfo>& infos) { 34 const std::vector<content::LocalStorageUsageInfo>& infos) {
26 DCHECK_CURRENTLY_ON(BrowserThread::UI); 35 DCHECK_CURRENTLY_ON(BrowserThread::UI);
27 DCHECK(!callback.is_null()); 36 DCHECK(!callback.is_null());
28 37
29 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> result; 38 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> result;
30 for (const content::LocalStorageUsageInfo& info : infos) { 39 for (const content::LocalStorageUsageInfo& info : infos) {
31 if (!BrowsingDataHelper::HasWebScheme(info.origin)) 40 if (!HasStorageScheme(info.origin))
32 continue; // Non-websafe state is not considered browsing data. 41 continue;
33 result.push_back(BrowsingDataLocalStorageHelper::LocalStorageInfo( 42 result.push_back(BrowsingDataLocalStorageHelper::LocalStorageInfo(
34 info.origin, info.data_size, info.last_modified)); 43 info.origin, info.data_size, info.last_modified));
35 } 44 }
36 45
37 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 46 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
38 base::Bind(callback, result)); 47 base::Bind(callback, result));
39 } 48 }
40 49
41 } // namespace 50 } // namespace
42 51
(...skipping 29 matching lines...) Expand all
72 81
73 //--------------------------------------------------------- 82 //---------------------------------------------------------
74 83
75 CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper( 84 CannedBrowsingDataLocalStorageHelper::CannedBrowsingDataLocalStorageHelper(
76 Profile* profile) 85 Profile* profile)
77 : BrowsingDataLocalStorageHelper(profile) { 86 : BrowsingDataLocalStorageHelper(profile) {
78 } 87 }
79 88
80 void CannedBrowsingDataLocalStorageHelper::AddLocalStorage( 89 void CannedBrowsingDataLocalStorageHelper::AddLocalStorage(
81 const GURL& origin) { 90 const GURL& origin) {
82 if (!BrowsingDataHelper::HasWebScheme(origin)) 91 if (!HasStorageScheme(origin))
83 return; // Non-websafe state is not considered browsing data. 92 return;
84 pending_local_storage_info_.insert(origin); 93 pending_local_storage_info_.insert(origin);
94 if (content::HasSuborigin(origin)) {
95 pending_origins_to_pending_suborigins_.insert(
96 std::make_pair(content::StripSuboriginFromUrl(origin), origin));
97 }
85 } 98 }
86 99
87 void CannedBrowsingDataLocalStorageHelper::Reset() { 100 void CannedBrowsingDataLocalStorageHelper::Reset() {
88 pending_local_storage_info_.clear(); 101 pending_local_storage_info_.clear();
102 pending_origins_to_pending_suborigins_.clear();
89 } 103 }
90 104
91 bool CannedBrowsingDataLocalStorageHelper::empty() const { 105 bool CannedBrowsingDataLocalStorageHelper::empty() const {
92 return pending_local_storage_info_.empty(); 106 return pending_local_storage_info_.empty();
93 } 107 }
94 108
95 size_t CannedBrowsingDataLocalStorageHelper::GetLocalStorageCount() const { 109 size_t CannedBrowsingDataLocalStorageHelper::GetLocalStorageCount() const {
96 return pending_local_storage_info_.size(); 110 return pending_local_storage_info_.size();
97 } 111 }
98 112
(...skipping 10 matching lines...) Expand all
109 std::list<LocalStorageInfo> result; 123 std::list<LocalStorageInfo> result;
110 for (const GURL& url : pending_local_storage_info_) 124 for (const GURL& url : pending_local_storage_info_)
111 result.push_back(LocalStorageInfo(url, 0, base::Time())); 125 result.push_back(LocalStorageInfo(url, 0, base::Time()));
112 126
113 BrowserThread::PostTask( 127 BrowserThread::PostTask(
114 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); 128 BrowserThread::UI, FROM_HERE, base::Bind(callback, result));
115 } 129 }
116 130
117 void CannedBrowsingDataLocalStorageHelper::DeleteOrigin(const GURL& origin) { 131 void CannedBrowsingDataLocalStorageHelper::DeleteOrigin(const GURL& origin) {
118 pending_local_storage_info_.erase(origin); 132 pending_local_storage_info_.erase(origin);
133 // All suborigins associated with |origin| must be removed.
134 // BrowsingDataLocalStorageHelper::DeleteOrigin takes care of doing that on
135 // the backend so it's not necessary to call it for each suborigin, but it is
136 // necessary to clear up the pending storage here.
119 BrowsingDataLocalStorageHelper::DeleteOrigin(origin); 137 BrowsingDataLocalStorageHelper::DeleteOrigin(origin);
138 if (pending_origins_to_pending_suborigins_.count(origin) > 0) {
139 auto it = pending_origins_to_pending_suborigins_.find(origin);
140 while (it != pending_origins_to_pending_suborigins_.end()) {
141 pending_local_storage_info_.erase(it->second);
142 pending_origins_to_pending_suborigins_.erase(it);
143 it = pending_origins_to_pending_suborigins_.find(origin);
144 }
145 }
146 pending_origins_to_pending_suborigins_.erase(origin);
120 } 147 }
121 148
122 CannedBrowsingDataLocalStorageHelper::~CannedBrowsingDataLocalStorageHelper() {} 149 CannedBrowsingDataLocalStorageHelper::~CannedBrowsingDataLocalStorageHelper() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698