refactor: remove base::AdaptCallbackForRepeating patch (#48790)

refactor: remove base::AdaptCallbackForRepeating patch

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot]
2025-11-05 18:25:01 -05:00
committed by GitHub
parent e1dadaa6a0
commit 11191f23b1
7 changed files with 51 additions and 44 deletions

View File

@@ -580,6 +580,7 @@ filenames = {
"shell/common/asar/asar_util.h",
"shell/common/asar/scoped_temporary_file.cc",
"shell/common/asar/scoped_temporary_file.h",
"shell/common/callback_util.h",
"shell/common/color_util.cc",
"shell/common/color_util.h",
"shell/common/crash_keys.cc",

View File

@@ -59,7 +59,6 @@ webview_fullscreen.patch
extend_apply_webpreferences.patch
build_libc_as_static_library.patch
build_do_not_depend_on_packed_resource_integrity.patch
refactor_restore_base_adaptcallbackforrepeating.patch
logging_win32_only_create_a_console_if_logging_to_stderr.patch
fix_media_key_usage_with_globalshortcuts.patch
feat_expose_raw_response_headers_from_urlloader.patch

View File

@@ -1,40 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Charles Kerr <charles@charleskerr.com>
Date: Wed, 9 Jun 2021 14:28:08 -0500
Subject: refactor: restore base::AdaptCallbackForRepeating
Undo https://chromium-review.googlesource.com/c/chromium/src/+/2941842
to reinstate base::AdaptCallbackForRepeating(). It was removed to fix
https://bugs.chromium.org/p/chromium/issues/detail?id=730593 .
We use AdaptCallbackForRepeating() in about a dozen places. This patch
should be removed as soon as those have been updated. Patching because
every instance is a FTBFS that prevents testing any one instance's fix.
diff --git a/base/functional/callback_helpers.h b/base/functional/callback_helpers.h
index f1aa11fec7c0994ac19a26a02800f25de8f2f519..bbfdb3e4839ed96e4c6238235458a421c917411f 100644
--- a/base/functional/callback_helpers.h
+++ b/base/functional/callback_helpers.h
@@ -99,6 +99,22 @@ RepeatingCallback<void(Args...)> ForwardRepeatingCallbacks(
std::move(v));
}
+// Wraps the given OnceCallback into a RepeatingCallback that relays its
+// invocation to the original OnceCallback on the first invocation. The
+// following invocations are just ignored.
+//
+// Note that this deliberately subverts the Once/Repeating paradigm of Callbacks
+// but helps ease the migration from old-style Callbacks. Avoid if possible; use
+// if necessary for migration. TODO(tzik): Remove it. https://crbug.com/730593
+template <typename... Args>
+RepeatingCallback<void(Args...)> AdaptCallbackForRepeating(
+ OnceCallback<void(Args...)> callback) {
+ using Helper = internal::OnceCallbackHolder<Args...>;
+ return base::BindRepeating(
+ &Helper::Run, std::make_unique<Helper>(std::move(callback),
+ /*ignore_extra_runs=*/true));
+}
+
// Wraps the given OnceCallback and returns two OnceCallbacks with an identical
// signature. On first invokation of either returned callbacks, the original
// callback is invoked. Invoking the remaining callback results in a crash.

View File

@@ -62,6 +62,7 @@
#include "shell/browser/net/resolve_proxy_helper.h"
#include "shell/browser/relauncher.h"
#include "shell/common/application_info.h"
#include "shell/common/callback_util.h"
#include "shell/common/electron_command_line.h"
#include "shell/common/electron_paths.h"
#include "shell/common/gin_converters/base_converter.h"
@@ -735,7 +736,8 @@ void App::AllowCertificateError(
bool is_main_frame_request,
bool strict_enforcement,
base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
auto adapted_callback = base::AdaptCallbackForRepeating(std::move(callback));
auto adapted_callback =
electron::AdaptCallbackForRepeating(std::move(callback));
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);
bool prevent_default = Emit(

View File

@@ -10,6 +10,7 @@
#include "shell/browser/api/electron_api_base_window.h"
#include "shell/browser/api/electron_api_web_frame_main.h"
#include "shell/browser/native_window_views.h"
#include "shell/common/callback_util.h"
#include "ui/display/screen.h"
#include "v8/include/cppgc/allocation.h"
#include "v8/include/v8-cppgc.h"
@@ -54,7 +55,7 @@ void MenuViews::PopupAt(BaseWindow* window,
// callback, it is fine passing OnceCallback to it because we reset the
// menu runner immediately when the menu is closed.
int32_t window_id = window->weak_map_id();
auto close_callback = base::AdaptCallbackForRepeating(
auto close_callback = electron::AdaptCallbackForRepeating(
base::BindOnce(&MenuViews::OnClosed, weak_factory_.GetWeakPtr(),
window_id, std::move(callback_with_ref)));
auto& runner = menu_runners_[window_id] =

View File

@@ -0,0 +1,43 @@
// Copyright (c) Microsoft GmbH.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_COMMON_CALLBACK_UTIL_H_
#define ELECTRON_SHELL_COMMON_CALLBACK_UTIL_H_
#include <memory>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
namespace electron {
namespace internal {
template <typename... Args>
class OnceCallbackHolder {
public:
explicit OnceCallbackHolder(base::OnceCallback<void(Args...)> cb)
: cb_(std::move(cb)) {}
void Run(Args... args) {
if (cb_)
std::move(cb_).Run(std::forward<Args>(args)...);
}
private:
base::OnceCallback<void(Args...)> cb_;
};
} // namespace internal
template <typename... Args>
base::RepeatingCallback<void(Args...)> AdaptCallbackForRepeating(
base::OnceCallback<void(Args...)> cb) {
using Holder = internal::OnceCallbackHolder<Args...>;
return base::BindRepeating(&Holder::Run,
std::make_unique<Holder>(std::move(cb)));
}
} // namespace electron
#endif // ELECTRON_SHELL_COMMON_CALLBACK_UTIL_H_

View File

@@ -8,6 +8,7 @@
#include <utility>
#include "base/functional/callback_helpers.h"
#include "shell/common/callback_util.h"
#include "shell/common/gin_helper/callback.h"
namespace gin {
@@ -41,7 +42,7 @@ struct Converter<base::OnceCallback<Sig>> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
base::OnceCallback<Sig> in) {
return gin::ConvertToV8(isolate,
base::AdaptCallbackForRepeating(std::move(in)));
electron::AdaptCallbackForRepeating(std::move(in)));
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,