| Index: chrome/browser/profiles/profile_statistics_aggregator.cc
|
| diff --git a/chrome/browser/profiles/profile_statistics_aggregator.cc b/chrome/browser/profiles/profile_statistics_aggregator.cc
|
| index c61688ca59ac0210cf5ad151f832b61002c81142..6064c4aecb9afabd4cce673e34e231257b19e3ae 100644
|
| --- a/chrome/browser/profiles/profile_statistics_aggregator.cc
|
| +++ b/chrome/browser/profiles/profile_statistics_aggregator.cc
|
| @@ -17,32 +17,16 @@
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/profiles/profile_statistics.h"
|
| #include "chrome/browser/profiles/profile_statistics_factory.h"
|
| +#include "chrome/browser/web_data_service_factory.h"
|
| +#include "components/browsing_data/core/counters/autofill_counter.h"
|
| #include "components/browsing_data/core/counters/bookmark_counter.h"
|
| #include "components/browsing_data/core/counters/history_counter.h"
|
| #include "components/browsing_data/core/counters/passwords_counter.h"
|
| #include "components/browsing_data/core/pref_names.h"
|
| -#include "components/prefs/pref_service.h"
|
| #include "content/public/browser/browser_thread.h"
|
|
|
| using browsing_data::BrowsingDataCounter;
|
|
|
| -namespace {
|
| -
|
| -// Callback for each pref. Every one that should be counted as a changed
|
| -// user pref will cause *count to be incremented.
|
| -void AccumulatePrefStats(const PrefService* pref_service,
|
| - int* count,
|
| - const std::string& key,
|
| - const base::Value& value) {
|
| - const PrefService::Preference* pref = pref_service->FindPreference(key);
|
| - // Skip all dictionaries, only want to count values.
|
| - if (!value.is_dict() && pref && pref->IsUserControlled() &&
|
| - !pref->IsDefaultValue())
|
| - ++(*count);
|
| -}
|
| -
|
| -} // namespace
|
| -
|
| ProfileStatisticsAggregator::ProfileStatisticsAggregator(
|
| Profile* profile,
|
| const base::Closure& done_callback)
|
| @@ -52,10 +36,6 @@ ProfileStatisticsAggregator::ProfileStatisticsAggregator(
|
|
|
| ProfileStatisticsAggregator::~ProfileStatisticsAggregator() {}
|
|
|
| -size_t ProfileStatisticsAggregator::GetCallbackCount() {
|
| - return stats_callbacks_.size();
|
| -}
|
| -
|
| void ProfileStatisticsAggregator::AddCallbackAndStartAggregator(
|
| const profiles::ProfileStatisticsCallback& stats_callback) {
|
| if (stats_callback)
|
| @@ -77,9 +57,9 @@ void ProfileStatisticsAggregator::StartAggregator() {
|
| DCHECK(g_browser_process->profile_manager()->IsValidProfile(profile_));
|
| profile_category_stats_.clear();
|
|
|
| - // Try to cancel tasks.
|
| - tracker_.TryCancelAll();
|
| + // Cancel tasks.
|
| counters_.clear();
|
| +
|
| // Initiate bookmark counting.
|
| bookmarks::BookmarkModel* bookmark_model =
|
| BookmarkModelFactory::GetForBrowserContext(profile_);
|
| @@ -101,13 +81,12 @@ void ProfileStatisticsAggregator::StartAggregator() {
|
| AddCounter(base::MakeUnique<browsing_data::PasswordsCounter>(
|
| password_store, /*sync_service=*/nullptr));
|
|
|
| - // Initiate preference counting (async).
|
| - tracker_.PostTaskAndReplyWithResult(
|
| - content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::UI)
|
| - .get(),
|
| - FROM_HERE, base::Bind(&ProfileStatisticsAggregator::CountPrefs, this),
|
| - base::Bind(&ProfileStatisticsAggregator::StatisticsCallback, this,
|
| - profiles::kProfileStatisticsSettings));
|
| + // Initiate autofill counting.
|
| + scoped_refptr<autofill::AutofillWebDataService> autofill_service =
|
| + WebDataServiceFactory::GetAutofillWebDataForProfile(
|
| + profile_, ServiceAccessType::EXPLICIT_ACCESS);
|
| + AddCounter(base::MakeUnique<browsing_data::AutofillCounter>(
|
| + autofill_service, /*sync_service=*/nullptr));
|
| }
|
|
|
| void ProfileStatisticsAggregator::OnCounterResult(
|
| @@ -119,24 +98,23 @@ void ProfileStatisticsAggregator::OnCounterResult(
|
| static_cast<BrowsingDataCounter::FinishedResult*>(result.get());
|
| int count = finished_result->Value();
|
| if (pref_name == browsing_data::BookmarkCounter::kPrefName) {
|
| - StatisticsCallbackSuccess(profiles::kProfileStatisticsBookmarks, count);
|
| + StatisticsCallback(profiles::kProfileStatisticsBookmarks, count);
|
| } else if (pref_name == browsing_data::prefs::kDeleteBrowsingHistory) {
|
| - StatisticsCallbackSuccess(profiles::kProfileStatisticsBrowsingHistory,
|
| - count);
|
| + StatisticsCallback(profiles::kProfileStatisticsBrowsingHistory, count);
|
| } else if (pref_name == browsing_data::prefs::kDeletePasswords) {
|
| - StatisticsCallbackSuccess(profiles::kProfileStatisticsPasswords, count);
|
| + StatisticsCallback(profiles::kProfileStatisticsPasswords, count);
|
| + } else if (pref_name == browsing_data::prefs::kDeleteFormData) {
|
| + StatisticsCallback(profiles::kProfileStatisticsAutofill, count);
|
| } else {
|
| - // TODO(dullweber): Add more cases when the other statistics are replaced.
|
| NOTREACHED();
|
| }
|
| }
|
|
|
| -void ProfileStatisticsAggregator::StatisticsCallback(
|
| - const char* category, ProfileStatValue result) {
|
| +void ProfileStatisticsAggregator::StatisticsCallback(const char* category,
|
| + int count) {
|
| profiles::ProfileCategoryStat datum;
|
| datum.category = category;
|
| - datum.count = result.count;
|
| - datum.success = result.success;
|
| + datum.count = count;
|
| profile_category_stats_.push_back(datum);
|
| for (const auto& stats_callback : stats_callbacks_) {
|
| DCHECK(stats_callback);
|
| @@ -149,32 +127,3 @@ void ProfileStatisticsAggregator::StatisticsCallback(
|
| done_callback_.Run();
|
| }
|
| }
|
| -
|
| -void ProfileStatisticsAggregator::StatisticsCallbackSuccess(
|
| - const char* category, int count) {
|
| - ProfileStatValue result;
|
| - result.count = count;
|
| - result.success = true;
|
| - StatisticsCallback(category, result);
|
| -}
|
| -
|
| -void ProfileStatisticsAggregator::StatisticsCallbackFailure(
|
| - const char* category) {
|
| - ProfileStatValue result;
|
| - result.count = 0;
|
| - result.success = false;
|
| - StatisticsCallback(category, result);
|
| -}
|
| -
|
| -ProfileStatisticsAggregator::ProfileStatValue
|
| - ProfileStatisticsAggregator::CountPrefs() const {
|
| - const PrefService* pref_service = profile_->GetPrefs();
|
| -
|
| - ProfileStatValue result;
|
| - if (pref_service) {
|
| - pref_service->IteratePreferenceValues(base::BindRepeating(
|
| - &AccumulatePrefStats, pref_service, base::Unretained(&result.count)));
|
| - result.success = true;
|
| - }
|
| - return result;
|
| -}
|
|
|