Commit e169ccbe authored by msramek's avatar msramek Committed by Commit bot

Move BrowsingDataRemover to content/

Changes in this CL:

1. The public interfaces BrowsingDataRemover and BrowsingDataRemoverDelegate
move to content/public/browser. BrowsingDataRemoverImpl moves to
content/browser/browsing_data.

2. Previously, BrowsingDataRemoverImpl was a KeyedService created by
BrowsingDataRemoverFactory. After this CL, it is owned by BrowserContext.
Conversely, ChromeBrowsingRemoverDelegate (which stays in chrome/) becomes
a KeyedService. The former BrowsingDataRemoverFactory is thus adapted into
ChromeBrowsingDataRemoverDelegateFactory.

BrowsingDataRemoverDelegate is now owned by the embedder (rather than
BrowsingDataRemover) and supplied by embedders through
BrowserContext::GetBrowsingDataRemoverDelegate(). Profile (in chrome/)
supplies ChromeBrowsingDataRemoverDelegate. The implementation for other
embedders is left as TODO.

3. BrowsingDataRemoverImplTest moves to content/browser/browsing/data.
browsing_data_remover_test_util that is used by this test as well as various
tests in chrome/ is moved to content/public/test.

4. BrowsingDataRemover can only delete download history if this is feature is
not disabled by administrator. Previously, BrowsingDataRemover queried
PrefService directly. We now pass this information through
BrowsingDataRemoverDelegate. The default value is true,
ChromeBrowsingDataRemoverDelegate queries PrefService.

5. The removal of ContentBrowserClient interfaces ClearCookies(), ClearCache(),
ClearSiteData() and their replacement by BrowsingDataRemover is left as a TODO.

6. All other changes are adding / removing includes, updating BUILD files,
replacing BrowsingDataRemoverFactory with BrowserContext::GetBrowsingDataRemover,
formatting (mostly triggered by prepending content:: to class names), and the
removal of forgotten "#ifdef (EXTENSIONS)" in BrowsingDataRemoverImplTest.

TBR=dbeam@chromium.org
BUG=668114

