0

base: add DoNothingWithBoundArgs to help binding nothing callbacks

This helpers avoids having the user declare empty lambdas when the
only point is to bind some variables to the nothing callback. In case
the receiver changes the callback type, this will keep working as
intended and won't require the user to change its manually declared
nothing callback.

Change-Id: I65172225f35d4c038b876a4767fc212e269bf19e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3960233
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Paul Semel <paulsemel@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1062705}
This commit is contained in:
Paul Semel
2022-10-24 09:20:54 +00:00
committed by Chromium LUCI CQ
parent 37dd946057
commit 4c1e3e8e7b
56 changed files with 205 additions and 128 deletions
android_webview/browser/gfx
ash/wm/desks/templates
base
cc/tiles
chrome
components
leveldb_proto
nacl
policy
services
app_service
storage
content
extensions/browser
google_apis/common
media
remoting/host/it2me
services
third_party/blink/renderer/platform/widget/compositing

@ -21,6 +21,7 @@
#include "android_webview/browser/gfx/task_queue_webview.h"
#include "android_webview/browser/gfx/viz_compositor_thread_runner_webview.h"
#include "android_webview/common/aw_switches.h"
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
@ -382,7 +383,7 @@ HardwareRendererViz::~HardwareRendererViz() {
DCHECK_CALLED_ON_VALID_THREAD(render_thread_checker_);
output_surface_provider_.shared_context_state()->MakeCurrent(nullptr);
VizCompositorThreadRunnerWebView::GetInstance()->ScheduleOnVizAndBlock(
base::BindOnce([](std::unique_ptr<OnViz>) {}, std::move(on_viz_)));
base::DoNothingWithBoundArgs(std::move(on_viz_)));
}
bool HardwareRendererViz::IsUsingVulkan() const {

@ -26,6 +26,7 @@
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/overview/overview_grid.h"
#include "ash/wm/overview/overview_grid_event_handler.h"
#include "base/callback_helpers.h"
#include "base/notreached.h"
#include "ui/aura/window.h"
#include "ui/aura/window_targeter.h"
@ -416,8 +417,7 @@ void SavedDeskLibraryView::AnimateDeskLaunch(const base::GUID& uuid,
source_screen_bounds.height());
views::AnimationBuilder()
.OnEnded(base::BindOnce([](std::unique_ptr<ui::LayerTreeOwner>) {},
std::move(item_layer_tree)))
.OnEnded(base::DoNothingWithBoundArgs(std::move(item_layer_tree)))
.Once()
// Animating the desk item up to the desk bar.
.SetDuration(kSaveAndRecallLaunchMoveDuration)

@ -359,6 +359,7 @@ mixed_component("base") {
"functional/callback_helpers.h",
"functional/callback_internal.cc",
"functional/callback_internal.h",
"functional/callback_tags.h",
"functional/function_ref.h",
"functional/identity.h",
"functional/invoke.h",

@ -16,6 +16,7 @@
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h" // IWYU pragma: export
#include "base/functional/callback_internal.h"
#include "base/functional/callback_tags.h"
#include "base/functional/function_ref.h"
#include "base/notreached.h"
#include "base/types/always_false.h"
@ -58,15 +59,30 @@ namespace base {
namespace internal {
struct NullCallbackTag {
template <typename Signature>
struct WithSignature {};
};
struct DoNothingCallbackTag {
template <typename Signature>
struct WithSignature {};
};
template <bool is_once,
typename R,
typename... UnboundArgs,
typename... BoundArgs>
static std::conditional_t<is_once,
OnceCallback<R(UnboundArgs...)>,
RepeatingCallback<R(UnboundArgs...)>>
ToDoNothingCallback(DoNothingCallbackTag::WithBoundArguments<BoundArgs...> t) {
return std::apply(
[](auto&&... args) {
if constexpr (is_once) {
return base::BindOnce(
[](TransformToUnwrappedType<is_once, BoundArgs>...,
UnboundArgs...) {},
std::move(args)...);
} else {
return base::BindRepeating(
[](TransformToUnwrappedType<is_once, BoundArgs>...,
UnboundArgs...) {},
std::move(args)...);
}
},
std::move(t.bound_args));
}
} // namespace internal
@ -110,6 +126,18 @@ class OnceCallback<R(Args...)> : public internal::CallbackBase {
return *this;
}
template <typename... BoundArgs>
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr OnceCallback(
internal::DoNothingCallbackTag::WithBoundArguments<BoundArgs...> tag)
: OnceCallback(
internal::ToDoNothingCallback<true, R, Args...>(std::move(tag))) {}
template <typename... BoundArgs>
constexpr OnceCallback& operator=(
internal::DoNothingCallbackTag::WithBoundArguments<BoundArgs...> tag) {
*this = internal::ToDoNothingCallback<true, R, Args...>(std::move(tag));
}
explicit OnceCallback(internal::BindStateBase* bind_state)
: internal::CallbackBase(bind_state) {}
@ -240,6 +268,18 @@ class RepeatingCallback<R(Args...)> : public internal::CallbackBaseCopyable {
return *this;
}
template <typename... BoundArgs>
// NOLINTNEXTLINE(google-explicit-constructor)
constexpr RepeatingCallback(
internal::DoNothingCallbackTag::WithBoundArguments<BoundArgs...> tag)
: RepeatingCallback(
internal::ToDoNothingCallback<false, R, Args...>(std::move(tag))) {}
template <typename... BoundArgs>
constexpr RepeatingCallback& operator=(
internal::DoNothingCallbackTag::WithBoundArguments<BoundArgs...> tag) {
*this = internal::ToDoNothingCallback<false, R, Args...>(std::move(tag));
}
explicit RepeatingCallback(internal::BindStateBase* bind_state)
: internal::CallbackBaseCopyable(bind_state) {}

@ -20,6 +20,7 @@
#include "base/check.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_tags.h"
namespace base {
@ -196,6 +197,20 @@ constexpr auto DoNothingAs() {
return internal::DoNothingCallbackTag::WithSignature<Signature>();
}
// Similar to DoNothing above, but with bound arguments. This helper is useful
// for keeping objects alive until the callback runs.
// Example:
//
// void F(base::OnceCallback<void(int)> result_callback);
//
// std::unique_ptr<MyClass> ptr;
// F(base::DoNothingWithBoundArgs(std::move(ptr)));
template <typename... Args>
constexpr auto DoNothingWithBoundArgs(Args&&... args) {
return internal::DoNothingCallbackTag::WithBoundArguments(
std::forward<Args>(args)...);
}
// Useful for creating a Closure that will delete a pointer when invoked. Only
// use this when necessary. In most cases MessageLoop::DeleteSoon() is a better
// fit.

@ -0,0 +1,34 @@
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This defines helpful tags for dealing with Callbacks. Those tags can be used
// to construct special callbacks. This lives in its own file to avoid circular
// dependencies.
#ifndef BASE_FUNCTIONAL_CALLBACK_TAGS_H_
#define BASE_FUNCTIONAL_CALLBACK_TAGS_H_
namespace base::internal {
struct NullCallbackTag {
template <typename Signature>
struct WithSignature {};
};
struct DoNothingCallbackTag {
template <typename Signature>
struct WithSignature {};
template <typename... BoundArgs>
struct WithBoundArguments {
std::tuple<BoundArgs...> bound_args;
constexpr explicit WithBoundArguments(BoundArgs... args)
: bound_args(std::forward<BoundArgs>(args)...) {}
};
};
} // namespace base::internal
#endif // BASE_FUNCTIONAL_CALLBACK_TAGS_H_

@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/callback_helpers.h"
#include "base/gtest_prod_util.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
@ -81,8 +82,7 @@ TEST_F(SequencedTaskRunnerTest, OnTaskRunnerDeleterOnMainThread) {
SequencedTaskRunner::GetCurrentDefault()),
OnTaskRunnerDeleter(SequencedTaskRunner::GetCurrentDefault()));
EXPECT_FALSE(deleted_on_main_thread);
foreign_runner_->PostTask(
FROM_HERE, BindOnce([](SequenceBoundUniquePtr) {}, std::move(ptr)));
foreign_runner_->PostTask(FROM_HERE, DoNothingWithBoundArgs(std::move(ptr)));
{
RunLoop run_loop;

@ -2140,8 +2140,8 @@ class PostTaskOnDestroy {
static void PostTaskWithPostingDestructor(int times) {
if (times > 0) {
ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, BindOnce([](std::unique_ptr<PostTaskOnDestroy>) {},
std::make_unique<PostTaskOnDestroy>(times - 1)));
FROM_HERE, DoNothingWithBoundArgs(
std::make_unique<PostTaskOnDestroy>(times - 1)));
}
}

@ -7,6 +7,7 @@
#include <utility>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/feature_list.h"
#include "base/task/task_traits.h"
#include "base/trace_event/trace_event.h"
@ -34,8 +35,7 @@ ImageController::~ImageController() {
// Delete `worker_state_` on `worker_task_runner_` (or elsewhere via the
// callback's destructor if `worker_task_runner_` stopped accepting tasks).
worker_task_runner_->PostTask(
FROM_HERE, base::BindOnce([](std::unique_ptr<WorkerState>) {},
std::move(worker_state_)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(worker_state_)));
}
}

@ -8,6 +8,7 @@
#include <utility>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/files/file_util.h"
#include "base/strings/string_piece.h"
#include "base/task/task_runner_util.h"
@ -64,8 +65,8 @@ FileStreamForwarder::~FileStreamForwarder() {
if (!callback_.is_null()) // Aborted before completion.
NotifyCompleted(false);
// Use the task runner to close the FD.
task_runner_->PostTask(
FROM_HERE, base::BindOnce([](base::ScopedFD fd) {}, std::move(fd_dest_)));
task_runner_->PostTask(FROM_HERE,
base::DoNothingWithBoundArgs(std::move(fd_dest_)));
}
void FileStreamForwarder::DestroyOnIOThread() {

@ -221,8 +221,7 @@ void DelayedRecordProcessorMetrics() {
LaunchProcessorMetricsService();
auto* remote_util_win_ptr = remote_util_win.get();
remote_util_win_ptr->RecordProcessorMetrics(
base::BindOnce([](mojo::Remote<chrome::mojom::ProcessorMetrics>) {},
std::move(remote_util_win)));
base::DoNothingWithBoundArgs(std::move(remote_util_win)));
}
// Initializes the ModuleDatabase on its owning sequence. Also starts the

@ -6,6 +6,7 @@
#include "ash/constants/ash_features.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/thread_pool.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
@ -79,9 +80,7 @@ MetricProvider::MetricProvider(std::unique_ptr<MetricCollector> collector,
MetricProvider::~MetricProvider() {
// Destroy the metric_collector_ on the collector sequence.
collector_task_runner_->PostTask(
FROM_HERE,
base::BindOnce([](std::unique_ptr<MetricCollector> collector_) {},
std::move(metric_collector_)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(metric_collector_)));
}
void MetricProvider::Init() {

@ -119,9 +119,7 @@ class AccountReconcilorLockWrapper
void DestroyAfterDelay() {
// TODO(dcheng): Should ReleaseSoon() support this use case?
content::GetUIThreadTaskRunner({})->PostDelayedTask(
FROM_HERE,
base::BindOnce([](scoped_refptr<AccountReconcilorLockWrapper>) {},
base::RetainedRef(this)),
FROM_HERE, base::DoNothingWithBoundArgs(base::RetainedRef(this)),
base::Milliseconds(g_dice_account_reconcilor_blocked_delay_ms));
}

@ -1035,10 +1035,9 @@ STDMETHODIMP PolicyStatusImpl::refreshPolicies() {
scoped_refptr<ComServerApp> com_server = AppServerSingletonInstance();
com_server->main_task_runner()->PostTask(
FROM_HERE,
base::BindOnce(
&UpdateService::FetchPolicies, com_server->update_service(),
base::BindOnce([](PolicyStatusImplPtr /* obj */, int /* result */) {},
PolicyStatusImplPtr(this))));
base::BindOnce(&UpdateService::FetchPolicies,
com_server->update_service(),
base::DoNothingWithBoundArgs(PolicyStatusImplPtr(this))));
return S_OK;
}

@ -473,8 +473,7 @@ void SharedProtoDatabase::OnDatabaseInit(bool create_if_missing,
// Hold on to shared db until the remove operation is done or Shutdown()
// clears the task.
Callbacks::UpdateCallback keep_shared_db_alive =
base::BindOnce([](scoped_refptr<SharedProtoDatabase>, bool) {},
base::WrapRefCounted<>(this));
base::DoNothingWithBoundArgs(base::WrapRefCounted<>(this));
delete_obsolete_task_.Reset(base::BindOnce(
&SharedProtoDatabase::DestroyObsoleteSharedProtoDatabaseClients, this,
std::move(keep_shared_db_alive)));

@ -8,6 +8,7 @@
#include <utility>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/debug/leak_annotations.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
@ -31,11 +32,10 @@ static const base::FilePath::CharType kTranslationCacheDirectoryName[] =
static const int kTranslationCacheInitializationDelayMs = 20;
void CloseBaseFile(base::File file) {
base::ThreadPool::PostTask(
FROM_HERE,
{base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
base::BindOnce([](base::File) {}, std::move(file)));
base::ThreadPool::PostTask(FROM_HERE,
{base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
base::DoNothingWithBoundArgs(std::move(file)));
}
} // namespace

@ -7,6 +7,7 @@
#include <utility>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/check_op.h"
#include "base/location.h"
#include "base/task/sequenced_task_runner.h"
@ -271,7 +272,7 @@ void ExternalPolicyDataFetcher::CancelJob(Job* job) {
// OnJobFinished() callback may still be pending for the canceled |job|.
job_task_runner_->PostTaskAndReply(
FROM_HERE, base::BindOnce(&Job::Cancel, base::Unretained(job)),
base::BindOnce([](Job*) {}, base::Owned(job)));
base::DoNothingWithBoundArgs(base::Owned(job)));
}
void ExternalPolicyDataFetcher::OnJobFinished(

@ -9,6 +9,7 @@
#include <vector>
#include "base/callback.h"
#include "base/callback_helpers.h"
#include "components/services/app_service/public/cpp/app_types.h"
#include "components/services/app_service/public/cpp/icon_types.h"
@ -143,8 +144,7 @@ std::unique_ptr<IconLoader::Releaser> IconCoalescer::LoadIconFromIconKey(
// The callback does nothing explicitly, but after it runs, it implicitly
// decrements the scoped_refptr's shared reference count, and therefore
// possibly deletes the underlying IconLoader::Releaser.
base::BindOnce([](scoped_refptr<RefCountedReleaser>) {},
std::move(shared_releaser)));
base::DoNothingWithBoundArgs(std::move(shared_releaser)));
}
void IconCoalescer::OnLoadIcon(IconLoader::Key key,

@ -71,7 +71,7 @@ class BarrierBuilder {
BarrierBuilder& operator=(const BarrierBuilder&) = delete;
base::OnceClosure AddClosure() {
return base::BindOnce([](scoped_refptr<ContinuationRef>) {}, continuation_);
return base::DoNothingWithBoundArgs(continuation_);
}
private:

@ -10,6 +10,7 @@
#include <utility>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/compiler_specific.h"
#include "base/files/file_util.h"
#include "base/guid.h"
@ -228,7 +229,7 @@ void TerminateOnUI(std::unique_ptr<base::Thread> thread,
base::ThreadPool::PostTask(
FROM_HERE,
{base::WithBaseSyncPrimitives(), base::TaskPriority::BEST_EFFORT},
BindOnce([](std::unique_ptr<base::Thread>) {}, std::move(thread)));
DoNothingWithBoundArgs(std::move(thread)));
}
}

@ -7,6 +7,7 @@
#include <utility>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/check_op.h"
#include "base/containers/cxx20_erase.h"
#include "base/location.h"
@ -239,8 +240,7 @@ ForwardingAudioStreamFactory::~ForwardingAudioStreamFactory() {
// causes issues in unit tests where the UI thread and the IO thread are the
// same.
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce([](std::unique_ptr<Core>) {}, std::move(core_)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(core_)));
}
void ForwardingAudioStreamFactory::LoopbackStreamStarted() {

@ -9,6 +9,7 @@
#include <utility>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
@ -99,9 +100,7 @@ KeepAliveHandleFactory::~KeepAliveHandleFactory() {
// Extend the lifetime of `context_` a bit. Note that `context_` has an
// ability to extend the lifetime of the associated render process.
GetUIThreadTaskRunner({})->PostDelayedTask(
FROM_HERE,
base::BindOnce([](std::unique_ptr<Context>) {}, std::move(context_)),
timeout_);
FROM_HERE, base::DoNothingWithBoundArgs(std::move(context_)), timeout_);
}
void KeepAliveHandleFactory::Bind(

@ -4,6 +4,7 @@
#include "content/browser/renderer_host/media/aec_dump_manager_impl.h"
#include "base/callback_helpers.h"
#include "base/files/file.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/thread_pool.h"
@ -89,9 +90,9 @@ void AecDumpManagerImpl::StartDump(int id, base::File file) {
auto it = agents_.find(id);
if (it == agents_.end()) {
// Post the file close to avoid blocking the current thread.
base::ThreadPool::PostTask(
FROM_HERE, {base::TaskPriority::LOWEST, base::MayBlock()},
base::BindOnce([](base::File) {}, std::move(file)));
base::ThreadPool::PostTask(FROM_HERE,
{base::TaskPriority::LOWEST, base::MayBlock()},
base::DoNothingWithBoundArgs(std::move(file)));
return;
}

@ -8,6 +8,7 @@
#include "base/bind.h"
#include "base/callback_forward.h"
#include "base/callback_helpers.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/bind_post_task.h"
#include "base/token.h"
@ -49,10 +50,8 @@ InProcessLaunchedVideoCaptureDevice::~InProcessLaunchedVideoCaptureDevice() {
media::VideoCaptureDevice* device_ptr = device_.release();
device_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&StopAndReleaseDeviceOnDeviceThread, device_ptr,
base::BindOnce([](scoped_refptr<base::SingleThreadTaskRunner>) {},
device_task_runner_)));
base::BindOnce(&StopAndReleaseDeviceOnDeviceThread, device_ptr,
base::DoNothingWithBoundArgs(device_task_runner_)));
}
void InProcessLaunchedVideoCaptureDevice::GetPhotoState(

@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/callback_helpers.h"
#include "base/check_op.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
@ -178,8 +179,7 @@ RenderFrameAudioInputStreamFactory::~RenderFrameAudioInputStreamFactory() {
// causes issues in unit tests where the UI thread and the IO thread are the
// same.
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce([](std::unique_ptr<Core>) {}, std::move(core_)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(core_)));
}
RenderFrameAudioInputStreamFactory::Core::Core(

@ -12,6 +12,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/callback_helpers.h"
#include "base/check_op.h"
#include "base/containers/flat_set.h"
#include "base/containers/unique_ptr_adapters.h"
@ -258,8 +259,7 @@ RenderFrameAudioOutputStreamFactory::~RenderFrameAudioOutputStreamFactory() {
// causes issues in unit tests where the UI thread and the IO thread are the
// same.
GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce([](std::unique_ptr<Core>) {}, std::move(core_)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(core_)));
}
void RenderFrameAudioOutputStreamFactory::

@ -272,8 +272,7 @@ void VideoCaptureManager::DoStopDevice(VideoCaptureController* controller) {
// ReleaseDeviceAsnyc() is executing, we pass it shared ownership to
// |controller|.
controller->ReleaseDeviceAsync(
base::BindOnce([](scoped_refptr<VideoCaptureController>) {},
GetControllerSharedRef(controller)));
base::DoNothingWithBoundArgs(GetControllerSharedRef(controller)));
}
void VideoCaptureManager::ProcessDeviceStartRequestQueue() {
@ -657,8 +656,7 @@ void VideoCaptureManager::MaybePostDesktopCaptureWindowId(
existing_device->SetDesktopCaptureWindowIdAsync(
window_id_it->second,
base::BindOnce([](scoped_refptr<VideoCaptureManager>) {},
scoped_refptr<VideoCaptureManager>(this)));
base::DoNothingWithBoundArgs(scoped_refptr<VideoCaptureManager>(this)));
notification_window_ids_.erase(window_id_it);
}

