Commit 3248025c authored by msramek's avatar msramek Committed by Commit bot

Extract embedder-specific data types from BrowsingDataRemover

Define BrowsingDataRemoverDelegate, a class to which BrowsingDataRemover
will delegate all embedder-specific deletions. This class is in 1:1
relationship to BrowsingDataRemover and is owned by it.

Create a Chrome-specific subclass ChromeBrowsingDataRemoverDelegate by
extracting all Chrome datatypes from BrowsingDataRemover::RemoveImpl().

This is the first step of the implementation plan. See the design doc for more
background and explanation of the next steps:
https://docs.google.com/document/d/1I6m4QwbTNhG6wdtazamhTnArJN-UMUGqpvwH6InBEaM/edit#heading=h.m5pzu7ah79n9

This change is covered by BrowsingDataRemoverTest and
BrowsingDataRemoverBrowserTest.

NOTES FOR REVIEWERS:
1. This CL tries to keep the diffs at minimum for easier review, even if the
method ordering could be improved. That will be improved in a follow-up CL.
2. However, the diffs widely differ in BrowsingDataRemover::RemoveImpl and
ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData. Fortunately, one can
convince themself that they are still equivalent by trusting the test coverage
(58 unittests and 6 browsertests).
3. One can convince themself that no datatype was left out by checking the
list of asynchronous tasks, such as "waiting_for_clear_cache_",
"waiting_for_clear_cookies_" etc. present in both .h files and in the AllDone()
method of both classes.
4. The distribution of datatypes might not be final. For example, downloads are
known to content but have a chrome/ dependency. Similarly, the DNS cache lives
in net/ but is retrieved via a class in chrome/. Future CLs might correct their
placement based on how strong the chrome/ dependencies are.

Patchset 3: Simplify the "bool waiting_for_clear_<type>" paradigm by encapsulating it to a SubTask class.

BUG=668114