Review-Url: https://codereview.chromium.org/2827523003
Cr-Commit-Position: refs/heads/master@{#467241}
parent ac3c4618
......@@ -166,12 +166,7 @@ split_static_library("browser") {
"browsing_data/browsing_data_quota_helper.h",
"browsing_data/browsing_data_quota_helper_impl.cc",
"browsing_data/browsing_data_quota_helper_impl.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.h",
"browsing_data/browsing_data_remover_impl.cc",
"browsing_data/browsing_data_remover_impl.h",
"browsing_data/browsing_data_service_worker_helper.cc",
"browsing_data/browsing_data_service_worker_helper.h",
"browsing_data/cache_counter.cc",
......@@ -180,6 +175,8 @@ split_static_library("browser") {
"browsing_data/canonical_cookie_hash.h",
"browsing_data/chrome_browsing_data_remover_delegate.cc",
"browsing_data/chrome_browsing_data_remover_delegate.h",
"browsing_data/chrome_browsing_data_remover_delegate_factory.cc",
"browsing_data/chrome_browsing_data_remover_delegate_factory.h",
"browsing_data/cookies_tree_model.cc",
"browsing_data/cookies_tree_model.h",
"browsing_data/downloads_counter.cc",
......
......@@ -19,7 +19,6 @@
#include "base/metrics/histogram_macros.h"
#include "base/scoped_observer.h"
#include "base/values.h"
#include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
#include "chrome/browser/engagement/important_sites_util.h"
#include "chrome/browser/history/web_history_service_factory.h"
......@@ -29,7 +28,9 @@
#include "components/browser_sync/profile_sync_service.h"
#include "components/browsing_data/core/history_notice_utils.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browsing_data_filter_builder.h"
#include "content/public/browser/browsing_data_remover.h"
#include "jni/BrowsingDataBridge_jni.h"
using base::android::AttachCurrentThread;
......@@ -37,6 +38,7 @@ using base::android::JavaParamRef;
using base::android::JavaRef;
using base::android::ScopedJavaLocalRef;
using base::android::ScopedJavaGlobalRef;
using content::BrowsingDataRemover;
namespace {
......@@ -101,7 +103,7 @@ static void ClearBrowsingData(
const JavaParamRef<jobjectArray>& jignoring_domains,
const JavaParamRef<jintArray>& jignoring_domain_reasons) {
BrowsingDataRemover* browsing_data_remover =
BrowsingDataRemoverFactory::GetForBrowserContext(GetOriginalProfile());
content::BrowserContext::GetBrowsingDataRemover(GetOriginalProfile());
std::vector<int> data_types_vector;
base::android::JavaIntArrayToIntVector(env, data_types, &data_types_vector);
......
......@@ -19,8 +19,7 @@
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/browsing_data_remover.h"
#include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
#include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
#include "chrome/browser/policy/cloud/user_policy_signin_service_factory.h"
......@@ -43,6 +42,7 @@
#include "components/signin/core/browser/signin_metrics.h"
#include "components/signin/core/common/profile_management_switches.h"
#include "components/signin/core/common/signin_pref_names.h"
#include "content/public/browser/browsing_data_remover.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/gaia_constants.h"
#include "jni/SigninManager_jni.h"
......@@ -55,12 +55,12 @@ namespace {
// A BrowsingDataRemover::Observer that clears all Profile data and then
// invokes a callback and deletes itself.
class ProfileDataRemover : public BrowsingDataRemover::Observer {
class ProfileDataRemover : public content::BrowsingDataRemover::Observer {
public:
ProfileDataRemover(Profile* profile, const base::Closure& callback)
: callback_(callback),
origin_runner_(base::ThreadTaskRunnerHandle::Get()),
remover_(BrowsingDataRemoverFactory::GetForBrowserContext(profile)) {
remover_(content::BrowserContext::GetBrowsingDataRemover(profile)) {
remover_->AddObserver(this);
remover_->RemoveAndReply(
base::Time(), base::Time::Max(),
......@@ -79,7 +79,7 @@ class ProfileDataRemover : public BrowsingDataRemover::Observer {
private:
base::Closure callback_;
scoped_refptr<base::SingleThreadTaskRunner> origin_runner_;
BrowsingDataRemover* remover_;
content::BrowsingDataRemover* remover_;
DISALLOW_COPY_AND_ASSIGN(ProfileDataRemover);
};
......
......@@ -11,9 +11,7 @@
#include "base/path_service.h"
#include "base/run_loop.h"
#include "chrome/browser/browsing_data/browsing_data_helper.h"
#include "chrome/browser/browsing_data/browsing_data_remover.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/cache_counter.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
#include "chrome/browser/chrome_notification_types.h"
......@@ -29,10 +27,12 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/browsing_data_filter_builder.h"
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_paths.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/browsing_data_remover_test_util.h"
#include "content/public/test/download_test_observer.h"
#include "net/dns/mock_host_resolver.h"
#include "net/http/transport_security_state.h"
......@@ -116,24 +116,25 @@ class BrowsingDataRemoverBrowserTest : public InProcessBrowserTest {
}
void RemoveAndWait(int remove_mask) {
BrowsingDataRemover* remover =
BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile());
BrowsingDataRemoverCompletionObserver completion_observer(remover);
remover->RemoveAndReply(base::Time(), base::Time::Max(), remove_mask,
BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB,
&completion_observer);
content::BrowsingDataRemover* remover =
content::BrowserContext::GetBrowsingDataRemover(browser()->profile());
content::BrowsingDataRemoverCompletionObserver completion_observer(remover);
remover->RemoveAndReply(
base::Time(), base::Time::Max(), remove_mask,
content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB,
&completion_observer);
completion_observer.BlockUntilCompletion();
}
void RemoveWithFilterAndWait(
int remove_mask,
std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
BrowsingDataRemover* remover =
BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile());
BrowsingDataRemoverCompletionObserver completion_observer(remover);
content::BrowsingDataRemover* remover =
content::BrowserContext::GetBrowsingDataRemover(browser()->profile());
content::BrowsingDataRemoverCompletionObserver completion_observer(remover);
remover->RemoveWithFilterAndReply(
base::Time(), base::Time::Max(), remove_mask,
BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB,
content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB,
std::move(filter_builder), &completion_observer);
completion_observer.BlockUntilCompletion();
}
......@@ -195,7 +196,7 @@ class BrowsingDataRemoverTransportSecurityStateBrowserTest
// Test BrowsingDataRemover for downloads.
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Download) {
DownloadAnItem();
RemoveAndWait(BrowsingDataRemover::DATA_TYPE_DOWNLOADS);
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS);
VerifyDownloadCount(0u);
}
......@@ -209,7 +210,7 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, DownloadProhibited) {
prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
DownloadAnItem();
RemoveAndWait(BrowsingDataRemover::DATA_TYPE_DOWNLOADS);
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS);
VerifyDownloadCount(1u);
}
#endif
......@@ -255,7 +256,7 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Cache) {
std::unique_ptr<BrowsingDataFilterBuilder> filter_builder =
BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST);
filter_builder->AddOrigin(url::Origin(url1));
RemoveWithFilterAndWait(BrowsingDataRemover::DATA_TYPE_CACHE,
RemoveWithFilterAndWait(content::BrowsingDataRemover::DATA_TYPE_CACHE,
std::move(filter_builder));
// After the partial deletion, the cache should be smaller but still nonempty.
......@@ -266,12 +267,12 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest, Cache) {
filter_builder =
BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST);
filter_builder->AddOrigin(url::Origin(url1));
RemoveWithFilterAndWait(BrowsingDataRemover::DATA_TYPE_CACHE,
RemoveWithFilterAndWait(content::BrowsingDataRemover::DATA_TYPE_CACHE,
std::move(filter_builder));
EXPECT_EQ(new_size, GetCacheSize());
// Delete the remaining data.
RemoveAndWait(BrowsingDataRemover::DATA_TYPE_CACHE);
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_CACHE);
// The cache is empty.
EXPECT_EQ(0, GetCacheSize());
......@@ -294,7 +295,7 @@ IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverBrowserTest,
// Verify that TransportSecurityState data is cleared for REMOVE_CACHE.
IN_PROC_BROWSER_TEST_F(BrowsingDataRemoverTransportSecurityStateBrowserTest,
ClearTransportSecurityState) {
RemoveAndWait(BrowsingDataRemover::DATA_TYPE_CACHE);
RemoveAndWait(content::BrowsingDataRemover::DATA_TYPE_CACHE);
base::RunLoop run_loop;
BrowserThread::PostTaskAndReply(
BrowserThread::IO, FROM_HERE,
......
......@@ -334,14 +334,20 @@ ChromeBrowsingDataRemoverDelegate::ChromeBrowsingDataRemoverDelegate(
#endif
weak_ptr_factory_(this) {}
ChromeBrowsingDataRemoverDelegate::~ChromeBrowsingDataRemoverDelegate() {
ChromeBrowsingDataRemoverDelegate::~ChromeBrowsingDataRemoverDelegate() {}
void ChromeBrowsingDataRemoverDelegate::Shutdown() {
history_task_tracker_.TryCancelAll();
template_url_sub_.reset();
}
BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher
content::BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher
ChromeBrowsingDataRemoverDelegate::GetOriginTypeMatcher() const {
return base::Bind(DoesOriginMatchEmbedderMask);
return base::Bind(&DoesOriginMatchEmbedderMask);
}
bool ChromeBrowsingDataRemoverDelegate::MayRemoveDownloadHistory() const {
return profile_->GetPrefs()->GetBoolean(prefs::kAllowDeletingBrowserHistory);
}
void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
......@@ -356,15 +362,18 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
// Embedder-defined DOM-accessible storage currently contains only
// one datatype, which is the durable storage permission.
if (remove_mask & BrowsingDataRemover::DATA_TYPE_EMBEDDER_DOM_STORAGE) {
if (remove_mask &
content::BrowsingDataRemover::DATA_TYPE_EMBEDDER_DOM_STORAGE) {
remove_mask |= DATA_TYPE_DURABLE_PERMISSION;
}
if (origin_type_mask & BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB) {
if (origin_type_mask &
content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB) {
base::RecordAction(
UserMetricsAction("ClearBrowsingData_MaskContainsUnprotectedWeb"));
}
if (origin_type_mask & BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB) {
if (origin_type_mask &
content::BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB) {
base::RecordAction(
UserMetricsAction("ClearBrowsingData_MaskContainsProtectedWeb"));
}
......@@ -377,11 +386,12 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
// If this fires, we added a new BrowsingDataHelper::OriginTypeMask without
// updating the user metrics above.
static_assert(
ALL_ORIGIN_TYPES == (BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB |
ALL_ORIGIN_TYPES ==
(content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB |
#if BUILDFLAG(ENABLE_EXTENSIONS)
ORIGIN_TYPE_EXTENSION |
ORIGIN_TYPE_EXTENSION |
#endif
BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB),
content::BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB),
"OriginTypeMask has been updated without updating user metrics");
//////////////////////////////////////////////////////////////////////////////
......@@ -410,9 +420,9 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
// All the UI entry points into the BrowsingDataRemoverImpl should be
// disabled, but this will fire if something was missed or added.
DCHECK(may_delete_history ||
(remove_mask & BrowsingDataRemover::DATA_TYPE_NO_CHECKS) ||
(remove_mask & content::BrowsingDataRemover::DATA_TYPE_NO_CHECKS) ||
(!(remove_mask & DATA_TYPE_HISTORY) &&
!(remove_mask & BrowsingDataRemover::DATA_TYPE_DOWNLOADS)));
!(remove_mask & content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS)));
//////////////////////////////////////////////////////////////////////////////
// DATA_TYPE_HISTORY
......@@ -643,7 +653,7 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
//////////////////////////////////////////////////////////////////////////////
// DATA_TYPE_DOWNLOADS
if ((remove_mask & BrowsingDataRemover::DATA_TYPE_DOWNLOADS) &&
if ((remove_mask & content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS) &&
may_delete_history) {
DownloadPrefs* download_prefs = DownloadPrefs::FromDownloadManager(
BrowserContext::GetDownloadManager(profile_));
......@@ -657,8 +667,9 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
// 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::DATA_TYPE_COOKIES &&
origin_type_mask & BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB) {
if ((remove_mask & content::BrowsingDataRemover::DATA_TYPE_COOKIES) &&
(origin_type_mask &
content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB)) {
base::RecordAction(UserMetricsAction("ClearBrowsingData_Cookies"));
// Clear the safebrowsing cookies only if time period is for "all time". It
......@@ -753,7 +764,7 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
clear_http_auth_cache_.GetCompletionCallback());
}
if (remove_mask & BrowsingDataRemover::DATA_TYPE_COOKIES) {
if (remove_mask & content::BrowsingDataRemover::DATA_TYPE_COOKIES) {
password_manager::PasswordStore* password_store =
PasswordStoreFactory::GetForProfile(profile_,
ServiceAccessType::EXPLICIT_ACCESS)
......@@ -809,7 +820,7 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
//////////////////////////////////////////////////////////////////////////////
// DATA_TYPE_CACHE
if (remove_mask & BrowsingDataRemover::DATA_TYPE_CACHE) {
if (remove_mask & content::BrowsingDataRemover::DATA_TYPE_CACHE) {
// Tell the renderers to clear their cache.
// TODO(crbug.com/668114): Renderer cache is a platform concept, and should
// live in BrowsingDataRemoverImpl. However, WebCacheManager itself is
......@@ -873,7 +884,7 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
#if defined(OS_ANDROID)
// 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::DATA_TYPE_CACHE)) {
if ((remove_mask & content::BrowsingDataRemover::DATA_TYPE_CACHE)) {
clear_offline_page_data_.Start();
offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_)
->DeleteCachedPagesByURLPredicate(
......@@ -897,8 +908,9 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
#if BUILDFLAG(ENABLE_PLUGINS)
// Plugin is data not separated for protected and unprotected web origins. We
// check the origin_type_mask_ to prevent unintended deletion.
if (remove_mask & DATA_TYPE_PLUGIN_DATA &&
origin_type_mask & BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB) {
if ((remove_mask & DATA_TYPE_PLUGIN_DATA) &&
(origin_type_mask &
content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB)) {
base::RecordAction(UserMetricsAction("ClearBrowsingData_LSOData"));
clear_plugin_data_count_ = 1;
......@@ -926,7 +938,7 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
//////////////////////////////////////////////////////////////////////////////
// DATA_TYPE_MEDIA_LICENSES
if (remove_mask & BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES) {
if (remove_mask & content::BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES) {
// TODO(jrummell): This UMA should be renamed to indicate it is for Media
// Licenses.
base::RecordAction(UserMetricsAction("ClearBrowsingData_ContentLicenses"));
......@@ -967,21 +979,21 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
// 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::DATA_TYPE_CACHE |
BrowsingDataRemover::DATA_TYPE_COOKIES))) {
if ((remove_mask & (content::BrowsingDataRemover::DATA_TYPE_CACHE |
content::BrowsingDataRemover::DATA_TYPE_COOKIES))) {
prefs->SetString(omnibox::kZeroSuggestCachedResults, std::string());
}
//////////////////////////////////////////////////////////////////////////////
// Domain reliability service.
if (remove_mask &
(BrowsingDataRemover::DATA_TYPE_COOKIES | DATA_TYPE_HISTORY)) {
(content::BrowsingDataRemover::DATA_TYPE_COOKIES | DATA_TYPE_HISTORY)) {
domain_reliability::DomainReliabilityService* service =
domain_reliability::DomainReliabilityServiceFactory::
GetForBrowserContext(profile_);
if (service) {
domain_reliability::DomainReliabilityClearMode mode;
if (remove_mask & BrowsingDataRemover::DATA_TYPE_COOKIES)
if (remove_mask & content::BrowsingDataRemover::DATA_TYPE_COOKIES)
mode = domain_reliability::CLEAR_CONTEXTS;
else
mode = domain_reliability::CLEAR_BEACONS;
......
......@@ -12,12 +12,13 @@
#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/keyed_service/core/keyed_service.h"
#include "components/offline_pages/core/offline_page_model.h"
#include "components/search_engines/template_url_service.h"
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/browsing_data_remover_delegate.h"
#include "extensions/features/features.h"
#include "media/media_features.h"
#include "ppapi/features/features.h"
......@@ -41,19 +42,23 @@ class PluginDataRemover;
// A delegate used by BrowsingDataRemover to delete data specific to Chrome
// as the embedder.
class ChromeBrowsingDataRemoverDelegate : public BrowsingDataRemoverDelegate
class ChromeBrowsingDataRemoverDelegate
: public content::BrowsingDataRemoverDelegate,
public KeyedService
#if BUILDFLAG(ENABLE_PLUGINS)
, public PepperFlashSettingsManager::Client
,
public PepperFlashSettingsManager::Client
#endif
{
public:
// This is an extension of BrowsingDataRemover::RemoveDataMask which includes
// all datatypes therefrom and adds additional Chrome-specific ones.
// This is an extension of content::BrowsingDataRemover::RemoveDataMask which
// includes all datatypes therefrom and adds additional Chrome-specific ones.
// TODO(crbug.com/668114): Extend this to uint64_t to ensure that we won't
// run out of space anytime soon.
enum DataType {
// Embedder can start adding datatypes after the last platform datatype.
DATA_TYPE_EMBEDDER_BEGIN = BrowsingDataRemover::DATA_TYPE_CONTENT_END << 1,
DATA_TYPE_EMBEDDER_BEGIN =
content::BrowsingDataRemover::DATA_TYPE_CONTENT_END << 1,
// Chrome-specific datatypes.
DATA_TYPE_HISTORY = DATA_TYPE_EMBEDDER_BEGIN,
......@@ -72,57 +77,60 @@ class ChromeBrowsingDataRemoverDelegate : public BrowsingDataRemoverDelegate
// "Site data" includes storage backend accessible to websites and some
// additional metadata kept by the browser (e.g. site usage data).
DATA_TYPE_SITE_DATA = BrowsingDataRemover::DATA_TYPE_APP_CACHE |
BrowsingDataRemover::DATA_TYPE_COOKIES |
BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS |
BrowsingDataRemover::DATA_TYPE_INDEXED_DB |
BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE |
BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS |
BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE |
BrowsingDataRemover::DATA_TYPE_WEB_SQL |
BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
DATA_TYPE_PLUGIN_DATA |
DATA_TYPE_SITE_DATA =
content::BrowsingDataRemover::DATA_TYPE_APP_CACHE |
content::BrowsingDataRemover::DATA_TYPE_COOKIES |
content::BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS |
content::BrowsingDataRemover::DATA_TYPE_INDEXED_DB |
content::BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE |
content::BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS |
content::BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE |
content::BrowsingDataRemover::DATA_TYPE_WEB_SQL |
content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
DATA_TYPE_PLUGIN_DATA |
#if defined(OS_ANDROID)
DATA_TYPE_WEB_APP_DATA |
DATA_TYPE_WEB_APP_DATA |
#endif
DATA_TYPE_SITE_USAGE_DATA |
DATA_TYPE_DURABLE_PERMISSION |
DATA_TYPE_EXTERNAL_PROTOCOL_DATA,
DATA_TYPE_SITE_USAGE_DATA |
DATA_TYPE_DURABLE_PERMISSION |
DATA_TYPE_EXTERNAL_PROTOCOL_DATA,
// Datatypes protected by Important Sites.
IMPORTANT_SITES_DATA_TYPES =
DATA_TYPE_SITE_DATA | BrowsingDataRemover::DATA_TYPE_CACHE,
DATA_TYPE_SITE_DATA | content::BrowsingDataRemover::DATA_TYPE_CACHE,
// Datatypes that can be deleted partially per URL / origin / domain,
// whichever makes sense.
FILTERABLE_DATA_TYPES = DATA_TYPE_SITE_DATA |
BrowsingDataRemover::DATA_TYPE_CACHE |
BrowsingDataRemover::DATA_TYPE_DOWNLOADS,
content::BrowsingDataRemover::DATA_TYPE_CACHE |
content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS,
// Includes all the available remove options. Meant to be used by clients
// that wish to wipe as much data as possible from a Profile, to make it
// look like a new Profile.
ALL_DATA_TYPES = DATA_TYPE_SITE_DATA |
BrowsingDataRemover::DATA_TYPE_CACHE |
BrowsingDataRemover::DATA_TYPE_DOWNLOADS |
content::BrowsingDataRemover::DATA_TYPE_CACHE |
content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS |
DATA_TYPE_FORM_DATA |
DATA_TYPE_HISTORY |
DATA_TYPE_PASSWORDS |
BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES,
content::BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES,
// Includes all available remove options. Meant to be used when the Profile
// is scheduled to be deleted, and all possible data should be wiped from
// disk as soon as possible.
WIPE_PROFILE = ALL_DATA_TYPES | BrowsingDataRemover::DATA_TYPE_NO_CHECKS,
WIPE_PROFILE =
ALL_DATA_TYPES | content::BrowsingDataRemover::DATA_TYPE_NO_CHECKS,
};
// This is an extension of BrowsingDataRemover::OriginType which includes all
// origin types therefrom and adds additional Chrome-specific ones.
// This is an extension of content::BrowsingDataRemover::OriginType which
// includes all origin types therefrom and adds additional Chrome-specific
// ones.
enum OriginType {
// Embedder can start adding origin types after the last
// platform origin type.
ORIGIN_TYPE_EMBEDDER_BEGIN = BrowsingDataRemover::ORIGIN_TYPE_CONTENT_END
<< 1,
ORIGIN_TYPE_EMBEDDER_BEGIN =
content::BrowsingDataRemover::ORIGIN_TYPE_CONTENT_END << 1,
#if BUILDFLAG(ENABLE_EXTENSIONS)
// Packaged apps and extensions (chrome-extension://*).
......@@ -130,11 +138,12 @@ class ChromeBrowsingDataRemoverDelegate : public BrowsingDataRemoverDelegate
#endif
// All origin types.
ALL_ORIGIN_TYPES = BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB |
ALL_ORIGIN_TYPES =
content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB |
#if BUILDFLAG(ENABLE_EXTENSIONS)
ORIGIN_TYPE_EXTENSION |
ORIGIN_TYPE_EXTENSION |
#endif
BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB,
content::BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB,
};
// Important sites protect a small set of sites from the deletion of certain
......@@ -172,9 +181,13 @@ class ChromeBrowsingDataRemoverDelegate : public BrowsingDataRemoverDelegate
ChromeBrowsingDataRemoverDelegate(content::BrowserContext* browser_context);
~ChromeBrowsingDataRemoverDelegate() override;
// KeyedService:
void Shutdown() override;
// BrowsingDataRemoverDelegate:
BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher GetOriginTypeMatcher()
const override;
content::BrowsingDataRemoverDelegate::EmbedderOriginTypeMatcher
GetOriginTypeMatcher() const override;
bool MayRemoveDownloadHistory() const override;
void RemoveEmbedderData(
const base::Time& delete_begin,
const base::Time& delete_end,
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Copyright 2017 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/browsing_data_remover_factory.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.h"
#include "base/memory/ptr_util.h"
#include "base/memory/singleton.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/browsing_data/browsing_data_remover_impl.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/domain_reliability/service_factory.h"
......@@ -39,18 +38,20 @@
#endif
// static
BrowsingDataRemoverFactory* BrowsingDataRemoverFactory::GetInstance() {
return base::Singleton<BrowsingDataRemoverFactory>::get();
ChromeBrowsingDataRemoverDelegateFactory*
ChromeBrowsingDataRemoverDelegateFactory::GetInstance() {
return base::Singleton<ChromeBrowsingDataRemoverDelegateFactory>::get();
}
// static
BrowsingDataRemover* BrowsingDataRemoverFactory::GetForBrowserContext(
content::BrowserContext* context) {
return static_cast<BrowsingDataRemover*>(
GetInstance()->GetServiceForBrowserContext(context, true));
ChromeBrowsingDataRemoverDelegate*
ChromeBrowsingDataRemoverDelegateFactory::GetForProfile(Profile* profile) {
return static_cast<ChromeBrowsingDataRemoverDelegate*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
BrowsingDataRemoverFactory::BrowsingDataRemoverFactory()
ChromeBrowsingDataRemoverDelegateFactory::
ChromeBrowsingDataRemoverDelegateFactory()
: BrowserContextKeyedServiceFactory(
"BrowsingDataRemover",
BrowserContextDependencyManager::GetInstance()) {
......@@ -81,9 +82,11 @@ BrowsingDataRemoverFactory::BrowsingDataRemoverFactory()
#endif
}
BrowsingDataRemoverFactory::~BrowsingDataRemoverFactory() {}
ChromeBrowsingDataRemoverDelegateFactory::
~ChromeBrowsingDataRemoverDelegateFactory() {}
content::BrowserContext* BrowsingDataRemoverFactory::GetBrowserContextToUse(
content::BrowserContext*
ChromeBrowsingDataRemoverDelegateFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
// For guest profiles the browsing data is in the OTR profile.
Profile* profile = static_cast<Profile*>(context);
......@@ -92,10 +95,7 @@ content::BrowserContext* BrowsingDataRemoverFactory::GetBrowserContextToUse(
return profile;
}
KeyedService* BrowsingDataRemoverFactory::BuildServiceInstanceFor(
KeyedService* ChromeBrowsingDataRemoverDelegateFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
BrowsingDataRemoverImpl* remover = new BrowsingDataRemoverImpl(context);
remover->SetEmbedderDelegate(
base::MakeUnique<ChromeBrowsingDataRemoverDelegate>(context));
return remover;
return new ChromeBrowsingDataRemoverDelegate(context);
}
// Copyright 2016 The Chromium Authors. All rights reserved.
// Copyright 2017 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_FACTORY_H_
#define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_REMOVER_FACTORY_H_
#ifndef CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_REMOVER_DELEGATE_FACTORY_H_
#define CHROME_BROWSER_BROWSING_DATA_CHROME_BROWSING_DATA_REMOVER_DELEGATE_FACTORY_H_
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
......@@ -12,22 +12,24 @@ template <typename T>
struct DefaultSingletonTraits;
}
class BrowsingDataRemover;
class ChromeBrowsingDataRemoverDelegate;
class Profile;
class BrowsingDataRemoverFactory : public BrowserContextKeyedServiceFactory {
class ChromeBrowsingDataRemoverDelegateFactory
: public BrowserContextKeyedServiceFactory {
public:
// Returns the singleton instance of BrowsingDataRemoverFactory.
static BrowsingDataRemoverFactory* GetInstance();
// Returns the singleton instance of ChromeBrowsingDataRemoverDelegateFactory.
static ChromeBrowsingDataRemoverDelegateFactory* GetInstance();
// Returns the BrowsingDataRemover associated with |context|.
static BrowsingDataRemover* GetForBrowserContext(
content::BrowserContext* context);
// Returns the ChromeBrowsingDataRemoverDelegate associated with |profile|.
static ChromeBrowsingDataRemoverDelegate* GetForProfile(Profile* profile);
private:
friend struct base::DefaultSingletonTraits<BrowsingDataRemoverFactory>;
friend struct base::DefaultSingletonTraits<
ChromeBrowsingDataRemoverDelegateFactory<