From 949fd0728fb56d06c33982a5523c5952511606e9 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Mon, 25 Jan 2021 02:27:40 +0100 Subject: [PATCH] refactor: replace base::Bind() with base::BindOnce() / base::BindRepeating() (#27447) --- shell/browser/api/electron_api_screen.cc | 14 +++++++------- shell/browser/api/message_port.cc | 2 +- .../extensions/electron_extension_system.cc | 10 +++++----- shell/browser/net/url_pipe_loader.cc | 2 +- shell/browser/ui/gtk/app_indicator_icon.cc | 5 +++-- shell/common/api/electron_api_clipboard.cc | 2 +- shell/common/gin_converters/callback_converter.h | 2 +- shell/common/gin_helper/callback.h | 3 ++- shell/common/gin_helper/wrappable.h | 2 +- shell/renderer/electron_autofill_agent.cc | 4 ++-- 10 files changed, 24 insertions(+), 22 deletions(-) diff --git a/shell/browser/api/electron_api_screen.cc b/shell/browser/api/electron_api_screen.cc index af6fb206df59..5676521799a5 100644 --- a/shell/browser/api/electron_api_screen.cc +++ b/shell/browser/api/electron_api_screen.cc @@ -109,22 +109,22 @@ static gfx::Rect DIPToScreenRect(electron::NativeWindow* window, void Screen::OnDisplayAdded(const display::Display& new_display) { base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( - FROM_HERE, base::Bind(&DelayEmit, base::Unretained(this), "display-added", - new_display)); + FROM_HERE, base::BindOnce(&DelayEmit, base::Unretained(this), + "display-added", new_display)); } void Screen::OnDisplayRemoved(const display::Display& old_display) { base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( - FROM_HERE, base::Bind(&DelayEmit, base::Unretained(this), - "display-removed", old_display)); + FROM_HERE, base::BindOnce(&DelayEmit, base::Unretained(this), + "display-removed", old_display)); } void Screen::OnDisplayMetricsChanged(const display::Display& display, uint32_t changed_metrics) { base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( - FROM_HERE, base::Bind(&DelayEmitWithMetrics, base::Unretained(this), - "display-metrics-changed", display, - MetricsToArray(changed_metrics))); + FROM_HERE, base::BindOnce(&DelayEmitWithMetrics, base::Unretained(this), + "display-metrics-changed", display, + MetricsToArray(changed_metrics))); } // static diff --git a/shell/browser/api/message_port.cc b/shell/browser/api/message_port.cc index 91bd073bf6f4..68cc46a1faf2 100644 --- a/shell/browser/api/message_port.cc +++ b/shell/browser/api/message_port.cc @@ -132,7 +132,7 @@ void MessagePort::Entangle(blink::MessagePortDescriptor port) { connector_->PauseIncomingMethodCallProcessing(); connector_->set_incoming_receiver(this); connector_->set_connection_error_handler( - base::Bind(&MessagePort::Close, weak_factory_.GetWeakPtr())); + base::BindOnce(&MessagePort::Close, weak_factory_.GetWeakPtr())); if (HasPendingActivity()) Pin(); } diff --git a/shell/browser/extensions/electron_extension_system.cc b/shell/browser/extensions/electron_extension_system.cc index 9c3abdb5842c..911ff382ad9a 100644 --- a/shell/browser/extensions/electron_extension_system.cc +++ b/shell/browser/extensions/electron_extension_system.cc @@ -173,11 +173,11 @@ AppSorting* ElectronExtensionSystem::app_sorting() { void ElectronExtensionSystem::RegisterExtensionWithRequestContexts( const Extension* extension, base::OnceClosure callback) { - base::PostTaskAndReply( - FROM_HERE, {BrowserThread::IO}, - base::Bind(&InfoMap::AddExtension, info_map(), - base::RetainedRef(extension), base::Time::Now(), false, false), - std::move(callback)); + base::PostTaskAndReply(FROM_HERE, {BrowserThread::IO}, + base::BindOnce(&InfoMap::AddExtension, info_map(), + base::RetainedRef(extension), + base::Time::Now(), false, false), + std::move(callback)); } void ElectronExtensionSystem::UnregisterExtensionWithRequestContexts( diff --git a/shell/browser/net/url_pipe_loader.cc b/shell/browser/net/url_pipe_loader.cc index f928eaa77325..12bf6563da1f 100644 --- a/shell/browser/net/url_pipe_loader.cc +++ b/shell/browser/net/url_pipe_loader.cc @@ -40,7 +40,7 @@ void URLPipeLoader::Start( const net::NetworkTrafficAnnotationTag& annotation, base::DictionaryValue upload_data) { loader_ = network::SimpleURLLoader::Create(std::move(request), annotation); - loader_->SetOnResponseStartedCallback(base::Bind( + loader_->SetOnResponseStartedCallback(base::BindOnce( &URLPipeLoader::OnResponseStarted, weak_factory_.GetWeakPtr())); // TODO(zcbenz): The old protocol API only supports string as upload data, diff --git a/shell/browser/ui/gtk/app_indicator_icon.cc b/shell/browser/ui/gtk/app_indicator_icon.cc index 011a811669cd..2f5db6f77005 100644 --- a/shell/browser/ui/gtk/app_indicator_icon.cc +++ b/shell/browser/ui/gtk/app_indicator_icon.cc @@ -365,8 +365,9 @@ void AppIndicatorIcon::UpdateClickActionReplacementMenuItem() { DCHECK(!tool_tip_.empty()); menu_->UpdateClickActionReplacementMenuItem( tool_tip_.c_str(), - base::Bind(&AppIndicatorIcon::OnClickActionReplacementMenuItemActivated, - base::Unretained(this))); + base::BindRepeating( + &AppIndicatorIcon::OnClickActionReplacementMenuItemActivated, + base::Unretained(this))); } void AppIndicatorIcon::OnClickActionReplacementMenuItemActivated() { diff --git a/shell/common/api/electron_api_clipboard.cc b/shell/common/api/electron_api_clipboard.cc index ca9225cc2775..50db8a1c59ae 100644 --- a/shell/common/api/electron_api_clipboard.cc +++ b/shell/common/api/electron_api_clipboard.cc @@ -185,7 +185,7 @@ gfx::Image Clipboard::ReadImage(gin_helper::Arguments* args) { clipboard->ReadImage( GetClipboardBuffer(args), /* data_dst = */ nullptr, - base::Bind( + base::BindOnce( [](base::Optional* image, const SkBitmap& result) { image->emplace(gfx::Image::CreateFrom1xBitmap(result)); }, diff --git a/shell/common/gin_converters/callback_converter.h b/shell/common/gin_converters/callback_converter.h index 7ec4838dc913..9342e2fc22cf 100644 --- a/shell/common/gin_converters/callback_converter.h +++ b/shell/common/gin_converters/callback_converter.h @@ -19,7 +19,7 @@ struct Converter> { // We don't use CreateFunctionTemplate here because it creates a new // FunctionTemplate everytime, which is cached by V8 and causes leaks. auto translater = - base::Bind(&gin_helper::NativeFunctionInvoker::Go, val); + base::BindRepeating(&gin_helper::NativeFunctionInvoker::Go, val); // To avoid memory leak, we ensure that the callback can only be called // for once. return gin_helper::CreateFunctionFromTranslater(isolate, translater, true); diff --git a/shell/common/gin_helper/callback.h b/shell/common/gin_helper/callback.h index 3221dd2b6ba8..363619bde3a2 100644 --- a/shell/common/gin_helper/callback.h +++ b/shell/common/gin_helper/callback.h @@ -142,7 +142,8 @@ template v8::Local CallbackToV8Leaked( v8::Isolate* isolate, const base::RepeatingCallback& val) { - Translater translater = base::Bind(&NativeFunctionInvoker::Go, val); + Translater translater = + base::BindRepeating(&NativeFunctionInvoker::Go, val); return CreateFunctionFromTranslater(isolate, translater, false); } diff --git a/shell/common/gin_helper/wrappable.h b/shell/common/gin_helper/wrappable.h index ff6f06c6c2a5..7568ac731081 100644 --- a/shell/common/gin_helper/wrappable.h +++ b/shell/common/gin_helper/wrappable.h @@ -26,7 +26,7 @@ class Wrappable : public WrappableBase { static void SetConstructor(v8::Isolate* isolate, const base::Callback& constructor) { v8::Local templ = gin_helper::CreateFunctionTemplate( - isolate, base::Bind(&internal::InvokeNew, constructor)); + isolate, base::BindRepeating(&internal::InvokeNew, constructor)); templ->InstanceTemplate()->SetInternalFieldCount(1); T::BuildPrototype(isolate, templ); gin::PerIsolateData::From(isolate)->SetFunctionTemplate(&kWrapperInfo, diff --git a/shell/renderer/electron_autofill_agent.cc b/shell/renderer/electron_autofill_agent.cc index 6c8a20d12bf9..ea083ed68412 100644 --- a/shell/renderer/electron_autofill_agent.cc +++ b/shell/renderer/electron_autofill_agent.cc @@ -53,8 +53,8 @@ AutofillAgent::AutofillAgent(content::RenderFrame* frame, blink::AssociatedInterfaceRegistry* registry) : content::RenderFrameObserver(frame), weak_ptr_factory_(this) { render_frame()->GetWebFrame()->SetAutofillClient(this); - registry->AddInterface( - base::Bind(&AutofillAgent::BindReceiver, base::Unretained(this))); + registry->AddInterface(base::BindRepeating(&AutofillAgent::BindReceiver, + base::Unretained(this))); } AutofillAgent::~AutofillAgent() = default;