Commit 8bf3bbcc authored by Joey Scarr's avatar Joey Scarr Committed by Commit Bot

Convert components/browsing_data to Once/RepeatingCallback.

Fixed: 1007673
Change-Id: Ia6a20e26124e8a8a0203c2460de9b6d2031fee57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2059749
Commit-Queue: Joey Scarr <jsca@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742981}
parent 04dd80dd
...@@ -302,7 +302,6 @@ _NOT_CONVERTED_TO_MODERN_BIND_AND_CALLBACK = '|'.join(( ...@@ -302,7 +302,6 @@ _NOT_CONVERTED_TO_MODERN_BIND_AND_CALLBACK = '|'.join((
'^components/autofill/', '^components/autofill/',
'^components/autofill_assistant/', '^components/autofill_assistant/',
'^components/browser_watcher/', '^components/browser_watcher/',
'^components/browsing_data/',
'^components/cast_channel/', '^components/cast_channel/',
'^components/chromeos_camera/', '^components/chromeos_camera/',
'^components/component_updater/', '^components/component_updater/',
......
...@@ -74,7 +74,7 @@ TEST_F(BrowsingDataCounterUtilsTest, CacheCounterResult) { ...@@ -74,7 +74,7 @@ TEST_F(BrowsingDataCounterUtilsTest, CacheCounterResult) {
test_case.is_basic_tab ? browsing_data::ClearBrowsingDataTab::BASIC test_case.is_basic_tab ? browsing_data::ClearBrowsingDataTab::BASIC
: browsing_data::ClearBrowsingDataTab::ADVANCED; : browsing_data::ClearBrowsingDataTab::ADVANCED;
counter.Init(GetProfile()->GetPrefs(), tab, counter.Init(GetProfile()->GetPrefs(), tab,
browsing_data::BrowsingDataCounter::Callback()); browsing_data::BrowsingDataCounter::ResultCallback());
CacheCounter::CacheResult result(&counter, test_case.bytes, CacheCounter::CacheResult result(&counter, test_case.bytes,
test_case.is_upper_limit); test_case.is_upper_limit);
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
......
...@@ -48,7 +48,7 @@ AutofillCounter::~AutofillCounter() { ...@@ -48,7 +48,7 @@ AutofillCounter::~AutofillCounter() {
void AutofillCounter::OnInitialized() { void AutofillCounter::OnInitialized() {
DCHECK(web_data_service_); DCHECK(web_data_service_);
sync_tracker_.OnInitialized(base::Bind(&IsAutofillSyncEnabled)); sync_tracker_.OnInitialized(base::BindRepeating(&IsAutofillSyncEnabled));
} }
const char* AutofillCounter::GetPrefName() const { const char* AutofillCounter::GetPrefName() const {
......
...@@ -28,25 +28,26 @@ BrowsingDataCounter::~BrowsingDataCounter() {} ...@@ -28,25 +28,26 @@ BrowsingDataCounter::~BrowsingDataCounter() {}
void BrowsingDataCounter::Init(PrefService* pref_service, void BrowsingDataCounter::Init(PrefService* pref_service,
ClearBrowsingDataTab clear_browsing_data_tab, ClearBrowsingDataTab clear_browsing_data_tab,
const Callback& callback) { ResultCallback callback) {
DCHECK(!initialized_); DCHECK(!initialized_);
callback_ = callback; callback_ = std::move(callback);
clear_browsing_data_tab_ = clear_browsing_data_tab; clear_browsing_data_tab_ = clear_browsing_data_tab;
pref_.Init(GetPrefName(), pref_service, pref_.Init(GetPrefName(), pref_service,
base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this))); base::BindRepeating(&BrowsingDataCounter::Restart,
period_.Init( base::Unretained(this)));
GetTimePeriodPreferenceName(GetTab()), pref_service, period_.Init(GetTimePeriodPreferenceName(GetTab()), pref_service,
base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this))); base::BindRepeating(&BrowsingDataCounter::Restart,
base::Unretained(this)));
initialized_ = true; initialized_ = true;
OnInitialized(); OnInitialized();
} }
void BrowsingDataCounter::InitWithoutPref(base::Time begin_time, void BrowsingDataCounter::InitWithoutPref(base::Time begin_time,
const Callback& callback) { ResultCallback callback) {
DCHECK(!initialized_); DCHECK(!initialized_);
use_delay_ = false; use_delay_ = false;
callback_ = callback; callback_ = std::move(callback);
clear_browsing_data_tab_ = ClearBrowsingDataTab::ADVANCED; clear_browsing_data_tab_ = ClearBrowsingDataTab::ADVANCED;
begin_time_ = begin_time; begin_time_ = begin_time;
initialized_ = true; initialized_ = true;
......
...@@ -78,7 +78,7 @@ class BrowsingDataCounter { ...@@ -78,7 +78,7 @@ class BrowsingDataCounter {
DISALLOW_COPY_AND_ASSIGN(SyncResult); DISALLOW_COPY_AND_ASSIGN(SyncResult);
}; };
typedef base::RepeatingCallback<void(std::unique_ptr<Result>)> Callback; typedef base::RepeatingCallback<void(std::unique_ptr<Result>)> ResultCallback;
// Every calculation progresses through a state machine. At initialization, // Every calculation progresses through a state machine. At initialization,
// the counter is IDLE. If a result is calculated within a given time // the counter is IDLE. If a result is calculated within a given time
...@@ -106,12 +106,12 @@ class BrowsingDataCounter { ...@@ -106,12 +106,12 @@ class BrowsingDataCounter {
// Should be called once to initialize this class. // Should be called once to initialize this class.
void Init(PrefService* pref_service, void Init(PrefService* pref_service,
ClearBrowsingDataTab clear_browsing_data_tab, ClearBrowsingDataTab clear_browsing_data_tab,
const Callback& callback); ResultCallback callback);
// Can be called instead of |Init()|, to create a counter that doesn't // Can be called instead of |Init()|, to create a counter that doesn't
// observe pref changes and counts data that was changed since |begin_time|. // observe pref changes and counts data that was changed since |begin_time|.
// This mode doesn't use delayed responses. // This mode doesn't use delayed responses.
void InitWithoutPref(base::Time begin_time, const Callback& callback); void InitWithoutPref(base::Time begin_time, ResultCallback callback);
// Name of the preference associated with this counter. // Name of the preference associated with this counter.
virtual const char* GetPrefName() const = 0; virtual const char* GetPrefName() const = 0;
...@@ -167,7 +167,7 @@ class BrowsingDataCounter { ...@@ -167,7 +167,7 @@ class BrowsingDataCounter {
// The callback that will be called when the UI should be updated with a new // The callback that will be called when the UI should be updated with a new
// counter value. // counter value.
Callback callback_; ResultCallback callback_;
// The boolean preference indicating whether this data type is to be deleted. // The boolean preference indicating whether this data type is to be deleted.
BooleanPrefMember pref_; BooleanPrefMember pref_;
......
...@@ -25,16 +25,13 @@ namespace { ...@@ -25,16 +25,13 @@ namespace {
static const char* kTestingDatatypePref = "counter.testing.datatype"; static const char* kTestingDatatypePref = "counter.testing.datatype";
void IgnoreResult(std::unique_ptr<BrowsingDataCounter::Result> result) {
}
class MockBrowsingDataCounter : public BrowsingDataCounter { class MockBrowsingDataCounter : public BrowsingDataCounter {
public: public:
MockBrowsingDataCounter() {} MockBrowsingDataCounter() = default;
~MockBrowsingDataCounter() override {} ~MockBrowsingDataCounter() override = default;
// There are two overloaded ReportResult methods. We need to disambiguate // There are two overloaded ReportResult methods. We need to disambiguate
// between them to be able to bind one of them in base::Bind(). // between them to be able to bind one of them in base::BindOnce().
using ReportResultType = using ReportResultType =
void(MockBrowsingDataCounter::*)(BrowsingDataCounter::ResultInt); void(MockBrowsingDataCounter::*)(BrowsingDataCounter::ResultInt);
...@@ -90,7 +87,7 @@ class BrowsingDataCounterTest : public testing::Test { ...@@ -90,7 +87,7 @@ class BrowsingDataCounterTest : public testing::Test {
counter_.reset(new MockBrowsingDataCounter()); counter_.reset(new MockBrowsingDataCounter());
counter_->Init(pref_service_.get(), counter_->Init(pref_service_.get(),
browsing_data::ClearBrowsingDataTab::ADVANCED, browsing_data::ClearBrowsingDataTab::ADVANCED,
base::Bind(&IgnoreResult)); base::DoNothing());
} }
void TearDown() override { void TearDown() override {
......
...@@ -18,10 +18,9 @@ static const int64_t kWebHistoryTimeoutSeconds = 10; ...@@ -18,10 +18,9 @@ static const int64_t kWebHistoryTimeoutSeconds = 10;
namespace browsing_data { namespace browsing_data {
HistoryCounter::HistoryCounter( HistoryCounter::HistoryCounter(history::HistoryService* history_service,
history::HistoryService* history_service, GetUpdatedWebHistoryServiceCallback callback,
const GetUpdatedWebHistoryServiceCallback& callback, syncer::SyncService* sync_service)
syncer::SyncService* sync_service)
: history_service_(history_service), : history_service_(history_service),
web_history_service_callback_(callback), web_history_service_callback_(callback),
sync_tracker_(this, sync_service), sync_tracker_(this, sync_service),
...@@ -31,11 +30,11 @@ HistoryCounter::HistoryCounter( ...@@ -31,11 +30,11 @@ HistoryCounter::HistoryCounter(
DCHECK(history_service_); DCHECK(history_service_);
} }
HistoryCounter::~HistoryCounter() {} HistoryCounter::~HistoryCounter() = default;
void HistoryCounter::OnInitialized() { void HistoryCounter::OnInitialized() {
sync_tracker_.OnInitialized(base::Bind(&HistoryCounter::IsHistorySyncEnabled, sync_tracker_.OnInitialized(base::BindRepeating(
base::Unretained(this))); &HistoryCounter::IsHistorySyncEnabled, base::Unretained(this)));
} }
bool HistoryCounter::HasTrackedTasksForTesting() { bool HistoryCounter::HasTrackedTasksForTesting() {
...@@ -114,8 +113,8 @@ void HistoryCounter::Count() { ...@@ -114,8 +113,8 @@ void HistoryCounter::Count() {
})"); })");
web_history_request_ = web_history->QueryHistory( web_history_request_ = web_history->QueryHistory(
base::string16(), options, base::string16(), options,
base::Bind(&HistoryCounter::OnGetWebHistoryCount, base::BindOnce(&HistoryCounter::OnGetWebHistoryCount,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
partial_traffic_annotation); partial_traffic_annotation);
// TODO(msramek): Include web history count when there is an API for it. // TODO(msramek): Include web history count when there is an API for it.
......
...@@ -19,7 +19,7 @@ namespace browsing_data { ...@@ -19,7 +19,7 @@ namespace browsing_data {
class HistoryCounter : public browsing_data::BrowsingDataCounter { class HistoryCounter : public browsing_data::BrowsingDataCounter {
public: public:
typedef base::Callback<history::WebHistoryService*()> typedef base::RepeatingCallback<history::WebHistoryService*()>
GetUpdatedWebHistoryServiceCallback; GetUpdatedWebHistoryServiceCallback;
class HistoryResult : public SyncResult { class HistoryResult : public SyncResult {
...@@ -37,7 +37,7 @@ class HistoryCounter : public browsing_data::BrowsingDataCounter { ...@@ -37,7 +37,7 @@ class HistoryCounter : public browsing_data::BrowsingDataCounter {
}; };
explicit HistoryCounter(history::HistoryService* history_service, explicit HistoryCounter(history::HistoryService* history_service,
const GetUpdatedWebHistoryServiceCallback& callback, GetUpdatedWebHistoryServiceCallback callback,
syncer::SyncService* sync_service); syncer::SyncService* sync_service);
~HistoryCounter() override; ~HistoryCounter() override;
......
...@@ -52,7 +52,7 @@ PasswordsCounter::~PasswordsCounter() { ...@@ -52,7 +52,7 @@ PasswordsCounter::~PasswordsCounter() {
} }
void PasswordsCounter::OnInitialized() { void PasswordsCounter::OnInitialized() {
sync_tracker_.OnInitialized(base::Bind(&IsPasswordSyncEnabled)); sync_tracker_.OnInitialized(base::BindRepeating(&IsPasswordSyncEnabled));
store_->AddObserver(this); store_->AddObserver(this);
} }
......
...@@ -16,7 +16,8 @@ class BrowsingDataCounter; ...@@ -16,7 +16,8 @@ class BrowsingDataCounter;
class SyncTracker : public syncer::SyncServiceObserver { class SyncTracker : public syncer::SyncServiceObserver {
public: public:
using SyncPredicate = base::Callback<bool(const syncer::SyncService*)>; using SyncPredicate =
base::RepeatingCallback<bool(const syncer::SyncService*)>;
SyncTracker(BrowsingDataCounter* counter, syncer::SyncService* sync_service); SyncTracker(BrowsingDataCounter* counter, syncer::SyncService* sync_service);
~SyncTracker() override; ~SyncTracker() override;
......
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