Commit 61856ac8 authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

[Code Health] Migrate extensions Blocklist to OnceCallback

This change migrates Callbacks in extensions::Blocklist to OnceCallbacks.

Bug: 1007786
Change-Id: If463e8b8fb776bfd1b5fdaae5b415c0216f6419e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2425863
Auto-Submit: Alan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809855}
parent 4c93f79b
...@@ -131,13 +131,14 @@ class SafeBrowsingClientImpl ...@@ -131,13 +131,14 @@ class SafeBrowsingClientImpl
DISALLOW_COPY_AND_ASSIGN(SafeBrowsingClientImpl); DISALLOW_COPY_AND_ASSIGN(SafeBrowsingClientImpl);
}; };
void CheckOneExtensionState(const Blocklist::IsBlocklistedCallback& callback, void CheckOneExtensionState(Blocklist::IsBlocklistedCallback callback,
const Blocklist::BlocklistStateMap& state_map) { const Blocklist::BlocklistStateMap& state_map) {
callback.Run(state_map.empty() ? NOT_BLOCKLISTED : state_map.begin()->second); std::move(callback).Run(state_map.empty() ? NOT_BLOCKLISTED
: state_map.begin()->second);
} }
void GetMalwareFromBlocklistStateMap( void GetMalwareFromBlocklistStateMap(
const Blocklist::GetMalwareIDsCallback& callback, Blocklist::GetMalwareIDsCallback callback,
const Blocklist::BlocklistStateMap& state_map) { const Blocklist::BlocklistStateMap& state_map) {
std::set<std::string> malware; std::set<std::string> malware;
for (const auto& state_pair : state_map) { for (const auto& state_pair : state_map) {
...@@ -149,7 +150,7 @@ void GetMalwareFromBlocklistStateMap( ...@@ -149,7 +150,7 @@ void GetMalwareFromBlocklistStateMap(
malware.insert(state_pair.first); malware.insert(state_pair.first);
} }
} }
callback.Run(malware); std::move(callback).Run(malware);
} }
} // namespace } // namespace
...@@ -191,12 +192,12 @@ Blocklist* Blocklist::Get(content::BrowserContext* context) { ...@@ -191,12 +192,12 @@ Blocklist* Blocklist::Get(content::BrowserContext* context) {
} }
void Blocklist::GetBlocklistedIDs(const std::set<std::string>& ids, void Blocklist::GetBlocklistedIDs(const std::set<std::string>& ids,
const GetBlocklistedIDsCallback& callback) { GetBlocklistedIDsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (ids.empty() || !GetDatabaseManager().get()) { if (ids.empty() || !GetDatabaseManager().get()) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, BlocklistStateMap())); FROM_HERE, base::BindOnce(std::move(callback), BlocklistStateMap()));
return; return;
} }
...@@ -205,25 +206,26 @@ void Blocklist::GetBlocklistedIDs(const std::set<std::string>& ids, ...@@ -205,25 +206,26 @@ void Blocklist::GetBlocklistedIDs(const std::set<std::string>& ids,
// extensions returned by SafeBrowsing will then be passed to // extensions returned by SafeBrowsing will then be passed to
// GetBlocklistStateIDs to get the particular BlocklistState for each id. // GetBlocklistStateIDs to get the particular BlocklistState for each id.
SafeBrowsingClientImpl::Start( SafeBrowsingClientImpl::Start(
ids, ids, base::BindOnce(&Blocklist::GetBlocklistStateForIDs, AsWeakPtr(),
base::Bind(&Blocklist::GetBlocklistStateForIDs, AsWeakPtr(), callback)); std::move(callback)));
} }
void Blocklist::GetMalwareIDs(const std::set<std::string>& ids, void Blocklist::GetMalwareIDs(const std::set<std::string>& ids,
const GetMalwareIDsCallback& callback) { GetMalwareIDsCallback callback) {
GetBlocklistedIDs(ids, GetBlocklistedIDs(ids, base::BindOnce(&GetMalwareFromBlocklistStateMap,
base::Bind(&GetMalwareFromBlocklistStateMap, callback)); std::move(callback)));
} }
void Blocklist::IsBlocklisted(const std::string& extension_id, void Blocklist::IsBlocklisted(const std::string& extension_id,
const IsBlocklistedCallback& callback) { IsBlocklistedCallback callback) {
std::set<std::string> check; std::set<std::string> check;
check.insert(extension_id); check.insert(extension_id);
GetBlocklistedIDs(check, base::Bind(&CheckOneExtensionState, callback)); GetBlocklistedIDs(
check, base::BindOnce(&CheckOneExtensionState, std::move(callback)));
} }
void Blocklist::GetBlocklistStateForIDs( void Blocklist::GetBlocklistStateForIDs(
const GetBlocklistedIDsCallback& callback, GetBlocklistedIDsCallback callback,
const std::set<std::string>& blocklisted_ids) { const std::set<std::string>& blocklisted_ids) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -242,7 +244,7 @@ void Blocklist::GetBlocklistStateForIDs( ...@@ -242,7 +244,7 @@ void Blocklist::GetBlocklistStateForIDs(
} }
if (ids_unknown_state.empty()) { if (ids_unknown_state.empty()) {
callback.Run(extensions_state); std::move(callback).Run(extensions_state);
} else { } else {
// After the extension blocklist states have been downloaded, call this // After the extension blocklist states have been downloaded, call this
// functions again, but prevent infinite cycle in case server is offline // functions again, but prevent infinite cycle in case server is offline
...@@ -251,12 +253,12 @@ void Blocklist::GetBlocklistStateForIDs( ...@@ -251,12 +253,12 @@ void Blocklist::GetBlocklistStateForIDs(
RequestExtensionsBlocklistState( RequestExtensionsBlocklistState(
ids_unknown_state, ids_unknown_state,
base::BindOnce(&Blocklist::ReturnBlocklistStateMap, AsWeakPtr(), base::BindOnce(&Blocklist::ReturnBlocklistStateMap, AsWeakPtr(),
callback, blocklisted_ids)); std::move(callback), blocklisted_ids));
} }
} }
void Blocklist::ReturnBlocklistStateMap( void Blocklist::ReturnBlocklistStateMap(
const GetBlocklistedIDsCallback& callback, GetBlocklistedIDsCallback callback,
const std::set<std::string>& blocklisted_ids) { const std::set<std::string>& blocklisted_ids) {
BlocklistStateMap extensions_state; BlocklistStateMap extensions_state;
for (const auto& blocklisted_id : blocklisted_ids) { for (const auto& blocklisted_id : blocklisted_ids) {
...@@ -267,7 +269,7 @@ void Blocklist::ReturnBlocklistStateMap( ...@@ -267,7 +269,7 @@ void Blocklist::ReturnBlocklistStateMap(
// we silently skip it. // we silently skip it.
} }
callback.Run(extensions_state); std::move(callback).Run(extensions_state);
} }
void Blocklist::RequestExtensionsBlocklistState( void Blocklist::RequestExtensionsBlocklistState(
......
...@@ -64,12 +64,12 @@ class Blocklist : public KeyedService, public base::SupportsWeakPtr<Blocklist> { ...@@ -64,12 +64,12 @@ class Blocklist : public KeyedService, public base::SupportsWeakPtr<Blocklist> {
using BlocklistStateMap = std::map<std::string, BlocklistState>; using BlocklistStateMap = std::map<std::string, BlocklistState>;
using GetBlocklistedIDsCallback = using GetBlocklistedIDsCallback =
base::Callback<void(const BlocklistStateMap&)>; base::OnceCallback<void(const BlocklistStateMap&)>;
using GetMalwareIDsCallback = using GetMalwareIDsCallback =
base::Callback<void(const std::set<std::string>&)>; base::OnceCallback<void(const std::set<std::string>&)>;
using IsBlocklistedCallback = base::Callback<void(BlocklistState)>; using IsBlocklistedCallback = base::OnceCallback<void(BlocklistState)>;
explicit Blocklist(ExtensionPrefs* prefs); explicit Blocklist(ExtensionPrefs* prefs);
...@@ -86,18 +86,18 @@ class Blocklist : public KeyedService, public base::SupportsWeakPtr<Blocklist> { ...@@ -86,18 +86,18 @@ class Blocklist : public KeyedService, public base::SupportsWeakPtr<Blocklist> {
// For a synchronous version which ONLY CHECKS CURRENTLY INSTALLED EXTENSIONS // For a synchronous version which ONLY CHECKS CURRENTLY INSTALLED EXTENSIONS
// see ExtensionPrefs::IsExtensionBlocklisted. // see ExtensionPrefs::IsExtensionBlocklisted.
void GetBlocklistedIDs(const std::set<std::string>& ids, void GetBlocklistedIDs(const std::set<std::string>& ids,
const GetBlocklistedIDsCallback& callback); GetBlocklistedIDsCallback callback);
// From the subset of extension IDs passed in via |ids|, select the ones // From the subset of extension IDs passed in via |ids|, select the ones
// marked in the blocklist as BLOCKLISTED_MALWARE and asynchronously pass // marked in the blocklist as BLOCKLISTED_MALWARE and asynchronously pass
// to |callback|. Basically, will call GetBlocklistedIDs and filter its // to |callback|. Basically, will call GetBlocklistedIDs and filter its
// results. // results.
void GetMalwareIDs(const std::set<std::string>& ids, void GetMalwareIDs(const std::set<std::string>& ids,
const GetMalwareIDsCallback& callback); GetMalwareIDsCallback callback);
// More convenient form of GetBlocklistedIDs for checking a single extension. // More convenient form of GetBlocklistedIDs for checking a single extension.
void IsBlocklisted(const std::string& extension_id, void IsBlocklisted(const std::string& extension_id,
const IsBlocklistedCallback& callback); IsBlocklistedCallback callback);
// Used to mock BlocklistStateFetcher in unit tests. Blocklist owns the // Used to mock BlocklistStateFetcher in unit tests. Blocklist owns the
// |fetcher|. // |fetcher|.
...@@ -126,7 +126,7 @@ class Blocklist : public KeyedService, public base::SupportsWeakPtr<Blocklist> { ...@@ -126,7 +126,7 @@ class Blocklist : public KeyedService, public base::SupportsWeakPtr<Blocklist> {
void NotifyObservers(); void NotifyObservers();
void GetBlocklistStateForIDs(const GetBlocklistedIDsCallback& callback, void GetBlocklistStateForIDs(GetBlocklistedIDsCallback callback,
const std::set<std::string>& blocklisted_ids); const std::set<std::string>& blocklisted_ids);
void RequestExtensionsBlocklistState(const std::set<std::string>& ids, void RequestExtensionsBlocklistState(const std::set<std::string>& ids,
...@@ -134,7 +134,7 @@ class Blocklist : public KeyedService, public base::SupportsWeakPtr<Blocklist> { ...@@ -134,7 +134,7 @@ class Blocklist : public KeyedService, public base::SupportsWeakPtr<Blocklist> {
void OnBlocklistStateReceived(const std::string& id, BlocklistState state); void OnBlocklistStateReceived(const std::string& id, BlocklistState state);
void ReturnBlocklistStateMap(const GetBlocklistedIDsCallback& callback, void ReturnBlocklistStateMap(GetBlocklistedIDsCallback callback,
const std::set<std::string>& blocklisted_ids); const std::set<std::string>& blocklisted_ids);
base::ObserverList<Observer>::Unchecked observers_; base::ObserverList<Observer>::Unchecked observers_;
......
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