@ -13,6 +13,7 @@
#include "base/base_switches.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/clang_profiling_buildflags.h"
#include "base/command_line.h"
#include "base/debug/alias.h"
@ -782,8 +783,7 @@ ChildThreadImpl::~ChildThreadImpl() {
void ChildThreadImpl::Shutdown() {
// Ensure that our IOThreadState's last ref goes away on the IO thread.
ChildThreadImpl::GetIOTaskRunner()->PostTask(
FROM_HERE, base::BindOnce([](scoped_refptr<IOThreadState>) {},
std::move(io_thread_state_)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(io_thread_state_)));
}
bool ChildThreadImpl::ShouldBeDestroyed() {

@ -7,6 +7,7 @@
#include <memory>
#include "base/barrier_closure.h"
#include "base/callback_helpers.h"
#include "base/memory/ref_counted.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/shared_cors_origin_access_list.h"
@ -36,8 +37,7 @@ void CorsOriginPatternSetter::SetForStoragePartition(
partition->GetNetworkContext()->SetCorsOriginAccessListsForOrigin(
source_origin_, mojo::Clone(allow_patterns_),
mojo::Clone(block_patterns_),
base::BindOnce([](scoped_refptr<CorsOriginPatternSetter> setter) {},
base::RetainedRef(this)));
base::DoNothingWithBoundArgs(base::RetainedRef(this)));
}
// static

@ -4,6 +4,7 @@
#include "content/public/test/web_transport_simple_test_server.h"
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h"
@ -25,9 +26,7 @@ WebTransportSimpleTestServer::WebTransportSimpleTestServer() {
WebTransportSimpleTestServer::~WebTransportSimpleTestServer() {
server_thread_->task_runner()->PostTask(
FROM_HERE,
base::BindOnce([](std::unique_ptr<net::QuicSimpleServer> server) {},
std::move(server_)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(server_)));
base::ScopedAllowBaseSyncPrimitivesForTesting allow_wait_for_thread_join;
server_thread_.reset();

@ -11,6 +11,7 @@
#include <string>
#include <utility>
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/location.h"
#include "base/no_destructor.h"
@ -674,8 +675,7 @@ void Shell::UpdateInspectedWebContentsIfNecessary(
for (auto* shell_devtools_bindings :
ShellDevToolsBindings::GetInstancesForWebContents(old_contents)) {
shell_devtools_bindings->UpdateInspectedWebContents(
new_contents, base::BindOnce([](scoped_refptr<PendingCallback>) {},
pending_callback));
new_contents, base::DoNothingWithBoundArgs(pending_callback));
}
}

@ -493,8 +493,7 @@ void ContentVerifier::GetContentHash(
// pointer to fix this. Also add unit test to exercise this code path
// explicitly.
content::GetIOThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce([](ContentHashCallback) {}, std::move(callback)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(callback)));
return;
}

@ -11,6 +11,7 @@
#include <utility>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h"
@ -262,8 +263,7 @@ UrlFetchRequestBase::DownloadData::DownloadData(
UrlFetchRequestBase::DownloadData::~DownloadData() {
if (output_file.IsValid()) {
blocking_task_runner_->PostTask(
FROM_HERE,
base::BindOnce([](base::File file) {}, std::move(output_file)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(output_file)));
}
}
@ -341,8 +341,7 @@ void UrlFetchRequestBase::OnComplete(bool success) {
DCHECK(download_data_);
blocking_task_runner()->PostTaskAndReply(
FROM_HERE,
base::BindOnce([](base::File file) {},
std::move(download_data_->output_file)),
base::DoNothingWithBoundArgs(std::move(download_data_->output_file)),
base::BindOnce(&UrlFetchRequestBase::OnOutputFileClosed,
weak_ptr_factory_.GetWeakPtr(), success));
}

@ -5,6 +5,7 @@
#include "media/audio/aecdump_recording_manager.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "media/audio/audio_manager.h"
@ -14,9 +15,9 @@ namespace {
void CloseFileWithoutBlocking(base::File file) {
// Post as a low-priority task to a thread pool to avoid blocking the
// current thread.
base::ThreadPool::PostTask(
FROM_HERE, {base::TaskPriority::LOWEST, base::MayBlock()},
base::BindOnce([](base::File) {}, std::move(file)));
base::ThreadPool::PostTask(FROM_HERE,
{base::TaskPriority::LOWEST, base::MayBlock()},
base::DoNothingWithBoundArgs(std::move(file)));
}
} // namespace

@ -5,6 +5,7 @@
#include "media/audio/android/aaudio_output.h"
#include "base/android/build_info.h"
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/thread_annotations.h"
@ -136,9 +137,7 @@ AAudioOutputStream::~AAudioOutputStream() {
// Keep |destruction_helper_| alive longer than |this|, so the |user_data|
// bound to the callback stays valid, until the callbacks stop.
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce([](std::unique_ptr<AAudioDestructionHelper>) {},
std::move(destruction_helper_)),
FROM_HERE, base::DoNothingWithBoundArgs(std::move(destruction_helper_)),
base::Seconds(1));
}

@ -6,6 +6,7 @@
#include <cmath>
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "media/base/audio_bus.h"
@ -320,7 +321,7 @@ std::unique_ptr<AudioBus> AudioBuffer::WrapOrCopyToAudioBus(
// Keep |buffer| alive as long as |audio_bus|.
audio_bus->SetWrappedDataDeleter(
base::BindOnce([](scoped_refptr<AudioBuffer>) {}, std::move(buffer)));
base::DoNothingWithBoundArgs(std::move(buffer)));
return audio_bus;
}

