Commit 6bfb082b authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

[🧹] Remove base::ResetAndReturn.

Bug: 841899
Tbr: thestig@chromium.org
Change-Id: I972785b8f6c189039c56049a8c132b7bf4c69876
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1584531
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#656276}
parent f989cad7
...@@ -50,16 +50,6 @@ template <template <typename> class CallbackType> ...@@ -50,16 +50,6 @@ template <template <typename> class CallbackType>
using EnableIfIsBaseCallback = using EnableIfIsBaseCallback =
std::enable_if_t<IsBaseCallback<CallbackType<void()>>::value>; std::enable_if_t<IsBaseCallback<CallbackType<void()>>::value>;
// Prefer std::move() over ResetAndReturn().
template <template <typename> class CallbackType,
typename RunType,
typename = EnableIfIsBaseCallback<CallbackType>>
CallbackType<RunType> ResetAndReturn(CallbackType<RunType>* cb) {
auto ret = std::move(*cb);
DCHECK(!*cb);
return ret;
}
namespace internal { namespace internal {
template <typename... Args> template <typename... Args>
......
...@@ -47,24 +47,6 @@ void Increment(int* value) { ...@@ -47,24 +47,6 @@ void Increment(int* value) {
(*value)++; (*value)++;
} }
TEST(CallbackHelpersTest, TestResetAndReturn) {
int run_count = 0;
base::Closure cb = base::Bind(&Increment, &run_count);
EXPECT_EQ(0, run_count);
base::ResetAndReturn(&cb).Run();
EXPECT_EQ(1, run_count);
EXPECT_FALSE(cb);
run_count = 0;
base::OnceClosure cb2 = base::BindOnce(&Increment, &run_count);
EXPECT_EQ(0, run_count);
base::ResetAndReturn(&cb2).Run();
EXPECT_EQ(1, run_count);
EXPECT_FALSE(cb2);
}
TEST(CallbackHelpersTest, TestScopedClosureRunnerExitScope) { TEST(CallbackHelpersTest, TestScopedClosureRunnerExitScope) {
int run_count = 0; int run_count = 0;
{ {
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/callback_internal.h" #include "base/callback_internal.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/test/test_timeouts.h" #include "base/test/test_timeouts.h"
...@@ -122,43 +121,25 @@ TEST_F(CallbackTest, Move) { ...@@ -122,43 +121,25 @@ TEST_F(CallbackTest, Move) {
EXPECT_EQ(callback_a_, null_callback_); EXPECT_EQ(callback_a_, null_callback_);
} }
struct TestForReentrancy {
TestForReentrancy()
: cb_already_run(false),
cb(BindRepeating(&TestForReentrancy::AssertCBIsNull,
Unretained(this))) {}
void AssertCBIsNull() {
ASSERT_TRUE(cb.is_null());
cb_already_run = true;
}
bool cb_already_run;
RepeatingClosure cb;
};
TEST_F(CallbackTest, ResetAndReturn) {
TestForReentrancy tfr;
ASSERT_FALSE(tfr.cb.is_null());
ASSERT_FALSE(tfr.cb_already_run);
ResetAndReturn(&tfr.cb).Run();
ASSERT_TRUE(tfr.cb.is_null());
ASSERT_TRUE(tfr.cb_already_run);
}
TEST_F(CallbackTest, NullAfterMoveRun) { TEST_F(CallbackTest, NullAfterMoveRun) {
RepeatingClosure cb = BindRepeating([] {}); RepeatingCallback<void(void*)> cb = BindRepeating([](void* param) {
EXPECT_TRUE(static_cast<RepeatingCallback<void(void*)>*>(param)->is_null());
});
ASSERT_TRUE(cb); ASSERT_TRUE(cb);
std::move(cb).Run(); std::move(cb).Run(&cb);
ASSERT_FALSE(cb); EXPECT_FALSE(cb);
const RepeatingClosure cb2 = BindRepeating([] {}); const RepeatingClosure cb2 = BindRepeating([] {});
ASSERT_TRUE(cb2); ASSERT_TRUE(cb2);
std::move(cb2).Run(); std::move(cb2).Run();
ASSERT_TRUE(cb2); EXPECT_TRUE(cb2);
OnceClosure cb3 = BindOnce([] {}); OnceCallback<void(void*)> cb3 = BindOnce([](void* param) {
EXPECT_TRUE(static_cast<OnceCallback<void(void*)>*>(param)->is_null());
});
ASSERT_TRUE(cb3); ASSERT_TRUE(cb3);
std::move(cb3).Run(); std::move(cb3).Run(&cb3);
ASSERT_FALSE(cb3); EXPECT_FALSE(cb3);
} }
TEST_F(CallbackTest, MaybeValidReturnsTrue) { TEST_F(CallbackTest, MaybeValidReturnsTrue) {
......
...@@ -339,8 +339,7 @@ void ArCoreDevice::OnRequestArCoreInstallOrUpdateResult(bool success) { ...@@ -339,8 +339,7 @@ void ArCoreDevice::OnRequestArCoreInstallOrUpdateResult(bool success) {
} }
DCHECK(session_state_->start_immersive_activity_callback_); DCHECK(session_state_->start_immersive_activity_callback_);
base::ResetAndReturn(&session_state_->start_immersive_activity_callback_) std::move(session_state_->start_immersive_activity_callback_).Run();
.Run();
} }
void ArCoreDevice::OnRequestInstallArModuleResult(bool success) { void ArCoreDevice::OnRequestInstallArModuleResult(bool success) {
...@@ -370,7 +369,7 @@ void ArCoreDevice::CallDeferredRequestSessionCallback(bool success) { ...@@ -370,7 +369,7 @@ void ArCoreDevice::CallDeferredRequestSessionCallback(bool success) {
return; return;
mojom::XRRuntime::RequestSessionCallback deferred_callback = mojom::XRRuntime::RequestSessionCallback deferred_callback =
base::ResetAndReturn(&session_state_->pending_request_session_callback_); std::move(session_state_->pending_request_session_callback_);
if (!success) { if (!success) {
std::move(deferred_callback).Run(nullptr, nullptr); std::move(deferred_callback).Run(nullptr, nullptr);
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/callback_helpers.h"
#include "base/containers/queue.h" #include "base/containers/queue.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
...@@ -450,7 +449,7 @@ void ArCoreGl::SubmitFrameMissing(int16_t frame_index, ...@@ -450,7 +449,7 @@ void ArCoreGl::SubmitFrameMissing(int16_t frame_index,
// update if we had deferred it. This will get the next frame's camera image // update if we had deferred it. This will get the next frame's camera image
// and pose in parallel while we're waiting for this frame's rendered image. // and pose in parallel while we're waiting for this frame's rendered image.
if (pending_getframedata_) { if (pending_getframedata_) {
base::ResetAndReturn(&pending_getframedata_).Run(); std::move(pending_getframedata_).Run();
} }
surface_->SwapBuffers(base::DoNothing()); surface_->SwapBuffers(base::DoNothing());
...@@ -492,7 +491,7 @@ void ArCoreGl::SubmitFrameDrawnIntoTexture(int16_t frame_index, ...@@ -492,7 +491,7 @@ void ArCoreGl::SubmitFrameDrawnIntoTexture(int16_t frame_index,
// update if we had deferred it. This will get the next frame's camera image // update if we had deferred it. This will get the next frame's camera image
// and pose in parallel while we're waiting for this frame's rendered image. // and pose in parallel while we're waiting for this frame's rendered image.
if (pending_getframedata_) { if (pending_getframedata_) {
base::ResetAndReturn(&pending_getframedata_).Run(); std::move(pending_getframedata_).Run();
} }
ar_image_transport_->CreateGpuFenceForSyncToken( ar_image_transport_->CreateGpuFenceForSyncToken(
...@@ -683,7 +682,7 @@ void ArCoreGl::OnBindingDisconnect() { ...@@ -683,7 +682,7 @@ void ArCoreGl::OnBindingDisconnect() {
CloseBindingsIfOpen(); CloseBindingsIfOpen();
base::ResetAndReturn(&session_shutdown_callback_).Run(); std::move(session_shutdown_callback_).Run();
} }
void ArCoreGl::CloseBindingsIfOpen() { void ArCoreGl::CloseBindingsIfOpen() {
......
...@@ -153,7 +153,7 @@ void ArCoreJavaUtils::OnDrawingSurfaceDestroyed( ...@@ -153,7 +153,7 @@ void ArCoreJavaUtils::OnDrawingSurfaceDestroyed(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) { const base::android::JavaParamRef<jobject>& obj) {
DVLOG(1) << __func__ << ":::"; DVLOG(1) << __func__ << ":::";
base::ResetAndReturn(&surface_destroyed_callback_).Run(); std::move(surface_destroyed_callback_).Run();
} }
void ArCoreJavaUtils::OnRequestInstallArModuleResult( void ArCoreJavaUtils::OnRequestInstallArModuleResult(
......
...@@ -64,7 +64,6 @@ bool ExtensionDevToolsInfoBarDelegate::ShouldExpire( ...@@ -64,7 +64,6 @@ bool ExtensionDevToolsInfoBarDelegate::ShouldExpire(
void ExtensionDevToolsInfoBarDelegate::InfoBarDismissed() { void ExtensionDevToolsInfoBarDelegate::InfoBarDismissed() {
DCHECK(!dismissed_callback_.is_null()); DCHECK(!dismissed_callback_.is_null());
// Use ResetAndReturn() since running the callback may delete |this|.
std::move(dismissed_callback_).Run(); std::move(dismissed_callback_).Run();
} }
......
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