Commit e980e86d authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

Convert //components/web_resource away from base::Bind()

As part of the effort to replace base::Bind by
base::Bind{Once, Repeating}, this CL converts the one usage of
base::Bind() in //components/web_resource to instead be a usage of
base::BindRepeating(). The rational for using base::BindRepeating() is
that the callback is being passed in to a PrefChangeRegistrar, which
can invoke it multiple times in response to pref changes.

This CL also takes the opportunity to update the PrefChangeRegistrar
API in question to take in a base::RepeatingClosure rather than a
base::Closure.

TBR=jochen@chromium.org

Bug: 1007753
Change-Id: I7550f64eedb9d0da719f9ff8617e2c4d9d415eab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1847216
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705009}
parent ddfa7205
......@@ -380,7 +380,6 @@ _NOT_CONVERTED_TO_MODERN_BIND_AND_CALLBACK = '|'.join((
'^components/variations/',
'^components/visitedlink/',
'^components/web_cache/',
'^components/web_resource/',
'^components/webcrypto/',
'^components/webdata/',
'^components/webdata_services/',
......
......@@ -24,8 +24,9 @@ void PrefChangeRegistrar::Init(PrefService* service) {
}
void PrefChangeRegistrar::Add(const std::string& path,
const base::Closure& obs) {
Add(path, base::Bind(&PrefChangeRegistrar::InvokeUnnamedCallback, obs));
const base::RepeatingClosure& obs) {
Add(path,
base::BindRepeating(&PrefChangeRegistrar::InvokeUnnamedCallback, obs));
}
void PrefChangeRegistrar::Add(const std::string& path,
......@@ -81,9 +82,9 @@ void PrefChangeRegistrar::OnPreferenceChanged(PrefService* service,
observers_[pref].Run(pref);
}
void PrefChangeRegistrar::InvokeUnnamedCallback(const base::Closure& callback,
void PrefChangeRegistrar::InvokeUnnamedCallback(base::OnceClosure callback,
const std::string& pref_name) {
callback.Run();
std::move(callback).Run();
}
PrefService* PrefChangeRegistrar::prefs() {
......
......@@ -40,7 +40,7 @@ class COMPONENTS_PREFS_EXPORT PrefChangeRegistrar final : public PrefObserver {
// the preference that is changing as its parameter.
//
// Only one observer may be registered per path.
void Add(const std::string& path, const base::Closure& obs);
void Add(const std::string& path, const base::RepeatingClosure& obs);
void Add(const std::string& path, const NamedChangeCallback& obs);
// Removes the pref observer registered for |path|.
......@@ -67,7 +67,7 @@ class COMPONENTS_PREFS_EXPORT PrefChangeRegistrar final : public PrefObserver {
void OnPreferenceChanged(PrefService* service,
const std::string& pref_name) override;
static void InvokeUnnamedCallback(const base::Closure& callback,
static void InvokeUnnamedCallback(base::OnceClosure callback,
const std::string& pref_name);
using ObserverMap = std::map<std::string, NamedChangeCallback>;
......
......@@ -33,7 +33,7 @@ bool EulaAcceptedNotifier::IsEulaAccepted() {
if (registrar_.IsEmpty()) {
registrar_.Init(local_state_);
registrar_.Add(prefs::kEulaAccepted,
base::Bind(&EulaAcceptedNotifier::OnPrefChanged,
base::BindRepeating(&EulaAcceptedNotifier::OnPrefChanged,
base::Unretained(this)));
}
return false;
......
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