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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/browsing_data/cookie_counting_helper.cc
diff --git a/chrome/browser/browsing_data/cookie_counting_helper.cc b/chrome/browser/browsing_data/cookie_counting_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4fe4aa641eadc3be51aedd2b28a771841711f648
--- /dev/null
+++ b/chrome/browser/browsing_data/cookie_counting_helper.cc
@@ -0,0 +1,268 @@
+// 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.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/browsing_data/cookie_counting_helper.h"
+
+#include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h"
+#include "chrome/browser/browsing_data/browsing_data_helper.h"
+#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "components/content_settings/core/browser/host_content_settings_map.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/dom_storage_context.h"
+#include "content/public/browser/local_storage_usage_info.h"
+#include "content/public/browser/session_storage_usage_info.h"
+#include "content/public/browser/storage_partition.h"
+#include "net/cookies/cookie_store.h"
+#include "net/cookies/cookie_util.h"
+#include "net/ssl/channel_id_service.h"
+#include "net/ssl/channel_id_store.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_getter.h"
+#include "ppapi/features/features.h"
+#include "storage/browser/quota/quota_manager.h"
+
+using content::BrowserThread;
+
+CookieCountingHelper::CookieCountingHelper(
+ Profile* profile,
+ base::Time begin,
+ base::Callback<void(int)> completion_callback)
+ : profile_(profile),
+ begin_(begin),
+ completion_callback_(completion_callback),
+ tasks_(0) {}
+
+CookieCountingHelper::~CookieCountingHelper() {}
+
+void CookieCountingHelper::CountAndDestroySelfWhenFinished() {
+ content::StoragePartition* partition =
+ content::BrowserContext::GetDefaultStoragePartition(profile_);
+
+ scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy(
+ profile_->GetSpecialStoragePolicy());
+
+ net::URLRequestContextGetter* rq_context = partition->GetURLRequestContext();
+
+ tasks_ += 1;
+ // Count origins with cookies.
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&CookieCountingHelper::GetCookiesOnIOThread,
+ base::Unretained(this), make_scoped_refptr(rq_context)));
+
+ storage::QuotaManager* quota_manager = partition->GetQuotaManager();
+ if (quota_manager) {
+ // Count origins with filesystem, websql, appcache, indexeddb,
+ // serviceworkers and cachestorage using quota manager.
+ storage::GetOriginsCallback origins_callback = base::Bind(
+ &CookieCountingHelper::GetQuotaOriginsCallback, base::Unretained(this));
+ const storage::StorageType types[] = {storage::kStorageTypeTemporary,
+ storage::kStorageTypePersistent,
+ storage::kStorageTypeSyncable};
+ for (auto type : types) {
+ tasks_ += 1;
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&storage::QuotaManager::GetOriginsModifiedSince,
+ quota_manager, type, begin_, origins_callback));
+ }
+ }
+
+ // Count origins with local storage or session storage.
+ content::DOMStorageContext* dom_storage = partition->GetDOMStorageContext();
+ if (dom_storage) {
+ tasks_ += 1;
+ auto local_callback =
+ base::Bind(&CookieCountingHelper::GetLocalStorageUsageInfoCallback,
+ base::Unretained(this), special_storage_policy);
+ dom_storage->GetLocalStorageUsage(local_callback);
+ tasks_ += 1;
+ auto session_callback =
+ base::Bind(&CookieCountingHelper::GetSessionStorageUsageInfoCallback,
+ base::Unretained(this), special_storage_policy);
+ dom_storage->GetSessionStorageUsage(session_callback);
+ }
+
+#if BUILDFLAG(ENABLE_PLUGINS)
+ // Count origins with flash data.
+ flash_lso_helper_ = BrowsingDataFlashLSOHelper::Create(profile_);
+ if (flash_lso_helper_) {
+ tasks_ += 1;
+ flash_lso_helper_->StartFetching(
+ base::Bind(&CookieCountingHelper::SitesWithFlashDataCallback,
+ base::Unretained(this)));
+ }
+#endif
+
+ // Counting site usage data and durable permission.
+ auto hcsm = HostContentSettingsMapFactory::GetForProfile(profile_);
+ tasks_ += 1;
+ std::vector<GURL> engagement = hcsm->GetSitesWithSettingsInPrefProvider(
+ CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT);
+ LOG(ERROR) << "engagement: " << engagement.size();
+ for (const GURL& url : engagement) {
+ LOG(ERROR) << "eng - " << url.spec();
+ }
+ Done(engagement);
+
+ tasks_ += 1;
+ std::vector<GURL> permissions = hcsm->GetSitesWithSettingsInPrefProvider(
+ CONTENT_SETTINGS_TYPE_DURABLE_STORAGE);
+ LOG(ERROR) << "permissions: " << permissions.size();
+ for (const GURL& url : permissions) {
+ LOG(ERROR) << "perm - " << url.spec();
+ }
+ Done(permissions);
+
+ // Count origins with channel ids.
+ tasks_ += 1;
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&CookieCountingHelper::GetChannelIDsOnIOThread,
+ base::Unretained(this), make_scoped_refptr(rq_context)));
+}
+
+void CookieCountingHelper::GetCookiesOnIOThread(
+ const scoped_refptr<net::URLRequestContextGetter>& rq_context) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ net::CookieStore* cookie_store =
+ rq_context->GetURLRequestContext()->cookie_store();
+
+ if (cookie_store) {
+ cookie_store->GetAllCookiesAsync(base::Bind(
+ &CookieCountingHelper::GetCookiesCallback, base::Unretained(this)));
+ } else {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&CookieCountingHelper::Done, base::Unretained(this),
+ std::vector<GURL>()));
+ }
+}
+
+void CookieCountingHelper::GetCookiesCallback(const net::CookieList& cookies) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ std::vector<GURL> origins;
+ for (const auto& cookie : cookies) {
+ if (cookie.CreationDate() >= begin_) {
+ GURL url = net::cookie_util::CookieOriginToURL(cookie.Domain(),
+ cookie.IsSecure());
+ origins.push_back(url);
+ }
+ }
+ LOG(ERROR) << "cookies: " << origins.size();
+ for (const auto& url : origins) {
+ LOG(ERROR) << "cookie - " << url.spec();
+ }
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&CookieCountingHelper::Done, base::Unretained(this), origins));
+}
+
+void CookieCountingHelper::GetQuotaOriginsCallback(
+ const std::set<GURL>& origin_set,
+ storage::StorageType type) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ std::vector<GURL> origins(origin_set.begin(), origin_set.end());
+ LOG(ERROR) << "quota " << type << ": " << origins.size();
+ for (const auto& url : origins) {
+ LOG(ERROR) << "quota - " << url.spec();
+ }
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&CookieCountingHelper::Done, base::Unretained(this), origins));
+}
+
+void CookieCountingHelper::GetLocalStorageUsageInfoCallback(
+ const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy,
+ const std::vector<content::LocalStorageUsageInfo>& infos) {
+ std::vector<GURL> origins;
+ for (const auto& info : infos) {
+ if (info.last_modified >= begin_ &&
+ !special_storage_policy->IsStorageProtected(info.origin)) {
+ origins.push_back(info.origin);
+ }
+ }
+ LOG(ERROR) << "local storage: " << origins.size();
+ for (const auto& url : origins) {
+ LOG(ERROR) << "local - " << url.spec();
+ }
+ Done(origins);
+}
+
+void CookieCountingHelper::GetSessionStorageUsageInfoCallback(
+ const scoped_refptr<storage::SpecialStoragePolicy>& special_storage_policy,
+ const std::vector<content::SessionStorageUsageInfo>& infos) {
+ std::vector<GURL> origins;
+ for (const auto& info : infos) {
+ // Session storage doesn't know about creation time.
+ if (!special_storage_policy->IsStorageProtected(info.origin)) {
+ origins.push_back(info.origin);
+ }
+ }
+ LOG(ERROR) << "session storage: " << origins.size();
+ for (const auto& url : origins) {
+ LOG(ERROR) << "session - " << url.spec();
+ }
+ Done(origins);
+}
+
+void CookieCountingHelper::SitesWithFlashDataCallback(
+ const std::vector<std::string>& sites) {
+ std::vector<GURL> origins;
+ for (const std::string& site : sites) {
+ origins.push_back(GURL(site));
+ }
+ LOG(ERROR) << "plugins: " << sites.size();
+ for (const auto& url : origins) {
+ LOG(ERROR) << "plugin - " << url.spec();
+ }
+ Done(origins);
+}
+
+void CookieCountingHelper::GetChannelIDsOnIOThread(
+ const scoped_refptr<net::URLRequestContextGetter>& rq_context) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ net::ChannelIDService* channel_id_service =
+ rq_context->GetURLRequestContext()->channel_id_service();
+ channel_id_service->GetChannelIDStore()->GetAllChannelIDs(base::Bind(
+ &CookieCountingHelper::GetChannelIDsCallback, base::Unretained(this)));
+}
+
+void CookieCountingHelper::GetChannelIDsCallback(
+ const net::ChannelIDStore::ChannelIDList& channel_ids) {
+ std::vector<GURL> origins;
+ for (const auto& channel_id : channel_ids) {
+ if (channel_id.creation_time() >= begin_) {
+ origins.push_back(GURL("https://" + channel_id.server_identifier()));
+ }
+ }
+ LOG(ERROR) << "channelids: " << origins.size();
+ for (const auto& url : origins) {
+ LOG(ERROR) << "channel - " << url.spec();
+ }
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&CookieCountingHelper::Done, base::Unretained(this), origins));
+}
+
+void CookieCountingHelper::Done(const std::vector<GURL>& origins) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK(tasks_ > 0);
+ for (const GURL& origin : origins) {
+ if (BrowsingDataHelper::HasWebScheme(origin)) {
+ unique_origins_.insert(origin);
+ }
+ }
+ if (--tasks_ > 0)
+ return;
+ LOG(ERROR) << "total origins with site data: " << unique_origins_.size();
+ for (const GURL& url : unique_origins_) {
+ LOG(ERROR) << "- " << url.spec();
+ }
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(completion_callback_, unique_origins_.size()));
+ base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
+}

Powered by Google App Engine
This is Rietveld 408576698