@ -15,6 +15,7 @@
#include "base/atomic_sequence_num.h"
#include "base/bind.h"
#include "base/bits.h"
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/process/memory.h"
#include "base/strings/string_piece.h"
@ -906,8 +907,7 @@ scoped_refptr<VideoFrame> VideoFrame::WrapVideoFrame(
// observers which signal that the underlying resource is okay to reuse. E.g.,
// VideoFramePool.
if (frame->wrapped_frame_) {
wrapping_frame->AddDestructionObserver(
base::BindOnce([](scoped_refptr<VideoFrame>) {}, frame));
wrapping_frame->AddDestructionObserver(base::DoNothingWithBoundArgs(frame));
frame = frame->wrapped_frame_;
}

@ -1117,7 +1117,7 @@ scoped_refptr<VideoFrame> CreateFromSkImage(sk_sp<SkImage> sk_image,
return nullptr;
frame->AddDestructionObserver(
base::BindOnce([](sk_sp<SkImage>) {}, std::move(sk_image)));
base::DoNothingWithBoundArgs(std::move(sk_image)));
return frame;
}

@ -17,6 +17,7 @@
#endif
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/read_only_shared_memory_region.h"
@ -757,8 +758,7 @@ void ExternalVideoEncoder::DestroyClientSoon() {
// reference to it within an encoder task.
if (client_) {
client_->task_runner()->PostTask(
FROM_HERE, base::BindOnce([](scoped_refptr<VEAClientImpl> client) {},
std::move(client_)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(client_)));
}
}

