refactor_restore_base_adaptcallbackforrepeating.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Charles Kerr <[email protected]>
  3. Date: Wed, 9 Jun 2021 14:28:08 -0500
  4. Subject: refactor: restore base::AdaptCallbackForRepeating
  5. Undo https://chromium-review.googlesource.com/c/chromium/src/+/2941842
  6. to reinstate base::AdaptCallbackForRepeating(). It was removed to fix
  7. https://bugs.chromium.org/p/chromium/issues/detail?id=730593 .
  8. We use AdaptCallbackForRepeating() in about a dozen places. This patch
  9. should be removed as soon as those have been updated. Patching because
  10. every instance is a FTBFS that prevents testing any one instance's fix.
  11. diff --git a/base/callback_helpers.h b/base/callback_helpers.h
  12. index 046130ff8cbc4945e94a4ee71ac6320b4f7c5369..c71c3e1720b3f4c7b7362d99957cd2479bf88a37 100644
  13. --- a/base/callback_helpers.h
  14. +++ b/base/callback_helpers.h
  15. @@ -94,6 +94,22 @@ class OnceCallbackHolder final {
  16. } // namespace internal
  17. +// Wraps the given OnceCallback into a RepeatingCallback that relays its
  18. +// invocation to the original OnceCallback on the first invocation. The
  19. +// following invocations are just ignored.
  20. +//
  21. +// Note that this deliberately subverts the Once/Repeating paradigm of Callbacks
  22. +// but helps ease the migration from old-style Callbacks. Avoid if possible; use
  23. +// if necessary for migration. TODO(tzik): Remove it. https://crbug.com/730593
  24. +template <typename... Args>
  25. +RepeatingCallback<void(Args...)> AdaptCallbackForRepeating(
  26. + OnceCallback<void(Args...)> callback) {
  27. + using Helper = internal::OnceCallbackHolder<Args...>;
  28. + return base::BindRepeating(
  29. + &Helper::Run, std::make_unique<Helper>(std::move(callback),
  30. + /*ignore_extra_runs=*/true));
  31. +}
  32. +
  33. // Wraps the given OnceCallback and returns two OnceCallbacks with an identical
  34. // signature. On first invokation of either returned callbacks, the original
  35. // callback is invoked. Invoking the remaining callback results in a crash.