refactor: replace base::Bind() with base::BindOnce() / base::BindRepeating() (#27447)
This commit is contained in:
parent
b11c5533e8
commit
949fd0728f
10 changed files with 24 additions and 22 deletions
|
@ -109,22 +109,22 @@ static gfx::Rect DIPToScreenRect(electron::NativeWindow* window,
|
||||||
|
|
||||||
void Screen::OnDisplayAdded(const display::Display& new_display) {
|
void Screen::OnDisplayAdded(const display::Display& new_display) {
|
||||||
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
|
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
|
||||||
FROM_HERE, base::Bind(&DelayEmit, base::Unretained(this), "display-added",
|
FROM_HERE, base::BindOnce(&DelayEmit, base::Unretained(this),
|
||||||
new_display));
|
"display-added", new_display));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::OnDisplayRemoved(const display::Display& old_display) {
|
void Screen::OnDisplayRemoved(const display::Display& old_display) {
|
||||||
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
|
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
|
||||||
FROM_HERE, base::Bind(&DelayEmit, base::Unretained(this),
|
FROM_HERE, base::BindOnce(&DelayEmit, base::Unretained(this),
|
||||||
"display-removed", old_display));
|
"display-removed", old_display));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::OnDisplayMetricsChanged(const display::Display& display,
|
void Screen::OnDisplayMetricsChanged(const display::Display& display,
|
||||||
uint32_t changed_metrics) {
|
uint32_t changed_metrics) {
|
||||||
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
|
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
|
||||||
FROM_HERE, base::Bind(&DelayEmitWithMetrics, base::Unretained(this),
|
FROM_HERE, base::BindOnce(&DelayEmitWithMetrics, base::Unretained(this),
|
||||||
"display-metrics-changed", display,
|
"display-metrics-changed", display,
|
||||||
MetricsToArray(changed_metrics)));
|
MetricsToArray(changed_metrics)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
|
@ -132,7 +132,7 @@ void MessagePort::Entangle(blink::MessagePortDescriptor port) {
|
||||||
connector_->PauseIncomingMethodCallProcessing();
|
connector_->PauseIncomingMethodCallProcessing();
|
||||||
connector_->set_incoming_receiver(this);
|
connector_->set_incoming_receiver(this);
|
||||||
connector_->set_connection_error_handler(
|
connector_->set_connection_error_handler(
|
||||||
base::Bind(&MessagePort::Close, weak_factory_.GetWeakPtr()));
|
base::BindOnce(&MessagePort::Close, weak_factory_.GetWeakPtr()));
|
||||||
if (HasPendingActivity())
|
if (HasPendingActivity())
|
||||||
Pin();
|
Pin();
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,11 +173,11 @@ AppSorting* ElectronExtensionSystem::app_sorting() {
|
||||||
void ElectronExtensionSystem::RegisterExtensionWithRequestContexts(
|
void ElectronExtensionSystem::RegisterExtensionWithRequestContexts(
|
||||||
const Extension* extension,
|
const Extension* extension,
|
||||||
base::OnceClosure callback) {
|
base::OnceClosure callback) {
|
||||||
base::PostTaskAndReply(
|
base::PostTaskAndReply(FROM_HERE, {BrowserThread::IO},
|
||||||
FROM_HERE, {BrowserThread::IO},
|
base::BindOnce(&InfoMap::AddExtension, info_map(),
|
||||||
base::Bind(&InfoMap::AddExtension, info_map(),
|
base::RetainedRef(extension),
|
||||||
base::RetainedRef(extension), base::Time::Now(), false, false),
|
base::Time::Now(), false, false),
|
||||||
std::move(callback));
|
std::move(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElectronExtensionSystem::UnregisterExtensionWithRequestContexts(
|
void ElectronExtensionSystem::UnregisterExtensionWithRequestContexts(
|
||||||
|
|
|
@ -40,7 +40,7 @@ void URLPipeLoader::Start(
|
||||||
const net::NetworkTrafficAnnotationTag& annotation,
|
const net::NetworkTrafficAnnotationTag& annotation,
|
||||||
base::DictionaryValue upload_data) {
|
base::DictionaryValue upload_data) {
|
||||||
loader_ = network::SimpleURLLoader::Create(std::move(request), annotation);
|
loader_ = network::SimpleURLLoader::Create(std::move(request), annotation);
|
||||||
loader_->SetOnResponseStartedCallback(base::Bind(
|
loader_->SetOnResponseStartedCallback(base::BindOnce(
|
||||||
&URLPipeLoader::OnResponseStarted, weak_factory_.GetWeakPtr()));
|
&URLPipeLoader::OnResponseStarted, weak_factory_.GetWeakPtr()));
|
||||||
|
|
||||||
// TODO(zcbenz): The old protocol API only supports string as upload data,
|
// TODO(zcbenz): The old protocol API only supports string as upload data,
|
||||||
|
|
|
@ -365,8 +365,9 @@ void AppIndicatorIcon::UpdateClickActionReplacementMenuItem() {
|
||||||
DCHECK(!tool_tip_.empty());
|
DCHECK(!tool_tip_.empty());
|
||||||
menu_->UpdateClickActionReplacementMenuItem(
|
menu_->UpdateClickActionReplacementMenuItem(
|
||||||
tool_tip_.c_str(),
|
tool_tip_.c_str(),
|
||||||
base::Bind(&AppIndicatorIcon::OnClickActionReplacementMenuItemActivated,
|
base::BindRepeating(
|
||||||
base::Unretained(this)));
|
&AppIndicatorIcon::OnClickActionReplacementMenuItemActivated,
|
||||||
|
base::Unretained(this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppIndicatorIcon::OnClickActionReplacementMenuItemActivated() {
|
void AppIndicatorIcon::OnClickActionReplacementMenuItemActivated() {
|
||||||
|
|
|
@ -185,7 +185,7 @@ gfx::Image Clipboard::ReadImage(gin_helper::Arguments* args) {
|
||||||
clipboard->ReadImage(
|
clipboard->ReadImage(
|
||||||
GetClipboardBuffer(args),
|
GetClipboardBuffer(args),
|
||||||
/* data_dst = */ nullptr,
|
/* data_dst = */ nullptr,
|
||||||
base::Bind(
|
base::BindOnce(
|
||||||
[](base::Optional<gfx::Image>* image, const SkBitmap& result) {
|
[](base::Optional<gfx::Image>* image, const SkBitmap& result) {
|
||||||
image->emplace(gfx::Image::CreateFrom1xBitmap(result));
|
image->emplace(gfx::Image::CreateFrom1xBitmap(result));
|
||||||
},
|
},
|
||||||
|
|
|
@ -19,7 +19,7 @@ struct Converter<base::RepeatingCallback<Sig>> {
|
||||||
// We don't use CreateFunctionTemplate here because it creates a new
|
// We don't use CreateFunctionTemplate here because it creates a new
|
||||||
// FunctionTemplate everytime, which is cached by V8 and causes leaks.
|
// FunctionTemplate everytime, which is cached by V8 and causes leaks.
|
||||||
auto translater =
|
auto translater =
|
||||||
base::Bind(&gin_helper::NativeFunctionInvoker<Sig>::Go, val);
|
base::BindRepeating(&gin_helper::NativeFunctionInvoker<Sig>::Go, val);
|
||||||
// To avoid memory leak, we ensure that the callback can only be called
|
// To avoid memory leak, we ensure that the callback can only be called
|
||||||
// for once.
|
// for once.
|
||||||
return gin_helper::CreateFunctionFromTranslater(isolate, translater, true);
|
return gin_helper::CreateFunctionFromTranslater(isolate, translater, true);
|
||||||
|
|
|
@ -142,7 +142,8 @@ template <typename Sig>
|
||||||
v8::Local<v8::Value> CallbackToV8Leaked(
|
v8::Local<v8::Value> CallbackToV8Leaked(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
const base::RepeatingCallback<Sig>& val) {
|
const base::RepeatingCallback<Sig>& val) {
|
||||||
Translater translater = base::Bind(&NativeFunctionInvoker<Sig>::Go, val);
|
Translater translater =
|
||||||
|
base::BindRepeating(&NativeFunctionInvoker<Sig>::Go, val);
|
||||||
return CreateFunctionFromTranslater(isolate, translater, false);
|
return CreateFunctionFromTranslater(isolate, translater, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Wrappable : public WrappableBase {
|
||||||
static void SetConstructor(v8::Isolate* isolate,
|
static void SetConstructor(v8::Isolate* isolate,
|
||||||
const base::Callback<Sig>& constructor) {
|
const base::Callback<Sig>& constructor) {
|
||||||
v8::Local<v8::FunctionTemplate> templ = gin_helper::CreateFunctionTemplate(
|
v8::Local<v8::FunctionTemplate> templ = gin_helper::CreateFunctionTemplate(
|
||||||
isolate, base::Bind(&internal::InvokeNew<Sig>, constructor));
|
isolate, base::BindRepeating(&internal::InvokeNew<Sig>, constructor));
|
||||||
templ->InstanceTemplate()->SetInternalFieldCount(1);
|
templ->InstanceTemplate()->SetInternalFieldCount(1);
|
||||||
T::BuildPrototype(isolate, templ);
|
T::BuildPrototype(isolate, templ);
|
||||||
gin::PerIsolateData::From(isolate)->SetFunctionTemplate(&kWrapperInfo,
|
gin::PerIsolateData::From(isolate)->SetFunctionTemplate(&kWrapperInfo,
|
||||||
|
|
|
@ -53,8 +53,8 @@ AutofillAgent::AutofillAgent(content::RenderFrame* frame,
|
||||||
blink::AssociatedInterfaceRegistry* registry)
|
blink::AssociatedInterfaceRegistry* registry)
|
||||||
: content::RenderFrameObserver(frame), weak_ptr_factory_(this) {
|
: content::RenderFrameObserver(frame), weak_ptr_factory_(this) {
|
||||||
render_frame()->GetWebFrame()->SetAutofillClient(this);
|
render_frame()->GetWebFrame()->SetAutofillClient(this);
|
||||||
registry->AddInterface(
|
registry->AddInterface(base::BindRepeating(&AutofillAgent::BindReceiver,
|
||||||
base::Bind(&AutofillAgent::BindReceiver, base::Unretained(this)));
|
base::Unretained(this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
AutofillAgent::~AutofillAgent() = default;
|
AutofillAgent::~AutofillAgent() = default;
|
||||||
|
|
Loading…
Reference in a new issue