@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/bits.h"
#include "base/callback.h"
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/threading/sequenced_task_runner_handle.h"
@ -362,8 +363,7 @@ bool Dav1dVideoDecoder::DecodeBuffer(scoped_refptr<DecoderBuffer> buffer) {
// When we use bind mode, our image data is dependent on the Dav1dPicture,
// so we must ensure it stays alive along enough.
frame->AddDestructionObserver(
base::BindOnce([](ScopedPtrDav1dPicture) {}, std::move(p)));
frame->AddDestructionObserver(base::DoNothingWithBoundArgs(std::move(p)));
output_cb_.Run(std::move(frame));
}

@ -5,6 +5,7 @@
#include "media/gpu/chromeos/mailbox_video_frame_converter.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/containers/contains.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
@ -109,7 +110,7 @@ class GpuDelegateImpl : public MailboxVideoFrameConverter::GpuDelegate {
DCHECK(shared_image_stub);
auto keep_video_frame_alive =
base::BindOnce([](scoped_refptr<VideoFrame>) {}, std::move(frame));
base::DoNothingWithBoundArgs(std::move(frame));
auto* scheduler = gpu_channel_->scheduler();
DCHECK(scheduler);
scheduler->ScheduleTask(gpu::Scheduler::Task(

@ -2343,8 +2343,7 @@ void V4L2SliceVideoDecodeAccelerator::FrameProcessed(
base::Unretained(this), decoded_buffer));
// This holds the IP video frame until everyone is done with it
surface->SetReleaseCallback(
base::BindOnce([](scoped_refptr<VideoFrame> frame) {}, frame));
surface->SetReleaseCallback(base::DoNothingWithBoundArgs(frame));
DCHECK_EQ(decoded_buffer_map_.count(decoded_buffer->BufferId()), 0u);
decoded_buffer_map_.emplace(decoded_buffer->BufferId(), ip_buffer_index);
surface->SetDecoded();

@ -1412,8 +1412,8 @@ bool V4L2VideoEncodeAccelerator::EnqueueInputRecord(
NOTIFY_ERROR(kPlatformFailureError);
return false;
}
frame->AddDestructionObserver(base::BindOnce([](std::vector<uint8_t>) {},
std::move(writable_buffer)));
frame->AddDestructionObserver(
base::DoNothingWithBoundArgs(std::move(writable_buffer)));
break;
}
case V4L2_MEMORY_DMABUF: {

@ -135,7 +135,7 @@ scoped_refptr<VideoFrame> CreateMappedVideoFrame(
DeallocateBuffers, std::move(va_image), std::move(src_video_frame)));
for (auto&& buffer : p016le_buffers) {
video_frame->AddDestructionObserver(
base::BindOnce([](std::unique_ptr<uint16_t[]>) {}, std::move(buffer)));
base::DoNothingWithBoundArgs(std::move(buffer)));
}
return video_frame;
}

