Commit 4cebdd48 authored by Hui Yingst's avatar Hui Yingst Committed by Chromium LUCI CQ

CodeHealthRotation: Migrate ScriptInjectionCallback::CompleteCallback to base::OnceCallback.

This CL migrates ScriptInjectionCallback::CompleteCallback to
base::OnceCallback, and migrates related uses of base::Bind to
base::BindOnce.

Bug: 1152265
Change-Id: If3182c7c0c45c5e1b45073dfe47edbf25d7081c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2572777
Commit-Queue: Hui Yingst <nigi@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834986}
parent 959f7c41
......@@ -23,14 +23,14 @@ void ExtensionJSRunner::RunJSFunction(v8::Local<v8::Function> function,
ResultCallback callback) {
ScriptInjectionCallback::CompleteCallback wrapper_callback;
if (callback) {
// TODO(devlin): Update ScriptContext to take a OnceCallback.
wrapper_callback = base::BindRepeating(
&ExtensionJSRunner::OnFunctionComplete, weak_factory_.GetWeakPtr(),
base::Passed(std::move(callback)));
wrapper_callback =
base::BindOnce(&ExtensionJSRunner::OnFunctionComplete,
weak_factory_.GetWeakPtr(), std::move(callback));
}
// TODO(devlin): Move ScriptContext::SafeCallFunction() into here?
script_context_->SafeCallFunction(function, argc, argv, wrapper_callback);
script_context_->SafeCallFunction(function, argc, argv,
std::move(wrapper_callback));
}
v8::MaybeLocal<v8::Value> ExtensionJSRunner::RunJSFunctionSync(
......
......@@ -326,7 +326,7 @@ void ModuleSystem::CallModuleMethodSafe(
const std::string& method_name,
int argc,
v8::Local<v8::Value> argv[],
const ScriptInjectionCallback::CompleteCallback& callback) {
ScriptInjectionCallback::CompleteCallback callback) {
TRACE_EVENT2("v8", "v8.callModuleMethodSafe", "module_name", module_name,
"method_name", method_name);
......@@ -349,7 +349,7 @@ void ModuleSystem::CallModuleMethodSafe(
{
v8::TryCatch try_catch(GetIsolate());
try_catch.SetCaptureMessage(true);
context_->SafeCallFunction(function, argc, argv, callback);
context_->SafeCallFunction(function, argc, argv, std::move(callback));
if (try_catch.HasCaught())
HandleException(try_catch);
}
......
......@@ -98,12 +98,11 @@ class ModuleSystem : public ObjectBackedNativeHandler {
const std::string& method_name,
int argc,
v8::Local<v8::Value> argv[]);
void CallModuleMethodSafe(
const std::string& module_name,
void CallModuleMethodSafe(const std::string& module_name,
const std::string& method_name,
int argc,
v8::Local<v8::Value> argv[],
const ScriptInjectionCallback::CompleteCallback& callback);
ScriptInjectionCallback::CompleteCallback callback);
// Register |native_handler| as a potential target for requireNative(), so
// calls to requireNative(|name|) from JS will return a new object created by
......
......@@ -355,7 +355,7 @@ void ScriptContext::SafeCallFunction(
const v8::Local<v8::Function>& function,
int argc,
v8::Local<v8::Value> argv[],
const ScriptInjectionCallback::CompleteCallback& callback) {
ScriptInjectionCallback::CompleteCallback callback) {
DCHECK(thread_checker_.CalledOnValidThread());
v8::HandleScope handle_scope(isolate());
v8::Context::Scope scope(v8_context());
......@@ -366,7 +366,7 @@ void ScriptContext::SafeCallFunction(
ScriptInjectionCallback* wrapper_callback = nullptr;
if (!callback.is_null()) {
// ScriptInjectionCallback manages its own lifetime.
wrapper_callback = new ScriptInjectionCallback(callback);
wrapper_callback = new ScriptInjectionCallback(std::move(callback));
}
web_frame_->RequestExecuteV8Function(v8_context(), function, global, argc,
argv, wrapper_callback);
......@@ -376,7 +376,7 @@ void ScriptContext::SafeCallFunction(
v8::Local<v8::Value> result;
if (!callback.is_null() && maybe_result.ToLocal(&result)) {
std::vector<v8::Local<v8::Value>> results(1, result);
callback.Run(results);
std::move(callback).Run(results);
}
}
}
......
......@@ -118,11 +118,10 @@ class ScriptContext {
void SafeCallFunction(const v8::Local<v8::Function>& function,
int argc,
v8::Local<v8::Value> argv[]);
void SafeCallFunction(
const v8::Local<v8::Function>& function,
void SafeCallFunction(const v8::Local<v8::Function>& function,
int argc,
v8::Local<v8::Value> argv[],
const ScriptInjectionCallback::CompleteCallback& callback);
ScriptInjectionCallback::CompleteCallback callback);
// Returns the availability of the API |api_name|.
Feature::Availability GetAvailability(const std::string& api_name);
......
......@@ -91,7 +91,7 @@ class TimedScriptInjectionCallback : public ScriptInjectionCallback {
public:
TimedScriptInjectionCallback(base::WeakPtr<ScriptInjection> injection)
: ScriptInjectionCallback(
base::Bind(&TimedScriptInjectionCallback::OnCompleted,
base::BindOnce(&TimedScriptInjectionCallback::OnCompleted,
base::Unretained(this))),
injection_(injection) {}
~TimedScriptInjectionCallback() override {}
......
......@@ -9,9 +9,8 @@
namespace extensions {
ScriptInjectionCallback::ScriptInjectionCallback(
const CompleteCallback& injection_completed_callback)
: injection_completed_callback_(injection_completed_callback) {
}
CompleteCallback injection_completed_callback)
: injection_completed_callback_(std::move(injection_completed_callback)) {}
ScriptInjectionCallback::~ScriptInjectionCallback() {
}
......@@ -19,7 +18,7 @@ ScriptInjectionCallback::~ScriptInjectionCallback() {
void ScriptInjectionCallback::Completed(
const blink::WebVector<v8::Local<v8::Value>>& result) {
std::vector<v8::Local<v8::Value>> stl_result(result.begin(), result.end());
injection_completed_callback_.Run(stl_result);
std::move(injection_completed_callback_).Run(stl_result);
delete this;
}
......
......@@ -20,9 +20,10 @@ namespace extensions {
class ScriptInjectionCallback : public blink::WebScriptExecutionCallback {
public:
using CompleteCallback =
base::Callback<void(const std::vector<v8::Local<v8::Value>>& result)>;
base::OnceCallback<void(const std::vector<v8::Local<v8::Value>>& result)>;
ScriptInjectionCallback(const CompleteCallback& injection_completed_callback);
explicit ScriptInjectionCallback(
CompleteCallback injection_completed_callback);
~ScriptInjectionCallback() override;
void Completed(const blink::WebVector<v8::Local<v8::Value>>& result) override;
......
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