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>
using EnableIfIsBaseCallback =
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 {
template <typename... Args>
......
......@@ -47,24 +47,6 @@ void Increment(int* 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) {
int run_count = 0;
{
......
......@@ -8,7 +8,6 @@
#include <utility>
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/callback_internal.h"
#include "base/memory/ref_counted.h"
#include "base/test/test_timeouts.h"
......@@ -122,43 +121,25 @@ TEST_F(CallbackTest, Move) {
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) {
RepeatingClosure cb = BindRepeating([] {});
RepeatingCallback<void(void*)> cb = BindRepeating([](void* param) {
EXPECT_TRUE(static_cast<RepeatingCallback<void(void*)>*>(param)->is_null());
});
ASSERT_TRUE(cb);
std::move(cb).Run();
ASSERT_FALSE(cb);
std::move(cb).Run(&cb);
EXPECT_FALSE(cb);
const RepeatingClosure cb2 = BindRepeating([] {});
ASSERT_TRUE(cb2);
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);
std::move(cb3).Run();
ASSERT_FALSE(cb3);
std::move(cb3).Run(&cb3);
EXPECT_FALSE(cb3);
}
TEST_F(CallbackTest, MaybeValidReturnsTrue) {
......
......@@ -339,8 +339,7 @@ void ArCoreDevice::OnRequestArCoreInstallOrUpdateResult(bool success) {
}
DCHECK(session_state_->start_immersive_activity_callback_);
base::ResetAndReturn(&session_state_->start_immersive_activity_callback_)
.Run();
std::move(session_state_->start_immersive_activity_callback_).Run();
}
void ArCoreDevice::OnRequestInstallArModuleResult(bool success) {
......@@ -370,7 +369,7 @@ void ArCoreDevice::CallDeferredRequestSessionCallback(bool success) {
return;
mojom::XRRuntime::RequestSessionCallback deferred_callback =
base::ResetAndReturn(&session_state_->pending_request_session_callback_);
std::move(session_state_->pending_request_session_callback_);
if (!success) {
std::move(deferred_callback).Run(nullptr, nullptr);
......
......@@ -12,7 +12,6 @@
#include "base/android/jni_android.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback_helpers.h"
#include "base/containers/queue.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
......@@ -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
// and pose in parallel while we're waiting for this frame's rendered image.
if (pending_getframedata_) {
base::ResetAndReturn(&pending_getframedata_).Run();
std::move(pending_getframedata_).Run();
}
surface_->SwapBuffers(base::DoNothing());
......@@ -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
// and pose in parallel while we're waiting for this frame's rendered image.
if (pending_getframedata_) {
base::ResetAndReturn(&pending_getframedata_).Run();
std::move(pending_getframedata_).Run();
}
ar_image_transport_->CreateGpuFenceForSyncToken(
......@@ -683,7 +682,7 @@ void ArCoreGl::OnBindingDisconnect() {
CloseBindingsIfOpen();
base::ResetAndReturn(&session_shutdown_callback_).Run();
std::move(session_shutdown_callback_).Run();
}
void ArCoreGl::CloseBindingsIfOpen() {
......
......@@ -153,7 +153,7 @@ void ArCoreJavaUtils::OnDrawingSurfaceDestroyed(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) {
DVLOG(1) << __func__ << ":::";
base::ResetAndReturn(&surface_destroyed_callback_).Run();
std::move(surface_destroyed_callback_).Run();
}
void ArCoreJavaUtils::OnRequestInstallArModuleResult(
......
......@@ -64,7 +64,6 @@ bool ExtensionDevToolsInfoBarDelegate::ShouldExpire(
void ExtensionDevToolsInfoBarDelegate::InfoBarDismissed() {
DCHECK(!dismissed_callback_.is_null());
// Use ResetAndReturn() since running the callback may delete |this|.
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