@ -7,6 +7,7 @@
#include <utility>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
@ -173,8 +174,7 @@ void MojoVideoEncodeAccelerator::Encode(scoped_refptr<VideoFrame> frame,
return;
}
vea_->Encode(frame, force_keyframe,
base::BindOnce([](scoped_refptr<VideoFrame>) {}, frame));
vea_->Encode(frame, force_keyframe, base::DoNothingWithBoundArgs(frame));
}
void MojoVideoEncodeAccelerator::UseOutputBitstreamBuffer(

@ -9,6 +9,7 @@
#include "base/barrier_closure.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
@ -300,8 +301,7 @@ void SynchronizeVideoFrameRead(scoped_refptr<VideoFrame> video_frame,
gl->EndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM);
// |on_query_done_cb| will keep |video_frame| alive.
auto on_query_done_cb =
base::BindOnce([](scoped_refptr<VideoFrame> video_frame) {}, video_frame);
auto on_query_done_cb = base::DoNothingWithBoundArgs(video_frame);
context_support->SignalQuery(query_id, std::move(on_query_done_cb));
// Delete the query immediately. This will cause |on_query_done_cb| to be

@ -4,6 +4,7 @@
#include "media/video/renderable_gpu_memory_buffer_video_frame_pool.h"
#include "base/callback_helpers.h"
#include "base/memory/weak_ptr.h"
#include "base/task/thread_pool.h"
#include "base/test/bind.h"
@ -230,8 +231,7 @@ TEST(RenderableGpuMemoryBufferVideoFramePool,
// Destroy frames on separate threads. TSAN will tell us if there's a problem.
for (int i = 0; i < kNumFrames; i++) {
base::ThreadPool::CreateSequencedTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce([](scoped_refptr<VideoFrame> video_frame0) {},
std::move(frames[i])));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(frames[i])));
}
pool.reset();
@ -256,8 +256,7 @@ TEST(RenderableGpuMemoryBufferVideoFramePool, ConcurrentCreateDestroy) {
// Destroy the frame on another thread. TSAN will tell us if there's a
// problem.
base::ThreadPool::CreateSequencedTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce([](scoped_refptr<VideoFrame> video_frame0) {},
std::move(video_frame0)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(video_frame0)));
// Create another frame on the main thread.
auto video_frame1 = pool->MaybeCreateVideoFrame(size0, color_space0);

