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

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

Issue 2594723002: Count number of origins with data affected by clearing "cookies and site data". (Closed)
Patch Set: remove comments Created 3 years, 11 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/browsing_data/site_data_counting_helper.h"
6
7 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h"
8 #include "chrome/browser/browsing_data/browsing_data_helper.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "components/content_settings/core/browser/host_content_settings_map.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/dom_storage_context.h"
14 #include "content/public/browser/local_storage_usage_info.h"
15 #include "content/public/browser/session_storage_usage_info.h"
16 #include "content/public/browser/storage_partition.h"
17 #include "net/cookies/cookie_store.h"
18 #include "net/cookies/cookie_util.h"
19 #include "net/ssl/channel_id_service.h"
20 #include "net/ssl/channel_id_store.h"
21 #include "net/url_request/url_request_context.h"
22 #include "net/url_request/url_request_context_getter.h"
23 #include "ppapi/features/features.h"
24 #include "storage/browser/quota/quota_manager.h"
25
26 using content::BrowserThread;
27
28 SiteDataCountingHelper::SiteDataCountingHelper(
29 Profile* profile,
30 base::Time begin,
31 base::Callback<void(int)> completion_callback)
32 : profile_(profile),
33 begin_(begin),
34 completion_callback_(completion_callback),
35 tasks_(0) {}
36
37 SiteDataCountingHelper::~SiteDataCountingHelper() {}
38
39 void SiteDataCountingHelper::CountAndDestroySelfWhenFinished() {
40 content::StoragePartition* partition =
41 content::BrowserContext::GetDefaultStoragePartition(profile_);
42
43 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy(
44 profile_->GetSpecialStoragePolicy());
45
46 net::URLRequestContextGetter* rq_context = partition->GetURLRequestContext();
47
48 tasks_ += 1;
49 // Count origins with cookies.
50 BrowserThread::PostTask(
51 BrowserThread::IO, FROM_HERE,
52 base::Bind(&SiteDataCountingHelper::GetCookiesOnIOThread,
53 base::Unretained(this), make_scoped_refptr(rq_context)));
54
55 storage::QuotaManager* quota_manager = partition->GetQuotaManager();
56 if (quota_manager) {
57 // Count origins with filesystem, websql, appcache, indexeddb,
58 // serviceworkers and cachestorage using quota manager.
59 storage::GetOriginsCallback origins_callback =
60 base::Bind(&SiteDataCountingHelper::GetQuotaOriginsCallback,
61 base::Unretained(this));
62 const storage::StorageType types[] = {storage::kStorageTypeTemporary,
63 storage::kStorageTypePersistent,
64 storage::kStorageTypeSyncable};
65 for (auto type : types) {
66 tasks_ += 1;
67 BrowserThread::PostTask(
68 BrowserThread::IO, FROM_HERE,
69 base::Bind(&storage::QuotaManager::GetOriginsModifiedSince,
70 quota_manager, type, begin_, origins_callback));
71 }
72 }
73
74 // Count origins with local storage or session storage.
75 content::DOMStorageContext* dom_storage = partition->GetDOMStorageContext();
76 if (dom_storage) {
77 tasks_ += 1;
78 auto local_callback =
79 base::Bind(&SiteDataCountingHelper::GetLocalStorageUsageInfoCallback,
80 base::Unretained(this), special_storage_policy);
81 dom_storage->GetLocalStorageUsage(local_callback);
82 tasks_ += 1;
83 auto session_callback =
84 base::Bind(&SiteDataCountingHelper::GetSessionStorageUsageInfoCallback,
85 base::Unretained(this), special_storage_policy);
86 dom_storage->GetSessionStorageUsage(session_callback);
87 }
88
89 #if BUILDFLAG(ENABLE_PLUGINS)
90 // Count origins with flash data.
91 flash_lso_helper_ = BrowsingDataFlashLSOHelper::Create(profile_);
92 if (flash_lso_helper_) {
93 tasks_ += 1;
94 flash_lso_helper_->StartFetching(
95 base::Bind(&SiteDataCountingHelper::SitesWithFlashDataCallback,
96 base::Unretained(this)));
97 }
98 #endif
99
100 // Counting site usage data and durable permission.
101 auto hcsm = HostContentSettingsMapFactory::GetForProfile(profile_);
102 tasks_ += 1;
103 GetOriginsFromHostContentSettignsMap(hcsm,
msramek 2017/01/10 10:23:02 APP_BANNER would also be removed as a part of REMO
dullweber 2017/01/10 13:18:34 Done.
104 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT);
105 tasks_ += 1;
106 GetOriginsFromHostContentSettignsMap(hcsm,
107 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE);
108
109 // Count origins with channel ids.
110 tasks_ += 1;
111 BrowserThread::PostTask(
112 BrowserThread::IO, FROM_HERE,
113 base::Bind(&SiteDataCountingHelper::GetChannelIDsOnIOThread,
114 base::Unretained(this), make_scoped_refptr(rq_context)));
115 }
116
117 void SiteDataCountingHelper::GetOriginsFromHostContentSettignsMap(
118 HostContentSettingsMap* hcsm,
119 ContentSettingsType type) {
120 std::set<GURL> origins;
121 ContentSettingsForOneType settings;
122 hcsm->GetSettingsForOneType(type, std::string(), &settings);
123 for (const auto& rule : settings) {
msramek 2017/01/10 10:23:02 Don't use auto if the type is not obvious. Here, i
dullweber 2017/01/10 13:18:34 Done.
124 origins.insert(GURL(rule.primary_pattern.ToString()));
125 }
126 Done(std::vector<GURL>(origins.begin(), origins.end()));
127 }
128
129 void SiteDataCountingHelper::GetCookiesOnIOThread(
130 const scoped_refptr<net::URLRequestContextGetter>& rq_context) {
131 DCHECK_CURRENTLY_ON(BrowserThread::IO);
132
133 net::CookieStore* cookie_store =
134 rq_context->GetURLRequestContext()->cookie_store();
135
136 if (cookie_store) {
137 cookie_store->GetAllCookiesAsync(base::Bind(
138 &SiteDataCountingHelper::GetCookiesCallback, base::Unretained(this)));
139 } else {
140 BrowserThread::PostTask(
141 BrowserThread::UI, FROM_HERE,
142 base::Bind(&SiteDataCountingHelper::Done, base::Unretained(this),
143 std::vector<GURL>()));
144 }
145 }
146
147 void SiteDataCountingHelper::GetCookiesCallback(
148 const net::CookieList& cookies) {
149 DCHECK_CURRENTLY_ON(BrowserThread::IO);
150 std::vector<GURL> origins;
151 for (const auto& cookie : cookies) {
msramek 2017/01/10 10:23:02 Ditto.
dullweber 2017/01/10 13:18:34 Done.
152 if (cookie.CreationDate() >= begin_) {
153 GURL url = net::cookie_util::CookieOriginToURL(cookie.Domain(),
154 cookie.IsSecure());
155 origins.push_back(url);
156 }
157 }
158 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
159 base::Bind(&SiteDataCountingHelper::Done,
160 base::Unretained(this), origins));
161 }
162
163 void SiteDataCountingHelper::GetQuotaOriginsCallback(
164 const std::set<GURL>& origin_set,
165 storage::StorageType type) {
166 DCHECK_CURRENTLY_ON(BrowserThread::IO);
167 std::vector<GURL> origins(origin_set.begin(), origin_set.end());
168 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
169 base::Bind(&SiteDataCountingHelper::Done,
170 base::Unretained(this), origins));
171 }
172
173 void SiteDataCountingHelper::GetLocalStorageUsageInfoCallback(
174 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy,
175 const std::vector<content::LocalStorageUsageInfo>& infos) {
176 std::vector<GURL> origins;
177 for (const auto& info : infos) {
178 if (info.last_modified >= begin_ &&
179 !special_storage_policy->IsStorageProtected(info.origin)) {
180 origins.push_back(info.origin);
181 }
182 }
183 Done(origins);
184 }
185
186 void SiteDataCountingHelper::GetSessionStorageUsageInfoCallback(
187 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy,
188 const std::vector<content::SessionStorageUsageInfo>& infos) {
189 std::vector<GURL> origins;
190 for (const auto& info : infos) {
191 // Session storage doesn't know about creation time.
192 if (!special_storage_policy->IsStorageProtected(info.origin)) {
193 origins.push_back(info.origin);
194 }
195 }
196 Done(origins);
197 }
198
199 void SiteDataCountingHelper::SitesWithFlashDataCallback(
200 const std::vector<std::string>& sites) {
201 std::vector<GURL> origins;
202 for (const std::string& site : sites) {
203 origins.push_back(GURL(site));
204 }
205 Done(origins);
206 }
207
208 void SiteDataCountingHelper::GetChannelIDsOnIOThread(
209 const scoped_refptr<net::URLRequestContextGetter>& rq_context) {
210 DCHECK_CURRENTLY_ON(BrowserThread::IO);
211 net::ChannelIDService* channel_id_service =
212 rq_context->GetURLRequestContext()->channel_id_service();
213 channel_id_service->GetChannelIDStore()->GetAllChannelIDs(base::Bind(
214 &SiteDataCountingHelper::GetChannelIDsCallback, base::Unretained(this)));
215 }
216
217 void SiteDataCountingHelper::GetChannelIDsCallback(
218 const net::ChannelIDStore::ChannelIDList& channel_ids) {
219 std::vector<GURL> origins;
220 for (const auto& channel_id : channel_ids) {
msramek 2017/01/10 10:23:02 Ditto.
dullweber 2017/01/10 13:18:34 Done.
221 if (channel_id.creation_time() >= begin_) {
222 origins.push_back(GURL("https://" + channel_id.server_identifier()));
msramek 2017/01/10 10:23:02 Hmm, this might lead to a wrong count. If I visit
dullweber 2017/01/10 13:18:34 Added a comment to explain the problem. There are
223 }
224 }
225 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
226 base::Bind(&SiteDataCountingHelper::Done,
227 base::Unretained(this), origins));
228 }
229
230 void SiteDataCountingHelper::Done(const std::vector<GURL>& origins) {
231 DCHECK_CURRENTLY_ON(BrowserThread::UI);
232 DCHECK(tasks_ > 0);
233 for (const GURL& origin : origins) {
234 if (BrowsingDataHelper::HasWebScheme(origin)) {
msramek 2017/01/10 10:23:02 If an origin with a non-web scheme, e.g. the file:
dullweber 2017/01/10 13:18:34 Oh, I took that from the BrowsingData*Helper class
235 unique_origins_.insert(origin);
236 }
237 }
238 if (--tasks_ > 0)
239 return;
240 base::ThreadTaskRunnerHandle::Get()->PostTask(
241 FROM_HERE, base::Bind(completion_callback_, unique_origins_.size()));
242 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
243 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698