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