@ -987,8 +987,7 @@ VideoEncodeAcceleratorAdapter::PrepareCpuFrame(
shared_frame->BackWithSharedMemory(handle->region());
shared_frame->AddDestructionObserver(
base::BindOnce([](std::unique_ptr<ReadOnlyRegionPool::Handle> handle) {},
std::move(handle)));
base::DoNothingWithBoundArgs(std::move(handle)));
return shared_frame;
}

@ -13,6 +13,7 @@
#include <memory>
#include <utility>
#include "base/callback_helpers.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
@ -369,7 +370,7 @@ void AudioProcessor::OnStartDump(base::File dump_file) {
// Post the file close to avoid blocking the control sequence.
base::ThreadPool::PostTask(
FROM_HERE, {base::TaskPriority::LOWEST, base::MayBlock()},
base::BindOnce([](base::File) {}, std::move(dump_file)));
base::DoNothingWithBoundArgs(std::move(dump_file)));
}
}

@ -630,9 +630,7 @@ void It2MeHost::DisconnectOnNetworkThread(protocol::ErrorCode error_code) {
// other end of the connection can display and log an accurate disconnect
// reason.
host_context_->network_task_runner()->PostDelayedTask(
FROM_HERE,
base::BindOnce([](std::unique_ptr<SignalStrategy> signaling) {},
std::move(signal_strategy_)),
FROM_HERE, base::DoNothingWithBoundArgs(std::move(signal_strategy_)),
kDestroySignalingDelay);
}

