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((
'^components/autofill/',
'^components/autofill_assistant/',
'^components/browser_watcher/',
'^components/browsing_data/',
'^components/cast_channel/',
'^components/chromeos_camera/',
'^components/component_updater/',
......
......@@ -74,7 +74,7 @@ TEST_F(BrowsingDataCounterUtilsTest, CacheCounterResult) {
test_case.is_basic_tab ? browsing_data::ClearBrowsingDataTab::BASIC
: browsing_data::ClearBrowsingDataTab::ADVANCED;
counter.Init(GetProfile()->GetPrefs(), tab,
browsing_data::BrowsingDataCounter::Callback());
browsing_data::BrowsingDataCounter::ResultCallback());
CacheCounter::CacheResult result(&counter, test_case.bytes,
test_case.is_upper_limit);
SCOPED_TRACE(base::StringPrintf(
......
......@@ -48,7 +48,7 @@ AutofillCounter::~AutofillCounter() {
void AutofillCounter::OnInitialized() {
DCHECK(web_data_service_);
sync_tracker_.OnInitialized(base::Bind(&IsAutofillSyncEnabled));
sync_tracker_.OnInitialized(base::BindRepeating(&IsAutofillSyncEnabled));
}
const char* AutofillCounter::GetPrefName() const {
......
......@@ -28,25 +28,26 @@ BrowsingDataCounter::~BrowsingDataCounter() {}
void BrowsingDataCounter::Init(PrefService* pref_service,
ClearBrowsingDataTab clear_browsing_data_tab,
const Callback& callback) {
ResultCallback callback) {
DCHECK(!initialized_);
callback_ = callback;
callback_ = std::move(callback);
clear_browsing_data_tab_ = clear_browsing_data_tab;
pref_.Init(GetPrefName(), pref_service,
base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this)));
period_.Init(
GetTimePeriodPreferenceName(GetTab()), pref_service,
base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this)));
base::BindRepeating(&BrowsingDataCounter::Restart,
base::Unretained(this)));
period_.Init(GetTimePeriodPreferenceName(GetTab()), pref_service,
base::BindRepeating(&BrowsingDataCounter::Restart,
base::Unretained(this)));
initialized_ = true;
OnInitialized();
}
void BrowsingDataCounter::InitWithoutPref(base::Time begin_time,
const Callback& callback) {
ResultCallback callback) {
DCHECK(!initialized_);
use_delay_ = false;
callback_ = callback;
callback_ = std::move(callback);
clear_browsing_data_tab_ = ClearBrowsingDataTab::ADVANCED;
begin_time_ = begin_time;
initialized_ = true;
......
......@@ -78,7 +78,7 @@ class BrowsingDataCounter {
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,
// the counter is IDLE. If a result is calculated within a given time
......@@ -106,12 +106,12 @@ class BrowsingDataCounter {
// Should be called once to initialize this class.
void Init(PrefService* pref_service,
ClearBrowsingDataTab clear_browsing_data_tab,
const Callback& callback);
ResultCallback callback);
// 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|.
// 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.
virtual const char* GetPrefName() const = 0;
......@@ -167,7 +167,7 @@ class BrowsingDataCounter {
// The callback that will be called when the UI should be updated with a new
// counter value.
Callback callback_;
ResultCallback callback_;
// The boolean preference indicating whether this data type is to be deleted.
BooleanPrefMember pref_;
......
......@@ -25,16 +25,13 @@ namespace {
static const char* kTestingDatatypePref = "counter.testing.datatype";
void IgnoreResult(std::unique_ptr<BrowsingDataCounter::Result> result) {
}
class MockBrowsingDataCounter : public BrowsingDataCounter {
public:
MockBrowsingDataCounter() {}
~MockBrowsingDataCounter() override {}
MockBrowsingDataCounter() = default;
~MockBrowsingDataCounter() override = default;
// 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 =
void(MockBrowsingDataCounter::*)(BrowsingDataCounter::ResultInt);
......@@ -90,7 +87,7 @@ class BrowsingDataCounterTest : public testing::Test {
counter_.reset(new MockBrowsingDataCounter());
counter_->Init(pref_service_.get(),
browsing_data::ClearBrowsingDataTab::ADVANCED,
base::Bind(&IgnoreResult));
base::DoNothing());
}
void TearDown() override {
......
......@@ -18,9 +18,8 @@ static const int64_t kWebHistoryTimeoutSeconds = 10;
namespace browsing_data {
HistoryCounter::HistoryCounter(
history::HistoryService* history_service,
const GetUpdatedWebHistoryServiceCallback& callback,
HistoryCounter::HistoryCounter(history::HistoryService* history_service,
GetUpdatedWebHistoryServiceCallback callback,
syncer::SyncService* sync_service)
: history_service_(history_service),
web_history_service_callback_(callback),
......@@ -31,11 +30,11 @@ HistoryCounter::HistoryCounter(
DCHECK(history_service_);
}
HistoryCounter::~HistoryCounter() {}
HistoryCounter::~HistoryCounter() = default;
void HistoryCounter::OnInitialized() {
sync_tracker_.OnInitialized(base::Bind(&HistoryCounter::IsHistorySyncEnabled,
base::Unretained(this)));
sync_tracker_.OnInitialized(base::BindRepeating(
&HistoryCounter::IsHistorySyncEnabled, base::Unretained(this)));
}
bool HistoryCounter::HasTrackedTasksForTesting() {
......@@ -114,7 +113,7 @@ void HistoryCounter::Count() {
})");
web_history_request_ = web_history->QueryHistory(
base::string16(), options,
base::Bind(&HistoryCounter::OnGetWebHistoryCount,
base::BindOnce(&HistoryCounter::OnGetWebHistoryCount,
weak_ptr_factory_.GetWeakPtr()),
partial_traffic_annotation);
......
......@@ -19,7 +19,7 @@ namespace browsing_data {
class HistoryCounter : public browsing_data::BrowsingDataCounter {
public:
typedef base::Callback<history::WebHistoryService*()>
typedef base::RepeatingCallback<history::WebHistoryService*()>
GetUpdatedWebHistoryServiceCallback;
class HistoryResult : public SyncResult {
......@@ -37,7 +37,7 @@ class HistoryCounter : public browsing_data::BrowsingDataCounter {
};
explicit HistoryCounter(history::HistoryService* history_service,
const GetUpdatedWebHistoryServiceCallback& callback,
GetUpdatedWebHistoryServiceCallback callback,
syncer::SyncService* sync_service);
~HistoryCounter() override;
......
......@@ -52,7 +52,7 @@ PasswordsCounter::~PasswordsCounter() {
}
void PasswordsCounter::OnInitialized() {
sync_tracker_.OnInitialized(base::Bind(&IsPasswordSyncEnabled));
sync_tracker_.OnInitialized(base::BindRepeating(&IsPasswordSyncEnabled));
store_->AddObserver(this);
}
......
......@@ -16,7 +16,8 @@ class BrowsingDataCounter;
class SyncTracker : public syncer::SyncServiceObserver {
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() 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