Commit 88f2dd7f authored by Jesse McKenna's avatar Jesse McKenna Committed by Commit Bot

CodeHealthRotation: migrate Bind to BindOnce/Repeating in c/b/profiles/profile_statistics*

This change migrates uses of base::Bind to BindOnce/BindRepeating, and
uses of base::Callback to OnceCallback/RepeatingCallback.

Please see crbug.com/714018 for full details about the migration.

Bug: 1147284
Change-Id: I60acd5432ab7189c8d855d224c96118b058c4ba7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2532136Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827226}
parent f47d2927
...@@ -18,7 +18,7 @@ ProfileStatistics::~ProfileStatistics() { ...@@ -18,7 +18,7 @@ ProfileStatistics::~ProfileStatistics() {
} }
void ProfileStatistics::GatherStatistics( void ProfileStatistics::GatherStatistics(
const profiles::ProfileStatisticsCallback& callback) { profiles::ProfileStatisticsCallback callback) {
// IsValidProfile() can be false in unit tests. // IsValidProfile() can be false in unit tests.
if (!g_browser_process->profile_manager()->IsValidProfile(profile_)) if (!g_browser_process->profile_manager()->IsValidProfile(profile_))
return; return;
...@@ -26,10 +26,10 @@ void ProfileStatistics::GatherStatistics( ...@@ -26,10 +26,10 @@ void ProfileStatistics::GatherStatistics(
if (!aggregator_) { if (!aggregator_) {
aggregator_ = std::make_unique<ProfileStatisticsAggregator>( aggregator_ = std::make_unique<ProfileStatisticsAggregator>(
profile_, base::Bind(&ProfileStatistics::DeregisterAggregator, profile_, base::BindOnce(&ProfileStatistics::DeregisterAggregator,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
aggregator_->AddCallbackAndStartAggregator(callback); aggregator_->AddCallbackAndStartAggregator(std::move(callback));
} }
void ProfileStatistics::DeregisterAggregator() { void ProfileStatistics::DeregisterAggregator() {
......
...@@ -26,7 +26,7 @@ class ProfileStatistics : public KeyedService { ...@@ -26,7 +26,7 @@ class ProfileStatistics : public KeyedService {
// Currently bookmarks, history, logins and autofill forms are counted. The // Currently bookmarks, history, logins and autofill forms are counted. The
// callback function will probably be called more than once, so binding // callback function will probably be called more than once, so binding
// parameters with bind::Passed() is prohibited. // parameters with bind::Passed() is prohibited.
void GatherStatistics(const profiles::ProfileStatisticsCallback& callback); void GatherStatistics(profiles::ProfileStatisticsCallback callback);
private: private:
friend class ProfileStatisticsFactory; friend class ProfileStatisticsFactory;
......
...@@ -29,25 +29,26 @@ using browsing_data::BrowsingDataCounter; ...@@ -29,25 +29,26 @@ using browsing_data::BrowsingDataCounter;
ProfileStatisticsAggregator::ProfileStatisticsAggregator( ProfileStatisticsAggregator::ProfileStatisticsAggregator(
Profile* profile, Profile* profile,
const base::Closure& done_callback) base::OnceClosure done_callback)
: profile_(profile), : profile_(profile),
profile_path_(profile_->GetPath()), profile_path_(profile_->GetPath()),
done_callback_(done_callback) {} done_callback_(std::move(done_callback)) {}
ProfileStatisticsAggregator::~ProfileStatisticsAggregator() {} ProfileStatisticsAggregator::~ProfileStatisticsAggregator() {}
void ProfileStatisticsAggregator::AddCallbackAndStartAggregator( void ProfileStatisticsAggregator::AddCallbackAndStartAggregator(
const profiles::ProfileStatisticsCallback& stats_callback) { profiles::ProfileStatisticsCallback stats_callback) {
if (stats_callback) if (stats_callback)
stats_callbacks_.push_back(stats_callback); stats_callbacks_.push_back(std::move(stats_callback));
StartAggregator(); StartAggregator();
} }
void ProfileStatisticsAggregator::AddCounter( void ProfileStatisticsAggregator::AddCounter(
std::unique_ptr<BrowsingDataCounter> counter) { std::unique_ptr<BrowsingDataCounter> counter) {
counter->InitWithoutPref( counter->InitWithoutPref(
base::Time(), base::Bind(&ProfileStatisticsAggregator::OnCounterResult, base::Time(),
base::Unretained(this))); base::BindRepeating(&ProfileStatisticsAggregator::OnCounterResult,
base::Unretained(this)));
counter->Restart(); counter->Restart();
counters_.push_back(std::move(counter)); counters_.push_back(std::move(counter));
} }
...@@ -123,7 +124,7 @@ void ProfileStatisticsAggregator::StatisticsCallback(const char* category, ...@@ -123,7 +124,7 @@ void ProfileStatisticsAggregator::StatisticsCallback(const char* category,
if (profile_category_stats_.size() == if (profile_category_stats_.size() ==
profiles::kProfileStatisticsCategories.size()) { profiles::kProfileStatisticsCategories.size()) {
if (done_callback_) DCHECK(done_callback_);
done_callback_.Run(); std::move(done_callback_).Run();
} }
} }
...@@ -24,14 +24,14 @@ class ProfileStatisticsAggregator { ...@@ -24,14 +24,14 @@ class ProfileStatisticsAggregator {
public: public:
ProfileStatisticsAggregator(Profile* profile, ProfileStatisticsAggregator(Profile* profile,
const base::Closure& done_callback); base::OnceClosure done_callback);
ProfileStatisticsAggregator(const ProfileStatisticsAggregator&) = delete; ProfileStatisticsAggregator(const ProfileStatisticsAggregator&) = delete;
ProfileStatisticsAggregator& operator=(const ProfileStatisticsAggregator&) = ProfileStatisticsAggregator& operator=(const ProfileStatisticsAggregator&) =
delete; delete;
~ProfileStatisticsAggregator(); ~ProfileStatisticsAggregator();
void AddCallbackAndStartAggregator( void AddCallbackAndStartAggregator(
const profiles::ProfileStatisticsCallback& stats_callback); profiles::ProfileStatisticsCallback stats_callback);
private: private:
// Start gathering statistics. Also cancels existing statistics tasks. // Start gathering statistics. Also cancels existing statistics tasks.
...@@ -58,7 +58,7 @@ class ProfileStatisticsAggregator { ...@@ -58,7 +58,7 @@ class ProfileStatisticsAggregator {
std::vector<profiles::ProfileStatisticsCallback> stats_callbacks_; std::vector<profiles::ProfileStatisticsCallback> stats_callbacks_;
// Callback function to be called when all statistics are calculated. // Callback function to be called when all statistics are calculated.
base::Closure done_callback_; base::OnceClosure done_callback_;
std::vector<std::unique_ptr<browsing_data::BrowsingDataCounter>> counters_; std::vector<std::unique_ptr<browsing_data::BrowsingDataCounter>> counters_;
}; };
......
...@@ -184,8 +184,8 @@ IN_PROC_BROWSER_TEST_F(ProfileStatisticsBrowserTest, GatherStatistics) { ...@@ -184,8 +184,8 @@ IN_PROC_BROWSER_TEST_F(ProfileStatisticsBrowserTest, GatherStatistics) {
ProfileStatisticsAggregatorState state; ProfileStatisticsAggregatorState state;
profile_stat->GatherStatistics( profile_stat->GatherStatistics(
base::Bind(&ProfileStatisticsAggregatorState::StatsCallback, base::BindRepeating(&ProfileStatisticsAggregatorState::StatsCallback,
base::Unretained(&state))); base::Unretained(&state)));
state.WaitForStats(); state.WaitForStats();
profiles::ProfileCategoryStats stats = state.GetStats(); profiles::ProfileCategoryStats stats = state.GetStats();
...@@ -205,15 +205,15 @@ IN_PROC_BROWSER_TEST_F(ProfileStatisticsBrowserTest, ...@@ -205,15 +205,15 @@ IN_PROC_BROWSER_TEST_F(ProfileStatisticsBrowserTest,
ProfileStatisticsAggregatorState state2; ProfileStatisticsAggregatorState state2;
profile_stat->GatherStatistics( profile_stat->GatherStatistics(
base::Bind(&ProfileStatisticsAggregatorState::StatsCallback, base::BindRepeating(&ProfileStatisticsAggregatorState::StatsCallback,
base::Unretained(&state1))); base::Unretained(&state1)));
state1.WaitForStats(); state1.WaitForStats();
state1.SetRequiredStatCountAndCreateRunLoop(stats_categories().size()); state1.SetRequiredStatCountAndCreateRunLoop(stats_categories().size());
profile_stat->GatherStatistics( profile_stat->GatherStatistics(
base::Bind(&ProfileStatisticsAggregatorState::StatsCallback, base::BindRepeating(&ProfileStatisticsAggregatorState::StatsCallback,
base::Unretained(&state2))); base::Unretained(&state2)));
state1.WaitForStats(); state1.WaitForStats();
state2.WaitForStats(); state2.WaitForStats();
......
...@@ -33,7 +33,8 @@ using ProfileCategoryStats = std::vector<ProfileCategoryStat>; ...@@ -33,7 +33,8 @@ using ProfileCategoryStats = std::vector<ProfileCategoryStat>;
// Definition of the callback function. Note that a copy of // Definition of the callback function. Note that a copy of
// |ProfileCategoryStats| is made each time the callback is called. // |ProfileCategoryStats| is made each time the callback is called.
using ProfileStatisticsCallback = base::Callback<void(ProfileCategoryStats)>; using ProfileStatisticsCallback =
base::RepeatingCallback<void(ProfileCategoryStats)>;
} // namespace profiles } // namespace profiles
#endif // CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_COMMON_H_ #endif // CHROME_BROWSER_PROFILES_PROFILE_STATISTICS_COMMON_H_
...@@ -115,8 +115,8 @@ TEST_F(ProfileStatisticsTest, WaitOrCountBookmarks) { ...@@ -115,8 +115,8 @@ TEST_F(ProfileStatisticsTest, WaitOrCountBookmarks) {
ProfileStatisticsAggregator aggregator( ProfileStatisticsAggregator aggregator(
profile, run_loop_aggregator_done.QuitClosure()); profile, run_loop_aggregator_done.QuitClosure());
aggregator.AddCallbackAndStartAggregator( aggregator.AddCallbackAndStartAggregator(
base::Bind(&BookmarkStatHelper::StatsCallback, base::BindRepeating(&BookmarkStatHelper::StatsCallback,
base::Unretained(&bookmark_stat_helper))); base::Unretained(&bookmark_stat_helper)));
// Wait until ProfileStatisticsAggregator::WaitOrCountBookmarks is run. // Wait until ProfileStatisticsAggregator::WaitOrCountBookmarks is run.
base::RunLoop run_loop1; base::RunLoop run_loop1;
......
...@@ -108,8 +108,8 @@ void ProfileInfoHandler::HandleGetProfileStats(const base::ListValue* args) { ...@@ -108,8 +108,8 @@ void ProfileInfoHandler::HandleGetProfileStats(const base::ListValue* args) {
AllowJavascript(); AllowJavascript();
ProfileStatisticsFactory::GetForProfile(profile_)->GatherStatistics( ProfileStatisticsFactory::GetForProfile(profile_)->GatherStatistics(
base::Bind(&ProfileInfoHandler::PushProfileStatsCount, base::BindRepeating(&ProfileInfoHandler::PushProfileStatsCount,
callback_weak_ptr_factory_.GetWeakPtr())); callback_weak_ptr_factory_.GetWeakPtr()));
} }
void ProfileInfoHandler::PushProfileStatsCount( void ProfileInfoHandler::PushProfileStatsCount(
......
...@@ -527,9 +527,9 @@ void UserManagerScreenHandler::GatherStatistics(base::Time start_time, ...@@ -527,9 +527,9 @@ void UserManagerScreenHandler::GatherStatistics(base::Time start_time,
Profile* profile) { Profile* profile) {
if (profile) { if (profile) {
ProfileStatisticsFactory::GetForProfile(profile)->GatherStatistics( ProfileStatisticsFactory::GetForProfile(profile)->GatherStatistics(
base::Bind(&UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback, base::BindRepeating(
weak_ptr_factory_.GetWeakPtr(), profile->GetPath(), &UserManagerScreenHandler::RemoveUserDialogLoadStatsCallback,
start_time)); weak_ptr_factory_.GetWeakPtr(), profile->GetPath(), start_time));
} }
} }
......
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