@ -12,6 +12,7 @@
#include <vector>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/containers/contains.h"
#include "base/location.h"
#include "base/memory/ref_counted_memory.h"
@ -862,8 +863,7 @@ UsbDeviceHandleImpl::~UsbDeviceHandleImpl() {
handle_.Reset();
} else {
blocking_task_runner_->PostTask(
FROM_HERE,
base::BindOnce([](ScopedLibusbDeviceHandle) {}, std::move(handle_)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(handle_)));
}
}

@ -218,8 +218,7 @@ void UsbDeviceHandleWin::Close() {
// this runner which will close it on completion. This is guaranteed to run
// after any queued operations have completed.
blocking_task_runner_->PostTask(
FROM_HERE,
base::BindOnce([](base::win::ScopedHandle) {}, std::move(hub_handle_)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(hub_handle_)));
}
for (auto& map_entry : interfaces_) {

@ -11,6 +11,7 @@
#include <vector>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/containers/fixed_flat_set.h"
#include "base/debug/alias.h"
@ -760,8 +761,7 @@ class URLLoader::FileOpenerForUpload {
static void PostCloseFiles(std::vector<base::File> opened_files) {
base::ThreadPool::PostTask(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING},
base::BindOnce([](std::vector<base::File>) {},
std::move(opened_files)));
base::DoNothingWithBoundArgs(std::move(opened_files)));
}
void StartOpeningNextBatch() {

@ -489,9 +489,7 @@ void ContextProviderCommandBuffer::OnLostContext() {
// be weak references in use further up the stack. This task is posted to
// ensure that destruction is deferred until it's safe.
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce([](scoped_refptr<ContextProviderCommandBuffer>) {},
base::WrapRefCounted(this)));
FROM_HERE, base::DoNothingWithBoundArgs(base::WrapRefCounted(this)));
for (auto& observer : observers_)
observer.OnContextLost();

