refactor_restore_base_adaptcallbackforrepeating.patch 2.0 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/functional/callback_helpers.h b/base/functional/callback_helpers.h
  12. index a491f22076c16addeb4aa5ad21678164fc979991..ef50f9d2c5681d7d88cd9c07b07baa52fe338d09 100644
  13. --- a/base/functional/callback_helpers.h
  14. +++ b/base/functional/callback_helpers.h
  15. @@ -100,6 +100,22 @@ RepeatingCallback<void(Args...)> ForwardRepeatingCallbacks(
  16. std::move(v));
  17. }
  18. +// Wraps the given OnceCallback into a RepeatingCallback that relays its
  19. +// invocation to the original OnceCallback on the first invocation. The
  20. +// following invocations are just ignored.
  21. +//
  22. +// Note that this deliberately subverts the Once/Repeating paradigm of Callbacks
  23. +// but helps ease the migration from old-style Callbacks. Avoid if possible; use
  24. +// if necessary for migration. TODO(tzik): Remove it. https://crbug.com/730593
  25. +template <typename... Args>
  26. +RepeatingCallback<void(Args...)> AdaptCallbackForRepeating(
  27. + OnceCallback<void(Args...)> callback) {
  28. + using Helper = internal::OnceCallbackHolder<Args...>;
  29. + return base::BindRepeating(
  30. + &Helper::Run, std::make_unique<Helper>(std::move(callback),
  31. + /*ignore_extra_runs=*/true));
  32. +}
  33. +
  34. // Wraps the given OnceCallback and returns two OnceCallbacks with an identical
  35. // signature. On first invokation of either returned callbacks, the original
  36. // callback is invoked. Invoking the remaining callback results in a crash.