Review-Url: https://codereview.chromium.org/2554413002
Cr-Commit-Position: refs/heads/master@{#438175}
parent c8dcfe32
...@@ -168,6 +168,7 @@ split_static_library("browser") { ...@@ -168,6 +168,7 @@ split_static_library("browser") {
"browsing_data/browsing_data_quota_helper_impl.h", "browsing_data/browsing_data_quota_helper_impl.h",
"browsing_data/browsing_data_remover.cc", "browsing_data/browsing_data_remover.cc",
"browsing_data/browsing_data_remover.h", "browsing_data/browsing_data_remover.h",
"browsing_data/browsing_data_remover_delegate.h",
"browsing_data/browsing_data_remover_factory.cc", "browsing_data/browsing_data_remover_factory.cc",
"browsing_data/browsing_data_remover_factory.h", "browsing_data/browsing_data_remover_factory.h",
"browsing_data/browsing_data_service_worker_helper.cc", "browsing_data/browsing_data_service_worker_helper.cc",
...@@ -176,6 +177,8 @@ split_static_library("browser") { ...@@ -176,6 +177,8 @@ split_static_library("browser") {
"browsing_data/cache_counter.h", "browsing_data/cache_counter.h",
"browsing_data/canonical_cookie_hash.cc", "browsing_data/canonical_cookie_hash.cc",
"browsing_data/canonical_cookie_hash.h", "browsing_data/canonical_cookie_hash.h",
"browsing_data/chrome_browsing_data_remover_delegate.cc",
"browsing_data/chrome_browsing_data_remover_delegate.h",
"browsing_data/cookies_tree_model.cc", "browsing_data/cookies_tree_model.cc",
"browsing_data/cookies_tree_model.h", "browsing_data/cookies_tree_model.h",
"browsing_data/downloads_counter.cc", "browsing_data/downloads_counter.cc",
......
...@@ -14,64 +14,16 @@ ...@@ -14,64 +14,16 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browsing_data/browsing_data_filter_builder.h" #include "chrome/browser/browsing_data/browsing_data_filter_builder.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h" #include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/browsing_data_remover_factory.h" #include "chrome/browser/browsing_data/browsing_data_remover_delegate.h"
#include "chrome/browser/browsing_data/registrable_domain_filter_builder.h" #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/domain_reliability/service_factory.h"
#include "chrome/browser/download/download_prefs.h" #include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/web_history_service_factory.h"
#include "chrome/browser/io_thread.h" #include "chrome/browser/io_thread.h"
#include "chrome/browser/media/media_device_id_salt.h"
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h"
#include "chrome/browser/net/predictor.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
#include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/permissions/permission_decision_auto_blocker.h"
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/prerender/prerender_manager_factory.h"
#include "chrome/browser/previews/previews_service.h"
#include "chrome/browser/previews/previews_service_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/web_data_service_factory.h"
#include "chrome/common/features.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/browsing_data/content/storage_partition_http_cache_data_remover.h" #include "components/browsing_data/content/storage_partition_http_cache_data_remover.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/domain_reliability/service.h"
#include "components/history/core/browser/history_service.h"
#include "components/nacl/browser/nacl_browser.h"
#include "components/nacl/browser/pnacl_host.h"
#include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h"
#include "components/ntp_snippets/content_suggestions_service.h"
#include "components/omnibox/browser/omnibox_pref_names.h"
#include "components/password_manager/core/browser/password_store.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/previews/core/previews_ui_service.h"
#include "components/search_engines/template_url_service.h"
#include "components/sessions/core/tab_restore_service.h"
#include "components/web_cache/browser/web_cache_manager.h" #include "components/web_cache/browser/web_cache_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h" #include "content/public/browser/download_manager.h"
...@@ -95,43 +47,10 @@ ...@@ -95,43 +47,10 @@
#include "storage/browser/quota/special_storage_policy.h" #include "storage/browser/quota/special_storage_policy.h"
#include "url/origin.h" #include "url/origin.h"
#if BUILDFLAG(ANDROID_JAVA_UI)
#include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
#include "chrome/browser/android/webapps/webapp_registry.h"
#include "chrome/browser/precache/precache_manager_factory.h"
#include "components/offline_pages/core/offline_page_feature.h"
#include "components/offline_pages/core/offline_page_model.h"
#include "components/precache/content/precache_manager.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/activity_log/activity_log.h"
#include "extensions/browser/extension_prefs.h"
#endif
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
#include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h" #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h"
#endif #endif
#if BUILDFLAG(ENABLE_SESSION_SERVICE)
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sessions/session_service_factory.h"
#endif
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chromeos/attestation/attestation_constants.h"
#include "chromeos/cryptohome/cryptohome_parameters.h"
#include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "components/user_manager/user.h"
#endif
#if BUILDFLAG(ENABLE_WEBRTC)
#include "chrome/browser/media/webrtc/webrtc_log_list.h"
#include "chrome/browser/media/webrtc/webrtc_log_util.h"
#endif
using base::UserMetricsAction; using base::UserMetricsAction;
using content::BrowserContext; using content::BrowserContext;
using content::BrowserThread; using content::BrowserThread;
...@@ -139,19 +58,6 @@ using content::DOMStorageContext; ...@@ -139,19 +58,6 @@ using content::DOMStorageContext;
namespace { namespace {
void UIThreadTrampolineHelper(const base::Closure& callback) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
}
// Convenience method to create a callback that can be run on any thread and
// will post the given |callback| back to the UI thread.
base::Closure UIThreadTrampoline(const base::Closure& callback) {
// We could directly bind &BrowserThread::PostTask, but that would require
// evaluating FROM_HERE when this method is called, as opposed to when the
// task is actually posted.
return base::Bind(&UIThreadTrampolineHelper, callback);
}
template <typename T> template <typename T>
void IgnoreArgumentHelper(const base::Closure& callback, T unused_argument) { void IgnoreArgumentHelper(const base::Closure& callback, T unused_argument) {
callback.Run(); callback.Run();
...@@ -175,21 +81,6 @@ bool DoesOriginMatchMaskAndUrls( ...@@ -175,21 +81,6 @@ bool DoesOriginMatchMaskAndUrls(
special_storage_policy); special_storage_policy);
} }
bool ForwardPrimaryPatternCallback(
const base::Callback<bool(const ContentSettingsPattern&)> predicate,
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern) {
return predicate.Run(primary_pattern);
}
void ClearHostnameResolutionCacheOnIOThread(
IOThread* io_thread,
base::Callback<bool(const std::string&)> host_filter) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
io_thread->ClearHostCache(host_filter);
}
void ClearHttpAuthCacheOnIOThread( void ClearHttpAuthCacheOnIOThread(
scoped_refptr<net::URLRequestContextGetter> context_getter, scoped_refptr<net::URLRequestContextGetter> context_getter,
base::Time delete_begin) { base::Time delete_begin) {
...@@ -204,55 +95,6 @@ void ClearHttpAuthCacheOnIOThread( ...@@ -204,55 +95,6 @@ void ClearHttpAuthCacheOnIOThread(
http_session->CloseAllConnections(); http_session->CloseAllConnections();
} }
void ClearNetworkPredictorOnIOThread(chrome_browser_net::Predictor* predictor) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(predictor);
predictor->DiscardInitialNavigationHistory();
predictor->DiscardAllResults();
}
#if !defined(DISABLE_NACL)
void ClearNaClCacheOnIOThread(const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
nacl::NaClBrowser::GetInstance()->ClearValidationCache(callback);
}
void ClearPnaclCacheOnIOThread(base::Time begin,
base::Time end,
const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
pnacl::PnaclHost::GetInstance()->ClearTranslationCacheEntriesBetween(
begin, end, callback);
}
#endif
void ClearCookiesOnIOThread(base::Time delete_begin,
base::Time delete_end,
net::URLRequestContextGetter* rq_context,
const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
net::CookieStore* cookie_store =
rq_context->GetURLRequestContext()->cookie_store();
cookie_store->DeleteAllCreatedBetweenAsync(delete_begin, delete_end,
IgnoreArgument<int>(callback));
}
void ClearCookiesWithPredicateOnIOThread(
base::Time delete_begin,
base::Time delete_end,
net::CookieStore::CookiePredicate predicate,
net::URLRequestContextGetter* rq_context,
const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
net::CookieStore* cookie_store =
rq_context->GetURLRequestContext()->cookie_store();
cookie_store->DeleteAllCreatedBetweenWithPredicateAsync(
delete_begin, delete_end, predicate, IgnoreArgument<int>(callback));
}
void OnClearedChannelIDsOnIOThread(net::URLRequestContextGetter* rq_context, void OnClearedChannelIDsOnIOThread(net::URLRequestContextGetter* rq_context,
const base::Closure& callback) { const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
...@@ -287,6 +129,33 @@ void ClearChannelIDsOnIOThread( ...@@ -287,6 +129,33 @@ void ClearChannelIDsOnIOThread(
BrowsingDataRemover::CompletionInhibitor* BrowsingDataRemover::CompletionInhibitor*
BrowsingDataRemover::completion_inhibitor_ = nullptr; BrowsingDataRemover::completion_inhibitor_ = nullptr;
BrowsingDataRemover::SubTask::SubTask(const base::Closure& forward_callback)
: is_pending_(false),
forward_callback_(forward_callback),
weak_ptr_factory_(this) {
DCHECK(!forward_callback_.is_null());
}
BrowsingDataRemover::SubTask::~SubTask() {}
void BrowsingDataRemover::SubTask::Start() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!is_pending_);
is_pending_ = true;
}
base::Closure BrowsingDataRemover::SubTask::GetCompletionCallback() {
return base::Bind(&BrowsingDataRemover::SubTask::CompletionCallback,
weak_ptr_factory_.GetWeakPtr());
}
void BrowsingDataRemover::SubTask::CompletionCallback() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(is_pending_);
is_pending_ = false;
forward_callback_.Run();
}
bool BrowsingDataRemover::TimeRange::operator==( bool BrowsingDataRemover::TimeRange::operator==(
const BrowsingDataRemover::TimeRange& other) const { const BrowsingDataRemover::TimeRange& other) const {
return begin == other.begin && end == other.end; return begin == other.begin && end == other.end;
...@@ -329,9 +198,15 @@ BrowsingDataRemover::BrowsingDataRemover( ...@@ -329,9 +198,15 @@ BrowsingDataRemover::BrowsingDataRemover(
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
flash_lso_helper_(BrowsingDataFlashLSOHelper::Create(profile_)), flash_lso_helper_(BrowsingDataFlashLSOHelper::Create(profile_)),
#endif #endif
#if BUILDFLAG(ANDROID_JAVA_UI) sub_task_forward_callback_(
webapp_registry_(new WebappRegistry()), base::Bind(&BrowsingDataRemover::NotifyIfDone,
#endif base::Unretained(this))),
synchronous_clear_operations_(sub_task_forward_callback_),
clear_embedder_data_(sub_task_forward_callback_),
clear_cache_(sub_task_forward_callback_),
clear_channel_ids_(sub_task_forward_callback_),
clear_http_auth_cache_(sub_task_forward_callback_),
clear_storage_partition_data_(sub_task_forward_callback_),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
DCHECK(browser_context); DCHECK(browser_context);
} }
...@@ -354,8 +229,7 @@ BrowsingDataRemover::~BrowsingDataRemover() { ...@@ -354,8 +229,7 @@ BrowsingDataRemover::~BrowsingDataRemover() {
} }
void BrowsingDataRemover::Shutdown() { void BrowsingDataRemover::Shutdown() {
history_task_tracker_.TryCancelAll(); embedder_delegate_.reset();
template_url_sub_.reset();
} }
void BrowsingDataRemover::SetRemoving(bool is_removing) { void BrowsingDataRemover::SetRemoving(bool is_removing) {
...@@ -463,8 +337,7 @@ void BrowsingDataRemover::RemoveImpl( ...@@ -463,8 +337,7 @@ void BrowsingDataRemover::RemoveImpl(
// 3. Do not support partial deletion, i.e. only delete your data if // 3. Do not support partial deletion, i.e. only delete your data if
// |filter_builder.IsEmptyBlacklist()|. Add a comment explaining why this // |filter_builder.IsEmptyBlacklist()|. Add a comment explaining why this
// is acceptable. // is acceptable.
DCHECK_CURRENTLY_ON(BrowserThread::UI); synchronous_clear_operations_.Start();
waiting_for_synchronous_clear_operations_ = true;
// crbug.com/140910: Many places were calling this with base::Time() as // crbug.com/140910: Many places were calling this with base::Time() as
// delete_end, even though they should've used base::Time::Max(). // delete_end, even though they should've used base::Time::Max().
...@@ -475,26 +348,6 @@ void BrowsingDataRemover::RemoveImpl( ...@@ -475,26 +348,6 @@ void BrowsingDataRemover::RemoveImpl(
remove_mask_ = remove_mask; remove_mask_ = remove_mask;
origin_type_mask_ = origin_type_mask; origin_type_mask_ = origin_type_mask;
base::Callback<bool(const GURL& url)> filter =
filter_builder.BuildGeneralFilter();
base::Callback<bool(const ContentSettingsPattern& url)> same_pattern_filter =
filter_builder.BuildWebsiteSettingsPatternMatchesFilter();
// Some backends support a filter that |is_null()| to make complete deletion
// more efficient.
base::Callback<bool(const GURL&)> nullable_filter =
filter_builder.IsEmptyBlacklist() ? base::Callback<bool(const GURL&)>()
: filter;
PrefService* prefs = profile_->GetPrefs();
bool may_delete_history = prefs->GetBoolean(
prefs::kAllowDeletingBrowserHistory);
// All the UI entry points into the BrowsingDataRemover should be disabled,
// but this will fire if something was missed or added.
DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) ||
(!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS)));
if (origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { if (origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
content::RecordAction( content::RecordAction(
UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb")); UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb"));
...@@ -515,173 +368,37 @@ void BrowsingDataRemover::RemoveImpl( ...@@ -515,173 +368,37 @@ void BrowsingDataRemover::RemoveImpl(
BrowsingDataHelper::EXTENSION), BrowsingDataHelper::EXTENSION),
"OriginTypeMask has been updated without updating user metrics"); "OriginTypeMask has been updated without updating user metrics");
if ((remove_mask & REMOVE_HISTORY) && may_delete_history) { // Record the combined deletion of cookies and cache.
history::HistoryService* history_service = CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE;
HistoryServiceFactory::GetForProfile( if (remove_mask & REMOVE_COOKIES &&
profile_, ServiceAccessType::EXPLICIT_ACCESS); origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
if (history_service) { choice = remove_mask & REMOVE_CACHE ? BOTH_COOKIES_AND_CACHE
// TODO(dmurph): Support all backends with filter (crbug.com/113621). : ONLY_COOKIES;
content::RecordAction(UserMetricsAction("ClearBrowsingData_History")); } else if (remove_mask & REMOVE_CACHE) {
waiting_for_clear_history_ = true; choice = ONLY_CACHE;
history_service->ExpireLocalAndRemoteHistoryBetween( }
WebHistoryServiceFactory::GetForProfile(profile_), std::set<GURL>(),
delete_begin_, delete_end_,
base::Bind(&BrowsingDataRemover::OnHistoryDeletionDone,
weak_ptr_factory_.GetWeakPtr()),
&history_task_tracker_);
}
// Currently, ContentSuggestionService instance exists only on Android.
ntp_snippets::ContentSuggestionsService* content_suggestions_service =
ContentSuggestionsServiceFactory::GetForProfileIfExists(profile_);
if (content_suggestions_service) {
content_suggestions_service->ClearHistory(delete_begin_, delete_end_,
filter);
}
// Remove the last visit dates meta-data from the bookmark model.
// TODO(vitaliii): Do not remove all dates, but only the ones matched by the
// time range and the filter.
bookmarks::BookmarkModel* bookmark_model =
BookmarkModelFactory::GetForBrowserContext(profile_);
if (bookmark_model)
ntp_snippets::RemoveAllLastVisitDates(bookmark_model);
#if BUILDFLAG(ENABLE_EXTENSIONS)
// The extension activity log contains details of which websites extensions
// were active on. It therefore indirectly stores details of websites a
// user has visited so best clean from here as well.
// TODO(msramek): Support all backends with filter (crbug.com/589586).
extensions::ActivityLog::GetInstance(profile_)->RemoveURLs(
std::set<GURL>());
// Clear launch times as they are a form of history.
// BrowsingDataFilterBuilder currently doesn't support extension origins.
// Therefore, clearing history for a small set of origins (WHITELIST) should
// never delete any extension launch times, while clearing for almost all
// origins (BLACKLIST) should always delete all of extension launch times.
if (filter_builder.mode() == BrowsingDataFilterBuilder::BLACKLIST) {
extensions::ExtensionPrefs* extension_prefs =
extensions::ExtensionPrefs::Get(profile_);
extension_prefs->ClearLastLaunchTimes();
}
#endif
// Need to clear the host cache and accumulated speculative data, as it also
// reveals some history. We have no mechanism to track when these items were
// created, so we'll not honor the time range.
// TODO(msramek): We can use the plugin filter here because plugins, same
// as the hostname resolution cache, key their entries by hostname. Rename
// BuildPluginFilter() to something more general to reflect this use.
if (g_browser_process->io_thread()) {
waiting_for_clear_hostname_resolution_cache_ = true;
BrowserThread::PostTaskAndReply(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearHostnameResolutionCacheOnIOThread,
g_browser_process->io_thread(),
filter_builder.BuildPluginFilter()),
base::Bind(&BrowsingDataRemover::OnClearedHostnameResolutionCache,
weak_ptr_factory_.GetWeakPtr()));
}
if (profile_->GetNetworkPredictor()) {
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
waiting_for_clear_network_predictor_ = true;
BrowserThread::PostTaskAndReply(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearNetworkPredictorOnIOThread,
profile_->GetNetworkPredictor()),
base::Bind(&BrowsingDataRemover::OnClearedNetworkPredictor,
weak_ptr_factory_.GetWeakPtr()));
profile_->GetNetworkPredictor()->ClearPrefsOnUIThread();
}
// As part of history deletion we also delete the auto-generated keywords.
TemplateURLService* keywords_model =
TemplateURLServiceFactory::GetForProfile(profile_);
if (keywords_model && !keywords_model->loaded()) {
// TODO(msramek): Store filters from the currently executed task on the
// object to avoid having to copy them to callback methods.
template_url_sub_ = keywords_model->RegisterOnLoadedCallback(
base::Bind(&BrowsingDataRemover::OnKeywordsLoaded,
weak_ptr_factory_.GetWeakPtr(), filter));
keywords_model->Load();
waiting_for_clear_keyword_data_ = true;
} else if (keywords_model) {
keywords_model->RemoveAutoGeneratedForUrlsBetween(filter, delete_begin_,
delete_end_);
}
// The PrerenderManager keeps history of prerendered pages, so clear that. UMA_HISTOGRAM_ENUMERATION(
// It also may have a prerendered page. If so, the page could be "History.ClearBrowsingData.UserDeletedCookieOrCache",
// considered to have a small amount of historical information, so delete choice, MAX_CHOICE_VALUE);
// it, too.
prerender::PrerenderManager* prerender_manager =
prerender::PrerenderManagerFactory::GetForBrowserContext(profile_);
if (prerender_manager) {
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
prerender_manager->ClearData(
prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS |
prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY);
}
// If the caller is removing history for all hosts, then clear ancillary // Managed devices and supervised users can have restrictions on history
// historical information. // deletion.
if (filter_builder.IsEmptyBlacklist()) { PrefService* prefs = profile_->GetPrefs();
// We also delete the list of recently closed tabs. Since these expire, bool may_delete_history = prefs->GetBoolean(
// they can't be more than a day old, so we can simply clear them all. prefs::kAllowDeletingBrowserHistory);
sessions::TabRestoreService* tab_service =
TabRestoreServiceFactory::GetForProfile(profile_);
if (tab_service) {
tab_service->ClearEntries();
tab_service->DeleteLastSession();
}
#if BUILDFLAG(ENABLE_SESSION_SERVICE)
// We also delete the last session when we delete the history.
SessionService* session_service =
SessionServiceFactory::GetForProfile(profile_);
if (session_service)
session_service->DeleteLastSession();
#endif
}
// The saved Autofill profiles and credit cards can include the origin from // All the UI entry points into the BrowsingDataRemover should be disabled,
// which these profiles and credit cards were learned. These are a form of // but this will fire if something was missed or added.
// history, so clear them as well. DCHECK(may_delete_history || (remove_mask & REMOVE_NOCHECKS) ||
// TODO(dmurph): Support all backends with filter (crbug.com/113621). (!(remove_mask & REMOVE_HISTORY) && !(remove_mask & REMOVE_DOWNLOADS)));
scoped_refptr<autofill::AutofillWebDataService> web_data_service =
WebDataServiceFactory::GetAutofillWebDataForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS);
if (web_data_service.get()) {
waiting_for_clear_autofill_origin_urls_ = true;
web_data_service->RemoveOriginURLsModifiedBetween(
delete_begin_, delete_end_);
// The above calls are done on the UI thread but do their work on the DB
// thread. So wait for it.
BrowserThread::PostTaskAndReply(
BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing),
base::Bind(&BrowsingDataRemover::OnClearedAutofillOriginURLs,
weak_ptr_factory_.GetWeakPtr()));
autofill::PersonalDataManager* data_manager =
autofill::PersonalDataManagerFactory::GetForProfile(profile_);
if (data_manager)
data_manager->Refresh();
}
#if BUILDFLAG(ENABLE_WEBRTC) //////////////////////////////////////////////////////////////////////////////
waiting_for_clear_webrtc_logs_ = true; // INITIALIZATION
BrowserThread::PostTaskAndReply( base::Callback<bool(const GURL& url)> filter =
BrowserThread::FILE, FROM_HERE, filter_builder.BuildGeneralFilter();
base::Bind(
&WebRtcLogUtil::DeleteOldAndRecentWebRtcLogFiles,
WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()),
delete_begin_),
base::Bind(&BrowsingDataRemover::OnClearedWebRtcLogs,
weak_ptr_factory_.GetWeakPtr()));
#endif
if ((remove_mask & REMOVE_HISTORY) && may_delete_history) {
// The SSL Host State that tracks SSL interstitial "proceed" decisions may // The SSL Host State that tracks SSL interstitial "proceed" decisions may
// include origins that the user has visited, so it must be cleared. // include origins that the user has visited, so it must be cleared.
// TODO(msramek): We can reuse the plugin filter here, since both plugins // TODO(msramek): We can reuse the plugin filter here, since both plugins
...@@ -693,51 +410,10 @@ void BrowsingDataRemover::RemoveImpl( ...@@ -693,51 +410,10 @@ void BrowsingDataRemover::RemoveImpl(
? base::Callback<bool(const std::string&)>() ? base::Callback<bool(const std::string&)>()
: filter_builder.BuildPluginFilter()); : filter_builder.BuildPluginFilter());
} }
#if BUILDFLAG(ANDROID_JAVA_UI)
precache::PrecacheManager* precache_manager =
precache::PrecacheManagerFactory::GetForBrowserContext(profile_);
// |precache_manager| could be nullptr if the profile is off the record.
if (!precache_manager) {
waiting_for_clear_precache_history_ = true;
precache_manager->ClearHistory();
// The above calls are done on the UI thread but do their work on the DB
// thread. So wait for it.
BrowserThread::PostTaskAndReply(
BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing),
base::Bind(&BrowsingDataRemover::OnClearedPrecacheHistory,
weak_ptr_factory_.GetWeakPtr()));
}
// Clear the history information (last launch time and origin URL) of any
// registered webapps.
webapp_registry_->ClearWebappHistoryForUrls(filter);
#endif
data_reduction_proxy::DataReductionProxySettings*
data_reduction_proxy_settings =
DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
profile_);
// |data_reduction_proxy_settings| is null if |profile_| is off the record.
if (data_reduction_proxy_settings) {
data_reduction_proxy::DataReductionProxyService*
data_reduction_proxy_service =
data_reduction_proxy_settings->data_reduction_proxy_service();
if (data_reduction_proxy_service) {
data_reduction_proxy_service->compression_stats()
->DeleteBrowsingHistory(delete_begin_, delete_end_);
}
}
// |previews_service| is null if |profile_| is off the record.
PreviewsService* previews_service =
PreviewsServiceFactory::GetForProfile(profile_);
if (previews_service && previews_service->previews_ui_service()) {
previews_service->previews_ui_service()->ClearBlackList(delete_begin_,
delete_end_);
}
} }
//////////////////////////////////////////////////////////////////////////////
// REMOVE_DOWNLOADS
if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) { if ((remove_mask & REMOVE_DOWNLOADS) && may_delete_history) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads")); content::RecordAction(UserMetricsAction("ClearBrowsingData_Downloads"));
content::DownloadManager* download_manager = content::DownloadManager* download_manager =
...@@ -749,55 +425,8 @@ void BrowsingDataRemover::RemoveImpl( ...@@ -749,55 +425,8 @@ void BrowsingDataRemover::RemoveImpl(
download_prefs->SetSaveFilePath(download_prefs->DownloadPath()); download_prefs->SetSaveFilePath(download_prefs->DownloadPath());
} }
uint32_t storage_partition_remove_mask = 0; //////////////////////////////////////////////////////////////////////////////
// REMOVE_CHANNEL_IDS
// We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set,
// so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB
// don't accidentally remove the cookies that are associated with the
// UNPROTECTED_WEB origin. This is necessary because cookies are not separated
// between UNPROTECTED_WEB and PROTECTED_WEB.
if (remove_mask & REMOVE_COOKIES &&
origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies"));
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_COOKIES;
// Clear the safebrowsing cookies only if time period is for "all time". It
// doesn't make sense to apply the time period of deleting in the last X
// hours/days to the safebrowsing cookies since they aren't the result of
// any user action.
if (delete_begin_ == base::Time()) {
safe_browsing::SafeBrowsingService* sb_service =
g_browser_process->safe_browsing_service();
if (sb_service) {
scoped_refptr<net::URLRequestContextGetter> sb_context =
sb_service->url_request_context();
++waiting_for_clear_cookies_count_;
if (filter_builder.IsEmptyBlacklist()) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearCookiesOnIOThread, delete_begin_, delete_end_,
base::RetainedRef(std::move(sb_context)),
UIThreadTrampoline(
base::Bind(&BrowsingDataRemover::OnClearedCookies,
weak_ptr_factory_.GetWeakPtr()))));
} else {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearCookiesWithPredicateOnIOThread, delete_begin_,
delete_end_, filter_builder.BuildCookieFilter(),
base::RetainedRef(std::move(sb_context)),
UIThreadTrampoline(
base::Bind(&BrowsingDataRemover::OnClearedCookies,
weak_ptr_factory_.GetWeakPtr()))));
}
}
}
MediaDeviceIDSalt::Reset(profile_->GetPrefs());
}
// Channel IDs are not separated for protected and unprotected web // Channel IDs are not separated for protected and unprotected web
// origins. We check the origin_type_mask_ to prevent unintended deletion. // origins. We check the origin_type_mask_ to prevent unintended deletion.
if (remove_mask & REMOVE_CHANNEL_IDS && if (remove_mask & REMOVE_CHANNEL_IDS &&
...@@ -808,28 +437,33 @@ void BrowsingDataRemover::RemoveImpl( ...@@ -808,28 +437,33 @@ void BrowsingDataRemover::RemoveImpl(
scoped_refptr<net::URLRequestContextGetter> rq_context = scoped_refptr<net::URLRequestContextGetter> rq_context =
content::BrowserContext::GetDefaultStoragePartition(profile_)-> content::BrowserContext::GetDefaultStoragePartition(profile_)->
GetURLRequestContext(); GetURLRequestContext();
waiting_for_clear_channel_ids_ = true; clear_channel_ids_.Start();
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::Bind(&ClearChannelIDsOnIOThread, base::Bind(&ClearChannelIDsOnIOThread,
filter_builder.BuildChannelIDFilter(), filter_builder.BuildChannelIDFilter(),
delete_begin_, delete_end_, std::move(rq_context), delete_begin_, delete_end_, std::move(rq_context),
base::Bind(&BrowsingDataRemover::OnClearedChannelIDs, clear_channel_ids_.GetCompletionCallback()));
weak_ptr_factory_.GetWeakPtr())));
} }
if (remove_mask & REMOVE_DURABLE_PERMISSION) { //////////////////////////////////////////////////////////////////////////////
HostContentSettingsMapFactory::GetForProfile(profile_) // STORAGE PARTITION DATA
->ClearSettingsForOneTypeWithPredicate( uint32_t storage_partition_remove_mask = 0;
CONTENT_SETTINGS_TYPE_DURABLE_STORAGE,
base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
}
// We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set,
// so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB
// don't accidentally remove the cookies that are associated with the
// UNPROTECTED_WEB origin. This is necessary because cookies are not separated
// between UNPROTECTED_WEB and PROTECTED_WEB.
if (remove_mask & REMOVE_COOKIES &&
origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_COOKIES;
}
if (remove_mask & REMOVE_LOCAL_STORAGE) { if (remove_mask & REMOVE_LOCAL_STORAGE) {
storage_partition_remove_mask |= storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE; content::StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE;
} }
if (remove_mask & REMOVE_INDEXEDDB) { if (remove_mask & REMOVE_INDEXEDDB) {
storage_partition_remove_mask |= storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_INDEXEDDB; content::StoragePartition::REMOVE_DATA_MASK_INDEXEDDB;
...@@ -855,13 +489,60 @@ void BrowsingDataRemover::RemoveImpl( ...@@ -855,13 +489,60 @@ void BrowsingDataRemover::RemoveImpl(
content::StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS; content::StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS;
} }
// Content Decryption Modules used by Encrypted Media store licenses in a
// private filesystem. These are different than content licenses used by
// Flash (which are deleted father down in this method).
if (remove_mask & REMOVE_MEDIA_LICENSES) {
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA;
}
if (storage_partition_remove_mask) {
clear_storage_partition_data_.Start();
content::StoragePartition* storage_partition;
if (storage_partition_for_testing_)
storage_partition = storage_partition_for_testing_;
else
storage_partition = BrowserContext::GetDefaultStoragePartition(profile_);
uint32_t quota_storage_remove_mask =
~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
if (delete_begin_ == base::Time() ||
origin_type_mask_ &
(BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) {
// If we're deleting since the beginning of time, or we're removing
// protected origins, then remove persistent quota data.
quota_storage_remove_mask |=
content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
}
// If cookies are supposed to be conditionally deleted from the storage
// partition, create a cookie matcher function.
content::StoragePartition::CookieMatcherFunction cookie_matcher;
if (!filter_builder.IsEmptyBlacklist() &&
(storage_partition_remove_mask &
content::StoragePartition::REMOVE_DATA_MASK_COOKIES)) {
cookie_matcher = filter_builder.BuildCookieFilter();
}
storage_partition->ClearData(
storage_partition_remove_mask, quota_storage_remove_mask,
base::Bind(&DoesOriginMatchMaskAndUrls, origin_type_mask_, filter),
cookie_matcher, delete_begin_, delete_end_,
clear_storage_partition_data_.GetCompletionCallback());
}
//////////////////////////////////////////////////////////////////////////////
// REMOVE_PLUGINS
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
// Plugin is data not separated for protected and unprotected web origins. We // Plugin is data not separated for protected and unprotected web origins. We
// check the origin_type_mask_ to prevent unintended deletion. // check the origin_type_mask_ to prevent unintended deletion.
if (remove_mask & REMOVE_PLUGIN_DATA && if (remove_mask & REMOVE_PLUGIN_DATA &&
origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) { origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData")); content::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData"));
waiting_for_clear_plugin_data_count_ = 1; clear_plugin_data_count_ = 1;
if (filter_builder.IsEmptyBlacklist()) { if (filter_builder.IsEmptyBlacklist()) {
DCHECK(!plugin_data_remover_); DCHECK(!plugin_data_remover_);
...@@ -884,331 +565,63 @@ void BrowsingDataRemover::RemoveImpl( ...@@ -884,331 +565,63 @@ void BrowsingDataRemover::RemoveImpl(
} }
#endif #endif
if (remove_mask & REMOVE_SITE_USAGE_DATA) { //////////////////////////////////////////////////////////////////////////////
HostContentSettingsMapFactory::GetForProfile(profile_) // CACHE
->ClearSettingsForOneTypeWithPredicate(
CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
}
if (remove_mask & REMOVE_SITE_USAGE_DATA || remove_mask & REMOVE_HISTORY) {
HostContentSettingsMapFactory::GetForProfile(profile_)
->ClearSettingsForOneTypeWithPredicate(
CONTENT_SETTINGS_TYPE_APP_BANNER,
base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
PermissionDecisionAutoBlocker::RemoveCountsByUrl(profile_, filter);
}
if (remove_mask & REMOVE_PASSWORDS) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords"));
password_manager::PasswordStore* password_store =
PasswordStoreFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
if (password_store) {
waiting_for_clear_passwords_ = true;
auto on_cleared_passwords =
base::Bind(&BrowsingDataRemover::OnClearedPasswords,
weak_ptr_factory_.GetWeakPtr());
password_store->RemoveLoginsByURLAndTime(
filter, delete_begin_, delete_end_, on_cleared_passwords);
}
}
if (remove_mask & REMOVE_COOKIES) {
password_manager::PasswordStore* password_store =
PasswordStoreFactory::GetForProfile(profile_,
ServiceAccessType::EXPLICIT_ACCESS)
.get();
if (password_store) {
waiting_for_clear_auto_sign_in_ = true;
base::Closure on_cleared_auto_sign_in =
base::Bind(&BrowsingDataRemover::OnClearedAutoSignIn,
weak_ptr_factory_.GetWeakPtr());
password_store->DisableAutoSignInForOrigins(
filter, on_cleared_auto_sign_in);
}
}
if (remove_mask & REMOVE_HISTORY) {
password_manager::PasswordStore* password_store =
PasswordStoreFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
if (password_store) {
waiting_for_clear_passwords_stats_ = true;
password_store->RemoveStatisticsByOriginAndTime(
nullable_filter, delete_begin_, delete_end_,
base::Bind(&BrowsingDataRemover::OnClearedPasswordsStats,
weak_ptr_factory_.GetWeakPtr()));
}
}
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
if (remove_mask & REMOVE_FORM_DATA) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill"));
scoped_refptr<autofill::AutofillWebDataService> web_data_service =
WebDataServiceFactory::GetAutofillWebDataForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS);
if (web_data_service.get()) {
waiting_for_clear_form_ = true;
web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
delete_end_);
web_data_service->RemoveAutofillDataModifiedBetween(
delete_begin_, delete_end_);
// The above calls are done on the UI thread but do their work on the DB
// thread. So wait for it.
BrowserThread::PostTaskAndReply(
BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing),
base::Bind(&BrowsingDataRemover::OnClearedFormData,
weak_ptr_factory_.GetWeakPtr()));
autofill::PersonalDataManager* data_manager =
autofill::PersonalDataManagerFactory::GetForProfile(profile_);
if (data_manager)
data_manager->Refresh();
}
}
if (remove_mask & REMOVE_CACHE) { if (remove_mask & REMOVE_CACHE) {
// Tell the renderers to clear their cache. // Tell the renderers to clear their cache.
web_cache::WebCacheManager::GetInstance()->ClearCache(); web_cache::WebCacheManager::GetInstance()->ClearCache();
content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache")); content::RecordAction(UserMetricsAction("ClearBrowsingData_Cache"));
waiting_for_clear_cache_ = true; clear_cache_.Start();
// StoragePartitionHttpCacheDataRemover deletes itself when it is done. // StoragePartitionHttpCacheDataRemover deletes itself when it is done.
if (filter_builder.IsEmptyBlacklist()) { if (filter_builder.IsEmptyBlacklist()) {
browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange(
BrowserContext::GetDefaultStoragePartition(profile_), BrowserContext::GetDefaultStoragePartition(profile_),
delete_begin_, delete_end_) delete_begin_, delete_end_)
->Remove(base::Bind(&BrowsingDataRemover::ClearedCache, ->Remove(clear_cache_.GetCompletionCallback());
weak_ptr_factory_.GetWeakPtr()));
} else { } else {
browsing_data::StoragePartitionHttpCacheDataRemover:: browsing_data::StoragePartitionHttpCacheDataRemover::
CreateForURLsAndRange( CreateForURLsAndRange(
BrowserContext::GetDefaultStoragePartition(profile_), BrowserContext::GetDefaultStoragePartition(profile_),
filter, delete_begin_, delete_end_) filter, delete_begin_, delete_end_)
->Remove(base::Bind(&BrowsingDataRemover::ClearedCache, ->Remove(clear_cache_.GetCompletionCallback());
weak_ptr_factory_.GetWeakPtr()));
}
#if !defined(DISABLE_NACL)
waiting_for_clear_nacl_cache_ = true;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearNaClCacheOnIOThread,
UIThreadTrampoline(
base::Bind(&BrowsingDataRemover::ClearedNaClCache,
weak_ptr_factory_.GetWeakPtr()))));
waiting_for_clear_pnacl_cache_ = true;
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearPnaclCacheOnIOThread, delete_begin_, delete_end_,
UIThreadTrampoline(
base::Bind(&BrowsingDataRemover::ClearedPnaclCache,
weak_ptr_factory_.GetWeakPtr()))));
#endif
// The PrerenderManager may have a page actively being prerendered, which
// is essentially a preemptively cached page.
prerender::PrerenderManager* prerender_manager =
prerender::PrerenderManagerFactory::GetForBrowserContext(profile_);
if (prerender_manager) {
prerender_manager->ClearData(
prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS);
} }
// Tell the shader disk cache to clear. // Tell the shader disk cache to clear.
content::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache")); content::RecordAction(UserMetricsAction("ClearBrowsingData_ShaderCache"));
storage_partition_remove_mask |= storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE; content::StoragePartition::REMOVE_DATA_MASK_SHADER_CACHE;
// When clearing cache, wipe accumulated network related data
// (TransportSecurityState and HttpServerPropertiesManager data).
waiting_for_clear_networking_history_ = true;
profile_->ClearNetworkingHistorySince(
delete_begin_,
base::Bind(&BrowsingDataRemover::OnClearedNetworkingHistory,
weak_ptr_factory_.GetWeakPtr()));
ntp_snippets::ContentSuggestionsService* content_suggestions_service =
ContentSuggestionsServiceFactory::GetForProfileIfExists(profile_);
if (content_suggestions_service)
content_suggestions_service->ClearAllCachedSuggestions();
// |ui_nqe_service| may be null if |profile_| is not a regular profile.
UINetworkQualityEstimatorService* ui_nqe_service =
UINetworkQualityEstimatorServiceFactory::GetForProfile(profile_);
DCHECK(profile_->GetProfileType() !=
Profile::ProfileType::REGULAR_PROFILE ||
ui_nqe_service != nullptr);
if (ui_nqe_service) {
// Network Quality Estimator (NQE) stores the quality (RTT, bandwidth
// etc.) of different networks in prefs. The stored quality is not
// broken down by URLs or timestamps, so clearing the cache should
// completely clear the prefs.
ui_nqe_service->ClearPrefs();
}
} }
//////////////////////////////////////////////////////////////////////////////
// Auth cache.
if (remove_mask & REMOVE_COOKIES || remove_mask & REMOVE_PASSWORDS) { if (remove_mask & REMOVE_COOKIES || remove_mask & REMOVE_PASSWORDS) {
scoped_refptr<net::URLRequestContextGetter> request_context = scoped_refptr<net::URLRequestContextGetter> request_context =
profile_->GetRequestContext(); profile_->GetRequestContext();
waiting_for_clear_http_auth_cache_ = true; clear_http_auth_cache_.Start();
BrowserThread::PostTaskAndReply( BrowserThread::PostTaskAndReply(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::Bind(&ClearHttpAuthCacheOnIOThread, std::move(request_context), base::Bind(&ClearHttpAuthCacheOnIOThread, std::move(request_context),
delete_begin_), delete_begin_),
base::Bind(&BrowsingDataRemover::OnClearedHttpAuthCache, clear_http_auth_cache_.GetCompletionCallback());
weak_ptr_factory_.GetWeakPtr()));
}
// Content Decryption Modules used by Encrypted Media store licenses in a
// private filesystem. These are different than content licenses used by
// Flash (which are deleted father down in this method).
if (remove_mask & REMOVE_MEDIA_LICENSES) {
storage_partition_remove_mask |=
content::StoragePartition::REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA;
}
if (storage_partition_remove_mask) {
waiting_for_clear_storage_partition_data_ = true;
content::StoragePartition* storage_partition;
if (storage_partition_for_testing_)
storage_partition = storage_partition_for_testing_;
else
storage_partition = BrowserContext::GetDefaultStoragePartition(profile_);
uint32_t quota_storage_remove_mask =
~content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
if (delete_begin_ == base::Time() ||
origin_type_mask_ &
(BrowsingDataHelper::PROTECTED_WEB | BrowsingDataHelper::EXTENSION)) {
// If we're deleting since the beginning of time, or we're removing
// protected origins, then remove persistent quota data.
quota_storage_remove_mask |=
content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
}
// If cookies are supposed to be conditionally deleted from the storage
// partition, create a cookie matcher function.
content::StoragePartition::CookieMatcherFunction cookie_matcher;
if (!filter_builder.IsEmptyBlacklist() &&
(storage_partition_remove_mask &
content::StoragePartition::REMOVE_DATA_MASK_COOKIES)) {
cookie_matcher = filter_builder.BuildCookieFilter();
}
storage_partition->ClearData(
storage_partition_remove_mask, quota_storage_remove_mask,
base::Bind(&DoesOriginMatchMaskAndUrls, origin_type_mask_, filter),
cookie_matcher, delete_begin_, delete_end_,
base::Bind(&BrowsingDataRemover::OnClearedStoragePartitionData,
weak_ptr_factory_.GetWeakPtr()));
} }
if (remove_mask & REMOVE_MEDIA_LICENSES) { //////////////////////////////////////////////////////////////////////////////
// TODO(jrummell): This UMA should be renamed to indicate it is for Media // Embedder data.
// Licenses. if (embedder_delegate_) {
content::RecordAction( clear_embedder_data_.Start();
UserMetricsAction("ClearBrowsingData_ContentLicenses")); embedder_delegate_->RemoveEmbedderData(
delete_begin_,
#if BUILDFLAG(ENABLE_PLUGINS) delete_end_,
waiting_for_clear_flash_content_licenses_ = true; remove_mask,
if (!pepper_flash_settings_manager_.get()) { filter_builder,
pepper_flash_settings_manager_.reset( origin_type_mask,
new PepperFlashSettingsManager(this, profile_)); clear_embedder_data_.GetCompletionCallback());
}
deauthorize_flash_content_licenses_request_id_ =
pepper_flash_settings_manager_->DeauthorizeContentLicenses(prefs);
#if defined(OS_CHROMEOS)
// On Chrome OS, also delete any content protection platform keys.
const user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
if (!user) {
LOG(WARNING) << "Failed to find user for current profile.";
} else {
chromeos::DBusThreadManager::Get()
->GetCryptohomeClient()
->TpmAttestationDeleteKeys(
chromeos::attestation::KEY_USER,
cryptohome::Identification(user->GetAccountId()),
chromeos::attestation::kContentProtectionKeyPrefix,
base::Bind(&BrowsingDataRemover::OnClearPlatformKeys,
weak_ptr_factory_.GetWeakPtr()));
waiting_for_clear_platform_keys_ = true;
}
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(ENABLE_PLUGINS)
}
// Remove omnibox zero-suggest cache results. Filtering is not supported.
// This is not a problem, as deleting more data than necessary will just cause
// another server round-trip; no data is actually lost.
if ((remove_mask & (REMOVE_CACHE | REMOVE_COOKIES)))
prefs->SetString(omnibox::kZeroSuggestCachedResults, std::string());
if (remove_mask & (REMOVE_COOKIES | REMOVE_HISTORY)) {
domain_reliability::DomainReliabilityService* service =
domain_reliability::DomainReliabilityServiceFactory::
GetForBrowserContext(profile_);
if (service) {
domain_reliability::DomainReliabilityClearMode mode;
if (remove_mask & REMOVE_COOKIES)
mode = domain_reliability::CLEAR_CONTEXTS;
else
mode = domain_reliability::CLEAR_BEACONS;
waiting_for_clear_domain_reliability_monitor_ = true;
service->ClearBrowsingData(
mode,
filter,
base::Bind(&BrowsingDataRemover::OnClearedDomainReliabilityMonitor,
weak_ptr_factory_.GetWeakPtr()));
}
}
#if BUILDFLAG(ANDROID_JAVA_UI)
// Clear all data associated with registered webapps.
if (remove_mask & REMOVE_WEBAPP_DATA)
webapp_registry_->UnregisterWebappsForUrls(filter);
// For now we're considering offline pages as cache, so if we're removing
// cache we should remove offline pages as well.
if ((remove_mask & REMOVE_CACHE)) {
waiting_for_clear_offline_page_data_ = true;
offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_)
->DeleteCachedPagesByURLPredicate(
filter, base::Bind(&BrowsingDataRemover::OnClearedOfflinePageData,
weak_ptr_factory_.GetWeakPtr()));
}
#endif
// Record the combined deletion of cookies and cache.
CookieOrCacheDeletionChoice choice = NEITHER_COOKIES_NOR_CACHE;
if (remove_mask & REMOVE_COOKIES &&
origin_type_mask_ & BrowsingDataHelper::UNPROTECTED_WEB) {
choice = remove_mask & REMOVE_CACHE ? BOTH_COOKIES_AND_CACHE
: ONLY_COOKIES;
} else if (remove_mask & REMOVE_CACHE) {
choice = ONLY_CACHE;
} }
// Notify in case all actions taken were synchronous. // Notify in case all actions taken were synchronous.
waiting_for_synchronous_clear_operations_ = false; synchronous_clear_operations_.GetCompletionCallback().Run();
NotifyIfDone();
UMA_HISTOGRAM_ENUMERATION(
"History.ClearBrowsingData.UserDeletedCookieOrCache",
choice, MAX_CHOICE_VALUE);
} }
void BrowsingDataRemover::AddObserver(Observer* observer) { void BrowsingDataRemover::AddObserver(Observer* observer) {
...@@ -1224,13 +637,6 @@ void BrowsingDataRemover::OverrideStoragePartitionForTesting( ...@@ -1224,13 +637,6 @@ void BrowsingDataRemover::OverrideStoragePartitionForTesting(
storage_partition_for_testing_ = storage_partition; storage_partition_for_testing_ = storage_partition;
} }
#if BUILDFLAG(ANDROID_JAVA_UI)
void BrowsingDataRemover::OverrideWebappRegistryForTesting(
std::unique_ptr<WebappRegistry> webapp_registry) {
webapp_registry_ = std::move(webapp_registry);
}
#endif
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
void BrowsingDataRemover::OverrideFlashLSOHelperForTesting( void BrowsingDataRemover::OverrideFlashLSOHelperForTesting(
scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper) { scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper) {
...@@ -1269,44 +675,13 @@ BrowsingDataRemover::RemovalTask::RemovalTask( ...@@ -1269,44 +675,13 @@ BrowsingDataRemover::RemovalTask::RemovalTask(
BrowsingDataRemover::RemovalTask::~RemovalTask() {} BrowsingDataRemover::RemovalTask::~RemovalTask() {}
bool BrowsingDataRemover::AllDone() { bool BrowsingDataRemover::AllDone() {
return !waiting_for_synchronous_clear_operations_ && return !synchronous_clear_operations_.is_pending() &&
!waiting_for_clear_autofill_origin_urls_ && !clear_embedder_data_.is_pending() &&
!waiting_for_clear_cache_ && !clear_cache_.is_pending() &&
!waiting_for_clear_flash_content_licenses_ && !clear_channel_ids_.is_pending() &&
!waiting_for_clear_channel_ids_ && !waiting_for_clear_cookies_count_ && !clear_http_auth_cache_.is_pending() &&
!waiting_for_clear_domain_reliability_monitor_ && !clear_storage_partition_data_.is_pending() &&
!waiting_for_clear_form_ && !waiting_for_clear_history_ && !clear_plugin_data_count_;
!waiting_for_clear_hostname_resolution_cache_ &&
!waiting_for_clear_http_auth_cache_ &&
!waiting_for_clear_keyword_data_ && !waiting_for_clear_nacl_cache_ &&
!waiting_for_clear_network_predictor_ &&
!waiting_for_clear_networking_history_ &&
!waiting_for_clear_passwords_ && !waiting_for_clear_passwords_stats_ &&
!waiting_for_clear_platform_keys_ &&
!waiting_for_clear_plugin_data_count_ &&
!waiting_for_clear_pnacl_cache_ &&
#if BUILDFLAG(ANDROID_JAVA_UI)
!waiting_for_clear_precache_history_ &&
!waiting_for_clear_offline_page_data_ &&
#endif
#if BUILDFLAG(ENABLE_WEBRTC)
!waiting_for_clear_webrtc_logs_ &&
#endif
!waiting_for_clear_storage_partition_data_ &&
!waiting_for_clear_auto_sign_in_;
}
void BrowsingDataRemover::OnKeywordsLoaded(
base::Callback<bool(const GURL&)> url_filter) {
// Deletes the entries from the model, and if we're not waiting on anything
// else notifies observers and deletes this BrowsingDataRemover.
TemplateURLService* model =
TemplateURLServiceFactory::GetForProfile(profile_);
model->RemoveAutoGeneratedForUrlsBetween(url_filter, delete_begin_,
delete_end_);
waiting_for_clear_keyword_data_ = false;
template_url_sub_.reset();
NotifyIfDone();
} }
void BrowsingDataRemover::Notify() { void BrowsingDataRemover::Notify() {
...@@ -1364,63 +739,13 @@ void BrowsingDataRemover::NotifyIfDone() { ...@@ -1364,63 +739,13 @@ void BrowsingDataRemover::NotifyIfDone() {
Notify(); Notify();
} }
void BrowsingDataRemover::OnHistoryDeletionDone() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_history_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::OnClearedHostnameResolutionCache() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_hostname_resolution_cache_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::OnClearedHttpAuthCache() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_http_auth_cache_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::OnClearedNetworkPredictor() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_network_predictor_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::OnClearedNetworkingHistory() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_networking_history_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::ClearedCache() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_cache_ = false;
NotifyIfDone();
}
#if !defined(DISABLE_NACL)
void BrowsingDataRemover::ClearedNaClCache() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_nacl_cache_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::ClearedPnaclCache() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_pnacl_cache_ = false;
NotifyIfDone();
}
#endif
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
void BrowsingDataRemover::OnWaitableEventSignaled( void BrowsingDataRemover::OnWaitableEventSignaled(
base::WaitableEvent* waitable_event) { base::WaitableEvent* waitable_event) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK_EQ(1, waiting_for_clear_plugin_data_count_); DCHECK_EQ(1, clear_plugin_data_count_);
waiting_for_clear_plugin_data_count_ = 0; clear_plugin_data_count_ = 0;
plugin_data_remover_.reset(); plugin_data_remover_.reset();
watcher_.StopWatching(); watcher_.StopWatching();
...@@ -1430,8 +755,8 @@ void BrowsingDataRemover::OnWaitableEventSignaled( ...@@ -1430,8 +755,8 @@ void BrowsingDataRemover::OnWaitableEventSignaled(
void BrowsingDataRemover::OnSitesWithFlashDataFetched( void BrowsingDataRemover::OnSitesWithFlashDataFetched(
base::Callback<bool(const std::string&)> plugin_filter, base::Callback<bool(const std::string&)> plugin_filter,
const std::vector<std::string>& sites) { const std::vector<std::string>& sites) {
DCHECK_EQ(1, waiting_for_clear_plugin_data_count_); DCHECK_EQ(1, clear_plugin_data_count_);
waiting_for_clear_plugin_data_count_ = 0; clear_plugin_data_count_ = 0;
std::vector<std::string> sites_to_delete; std::vector<std::string> sites_to_delete;
for (const std::string& site : sites) { for (const std::string& site : sites) {
...@@ -1439,7 +764,7 @@ void BrowsingDataRemover::OnSitesWithFlashDataFetched( ...@@ -1439,7 +764,7 @@ void BrowsingDataRemover::OnSitesWithFlashDataFetched(
sites_to_delete.push_back(site); sites_to_delete.push_back(site);
} }
waiting_for_clear_plugin_data_count_ = sites_to_delete.size(); clear_plugin_data_count_ = sites_to_delete.size();
for (const std::string& site : sites_to_delete) { for (const std::string& site : sites_to_delete) {
flash_lso_helper_->DeleteFlashLSOsForSite( flash_lso_helper_->DeleteFlashLSOsForSite(
...@@ -1452,109 +777,7 @@ void BrowsingDataRemover::OnSitesWithFlashDataFetched( ...@@ -1452,109 +777,7 @@ void BrowsingDataRemover::OnSitesWithFlashDataFetched(
} }
void BrowsingDataRemover::OnFlashDataDeleted() { void BrowsingDataRemover::OnFlashDataDeleted() {
waiting_for_clear_plugin_data_count_--; clear_plugin_data_count_--;
NotifyIfDone();
}
void BrowsingDataRemover::OnDeauthorizeFlashContentLicensesCompleted(
uint32_t request_id,
bool /* success */) {
DCHECK(waiting_for_clear_flash_content_licenses_);
DCHECK_EQ(request_id, deauthorize_flash_content_licenses_request_id_);
waiting_for_clear_flash_content_licenses_ = false;
NotifyIfDone();
}
#endif
#if defined(OS_CHROMEOS)
void BrowsingDataRemover::OnClearPlatformKeys(
chromeos::DBusMethodCallStatus call_status,
bool result) {
DCHECK(waiting_for_clear_platform_keys_);
LOG_IF(ERROR, call_status != chromeos::DBUS_METHOD_CALL_SUCCESS || !result)
<< "Failed to clear platform keys.";
waiting_for_clear_platform_keys_ = false;
NotifyIfDone();
}
#endif
void BrowsingDataRemover::OnClearedPasswords() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_passwords_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::OnClearedPasswordsStats() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_passwords_stats_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::OnClearedAutoSignIn() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_auto_sign_in_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::OnClearedCookies() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK_GT(waiting_for_clear_cookies_count_, 0);
--waiting_for_clear_cookies_count_;
NotifyIfDone();
}
void BrowsingDataRemover::OnClearedChannelIDs() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_channel_ids_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::OnClearedFormData() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_form_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::OnClearedAutofillOriginURLs() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_autofill_origin_urls_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::OnClearedStoragePartitionData() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_storage_partition_data_ = false;
NotifyIfDone();
}
#if BUILDFLAG(ENABLE_WEBRTC)
void BrowsingDataRemover::OnClearedWebRtcLogs() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_webrtc_logs_ = false;
NotifyIfDone(); NotifyIfDone();
} }
#endif #endif
#if BUILDFLAG(ANDROID_JAVA_UI)
void BrowsingDataRemover::OnClearedPrecacheHistory() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_precache_history_ = false;
NotifyIfDone();
}
void BrowsingDataRemover::OnClearedOfflinePageData(
offline_pages::OfflinePageModel::DeletePageResult result) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_offline_page_data_ = false;
NotifyIfDone();
}
#endif
void BrowsingDataRemover::OnClearedDomainReliabilityMonitor() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
waiting_for_clear_domain_reliability_monitor_ = false;
NotifyIfDone();
}
...@@ -13,44 +13,23 @@ ...@@ -13,44 +13,23 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/sequenced_task_runner_helpers.h"
#include "base/synchronization/waitable_event_watcher.h" #include "base/synchronization/waitable_event_watcher.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/browsing_data/browsing_data_remover_delegate.h"
#include "chrome/common/features.h" #include "chrome/common/features.h"
#include "components/browsing_data/core/browsing_data_utils.h" #include "components/browsing_data/core/browsing_data_utils.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/offline_pages/core/offline_page_model.h"
#include "components/prefs/pref_member.h"
#include "components/search_engines/template_url_service.h"
#include "media/media_features.h"
#include "ppapi/features/features.h" #include "ppapi/features/features.h"
#include "storage/common/quota/quota_types.h" #include "storage/common/quota/quota_types.h"
#include "url/gurl.h" #include "url/gurl.h"
#if BUILDFLAG(ENABLE_PLUGINS)
#include "chrome/browser/pepper_flash_settings_manager.h"
#endif
#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_method_call_status.h"
#endif
class BrowsingDataFilterBuilder; class BrowsingDataFilterBuilder;
class BrowsingDataFlashLSOHelper; class BrowsingDataFlashLSOHelper;
class BrowsingDataRemoverFactory; class BrowsingDataRemoverFactory;
class Profile; class Profile;
class WebappRegistry;
namespace chrome_browser_net {
class Predictor;
}
namespace content { namespace content {
class BrowserContext; class BrowserContext;
...@@ -90,11 +69,7 @@ class StoragePartition; ...@@ -90,11 +69,7 @@ class StoragePartition;
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
class BrowsingDataRemover : public KeyedService class BrowsingDataRemover : public KeyedService {
#if BUILDFLAG(ENABLE_PLUGINS)
, public PepperFlashSettingsManager::Client
#endif
{
public: public:
// Mask used for Remove. // Mask used for Remove.
enum RemoveDataMask { enum RemoveDataMask {
...@@ -223,6 +198,32 @@ class BrowsingDataRemover : public KeyedService ...@@ -223,6 +198,32 @@ class BrowsingDataRemover : public KeyedService
virtual ~CompletionInhibitor() {} virtual ~CompletionInhibitor() {}
}; };
// Used to track the deletion of a single data storage backend.
class SubTask {
public:
// Creates a SubTask that calls |forward_callback| when completed.
// |forward_callback| is only kept as a reference and must outlive SubTask.
explicit SubTask(const base::Closure& forward_callback);
~SubTask();
// Indicate that the task is in progress and we're waiting.
void Start();
// Returns a callback that should be called to indicate that the task
// has been finished.
base::Closure GetCompletionCallback();
// Whether the task is still in progress.
bool is_pending() const { return is_pending_; }
private:
void CompletionCallback();
bool is_pending_;
const base::Closure& forward_callback_;
base::WeakPtrFactory<SubTask> weak_ptr_factory_;
};
static TimeRange Unbounded(); static TimeRange Unbounded();
static TimeRange Period(browsing_data::TimePeriod period); static TimeRange Period(browsing_data::TimePeriod period);
...@@ -239,6 +240,17 @@ class BrowsingDataRemover : public KeyedService ...@@ -239,6 +240,17 @@ class BrowsingDataRemover : public KeyedService
completion_inhibitor_ = inhibitor; completion_inhibitor_ = inhibitor;
} }
// Called by the embedder to provide the delegate that will take care of
// deleting embedder-specific data.
void set_embedder_delegate(
std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate) {
embedder_delegate_ = std::move(embedder_delegate);
}
BrowsingDataRemoverDelegate* get_embedder_delegate() const {
return embedder_delegate_.get();
}
// Removes browsing data within the given |time_range|, with datatypes being // Removes browsing data within the given |time_range|, with datatypes being
// specified by |remove_mask| and origin types by |origin_type_mask|. // specified by |remove_mask| and origin types by |origin_type_mask|.
void Remove(const TimeRange& time_range, void Remove(const TimeRange& time_range,
...@@ -277,11 +289,6 @@ class BrowsingDataRemover : public KeyedService ...@@ -277,11 +289,6 @@ class BrowsingDataRemover : public KeyedService
void OverrideStoragePartitionForTesting( void OverrideStoragePartitionForTesting(
content::StoragePartition* storage_partition); content::StoragePartition* storage_partition);
#if BUILDFLAG(ANDROID_JAVA_UI)
void OverrideWebappRegistryForTesting(
std::unique_ptr<WebappRegistry> webapp_registry);
#endif
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
void OverrideFlashLSOHelperForTesting( void OverrideFlashLSOHelperForTesting(
scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper); scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper);
...@@ -347,10 +354,6 @@ class BrowsingDataRemover : public KeyedService ...@@ -347,10 +354,6 @@ class BrowsingDataRemover : public KeyedService
// not already removing, and vice-versa. // not already removing, and vice-versa.
void SetRemoving(bool is_removing); void SetRemoving(bool is_removing);
// Callback for when TemplateURLService has finished loading. Clears the data,
// clears the respective waiting flag, and invokes NotifyIfDone.
void OnKeywordsLoaded(base::Callback<bool(const GURL&)> url_filter);
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
// Called when plugin data has been cleared. Invokes NotifyIfDone. // Called when plugin data has been cleared. Invokes NotifyIfDone.
void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); void OnWaitableEventSignaled(base::WaitableEvent* waitable_event);
...@@ -362,15 +365,6 @@ class BrowsingDataRemover : public KeyedService ...@@ -362,15 +365,6 @@ class BrowsingDataRemover : public KeyedService
// Indicates that LSO cookies for one website have been deleted. // Indicates that LSO cookies for one website have been deleted.
void OnFlashDataDeleted(); void OnFlashDataDeleted();
// PepperFlashSettingsManager::Client implementation.
void OnDeauthorizeFlashContentLicensesCompleted(uint32_t request_id,
bool success) override;
#endif
#if defined (OS_CHROMEOS)
void OnClearPlatformKeys(chromeos::DBusMethodCallStatus call_status,
bool result);
#endif #endif
// Executes the next removal task. Called after the previous task was finished // Executes the next removal task. Called after the previous task was finished
...@@ -396,89 +390,15 @@ class BrowsingDataRemover : public KeyedService ...@@ -396,89 +390,15 @@ class BrowsingDataRemover : public KeyedService
// Checks if we are all done, and if so, calls Notify(). // Checks if we are all done, and if so, calls Notify().
void NotifyIfDone(); void NotifyIfDone();
// Called when history deletion is done.
void OnHistoryDeletionDone();
// Callback for when the hostname resolution cache has been cleared.
// Clears the respective waiting flag and invokes NotifyIfDone.
void OnClearedHostnameResolutionCache();
// Callback for when HTTP auth cache has been cleared.
// Clears the respective waiting flag and invokes NotifyIfDone.
void OnClearedHttpAuthCache();
// Callback for when speculative data in the network Predictor has been
// cleared. Clears the respective waiting flag and invokes
// NotifyIfDone.
void OnClearedNetworkPredictor();
// Callback for when network related data in ProfileIOData has been cleared.
// Clears the respective waiting flag and invokes NotifyIfDone.
void OnClearedNetworkingHistory();
// Callback for when the cache has been deleted. Invokes
// NotifyIfDone.
void ClearedCache();
#if !defined(DISABLE_NACL)
// Callback for when the NaCl cache has been deleted. Invokes
// NotifyIfDone.
void ClearedNaClCache();
// Callback for when the PNaCl translation cache has been deleted. Invokes
// NotifyIfDone.
void ClearedPnaclCache();
#endif
// Callback for when passwords for the requested time range have been cleared.
void OnClearedPasswords();
// Callback for when passwords stats for the requested time range have been
// cleared.
void OnClearedPasswordsStats();
// Callback for when the autosignin state of passwords has been revoked.
void OnClearedAutoSignIn();
// Callback for when cookies have been deleted. Invokes NotifyIfDone.
void OnClearedCookies();
// Callback for when channel IDs have been deleted. Invokes
// NotifyIfDone.
void OnClearedChannelIDs();
// Callback from the above method.
void OnClearedFormData();
// Callback for when the Autofill profile and credit card origin URLs have
// been deleted.
void OnClearedAutofillOriginURLs();
// Callback on UI thread when the storage partition related data are cleared.
void OnClearedStoragePartitionData();
#if BUILDFLAG(ENABLE_WEBRTC)
// Callback on UI thread when the WebRTC logs have been deleted.
void OnClearedWebRtcLogs();
#endif
#if BUILDFLAG(ANDROID_JAVA_UI)
// Callback on UI thread when the precache history has been cleared.
void OnClearedPrecacheHistory();
// Callback on UI thread when the offline page data has been cleared.
void OnClearedOfflinePageData(
offline_pages::OfflinePageModel::DeletePageResult result);
#endif
void OnClearedDomainReliabilityMonitor();
// Returns true if we're all done. // Returns true if we're all done.
bool AllDone(); bool AllDone();
// Profile we're to remove from. // Profile we're to remove from.
Profile* profile_; Profile* profile_;
// A delegate to delete the embedder-specific data.
std::unique_ptr<BrowsingDataRemoverDelegate> embedder_delegate_;
// Start time to delete from. // Start time to delete from.
base::Time delete_begin_; base::Time delete_begin_;
...@@ -509,64 +429,29 @@ class BrowsingDataRemover : public KeyedService ...@@ -509,64 +429,29 @@ class BrowsingDataRemover : public KeyedService
// Used for per-site plugin data deletion. // Used for per-site plugin data deletion.
scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper_; scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper_;
// Used to deauthorize content licenses for Pepper Flash.
std::unique_ptr<PepperFlashSettingsManager> pepper_flash_settings_manager_;
#endif #endif
uint32_t deauthorize_flash_content_licenses_request_id_ = 0; // A callback to NotifyIfDone() used by SubTasks instances.
// True if we're waiting for various data to be deleted. const base::Closure sub_task_forward_callback_;
// Keeping track of various subtasks to be completed.
// These may only be accessed from UI thread in order to avoid races! // These may only be accessed from UI thread in order to avoid races!
bool waiting_for_synchronous_clear_operations_ = false; SubTask synchronous_clear_operations_;
bool waiting_for_clear_autofill_origin_urls_ = false; SubTask clear_embedder_data_;
bool waiting_for_clear_cache_ = false; SubTask clear_cache_;
bool waiting_for_clear_channel_ids_ = false; SubTask clear_channel_ids_;
bool waiting_for_clear_flash_content_licenses_ = false; SubTask clear_http_auth_cache_;
// Non-zero if waiting for cookies to be cleared. SubTask clear_storage_partition_data_;
int waiting_for_clear_cookies_count_ = 0;
// Counts the number of plugin data tasks. Should be the number of LSO cookies // Counts the number of plugin data tasks. Should be the number of LSO cookies
// to be deleted, or 1 while we're fetching LSO cookies or deleting in bulk. // to be deleted, or 1 while we're fetching LSO cookies or deleting in bulk.
int waiting_for_clear_plugin_data_count_ = 0; int clear_plugin_data_count_ = 0;
bool waiting_for_clear_domain_reliability_monitor_ = false;
bool waiting_for_clear_form_ = false;
bool waiting_for_clear_history_ = false;
bool waiting_for_clear_hostname_resolution_cache_ = false;
bool waiting_for_clear_http_auth_cache_ = false;
bool waiting_for_clear_keyword_data_ = false;
bool waiting_for_clear_nacl_cache_ = false;
bool waiting_for_clear_network_predictor_ = false;
bool waiting_for_clear_networking_history_ = false;
bool waiting_for_clear_passwords_ = false;
bool waiting_for_clear_passwords_stats_ = false;
bool waiting_for_clear_platform_keys_ = false;
bool waiting_for_clear_pnacl_cache_ = false;
#if BUILDFLAG(ANDROID_JAVA_UI)
bool waiting_for_clear_precache_history_ = false;
bool waiting_for_clear_offline_page_data_ = false;
#endif
bool waiting_for_clear_storage_partition_data_ = false;
#if BUILDFLAG(ENABLE_WEBRTC)
bool waiting_for_clear_webrtc_logs_ = false;
#endif
bool waiting_for_clear_auto_sign_in_ = false;
// Observers of the global state and individual tasks. // Observers of the global state and individual tasks.
base::ObserverList<Observer, true> observer_list_; base::ObserverList<Observer, true> observer_list_;
// Used if we need to clear history.
base::CancelableTaskTracker history_task_tracker_;
std::unique_ptr<TemplateURLService::Subscription> template_url_sub_;
// We do not own this. // We do not own this.
content::StoragePartition* storage_partition_for_testing_ = nullptr; content::StoragePartition* storage_partition_for_testing_ = nullptr;
#if BUILDFLAG(ANDROID_JAVA_UI)
// WebappRegistry makes calls across the JNI. In unit tests, the Java side is
// not initialised, so the registry must be mocked out.
std::unique_ptr<WebappRegistry> webapp_registry_;
#endif
base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_; base::WeakPtrFactory<BrowsingDataRemover> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover); DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemover);
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_DELEGATE_H_
#define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_DELEGATE_H_
class BrowsingDataFilterBuilder;
class BrowsingDataRemoverDelegate {
public:
virtual ~BrowsingDataRemoverDelegate() {}
virtual void RemoveEmbedderData(
const base::Time& delete_begin,
const base::Time& delete_end,
int remove_mask,
const BrowsingDataFilterBuilder& filter_builder,
int origin_type_mask,
const base::Closure& callback) = 0;
};
#endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_DELEGATE_H_
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
#include "chrome/browser/browsing_data/browsing_data_remover_factory.h" #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
#include "base/memory/ptr_util.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h" #include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/browsing_data/browsing_data_remover.h" #include "chrome/browser/browsing_data/browsing_data_remover.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/domain_reliability/service_factory.h" #include "chrome/browser/domain_reliability/service_factory.h"
#include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_service_factory.h"
...@@ -92,5 +94,8 @@ content::BrowserContext* BrowsingDataRemoverFactory::GetBrowserContextToUse( ...@@ -92,5 +94,8 @@ content::BrowserContext* BrowsingDataRemoverFactory::GetBrowserContextToUse(
KeyedService* BrowsingDataRemoverFactory::BuildServiceInstanceFor( KeyedService* BrowsingDataRemoverFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
return new BrowsingDataRemover(context); BrowsingDataRemover* remover = new BrowsingDataRemover(context);
remover->set_embedder_delegate(
base::MakeUnique<ChromeBrowsingDataRemoverDelegate>(context));
return remover;
} }
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "chrome/browser/browsing_data/browsing_data_helper.h" #include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/browsing_data_remover_factory.h" #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
#include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
#include "chrome/browser/browsing_data/registrable_domain_filter_builder.h" #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/domain_reliability/service_factory.h" #include "chrome/browser/domain_reliability/service_factory.h"
...@@ -1129,8 +1130,9 @@ class BrowsingDataRemoverTest : public testing::Test { ...@@ -1129,8 +1130,9 @@ class BrowsingDataRemoverTest : public testing::Test {
BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get()); BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get());
#if BUILDFLAG(ANDROID_JAVA_UI) #if BUILDFLAG(ANDROID_JAVA_UI)
remover_->OverrideWebappRegistryForTesting( static_cast<ChromeBrowsingDataRemoverDelegate*>(
std::unique_ptr<WebappRegistry>(new TestWebappRegistry())); remover_->get_embedder_delegate())->OverrideWebappRegistryForTesting(
base::WrapUnique<WebappRegistry>(new TestWebappRegistry()));
#endif #endif
} }
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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/chrome_browsing_data_remover_delegate.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browsing_data/browsing_data_filter_builder.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/registrable_domain_filter_builder.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/domain_reliability/service_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/web_history_service_factory.h"
#include "chrome/browser/io_thread.h"
#include "chrome/browser/media/media_device_id_salt.h"
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h"
#include "chrome/browser/net/predictor.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
#include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/permissions/permission_decision_auto_blocker.h"
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/prerender/prerender_manager_factory.h"
#include "chrome/browser/previews/previews_service.h"
#include "chrome/browser/previews/previews_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/web_data_service_factory.h"
#include "chrome/common/features.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_compression_stats.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/domain_reliability/service.h"
#include "components/history/core/browser/history_service.h"
#include "components/nacl/browser/nacl_browser.h"
#include "components/nacl/browser/pnacl_host.h"
#include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h"
#include "components/ntp_snippets/content_suggestions_service.h"
#include "components/omnibox/browser/omnibox_pref_names.h"
#include "components/password_manager/core/browser/password_store.h"
#include "components/prefs/pref_service.h"
#include "components/previews/core/previews_ui_service.h"
#include "components/search_engines/template_url_service.h"
#include "components/sessions/core/tab_restore_service.h"
#include "content/public/browser/user_metrics.h"
#include "net/cookies/cookie_store.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#if BUILDFLAG(ANDROID_JAVA_UI)
#include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
#include "chrome/browser/android/webapps/webapp_registry.h"
#include "chrome/browser/precache/precache_manager_factory.h"
#include "components/offline_pages/core/offline_page_feature.h"
#include "components/offline_pages/core/offline_page_model.h"
#include "components/precache/content/precache_manager.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/activity_log/activity_log.h"
#include "extensions/browser/extension_prefs.h"
#endif
#if BUILDFLAG(ENABLE_SESSION_SERVICE)
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sessions/session_service_factory.h"
#endif
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chromeos/attestation/attestation_constants.h"
#include "chromeos/cryptohome/cryptohome_parameters.h"
#include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "components/user_manager/user.h"
#endif
#if BUILDFLAG(ENABLE_WEBRTC)
#include "chrome/browser/media/webrtc/webrtc_log_list.h"
#include "chrome/browser/media/webrtc/webrtc_log_util.h"
#endif
using base::UserMetricsAction;
using content::BrowserContext;
using content::BrowserThread;
namespace {
void UIThreadTrampolineHelper(const base::Closure& callback) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
}
// Convenience method to create a callback that can be run on any thread and
// will post the given |callback| back to the UI thread.
base::Closure UIThreadTrampoline(const base::Closure& callback) {
// We could directly bind &BrowserThread::PostTask, but that would require
// evaluating FROM_HERE when this method is called, as opposed to when the
// task is actually posted.
return base::Bind(&UIThreadTrampolineHelper, callback);
}
template <typename T>
void IgnoreArgumentHelper(const base::Closure& callback, T unused_argument) {
callback.Run();
}
// Another convenience method to turn a callback without arguments into one that
// accepts (and ignores) a single argument.
template <typename T>
base::Callback<void(T)> IgnoreArgument(const base::Closure& callback) {
return base::Bind(&IgnoreArgumentHelper<T>, callback);
}
bool ForwardPrimaryPatternCallback(
const base::Callback<bool(const ContentSettingsPattern&)> predicate,
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern) {
return predicate.Run(primary_pattern);
}
#if !defined(DISABLE_NACL)
void ClearNaClCacheOnIOThread(const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
nacl::NaClBrowser::GetInstance()->ClearValidationCache(callback);
}
void ClearPnaclCacheOnIOThread(base::Time begin,
base::Time end,
const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
pnacl::PnaclHost::GetInstance()->ClearTranslationCacheEntriesBetween(
begin, end, callback);
}
#endif
void ClearCookiesOnIOThread(base::Time delete_begin,
base::Time delete_end,
net::URLRequestContextGetter* rq_context,
const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
net::CookieStore* cookie_store =
rq_context->GetURLRequestContext()->cookie_store();
cookie_store->DeleteAllCreatedBetweenAsync(delete_begin, delete_end,
IgnoreArgument<int>(callback));
}
void ClearCookiesWithPredicateOnIOThread(
base::Time delete_begin,
base::Time delete_end,
net::CookieStore::CookiePredicate predicate,
net::URLRequestContextGetter* rq_context,
const base::Closure& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
net::CookieStore* cookie_store =
rq_context->GetURLRequestContext()->cookie_store();
cookie_store->DeleteAllCreatedBetweenWithPredicateAsync(
delete_begin, delete_end, predicate, IgnoreArgument<int>(callback));
}
void ClearNetworkPredictorOnIOThread(chrome_browser_net::Predictor* predictor) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(predictor);
predictor->DiscardInitialNavigationHistory();
predictor->DiscardAllResults();
}
void ClearHostnameResolutionCacheOnIOThread(
IOThread* io_thread,
base::Callback<bool(const std::string&)> host_filter) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
io_thread->ClearHostCache(host_filter);
}
} // namespace
ChromeBrowsingDataRemoverDelegate::ChromeBrowsingDataRemoverDelegate(
BrowserContext* browser_context)
: profile_(Profile::FromBrowserContext(browser_context)),
sub_task_forward_callback_(
base::Bind(&ChromeBrowsingDataRemoverDelegate::NotifyIfDone,
base::Unretained(this))),
synchronous_clear_operations_(sub_task_forward_callback_),
clear_autofill_origin_urls_(sub_task_forward_callback_),
clear_flash_content_licenses_(sub_task_forward_callback_),
clear_domain_reliability_monitor_(sub_task_forward_callback_),
clear_form_(sub_task_forward_callback_),
clear_history_(sub_task_forward_callback_),
clear_keyword_data_(sub_task_forward_callback_),
#if !defined(DISABLE_NACL)
clear_nacl_cache_(sub_task_forward_callback_),
clear_pnacl_cache_(sub_task_forward_callback_),
#endif
clear_hostname_resolution_cache_(sub_task_forward_callback_),
clear_network_predictor_(sub_task_forward_callback_),
clear_networking_history_(sub_task_forward_callback_),
clear_passwords_(sub_task_forward_callback_),
clear_passwords_stats_(sub_task_forward_callback_),
clear_platform_keys_(sub_task_forward_callback_),
#if BUILDFLAG(ANDROID_JAVA_UI)
clear_precache_history_(sub_task_forward_callback_),
clear_offline_page_data_(sub_task_forward_callback_),
#endif
#if BUILDFLAG(ENABLE_WEBRTC)
clear_webrtc_logs_(sub_task_forward_callback_),
#endif
clear_auto_sign_in_(sub_task_forward_callback_),
#if BUILDFLAG(ANDROID_JAVA_UI)
webapp_registry_(new WebappRegistry()),
#endif
weak_ptr_factory_(this) {}
ChromeBrowsingDataRemoverDelegate::~ChromeBrowsingDataRemoverDelegate() {
history_task_tracker_.TryCancelAll();
template_url_sub_.reset();
}
void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
const base::Time& delete_begin,
const base::Time& delete_end,
int remove_mask,
const BrowsingDataFilterBuilder& filter_builder,
int origin_type_mask,
const base::Closure& callback) {
//////////////////////////////////////////////////////////////////////////////
// INITIALIZATION
synchronous_clear_operations_.Start();
callback_ = callback;
delete_begin_ = delete_begin;
delete_end_ = delete_end;
base::Callback<bool(const GURL& url)> filter =
filter_builder.BuildGeneralFilter();
base::Callback<bool(const ContentSettingsPattern& url)> same_pattern_filter =
filter_builder.BuildWebsiteSettingsPatternMatchesFilter();
// Some backends support a filter that |is_null()| to make complete deletion
// more efficient.
base::Callback<bool(const GURL&)> nullable_filter =
filter_builder.IsEmptyBlacklist() ? base::Callback<bool(const GURL&)>()
: filter;
// Managed devices and supervised users can have restrictions on history
// deletion.
PrefService* prefs = profile_->GetPrefs();
bool may_delete_history = prefs->GetBoolean(
prefs::kAllowDeletingBrowserHistory);
//////////////////////////////////////////////////////////////////////////////
// REMOVE_HISTORY
if ((remove_mask & BrowsingDataRemover::REMOVE_HISTORY) &&
may_delete_history) {
history::HistoryService* history_service =
HistoryServiceFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS);
if (history_service) {
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
content::RecordAction(UserMetricsAction("ClearBrowsingData_History"));
clear_history_.Start();
history_service->ExpireLocalAndRemoteHistoryBetween(
WebHistoryServiceFactory::GetForProfile(profile_), std::set<GURL>(),
delete_begin_, delete_end_,
clear_history_.GetCompletionCallback(),
&history_task_tracker_);
}
// Currently, ContentSuggestionService instance exists only on Android.
ntp_snippets::ContentSuggestionsService* content_suggestions_service =
ContentSuggestionsServiceFactory::GetForProfileIfExists(profile_);
if (content_suggestions_service) {
content_suggestions_service->ClearHistory(delete_begin_, delete_end_,
filter);
}
// Remove the last visit dates meta-data from the bookmark model.
// TODO(vitaliii): Do not remove all dates, but only the ones matched by the
// time range and the filter.
bookmarks::BookmarkModel* bookmark_model =
BookmarkModelFactory::GetForBrowserContext(profile_);
if (bookmark_model)
ntp_snippets::RemoveAllLastVisitDates(bookmark_model);
#if BUILDFLAG(ENABLE_EXTENSIONS)
// The extension activity log contains details of which websites extensions
// were active on. It therefore indirectly stores details of websites a
// user has visited so best clean from here as well.
// TODO(msramek): Support all backends with filter (crbug.com/589586).
extensions::ActivityLog::GetInstance(profile_)->RemoveURLs(
std::set<GURL>());
// Clear launch times as they are a form of history.
// BrowsingDataFilterBuilder currently doesn't support extension origins.
// Therefore, clearing history for a small set of origins (WHITELIST) should
// never delete any extension launch times, while clearing for almost all
// origins (BLACKLIST) should always delete all of extension launch times.
if (filter_builder.mode() == BrowsingDataFilterBuilder::BLACKLIST) {
extensions::ExtensionPrefs* extension_prefs =
extensions::ExtensionPrefs::Get(profile_);
extension_prefs->ClearLastLaunchTimes();
}
#endif
// Need to clear the host cache and accumulated speculative data, as it also
// reveals some history. We have no mechanism to track when these items were
// created, so we'll not honor the time range.
// TODO(msramek): We can use the plugin filter here because plugins, same
// as the hostname resolution cache, key their entries by hostname. Rename
// BuildPluginFilter() to something more general to reflect this use.
if (g_browser_process->io_thread()) {
clear_hostname_resolution_cache_.Start();
BrowserThread::PostTaskAndReply(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearHostnameResolutionCacheOnIOThread,
g_browser_process->io_thread(),
filter_builder.BuildPluginFilter()),
clear_hostname_resolution_cache_.GetCompletionCallback());
}
if (profile_->GetNetworkPredictor()) {
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
clear_network_predictor_.Start();
BrowserThread::PostTaskAndReply(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearNetworkPredictorOnIOThread,
profile_->GetNetworkPredictor()),
clear_network_predictor_.GetCompletionCallback());
profile_->GetNetworkPredictor()->ClearPrefsOnUIThread();
}
// As part of history deletion we also delete the auto-generated keywords.
TemplateURLService* keywords_model =
TemplateURLServiceFactory::GetForProfile(profile_);
if (keywords_model && !keywords_model->loaded()) {
// TODO(msramek): Store filters from the currently executed task on the
// object to avoid having to copy them to callback methods.
template_url_sub_ = keywords_model->RegisterOnLoadedCallback(
base::Bind(&ChromeBrowsingDataRemoverDelegate::OnKeywordsLoaded,
weak_ptr_factory_.GetWeakPtr(), filter));
keywords_model->Load();
clear_keyword_data_.Start();
} else if (keywords_model) {
keywords_model->RemoveAutoGeneratedForUrlsBetween(filter, delete_begin_,
delete_end_);
}
// The PrerenderManager keeps history of prerendered pages, so clear that.
// It also may have a prerendered page. If so, the page could be
// considered to have a small amount of historical information, so delete
// it, too.
prerender::PrerenderManager* prerender_manager =
prerender::PrerenderManagerFactory::GetForBrowserContext(profile_);
if (prerender_manager) {
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
prerender_manager->ClearData(
prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS |
prerender::PrerenderManager::CLEAR_PRERENDER_HISTORY);
}
// If the caller is removing history for all hosts, then clear ancillary
// historical information.
if (filter_builder.IsEmptyBlacklist()) {
// We also delete the list of recently closed tabs. Since these expire,
// they can't be more than a day old, so we can simply clear them all.
sessions::TabRestoreService* tab_service =
TabRestoreServiceFactory::GetForProfile(profile_);
if (tab_service) {
tab_service->ClearEntries();
tab_service->DeleteLastSession();
}
#if BUILDFLAG(ENABLE_SESSION_SERVICE)
// We also delete the last session when we delete the history.
SessionService* session_service =
SessionServiceFactory::GetForProfile(profile_);
if (session_service)
session_service->DeleteLastSession();
#endif
}
// The saved Autofill profiles and credit cards can include the origin from
// which these profiles and credit cards were learned. These are a form of
// history, so clear them as well.
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
scoped_refptr<autofill::AutofillWebDataService> web_data_service =
WebDataServiceFactory::GetAutofillWebDataForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS);
if (web_data_service.get()) {
clear_autofill_origin_urls_.Start();
web_data_service->RemoveOriginURLsModifiedBetween(
delete_begin_, delete_end_);
// The above calls are done on the UI thread but do their work on the DB
// thread. So wait for it.
BrowserThread::PostTaskAndReply(
BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing),
clear_autofill_origin_urls_.GetCompletionCallback());
autofill::PersonalDataManager* data_manager =
autofill::PersonalDataManagerFactory::GetForProfile(profile_);
if (data_manager)
data_manager->Refresh();
}
#if BUILDFLAG(ENABLE_WEBRTC)
clear_webrtc_logs_.Start();
BrowserThread::PostTaskAndReply(
BrowserThread::FILE, FROM_HERE,
base::Bind(
&WebRtcLogUtil::DeleteOldAndRecentWebRtcLogFiles,
WebRtcLogList::GetWebRtcLogDirectoryForProfile(profile_->GetPath()),
delete_begin_),
clear_webrtc_logs_.GetCompletionCallback());
#endif
#if BUILDFLAG(ANDROID_JAVA_UI)
precache::PrecacheManager* precache_manager =
precache::PrecacheManagerFactory::GetForBrowserContext(profile_);
// |precache_manager| could be nullptr if the profile is off the record.
if (!precache_manager) {
clear_precache_history_.Start();
precache_manager->ClearHistory();
// The above calls are done on the UI thread but do their work on the DB
// thread. So wait for it.
BrowserThread::PostTaskAndReply(
BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing),
clear_precache_history_.GetCompletionCallback());
}
// Clear the history information (last launch time and origin URL) of any
// registered webapps.
webapp_registry_->ClearWebappHistoryForUrls(filter);
#endif
data_reduction_proxy::DataReductionProxySettings*
data_reduction_proxy_settings =
DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
profile_);
// |data_reduction_proxy_settings| is null if |profile_| is off the record.
if (data_reduction_proxy_settings) {
data_reduction_proxy::DataReductionProxyService*
data_reduction_proxy_service =
data_reduction_proxy_settings->data_reduction_proxy_service();
if (data_reduction_proxy_service) {
data_reduction_proxy_service->compression_stats()
->DeleteBrowsingHistory(delete_begin_, delete_end_);
}
}
// |previews_service| is null if |profile_| is off the record.
PreviewsService* previews_service =
PreviewsServiceFactory::GetForProfile(profile_);
if (previews_service && previews_service->previews_ui_service()) {
previews_service->previews_ui_service()->ClearBlackList(delete_begin_,
delete_end_);
}
}
//////////////////////////////////////////////////////////////////////////////
// REMOVE_COOKIES
// We ignore the REMOVE_COOKIES request if UNPROTECTED_WEB is not set,
// so that callers who request REMOVE_SITE_DATA with PROTECTED_WEB
// don't accidentally remove the cookies that are associated with the
// UNPROTECTED_WEB origin. This is necessary because cookies are not separated
// between UNPROTECTED_WEB and PROTECTED_WEB.
if (remove_mask & BrowsingDataRemover::REMOVE_COOKIES &&
origin_type_mask & BrowsingDataHelper::UNPROTECTED_WEB) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies"));
// Clear the safebrowsing cookies only if time period is for "all time". It
// doesn't make sense to apply the time period of deleting in the last X
// hours/days to the safebrowsing cookies since they aren't the result of
// any user action.
if (delete_begin_ == base::Time()) {
safe_browsing::SafeBrowsingService* sb_service =
g_browser_process->safe_browsing_service();
if (sb_service) {
scoped_refptr<net::URLRequestContextGetter> sb_context =
sb_service->url_request_context();
++clear_cookies_count_;
if (filter_builder.IsEmptyBlacklist()) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(
&ClearCookiesOnIOThread, delete_begin_, delete_end_,
base::RetainedRef(std::move(sb_context)),
UIThreadTrampoline(
base::Bind(
&ChromeBrowsingDataRemoverDelegate::OnClearedCookies,
weak_ptr_factory_.GetWeakPtr()))));
} else {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(
&ClearCookiesWithPredicateOnIOThread, delete_begin_,
delete_end_, filter_builder.BuildCookieFilter(),
base::RetainedRef(std::move(sb_context)),
UIThreadTrampoline(
base::Bind(
&ChromeBrowsingDataRemoverDelegate::OnClearedCookies,
weak_ptr_factory_.GetWeakPtr()))));
}
}
}
MediaDeviceIDSalt::Reset(profile_->GetPrefs());
}
//////////////////////////////////////////////////////////////////////////////
// REMOVE_DURABLE_PERMISSION
if (remove_mask & BrowsingDataRemover::REMOVE_DURABLE_PERMISSION) {
HostContentSettingsMapFactory::GetForProfile(profile_)
->ClearSettingsForOneTypeWithPredicate(
CONTENT_SETTINGS_TYPE_DURABLE_STORAGE,
base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
}
//////////////////////////////////////////////////////////////////////////////
// REMOVE_SITE_USAGE_DATA
if (remove_mask & BrowsingDataRemover::REMOVE_SITE_USAGE_DATA) {
HostContentSettingsMapFactory::GetForProfile(profile_)
->ClearSettingsForOneTypeWithPredicate(
CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
}
if ((remove_mask & BrowsingDataRemover::REMOVE_SITE_USAGE_DATA) ||
(remove_mask & BrowsingDataRemover::REMOVE_HISTORY)) {
HostContentSettingsMapFactory::GetForProfile(profile_)
->ClearSettingsForOneTypeWithPredicate(
CONTENT_SETTINGS_TYPE_APP_BANNER,
base::Bind(&ForwardPrimaryPatternCallback, same_pattern_filter));
PermissionDecisionAutoBlocker::RemoveCountsByUrl(profile_, filter);
}
//////////////////////////////////////////////////////////////////////////////
// Password manager
if (remove_mask & BrowsingDataRemover::REMOVE_PASSWORDS) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords"));
password_manager::PasswordStore* password_store =
PasswordStoreFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
if (password_store) {
clear_passwords_.Start();
password_store->RemoveLoginsByURLAndTime(
filter, delete_begin_, delete_end_,
clear_passwords_.GetCompletionCallback());
}
}
if (remove_mask & BrowsingDataRemover::REMOVE_COOKIES) {
password_manager::PasswordStore* password_store =
PasswordStoreFactory::GetForProfile(profile_,
ServiceAccessType::EXPLICIT_ACCESS)
.get();
if (password_store) {
clear_auto_sign_in_.Start();
password_store->DisableAutoSignInForOrigins(
filter, clear_auto_sign_in_.GetCompletionCallback());
}
}
if (remove_mask & BrowsingDataRemover::REMOVE_HISTORY) {
password_manager::PasswordStore* password_store =
PasswordStoreFactory::GetForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS).get();
if (password_store) {
clear_passwords_stats_.Start();
password_store->RemoveStatisticsByOriginAndTime(
nullable_filter, delete_begin_, delete_end_,
clear_passwords_stats_.GetCompletionCallback());
}
}
//////////////////////////////////////////////////////////////////////////////
// REMOVE_FORM_DATA
// TODO(dmurph): Support all backends with filter (crbug.com/113621).
if (remove_mask & BrowsingDataRemover::REMOVE_FORM_DATA) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Autofill"));
scoped_refptr<autofill::AutofillWebDataService> web_data_service =
WebDataServiceFactory::GetAutofillWebDataForProfile(
profile_, ServiceAccessType::EXPLICIT_ACCESS);
if (web_data_service.get()) {
clear_form_.Start();
web_data_service->RemoveFormElementsAddedBetween(delete_begin_,
delete_end_);
web_data_service->RemoveAutofillDataModifiedBetween(
delete_begin_, delete_end_);
// The above calls are done on the UI thread but do their work on the DB
// thread. So wait for it.
BrowserThread::PostTaskAndReply(
BrowserThread::DB, FROM_HERE, base::Bind(&base::DoNothing),
clear_form_.GetCompletionCallback());
autofill::PersonalDataManager* data_manager =
autofill::PersonalDataManagerFactory::GetForProfile(profile_);
if (data_manager)
data_manager->Refresh();
}
}
//////////////////////////////////////////////////////////////////////////////
// REMOVE_CACHE
if (remove_mask & BrowsingDataRemover::REMOVE_CACHE) {
#if !defined(DISABLE_NACL)
clear_nacl_cache_.Start();
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&ClearNaClCacheOnIOThread,
UIThreadTrampoline(
clear_nacl_cache_.GetCompletionCallback())));
clear_pnacl_cache_.Start();
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(
&ClearPnaclCacheOnIOThread, delete_begin_, delete_end_,
UIThreadTrampoline(clear_pnacl_cache_.GetCompletionCallback())));
#endif
// The PrerenderManager may have a page actively being prerendered, which
// is essentially a preemptively cached page.
prerender::PrerenderManager* prerender_manager =
prerender::PrerenderManagerFactory::GetForBrowserContext(profile_);
if (prerender_manager) {
prerender_manager->ClearData(
prerender::PrerenderManager::CLEAR_PRERENDER_CONTENTS);
}
// When clearing cache, wipe accumulated network related data
// (TransportSecurityState and HttpServerPropertiesManager data).
clear_networking_history_.Start();
profile_->ClearNetworkingHistorySince(
delete_begin_,
clear_networking_history_.GetCompletionCallback());
ntp_snippets::ContentSuggestionsService* content_suggestions_service =
ContentSuggestionsServiceFactory::GetForProfileIfExists(profile_);
if (content_suggestions_service)
content_suggestions_service->ClearAllCachedSuggestions();
// |ui_nqe_service| may be null if |profile_| is not a regular profile.
UINetworkQualityEstimatorService* ui_nqe_service =
UINetworkQualityEstimatorServiceFactory::GetForProfile(profile_);
DCHECK(profile_->GetProfileType() !=
Profile::ProfileType::REGULAR_PROFILE ||
ui_nqe_service != nullptr);
if (ui_nqe_service) {
// Network Quality Estimator (NQE) stores the quality (RTT, bandwidth
// etc.) of different networks in prefs. The stored quality is not
// broken down by URLs or timestamps, so clearing the cache should
// completely clear the prefs.
ui_nqe_service->ClearPrefs();
}
#if BUILDFLAG(ANDROID_JAVA_UI)
// For now we're considering offline pages as cache, so if we're removing
// cache we should remove offline pages as well.
if ((remove_mask & BrowsingDataRemover::REMOVE_CACHE)) {
clear_offline_page_data_.Start();
offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_)
->DeleteCachedPagesByURLPredicate(
filter,
IgnoreArgument<offline_pages::OfflinePageModel::DeletePageResult>(
clear_offline_page_data_.GetCompletionCallback()));
}
#endif
}
//////////////////////////////////////////////////////////////////////////////
// REMOVE_MEDIA_LICENSES
if (remove_mask & BrowsingDataRemover::REMOVE_MEDIA_LICENSES) {
// TODO(jrummell): This UMA should be renamed to indicate it is for Media
// Licenses.
content::RecordAction(
UserMetricsAction("ClearBrowsingData_ContentLicenses"));
#if BUILDFLAG(ENABLE_PLUGINS)
clear_flash_content_licenses_.Start();
if (!pepper_flash_settings_manager_.get()) {
pepper_flash_settings_manager_.reset(
new PepperFlashSettingsManager(this, profile_));
}
deauthorize_flash_content_licenses_request_id_ =
pepper_flash_settings_manager_->DeauthorizeContentLicenses(prefs);
#if defined(OS_CHROMEOS)
// On Chrome OS, also delete any content protection platform keys.
const user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
if (!user) {
LOG(WARNING) << "Failed to find user for current profile.";
} else {
clear_platform_keys_.Start();
chromeos::DBusThreadManager::Get()
->GetCryptohomeClient()
->TpmAttestationDeleteKeys(
chromeos::attestation::KEY_USER,
cryptohome::Identification(user->GetAccountId()),
chromeos::attestation::kContentProtectionKeyPrefix,
base::Bind(
&ChromeBrowsingDataRemoverDelegate::OnClearPlatformKeys,
weak_ptr_factory_.GetWeakPtr()));
}
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(ENABLE_PLUGINS)
}
//////////////////////////////////////////////////////////////////////////////
// Zero suggest.
// Remove omnibox zero-suggest cache results. Filtering is not supported.
// This is not a problem, as deleting more data than necessary will just cause
// another server round-trip; no data is actually lost.
if ((remove_mask & (BrowsingDataRemover::REMOVE_CACHE |
BrowsingDataRemover::REMOVE_COOKIES))) {
prefs->SetString(omnibox::kZeroSuggestCachedResults, std::string());
}
//////////////////////////////////////////////////////////////////////////////
// Domain reliability service.
if (remove_mask & (BrowsingDataRemover::REMOVE_COOKIES |
BrowsingDataRemover::REMOVE_HISTORY)) {
domain_reliability::DomainReliabilityService* service =
domain_reliability::DomainReliabilityServiceFactory::
GetForBrowserContext(profile_);
if (service) {
domain_reliability::DomainReliabilityClearMode mode;
if (remove_mask & BrowsingDataRemover::REMOVE_COOKIES)
mode = domain_reliability::CLEAR_CONTEXTS;
else
mode = domain_reliability::CLEAR_BEACONS;
clear_domain_reliability_monitor_.Start();
service->ClearBrowsingData(
mode,
filter,
clear_domain_reliability_monitor_.GetCompletionCallback());
}
}
//////////////////////////////////////////////////////////////////////////////
// REMOVE_WEBAPP_DATA
#if BUILDFLAG(ANDROID_JAVA_UI)
// Clear all data associated with registered webapps.
if (remove_mask & BrowsingDataRemover::REMOVE_WEBAPP_DATA)
webapp_registry_->UnregisterWebappsForUrls(filter);
#endif
synchronous_clear_operations_.GetCompletionCallback().Run();
}
void ChromeBrowsingDataRemoverDelegate::NotifyIfDone() {
if (!AllDone())
return;
DCHECK(!callback_.is_null());
callback_.Run();
}
bool ChromeBrowsingDataRemoverDelegate::AllDone() {
return !clear_cookies_count_ &&
!synchronous_clear_operations_.is_pending() &&
!clear_autofill_origin_urls_.is_pending() &&
!clear_flash_content_licenses_.is_pending() &&
!clear_domain_reliability_monitor_.is_pending() &&
!clear_form_.is_pending() &&
!clear_history_.is_pending() &&
!clear_hostname_resolution_cache_.is_pending() &&
!clear_keyword_data_.is_pending() &&
#if !defined(DISABLE_NACL)
!clear_nacl_cache_.is_pending() &&
!clear_pnacl_cache_.is_pending() &&
#endif
!clear_network_predictor_.is_pending() &&
!clear_networking_history_.is_pending() &&
!clear_passwords_.is_pending() &&
!clear_passwords_stats_.is_pending() &&
!clear_platform_keys_.is_pending() &&
#if BUILDFLAG(ANDROID_JAVA_UI)
!clear_precache_history_.is_pending() &&
!clear_offline_page_data_.is_pending() &&
#endif
#if BUILDFLAG(ENABLE_WEBRTC)
!clear_webrtc_logs_.is_pending() &&
#endif
!clear_auto_sign_in_.is_pending();
}
#if BUILDFLAG(ANDROID_JAVA_UI)
void ChromeBrowsingDataRemoverDelegate::OverrideWebappRegistryForTesting(
std::unique_ptr<WebappRegistry> webapp_registry) {
webapp_registry_ = std::move(webapp_registry);
}
#endif
void ChromeBrowsingDataRemoverDelegate::OnKeywordsLoaded(
base::Callback<bool(const GURL&)> url_filter) {
// Deletes the entries from the model.
TemplateURLService* model =
TemplateURLServiceFactory::GetForProfile(profile_);
model->RemoveAutoGeneratedForUrlsBetween(url_filter, delete_begin_,
delete_end_);
template_url_sub_.reset();
clear_keyword_data_.GetCompletionCallback().Run();
}
void ChromeBrowsingDataRemoverDelegate::OnClearedCookies() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK_GT(clear_cookies_count_, 0);
--clear_cookies_count_;
NotifyIfDone();
}
#if BUILDFLAG(ENABLE_PLUGINS)
void ChromeBrowsingDataRemoverDelegate::
OnDeauthorizeFlashContentLicensesCompleted(
uint32_t request_id,
bool /* success */) {
DCHECK_EQ(request_id, deauthorize_flash_content_licenses_request_id_);
clear_flash_content_licenses_.GetCompletionCallback().Run();
}
#endif
#if defined(OS_CHROMEOS)
void ChromeBrowsingDataRemoverDelegate::OnClearPlatformKeys(
chromeos::DBusMethodCallStatus call_status,
bool result) {
LOG_IF(ERROR, call_status != chromeos::DBUS_METHOD_CALL_SUCCESS || !result)
<< "Failed to clear platform keys.";
clear_platform_keys_.GetCompletionCallback().Run();
}
#endif
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_REMOVER_DELEGATE_H_
#define CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_REMOVER_DELEGATE_H_
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/synchronization/waitable_event_watcher.h"
#include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/browsing_data/browsing_data_remover.h"
#include "chrome/browser/browsing_data/browsing_data_remover_delegate.h"
#include "chrome/common/features.h"
#include "components/browsing_data/core/browsing_data_utils.h"
#include "components/offline_pages/core/offline_page_model.h"
#include "components/search_engines/template_url_service.h"
#include "media/media_features.h"
#include "ppapi/features/features.h"
#if BUILDFLAG(ENABLE_PLUGINS)
#include "chrome/browser/pepper_flash_settings_manager.h"
#endif
#if defined(OS_CHROMEOS)
#include "chromeos/dbus/dbus_method_call_status.h"
#endif
class WebappRegistry;
// A delegate used by BrowsingDataRemover to delete data specific to Chrome
// as the embedder.
class ChromeBrowsingDataRemoverDelegate : public BrowsingDataRemoverDelegate
#if BUILDFLAG(ENABLE_PLUGINS)
, public PepperFlashSettingsManager::Client
#endif
{
public:
ChromeBrowsingDataRemoverDelegate(content::BrowserContext* browser_context);
~ChromeBrowsingDataRemoverDelegate() override;
// Removes Chrome-specific data.
void RemoveEmbedderData(
const base::Time& delete_begin,
const base::Time& delete_end,
int remove_mask,
const BrowsingDataFilterBuilder& filter_builder,
int origin_type_mask,
const base::Closure& callback) override;
#if BUILDFLAG(ANDROID_JAVA_UI)
void OverrideWebappRegistryForTesting(
std::unique_ptr<WebappRegistry> webapp_registry);
#endif
private:
// If AllDone(), calls the callback provided in RemoveEmbedderData().
void NotifyIfDone();
// Whether there are no running deletion tasks.
bool AllDone();
// Callback for when TemplateURLService has finished loading. Clears the data,
// clears the respective waiting flag, and invokes NotifyIfDone.
void OnKeywordsLoaded(base::Callback<bool(const GURL&)> url_filter);
#if defined (OS_CHROMEOS)
void OnClearPlatformKeys(chromeos::DBusMethodCallStatus call_status,
bool result);
#endif
// Callback for when cookies have been deleted. Invokes NotifyIfDone.
void OnClearedCookies();
#if BUILDFLAG(ENABLE_PLUGINS)
// PepperFlashSettingsManager::Client implementation.
void OnDeauthorizeFlashContentLicensesCompleted(uint32_t request_id,
bool success) override;
#endif
// The profile for which the data will be deleted.
Profile* profile_;
// Start time to delete from.
base::Time delete_begin_;
// End time to delete to.
base::Time delete_end_;
// Completion callback to call when all data are deleted.
base::Closure callback_;
// A callback to NotifyIfDone() used by SubTasks instances.
const base::Closure sub_task_forward_callback_;
// Keeping track of various subtasks to be completed.
// Non-zero if waiting for SafeBrowsing cookies to be cleared.
int clear_cookies_count_ = 0;
BrowsingDataRemover::SubTask synchronous_clear_operations_;
BrowsingDataRemover::SubTask clear_autofill_origin_urls_;
BrowsingDataRemover::SubTask clear_flash_content_licenses_;
BrowsingDataRemover::SubTask clear_domain_reliability_monitor_;
BrowsingDataRemover::SubTask clear_form_;
BrowsingDataRemover::SubTask clear_history_;
BrowsingDataRemover::SubTask clear_keyword_data_;
#if !defined(DISABLE_NACL)
BrowsingDataRemover::SubTask clear_nacl_cache_;
BrowsingDataRemover::SubTask clear_pnacl_cache_;
#endif
BrowsingDataRemover::SubTask clear_hostname_resolution_cache_;
BrowsingDataRemover::SubTask clear_network_predictor_;
BrowsingDataRemover::SubTask clear_networking_history_;
BrowsingDataRemover::SubTask clear_passwords_;
BrowsingDataRemover::SubTask clear_passwords_stats_;
BrowsingDataRemover::SubTask clear_platform_keys_;
#if BUILDFLAG(ANDROID_JAVA_UI)
BrowsingDataRemover::SubTask clear_precache_history_;
BrowsingDataRemover::SubTask clear_offline_page_data_;
#endif
#if BUILDFLAG(ENABLE_WEBRTC)
BrowsingDataRemover::SubTask clear_webrtc_logs_;
#endif
BrowsingDataRemover::SubTask clear_auto_sign_in_;
#if BUILDFLAG(ENABLE_PLUGINS)
uint32_t deauthorize_flash_content_licenses_request_id_ = 0;
// Used to deauthorize content licenses for Pepper Flash.
std::unique_ptr<PepperFlashSettingsManager> pepper_flash_settings_manager_;
#endif
// Used if we need to clear history.
base::CancelableTaskTracker history_task_tracker_;
std::unique_ptr<TemplateURLService::Subscription> template_url_sub_;
#if BUILDFLAG(ANDROID_JAVA_UI)
// WebappRegistry makes calls across the JNI. In unit tests, the Java side is
// not initialised, so the registry must be mocked out.
std::unique_ptr<WebappRegistry> webapp_registry_;
#endif
base::WeakPtrFactory<ChromeBrowsingDataRemoverDelegate> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ChromeBrowsingDataRemoverDelegate);
};
#endif // CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_REMOVER_DELEGATE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment