Commit c6d95344 authored by ioanap's avatar ioanap Committed by Commit bot

Add BrowsingDataCounterFactory

Add a factory to facilitate the creation of browsing data counters for when they will be fully componentized.

BUG=620317

Review-Url: https://codereview.chromium.org/2121203002
Cr-Commit-Position: refs/heads/master@{#404648}
parent f79dd600
......@@ -5,6 +5,7 @@
#include "chrome/browser/android/browsing_data/browsing_data_counter_bridge.h"
#include "base/android/jni_string.h"
#include "chrome/browser/browsing_data/browsing_data_counter_factory.h"
#include "chrome/browser/browsing_data/browsing_data_counter_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
......@@ -26,7 +27,7 @@ BrowsingDataCounterBridge::BrowsingDataCounterBridge(
Profile* profile =
ProfileManager::GetActiveUserProfile()->GetOriginalProfile();
counter_.reset(CreateCounterForPreference(pref, profile));
counter_ = BrowsingDataCounterFactory::GetForProfileAndPref(profile, pref);
if (!counter_)
return;
......
// 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/browsing_data_counter_factory.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/browsing_data/autofill_counter.h"
#include "chrome/browser/browsing_data/browsing_data_counter_utils.h"
#include "chrome/browser/browsing_data/cache_counter.h"
#include "chrome/browser/browsing_data/downloads_counter.h"
#include "chrome/browser/browsing_data/history_counter.h"
#include "chrome/browser/browsing_data/media_licenses_counter.h"
#include "chrome/browser/browsing_data/passwords_counter.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/browsing_data/counters/browsing_data_counter.h"
#if defined(ENABLE_EXTENSIONS)
#include "chrome/browser/browsing_data/hosted_apps_counter.h"
#endif
// static
std::unique_ptr<browsing_data::BrowsingDataCounter>
BrowsingDataCounterFactory::GetForProfileAndPref(Profile* profile,
const std::string& pref_name) {
if (!AreCountersEnabled())
return nullptr;
if (pref_name == prefs::kDeleteBrowsingHistory)
return base::MakeUnique<HistoryCounter>(profile);
if (pref_name == prefs::kDeleteCache)
return base::MakeUnique<CacheCounter>(profile);
if (pref_name == prefs::kDeletePasswords)
return base::MakeUnique<PasswordsCounter>(profile);
if (pref_name == prefs::kDeleteFormData)
return base::MakeUnique<AutofillCounter>(profile);
if (pref_name == prefs::kDeleteDownloadHistory)
return base::MakeUnique<DownloadsCounter>(profile);
if (pref_name == prefs::kDeleteMediaLicenses)
return base::MakeUnique<MediaLicensesCounter>(profile);
#if defined(ENABLE_EXTENSIONS)
if (pref_name == prefs::kDeleteHostedAppsData)
return base::MakeUnique<HostedAppsCounter>(profile);
#endif
return nullptr;
}
// 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_COUNTER_FACTORY_H_
#define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_FACTORY_H_
#include <memory>
#include <string>
#include "base/macros.h"
class Profile;
namespace browsing_data {
class BrowsingDataCounter;
}
class BrowsingDataCounterFactory {
public:
// Creates a new instance of BrowsingDataCounter that is counting the data
// for |profile|, related to a given deletion preference |pref_name|.
static std::unique_ptr<browsing_data::BrowsingDataCounter>
GetForProfileAndPref(Profile* profile, const std::string& pref_name);
private:
BrowsingDataCounterFactory();
~BrowsingDataCounterFactory();
DISALLOW_COPY_AND_ASSIGN(BrowsingDataCounterFactory);
};
#endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_FACTORY_H_
......@@ -261,21 +261,3 @@ bool GetDeletionPreferenceFromDataType(
NOTREACHED();
return false;
}
browsing_data::BrowsingDataCounter* CreateCounterForPreference(
std::string pref_name,
Profile* profile) {
if (!AreCountersEnabled())
return nullptr;
if (pref_name == prefs::kDeleteBrowsingHistory)
return new HistoryCounter(profile);
if (pref_name == prefs::kDeleteCache)
return new CacheCounter(profile);
if (pref_name == prefs::kDeletePasswords)
return new PasswordsCounter(profile);
if (pref_name == prefs::kDeleteFormData)
return new AutofillCounter(profile);
return nullptr;
}
......@@ -24,10 +24,4 @@ bool GetDeletionPreferenceFromDataType(
browsing_data::BrowsingDataType data_type,
std::string* out_pref);
// Creates a new instance of BrowsingDataCounter that is counting the data
// related to a given deletion preference |pref_name|.
browsing_data::BrowsingDataCounter* CreateCounterForPreference(
std::string pref_name,
Profile* profile);
#endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_COUNTER_UTILS_H_
......@@ -21,15 +21,11 @@
#include "base/values.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browsing_data/autofill_counter.h"
#include "chrome/browser/browsing_data/browsing_data_counter_factory.h"
#include "chrome/browser/browsing_data/browsing_data_counter_utils.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/cache_counter.h"
#include "chrome/browser/browsing_data/history_counter.h"
#include "chrome/browser/browsing_data/media_licenses_counter.h"
#include "chrome/browser/browsing_data/passwords_counter.h"
#include "chrome/browser/history/web_history_service_factory.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h"
......@@ -63,6 +59,14 @@ const char kMyActivityUrlInDialog[] =
const int kMaxTimesHistoryNoticeShown = 1;
const char* kCounterPrefs[] = {
prefs::kDeleteBrowsingHistory,
prefs::kDeleteCache,
prefs::kDeleteFormData,
prefs::kDeleteMediaLicenses,
prefs::kDeletePasswords,
};
} // namespace
namespace options {
......@@ -93,11 +97,10 @@ void ClearBrowserDataHandler::InitializeHandler() {
if (AreCountersEnabled()) {
Profile* profile = Profile::FromWebUI(web_ui());
AddCounter(base::WrapUnique(new PasswordsCounter(profile)));
AddCounter(base::WrapUnique(new HistoryCounter(profile)));
AddCounter(base::WrapUnique(new CacheCounter(profile)));
AddCounter(base::WrapUnique(new AutofillCounter(profile)));
AddCounter(base::WrapUnique(new MediaLicensesCounter(profile)));
for (const std::string& pref : kCounterPrefs) {
AddCounter(
BrowsingDataCounterFactory::GetForProfileAndPref(profile, pref));
}
sync_service_ = ProfileSyncServiceFactory::GetForProfile(profile);
if (sync_service_)
......
......@@ -10,16 +10,10 @@
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/sparse_histogram.h"
#include "chrome/browser/browsing_data/autofill_counter.h"
#include "chrome/browser/browsing_data/browsing_data_counter_factory.h"
#include "chrome/browser/browsing_data/browsing_data_counter_utils.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/cache_counter.h"
#include "chrome/browser/browsing_data/downloads_counter.h"
#include "chrome/browser/browsing_data/history_counter.h"
#include "chrome/browser/browsing_data/hosted_apps_counter.h"
#include "chrome/browser/browsing_data/media_licenses_counter.h"
#include "chrome/browser/browsing_data/passwords_counter.h"
#include "chrome/browser/history/web_history_service_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/common/channel_info.h"
......@@ -33,7 +27,18 @@ namespace {
const int kMaxTimesHistoryNoticeShown = 1;
}
// TODO(msramek): Get the list of deletion preferences from the JS side.
const char* kCounterPrefs[] = {
prefs::kDeleteBrowsingHistory,
prefs::kDeleteCache,
prefs::kDeleteDownloadHistory,
prefs::kDeleteFormData,
prefs::kDeleteHostedAppsData,
prefs::kDeleteMediaLicenses,
prefs::kDeletePasswords,
};
} // namespace
namespace settings {
......@@ -215,14 +220,10 @@ void ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged() {
void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) {
AllowJavascript();
// TODO(msramek): Simplify this using a factory.
AddCounter(base::WrapUnique(new AutofillCounter(profile_)));
AddCounter(base::WrapUnique(new CacheCounter(profile_)));
AddCounter(base::WrapUnique(new DownloadsCounter(profile_)));
AddCounter(base::WrapUnique(new HistoryCounter(profile_)));
AddCounter(base::WrapUnique(new HostedAppsCounter(profile_)));
AddCounter(base::WrapUnique(new PasswordsCounter(profile_)));
AddCounter(base::WrapUnique(new MediaLicensesCounter(profile_)));
for (const std::string& pref : kCounterPrefs) {
AddCounter(
BrowsingDataCounterFactory::GetForProfileAndPref(profile_, pref));
}
OnStateChanged();
RefreshHistoryNotice();
......
......@@ -71,6 +71,8 @@
'browser/browsing_data/browsing_data_channel_id_helper.h',
'browser/browsing_data/browsing_data_cookie_helper.cc',
'browser/browsing_data/browsing_data_cookie_helper.h',
'browser/browsing_data/browsing_data_counter_factory.cc',
'browser/browsing_data/browsing_data_counter_factory.h',
'browser/browsing_data/browsing_data_counter_utils.cc',
'browser/browsing_data/browsing_data_counter_utils.h',
'browser/browsing_data/browsing_data_database_helper.cc',
......
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