@ -4,6 +4,7 @@
#include "third_party/blink/renderer/platform/widget/compositing/queue_report_time_swap_promise.h"
#include "base/callback_helpers.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_ANDROID)
@ -56,9 +57,8 @@ QueueReportTimeSwapPromise::~QueueReportTimeSwapPromise() {
if (compositor_task_runner_ && (drain_callback_ || swap_callback_)) {
DCHECK(!compositor_task_runner_->BelongsToCurrentThread());
compositor_task_runner_->PostTask(
FROM_HERE,
base::BindOnce([](DrainCallback, base::OnceClosure) {},
std::move(drain_callback_), std::move(swap_callback_)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(drain_callback_),
std::move(swap_callback_)));
}
}

@ -4,6 +4,7 @@
#include "third_party/blink/renderer/platform/widget/compositing/widget_compositor.h"
#include "base/callback_helpers.h"
#include "cc/trees/layer_tree_host.h"
#include "third_party/blink/renderer/platform/widget/compositing/queue_report_time_swap_promise.h"
#include "third_party/blink/renderer/platform/widget/widget_base.h"
@ -106,9 +107,8 @@ void WidgetCompositor::CreateQueueSwapPromise(
} else if (compositor_task_runner_) {
// Delete callbacks on the compositor thread.
compositor_task_runner_->PostTask(
FROM_HERE,
base::BindOnce([](base::OnceCallback<void(int)>, base::OnceClosure) {},
std::move(drain_callback), std::move(swap_callback)));
FROM_HERE, base::DoNothingWithBoundArgs(std::move(drain_callback),
std::move(swap_callback)));
}
}