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

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

Issue 2594723002: Count number of origins with data affected by clearing "cookies and site data". (Closed)
Patch Set: Add comments for issues with incomplete data deletion 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 (c) 2016 The Chromium Authors. All rights reserved.
msramek 2017/01/09 12:54:43 Ditto.
dullweber 2017/01/09 16:05:46 Done.
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/cookie_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 CookieCountingHelper::CookieCountingHelper(
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 CookieCountingHelper::~CookieCountingHelper() {}
38
39 void CookieCountingHelper::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(&CookieCountingHelper::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 = base::Bind(
60 &CookieCountingHelper::GetQuotaOriginsCallback, base::Unretained(this));
61 const storage::StorageType types[] = {storage::kStorageTypeTemporary,
62 storage::kStorageTypePersistent,
63 storage::kStorageTypeSyncable};
64 for (auto type : types) {
65 tasks_ += 1;
66 BrowserThread::PostTask(
67 BrowserThread::IO, FROM_HERE,
68 base::Bind(&storage::QuotaManager::GetOriginsModifiedSince,
69 quota_manager, type, begin_, origins_callback));
70 }
71 }
72
73 // Count origins with local storage or session storage.
74 content::DOMStorageContext* dom_storage = partition->GetDOMStorageContext();
75 if (dom_storage) {
76 tasks_ += 1;
77 auto local_callback =
78 base::Bind(&CookieCountingHelper::GetLocalStorageUsageInfoCallback,
79 base::Unretained(this), special_storage_policy);
80 dom_storage->GetLocalStorageUsage(local_callback);
81 tasks_ += 1;
82 auto session_callback =
83 base::Bind(&CookieCountingHelper::GetSessionStorageUsageInfoCallback,
84 base::Unretained(this), special_storage_policy);
85 dom_storage->GetSessionStorageUsage(session_callback);
86 }
87
88 #if BUILDFLAG(ENABLE_PLUGINS)
89 // Count origins with flash data.
90 flash_lso_helper_ = BrowsingDataFlashLSOHelper::Create(profile_);
91 if (flash_lso_helper_) {
92 tasks_ += 1;
93 flash_lso_helper_->StartFetching(
94 base::Bind(&CookieCountingHelper::SitesWithFlashDataCallback,
95 base::Unretained(this)));
96 }
97 #endif
98
99 // Counting site usage data and durable permission.
100 auto hcsm = HostContentSettingsMapFactory::GetForProfile(profile_);
101 tasks_ += 1;
102 std::vector<GURL> engagement = hcsm->GetSitesWithSettingsInPrefProvider(
103 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT);
104 LOG(ERROR) << "engagement: " << engagement.size();
105 for (const GURL& url : engagement) {
106 LOG(ERROR) << "eng - " << url.spec();
107 }
108 Done(engagement);
109
110 tasks_ += 1;
111 std::vector<GURL> permissions = hcsm->GetSitesWithSettingsInPrefProvider(
112 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE);
113 LOG(ERROR) << "permissions: " << permissions.size();
114 for (const GURL& url : permissions) {
115 LOG(ERROR) << "perm - " << url.spec();
116 }
117 Done(permissions);
118
119 // Count origins with channel ids.
120 tasks_ += 1;
121 BrowserThread::PostTask(
122 BrowserThread::IO, FROM_HERE,
123 base::Bind(&CookieCountingHelper::GetChannelIDsOnIOThread,
124 base::Unretained(this), make_scoped_refptr(rq_context)));
125 }
126
127 void CookieCountingHelper::GetCookiesOnIOThread(
128 const scoped_refptr<net::URLRequestContextGetter>& rq_context) {
129 DCHECK_CURRENTLY_ON(BrowserThread::IO);
130
131 net::CookieStore* cookie_store =
132 rq_context->GetURLRequestContext()->cookie_store();
133
134 if (cookie_store) {
135 cookie_store->GetAllCookiesAsync(base::Bind(
136 &CookieCountingHelper::GetCookiesCallback, base::Unretained(this)));
137 } else {
138 BrowserThread::PostTask(
139 BrowserThread::UI, FROM_HERE,
140 base::Bind(&CookieCountingHelper::Done, base::Unretained(this),
141 std::vector<GURL>()));
142 }
143 }
144
145 void CookieCountingHelper::GetCookiesCallback(const net::CookieList& cookies) {
146 DCHECK_CURRENTLY_ON(BrowserThread::IO);
147 std::vector<GURL> origins;
148 for (const auto& cookie : cookies) {
149 if (cookie.CreationDate() >= begin_) {
150 GURL url = net::cookie_util::CookieOriginToURL(cookie.Domain(),
151 cookie.IsSecure());
152 origins.push_back(url);
153 }
154 }
155 LOG(ERROR) << "cookies: " << origins.size();
156 for (const auto& url : origins) {
157 LOG(ERROR) << "cookie - " << url.spec();
158 }
159 BrowserThread::PostTask(
160 BrowserThread::UI, FROM_HERE,
161 base::Bind(&CookieCountingHelper::Done, base::Unretained(this), origins));
162 }
163
164 void CookieCountingHelper::GetQuotaOriginsCallback(
165 const std::set<GURL>& origin_set,
166 storage::StorageType type) {
167 DCHECK_CURRENTLY_ON(BrowserThread::IO);
168 std::vector<GURL> origins(origin_set.begin(), origin_set.end());
169 LOG(ERROR) << "quota " << type << ": " << origins.size();
170 for (const auto& url : origins) {
171 LOG(ERROR) << "quota - " << url.spec();
172 }
173 BrowserThread::PostTask(
174 BrowserThread::UI, FROM_HERE,
175 base::Bind(&CookieCountingHelper::Done, base::Unretained(this), origins));
176 }
177
178 void CookieCountingHelper::GetLocalStorageUsageInfoCallback(
179 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy,
180 const std::vector<content::LocalStorageUsageInfo>& infos) {
181 std::vector<GURL> origins;
182 for (const auto& info : infos) {
183 if (info.last_modified >= begin_ &&
184 !special_storage_policy->IsStorageProtected(info.origin)) {
185 origins.push_back(info.origin);
186 }
187 }
188 LOG(ERROR) << "local storage: " << origins.size();
189 for (const auto& url : origins) {
190 LOG(ERROR) << "local - " << url.spec();
191 }
192 Done(origins);
193 }
194
195 void CookieCountingHelper::GetSessionStorageUsageInfoCallback(
196 const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy,
197 const std::vector<content::SessionStorageUsageInfo>& infos) {
198 std::vector<GURL> origins;
199 for (const auto& info : infos) {
200 // Session storage doesn't know about creation time.
201 if (!special_storage_policy->IsStorageProtected(info.origin)) {
202 origins.push_back(info.origin);
203 }
204 }
205 LOG(ERROR) << "session storage: " << origins.size();
206 for (const auto& url : origins) {
207 LOG(ERROR) << "session - " << url.spec();
208 }
209 Done(origins);
210 }
211
212 void CookieCountingHelper::SitesWithFlashDataCallback(
213 const std::vector<std::string>& sites) {
214 std::vector<GURL> origins;
215 for (const std::string& site : sites) {
216 origins.push_back(GURL(site));
217 }
218 LOG(ERROR) << "plugins: " << sites.size();
219 for (const auto& url : origins) {
220 LOG(ERROR) << "plugin - " << url.spec();
221 }
222 Done(origins);
223 }
224
225 void CookieCountingHelper::GetChannelIDsOnIOThread(
226 const scoped_refptr<net::URLRequestContextGetter>& rq_context) {
227 DCHECK_CURRENTLY_ON(BrowserThread::IO);
228 net::ChannelIDService* channel_id_service =
229 rq_context->GetURLRequestContext()->channel_id_service();
230 channel_id_service->GetChannelIDStore()->GetAllChannelIDs(base::Bind(
231 &CookieCountingHelper::GetChannelIDsCallback, base::Unretained(this)));
232 }
233
234 void CookieCountingHelper::GetChannelIDsCallback(
235 const net::ChannelIDStore::ChannelIDList& channel_ids) {
236 std::vector<GURL> origins;
237 for (const auto& channel_id : channel_ids) {
238 if (channel_id.creation_time() >= begin_) {
239 origins.push_back(GURL("https://" + channel_id.server_identifier()));
240 }
241 }
242 LOG(ERROR) << "channelids: " << origins.size();
243 for (const auto& url : origins) {
244 LOG(ERROR) << "channel - " << url.spec();
245 }
246 BrowserThread::PostTask(
247 BrowserThread::UI, FROM_HERE,
248 base::Bind(&CookieCountingHelper::Done, base::Unretained(this), origins));
249 }
250
251 void CookieCountingHelper::Done(const std::vector<GURL>& origins) {
252 DCHECK_CURRENTLY_ON(BrowserThread::UI);
253 DCHECK(tasks_ > 0);
254 for (const GURL& origin : origins) {
255 if (BrowsingDataHelper::HasWebScheme(origin)) {
256 unique_origins_.insert(origin);
257 }
258 }
259 if (--tasks_ > 0)
260 return;
261 LOG(ERROR) << "total origins with site data: " << unique_origins_.size();
262 for (const GURL& url : unique_origins_) {
263 LOG(ERROR) << "- " << url.spec();
264 }
265 base::ThreadTaskRunnerHandle::Get()->PostTask(
266 FROM_HERE, base::Bind(completion_callback_, unique_origins_.size()));
267 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
268 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698