Commit 5a4f243d authored by Yi Gu's avatar Yi Gu Committed by Chromium LUCI CQ

[CodeHealth] Convert c/b//extensions from base::Bind and base::Callback to Once/Repeating

Bug: 1152282
Change-Id: I9394d301b39b1c20410d462149aede16618f89d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2595347Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Commit-Queue: Yi Gu <yigu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837694}
parent 9cd96859
...@@ -58,7 +58,7 @@ const int kRefreshRequiredActionsMask = ...@@ -58,7 +58,7 @@ const int kRefreshRequiredActionsMask =
ExtensionActionRunner::PendingScript::PendingScript( ExtensionActionRunner::PendingScript::PendingScript(
UserScript::RunLocation run_location, UserScript::RunLocation run_location,
const base::Closure& permit_script) base::RepeatingClosure permit_script)
: run_location(run_location), permit_script(permit_script) {} : run_location(run_location), permit_script(permit_script) {}
ExtensionActionRunner::PendingScript::PendingScript( ExtensionActionRunner::PendingScript::PendingScript(
...@@ -98,7 +98,7 @@ ExtensionAction::ShowAction ExtensionActionRunner::RunAction( ...@@ -98,7 +98,7 @@ ExtensionAction::ShowAction ExtensionActionRunner::RunAction(
if ((blocked & kRefreshRequiredActionsMask) != 0) { if ((blocked & kRefreshRequiredActionsMask) != 0) {
ShowBlockedActionBubble( ShowBlockedActionBubble(
extension, extension,
base::Bind( base::BindOnce(
&ExtensionActionRunner::OnBlockedActionBubbleForRunActionClosed, &ExtensionActionRunner::OnBlockedActionBubbleForRunActionClosed,
weak_factory_.GetWeakPtr(), extension->id())); weak_factory_.GetWeakPtr(), extension->id()));
return ExtensionAction::ACTION_NONE; return ExtensionAction::ACTION_NONE;
...@@ -150,11 +150,12 @@ void ExtensionActionRunner::HandlePageAccessModified(const Extension* extension, ...@@ -150,11 +150,12 @@ void ExtensionActionRunner::HandlePageAccessModified(const Extension* extension,
// TODO(devlin): The bubble text should make it clear that permissions are // TODO(devlin): The bubble text should make it clear that permissions are
// granted only after the user accepts the refresh. // granted only after the user accepts the refresh.
ShowBlockedActionBubble( ShowBlockedActionBubble(
extension, base::Bind(&ExtensionActionRunner:: extension,
OnBlockedActionBubbleForPageAccessGrantClosed, base::BindOnce(&ExtensionActionRunner::
weak_factory_.GetWeakPtr(), extension->id(), OnBlockedActionBubbleForPageAccessGrantClosed,
web_contents()->GetLastCommittedURL(), weak_factory_.GetWeakPtr(), extension->id(),
current_access, new_access)); web_contents()->GetLastCommittedURL(), current_access,
new_access));
return; return;
} }
...@@ -246,7 +247,7 @@ ExtensionActionRunner::RequiresUserConsentForScriptInjection( ...@@ -246,7 +247,7 @@ ExtensionActionRunner::RequiresUserConsentForScriptInjection(
void ExtensionActionRunner::RequestScriptInjection( void ExtensionActionRunner::RequestScriptInjection(
const Extension* extension, const Extension* extension,
UserScript::RunLocation run_location, UserScript::RunLocation run_location,
const base::Closure& callback) { base::RepeatingClosure callback) {
CHECK(extension); CHECK(extension);
PendingScriptList& list = pending_scripts_[extension->id()]; PendingScriptList& list = pending_scripts_[extension->id()];
list.push_back(PendingScript(run_location, callback)); list.push_back(PendingScript(run_location, callback));
...@@ -320,8 +321,8 @@ void ExtensionActionRunner::OnRequestScriptInjectionPermission( ...@@ -320,8 +321,8 @@ void ExtensionActionRunner::OnRequestScriptInjectionPermission(
// by this object. // by this object.
RequestScriptInjection( RequestScriptInjection(
extension, run_location, extension, run_location,
base::Bind(&ExtensionActionRunner::PermitScriptInjection, base::BindRepeating(&ExtensionActionRunner::PermitScriptInjection,
base::Unretained(this), request_id)); base::Unretained(this), request_id));
break; break;
case PermissionsData::PageAccess::kDenied: case PermissionsData::PageAccess::kDenied:
// We should usually only get a "deny access" if the page changed (as the // We should usually only get a "deny access" if the page changed (as the
...@@ -370,7 +371,7 @@ void ExtensionActionRunner::LogUMA() const { ...@@ -370,7 +371,7 @@ void ExtensionActionRunner::LogUMA() const {
void ExtensionActionRunner::ShowBlockedActionBubble( void ExtensionActionRunner::ShowBlockedActionBubble(
const Extension* extension, const Extension* extension,
const base::Callback<void(ToolbarActionsBarBubbleDelegate::CloseAction)>& base::OnceCallback<void(ToolbarActionsBarBubbleDelegate::CloseAction)>
callback) { callback) {
Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); Browser* browser = chrome::FindBrowserWithWebContents(web_contents());
ExtensionsContainer* const extensions_container = ExtensionsContainer* const extensions_container =
...@@ -379,11 +380,11 @@ void ExtensionActionRunner::ShowBlockedActionBubble( ...@@ -379,11 +380,11 @@ void ExtensionActionRunner::ShowBlockedActionBubble(
return; return;
if (default_bubble_close_action_for_testing_) { if (default_bubble_close_action_for_testing_) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE, base::BindOnce(std::move(callback),
base::BindOnce(callback, *default_bubble_close_action_for_testing_)); *default_bubble_close_action_for_testing_));
} else { } else {
extensions_container->ShowToolbarActionBubble( extensions_container->ShowToolbarActionBubble(
std::make_unique<BlockedActionBubbleDelegate>(callback, std::make_unique<BlockedActionBubbleDelegate>(std::move(callback),
extension->id())); extension->id()));
} }
} }
......
...@@ -114,7 +114,7 @@ class ExtensionActionRunner : public content::WebContentsObserver, ...@@ -114,7 +114,7 @@ class ExtensionActionRunner : public content::WebContentsObserver,
} }
void RequestScriptInjectionForTesting(const Extension* extension, void RequestScriptInjectionForTesting(const Extension* extension,
UserScript::RunLocation run_location, UserScript::RunLocation run_location,
const base::Closure& callback) { base::RepeatingClosure callback) {
return RequestScriptInjection(extension, run_location, callback); return RequestScriptInjection(extension, run_location, callback);
} }
void ClearInjectionsForTesting(const Extension& extension) { void ClearInjectionsForTesting(const Extension& extension) {
...@@ -125,7 +125,7 @@ class ExtensionActionRunner : public content::WebContentsObserver, ...@@ -125,7 +125,7 @@ class ExtensionActionRunner : public content::WebContentsObserver,
private: private:
struct PendingScript { struct PendingScript {
PendingScript(UserScript::RunLocation run_location, PendingScript(UserScript::RunLocation run_location,
const base::Closure& permit_script); base::RepeatingClosure permit_script);
PendingScript(const PendingScript& other); PendingScript(const PendingScript& other);
~PendingScript(); ~PendingScript();
...@@ -133,7 +133,7 @@ class ExtensionActionRunner : public content::WebContentsObserver, ...@@ -133,7 +133,7 @@ class ExtensionActionRunner : public content::WebContentsObserver,
UserScript::RunLocation run_location; UserScript::RunLocation run_location;
// The callback to run when the script is permitted by the user. // The callback to run when the script is permitted by the user.
base::Closure permit_script; base::RepeatingClosure permit_script;
}; };
using PendingScriptList = std::vector<PendingScript>; using PendingScriptList = std::vector<PendingScript>;
...@@ -150,7 +150,7 @@ class ExtensionActionRunner : public content::WebContentsObserver, ...@@ -150,7 +150,7 @@ class ExtensionActionRunner : public content::WebContentsObserver,
// |callback| is run is that, if it is run, it will run on the current page. // |callback| is run is that, if it is run, it will run on the current page.
void RequestScriptInjection(const Extension* extension, void RequestScriptInjection(const Extension* extension,
UserScript::RunLocation run_location, UserScript::RunLocation run_location,
const base::Closure& callback); base::RepeatingClosure callback);
// Runs any pending injections for the corresponding extension. // Runs any pending injections for the corresponding extension.
void RunPendingScriptsForExtension(const Extension* extension); void RunPendingScriptsForExtension(const Extension* extension);
...@@ -176,7 +176,7 @@ class ExtensionActionRunner : public content::WebContentsObserver, ...@@ -176,7 +176,7 @@ class ExtensionActionRunner : public content::WebContentsObserver,
// closed. // closed.
void ShowBlockedActionBubble( void ShowBlockedActionBubble(
const Extension* extension, const Extension* extension,
const base::Callback<void(ToolbarActionsBarBubbleDelegate::CloseAction)>& base::OnceCallback<void(ToolbarActionsBarBubbleDelegate::CloseAction)>
callback); callback);
// Called when the blocked actions bubble invoked to run the extension action // Called when the blocked actions bubble invoked to run the extension action
......
...@@ -70,7 +70,7 @@ class ExtensionActionRunnerUnitTest : public ChromeRenderViewHostTestHarness { ...@@ -70,7 +70,7 @@ class ExtensionActionRunnerUnitTest : public ChromeRenderViewHostTestHarness {
private: private:
// Returns a closure to use as a script execution for a given extension. // Returns a closure to use as a script execution for a given extension.
base::Closure GetExecutionCallbackForExtension( base::RepeatingClosure GetExecutionCallbackForExtension(
const std::string& extension_id); const std::string& extension_id);
// Increment the number of executions for the given |extension_id|. // Increment the number of executions for the given |extension_id|.
...@@ -153,12 +153,14 @@ size_t ExtensionActionRunnerUnitTest::GetExecutionCountForExtension( ...@@ -153,12 +153,14 @@ size_t ExtensionActionRunnerUnitTest::GetExecutionCountForExtension(
return 0u; return 0u;
} }
base::Closure ExtensionActionRunnerUnitTest::GetExecutionCallbackForExtension( base::RepeatingClosure
ExtensionActionRunnerUnitTest::GetExecutionCallbackForExtension(
const std::string& extension_id) { const std::string& extension_id) {
// We use base unretained here, but if this ever gets executed outside of // We use base unretained here, but if this ever gets executed outside of
// this test's lifetime, we have a major problem anyway. // this test's lifetime, we have a major problem anyway.
return base::Bind(&ExtensionActionRunnerUnitTest::IncrementExecutionCount, return base::BindRepeating(
base::Unretained(this), extension_id); &ExtensionActionRunnerUnitTest::IncrementExecutionCount,
base::Unretained(this), extension_id);
} }
void ExtensionActionRunnerUnitTest::IncrementExecutionCount( void ExtensionActionRunnerUnitTest::IncrementExecutionCount(
......
...@@ -18,8 +18,8 @@ ExtensionInstallPromptTestHelper::~ExtensionInstallPromptTestHelper() {} ...@@ -18,8 +18,8 @@ ExtensionInstallPromptTestHelper::~ExtensionInstallPromptTestHelper() {}
ExtensionInstallPrompt::DoneCallback ExtensionInstallPrompt::DoneCallback
ExtensionInstallPromptTestHelper::GetCallback() { ExtensionInstallPromptTestHelper::GetCallback() {
return base::Bind(&ExtensionInstallPromptTestHelper::HandleResult, return base::BindOnce(&ExtensionInstallPromptTestHelper::HandleResult,
base::Unretained(this)); base::Unretained(this));
} }
ExtensionInstallPrompt::Result ExtensionInstallPrompt::Result
......
...@@ -870,7 +870,7 @@ void ExtensionTabUtil::CreateTab(std::unique_ptr<WebContents> web_contents, ...@@ -870,7 +870,7 @@ void ExtensionTabUtil::CreateTab(std::unique_ptr<WebContents> web_contents,
// static // static
void ExtensionTabUtil::ForEachTab( void ExtensionTabUtil::ForEachTab(
const base::Callback<void(WebContents*)>& callback) { base::RepeatingCallback<void(WebContents*)> callback) {
for (auto* web_contents : AllTabContentses()) for (auto* web_contents : AllTabContentses())
callback.Run(web_contents); callback.Run(web_contents);
} }
......
...@@ -228,7 +228,7 @@ class ExtensionTabUtil { ...@@ -228,7 +228,7 @@ class ExtensionTabUtil {
// Executes the specified callback for all tabs in all browser windows. // Executes the specified callback for all tabs in all browser windows.
static void ForEachTab( static void ForEachTab(
const base::Callback<void(content::WebContents*)>& callback); base::RepeatingCallback<void(content::WebContents*)> callback);
static WindowController* GetWindowControllerOfTab( static WindowController* GetWindowControllerOfTab(
const content::WebContents* web_contents); const content::WebContents* web_contents);
......
...@@ -247,9 +247,9 @@ void UpdateOverridesLists(Profile* profile, ...@@ -247,9 +247,9 @@ void UpdateOverridesLists(Profile* profile,
behavior)) { behavior)) {
// This is the active override, so we need to find all existing // This is the active override, so we need to find all existing
// tabs for this override and get them to reload the original URL. // tabs for this override and get them to reload the original URL.
base::Callback<void(WebContents*)> callback = base::RepeatingCallback<void(WebContents*)> callback =
base::Bind(&UnregisterAndReplaceOverrideForWebContents, base::BindRepeating(&UnregisterAndReplaceOverrideForWebContents,
page_override_pair.first, profile); page_override_pair.first, profile);
extensions::ExtensionTabUtil::ForEachTab(callback); extensions::ExtensionTabUtil::ForEachTab(callback);
} }
} }
...@@ -317,7 +317,7 @@ bool ValidateOverrideURL(const base::Value* override_url_value, ...@@ -317,7 +317,7 @@ bool ValidateOverrideURL(const base::Value* override_url_value,
// Fetches each list in the overrides dictionary and runs |callback| on it. // Fetches each list in the overrides dictionary and runs |callback| on it.
void ForEachOverrideList( void ForEachOverrideList(
Profile* profile, Profile* profile,
const base::Callback<void(base::ListValue*)>& callback) { base::RepeatingCallback<void(base::ListValue*)> callback) {
PrefService* prefs = profile->GetPrefs(); PrefService* prefs = profile->GetPrefs();
DictionaryPrefUpdate update(prefs, ExtensionWebUI::kExtensionURLOverrides); DictionaryPrefUpdate update(prefs, ExtensionWebUI::kExtensionURLOverrides);
base::DictionaryValue* all_overrides = update.Get(); base::DictionaryValue* all_overrides = update.Get();
...@@ -519,7 +519,7 @@ size_t ExtensionWebUI::GetNumberOfExtensionsOverridingURL( ...@@ -519,7 +519,7 @@ size_t ExtensionWebUI::GetNumberOfExtensionsOverridingURL(
// static // static
void ExtensionWebUI::InitializeChromeURLOverrides(Profile* profile) { void ExtensionWebUI::InitializeChromeURLOverrides(Profile* profile) {
ForEachOverrideList(profile, base::Bind(&InitializeOverridesList)); ForEachOverrideList(profile, base::BindRepeating(&InitializeOverridesList));
} }
// static // static
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
BlockedActionBubbleDelegate::BlockedActionBubbleDelegate( BlockedActionBubbleDelegate::BlockedActionBubbleDelegate(
const base::Callback<void(CloseAction)>& callback, base::OnceCallback<void(CloseAction)> callback,
const std::string& extension_id) const std::string& extension_id)
: callback_(callback), extension_id_(extension_id) {} : callback_(std::move(callback)), extension_id_(extension_id) {}
BlockedActionBubbleDelegate::~BlockedActionBubbleDelegate() {} BlockedActionBubbleDelegate::~BlockedActionBubbleDelegate() {}
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// in order to run any blocked actions the extension may have. // in order to run any blocked actions the extension may have.
class BlockedActionBubbleDelegate : public ToolbarActionsBarBubbleDelegate { class BlockedActionBubbleDelegate : public ToolbarActionsBarBubbleDelegate {
public: public:
BlockedActionBubbleDelegate(const base::Callback<void(CloseAction)>& callback, BlockedActionBubbleDelegate(base::OnceCallback<void(CloseAction)> callback,
const std::string& extension_id); const std::string& extension_id);
~BlockedActionBubbleDelegate() override; ~BlockedActionBubbleDelegate() override;
...@@ -33,7 +33,7 @@ class BlockedActionBubbleDelegate : public ToolbarActionsBarBubbleDelegate { ...@@ -33,7 +33,7 @@ class BlockedActionBubbleDelegate : public ToolbarActionsBarBubbleDelegate {
void OnBubbleShown(const base::Closure& close_bubble_callback) override; void OnBubbleShown(const base::Closure& close_bubble_callback) override;
void OnBubbleClosed(CloseAction action) override; void OnBubbleClosed(CloseAction action) override;
base::Callback<void(CloseAction)> callback_; base::OnceCallback<void(CloseAction)> callback_;
std::string extension_id_; std::string extension_id_;
DISALLOW_COPY_AND_ASSIGN(BlockedActionBubbleDelegate); DISALLOW_COPY_AND_ASSIGN(BlockedActionBubbleDelegate);
......
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