Commit 7251ca10 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Convert base::Bind and base::Callback in ash/wm to Once/Repeating

Bug: 1007633
Change-Id: I0a020fa00b0d48a5cdcddb75062bad878b17e183
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1931263
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarJun Mukai <mukai@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718299}
parent 5a319b1a
......@@ -80,7 +80,7 @@ class LockActionHandlerLayoutManagerTest : public AshTestBase {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kEnableVirtualKeyboard);
action_background_controller_factory_ = base::Bind(
action_background_controller_factory_ = base::BindRepeating(
&LockActionHandlerLayoutManagerTest::CreateActionBackgroundController,
base::Unretained(this));
LockScreenActionBackgroundController::SetFactoryCallbackForTesting(
......
......@@ -145,11 +145,11 @@ void LockStateController::CancelLockAnimation() {
VLOG(1) << "CancelLockAnimation";
animating_lock_ = false;
Shell::Get()->wallpaper_controller()->UpdateWallpaperBlur(false);
base::Closure next_animation_starter =
base::Bind(&LockStateController::LockAnimationCancelled,
weak_ptr_factory_.GetWeakPtr());
base::OnceClosure next_animation_starter =
base::BindOnce(&LockStateController::LockAnimationCancelled,
weak_ptr_factory_.GetWeakPtr());
SessionStateAnimator::AnimationSequence* animation_sequence =
animator_->BeginAnimationSequence(next_animation_starter);
animator_->BeginAnimationSequence(std::move(next_animation_starter));
animation_sequence->StartAnimation(
SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
......@@ -314,11 +314,11 @@ void LockStateController::PreLockAnimation(
SessionStateAnimator::AnimationSpeed speed,
bool request_lock_on_completion) {
Shell::Get()->wallpaper_controller()->UpdateWallpaperBlur(true);
base::Closure next_animation_starter =
base::Bind(&LockStateController::PreLockAnimationFinished,
weak_ptr_factory_.GetWeakPtr(), request_lock_on_completion);
base::OnceClosure next_animation_starter = base::BindOnce(
&LockStateController::PreLockAnimationFinished,
weak_ptr_factory_.GetWeakPtr(), request_lock_on_completion);
SessionStateAnimator::AnimationSequence* animation_sequence =
animator_->BeginAnimationSequence(next_animation_starter);
animator_->BeginAnimationSequence(std::move(next_animation_starter));
animation_sequence->StartAnimation(
SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
......@@ -337,11 +337,11 @@ void LockStateController::PreLockAnimation(
void LockStateController::StartPostLockAnimation() {
VLOG(1) << "StartPostLockAnimation";
base::Closure next_animation_starter =
base::Bind(&LockStateController::PostLockAnimationFinished,
weak_ptr_factory_.GetWeakPtr());
base::OnceClosure next_animation_starter =
base::BindOnce(&LockStateController::PostLockAnimationFinished,
weak_ptr_factory_.GetWeakPtr());
SessionStateAnimator::AnimationSequence* animation_sequence =
animator_->BeginAnimationSequence(next_animation_starter);
animator_->BeginAnimationSequence(std::move(next_animation_starter));
animation_sequence->StartAnimation(
SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
......@@ -375,11 +375,11 @@ void LockStateController::StartUnlockAnimationBeforeUIDestroyed(
void LockStateController::StartUnlockAnimationAfterUIDestroyed() {
VLOG(1) << "StartUnlockAnimationAfterUIDestroyed";
base::Closure next_animation_starter =
base::Bind(&LockStateController::UnlockAnimationAfterUIDestroyedFinished,
weak_ptr_factory_.GetWeakPtr());
base::OnceClosure next_animation_starter = base::BindOnce(
&LockStateController::UnlockAnimationAfterUIDestroyedFinished,
weak_ptr_factory_.GetWeakPtr());
SessionStateAnimator::AnimationSequence* animation_sequence =
animator_->BeginAnimationSequence(next_animation_starter);
animator_->BeginAnimationSequence(std::move(next_animation_starter));
animation_sequence->StartAnimation(
SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
......
......@@ -287,8 +287,8 @@ class LockStateControllerTest : public PowerButtonTestBase {
}
void SuccessfulAuthentication(bool* call_flag) {
base::Closure closure = base::Bind(&CheckCalledCallback, call_flag);
lock_state_controller_->OnLockScreenHide(closure);
base::OnceClosure closure = base::BindOnce(&CheckCalledCallback, call_flag);
lock_state_controller_->OnLockScreenHide(std::move(closure));
}
std::unique_ptr<ShutdownController::ScopedResetterForTest>
......
......@@ -289,27 +289,27 @@ void StartGrayscaleBrightnessAnimationForWindow(
// finished. It is used in when undoing shutdown animation.
class CallbackAnimationObserver : public ui::LayerAnimationObserver {
public:
explicit CallbackAnimationObserver(base::Closure callback)
: callback_(callback) {}
explicit CallbackAnimationObserver(base::OnceClosure callback)
: callback_(std::move(callback)) {}
~CallbackAnimationObserver() override = default;
private:
// Overridden from ui::LayerAnimationObserver:
void OnLayerAnimationEnded(ui::LayerAnimationSequence* seq) override {
// Drop foreground once animation is over.
callback_.Run();
std::move(callback_).Run();
delete this;
}
void OnLayerAnimationAborted(ui::LayerAnimationSequence* seq) override {
// Drop foreground once animation is over.
callback_.Run();
std::move(callback_).Run();
delete this;
}
void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq) override {}
base::Closure callback_;
base::OnceClosure callback_;
DISALLOW_COPY_AND_ASSIGN(CallbackAnimationObserver);
};
......@@ -550,7 +550,7 @@ void SessionStateAnimatorImpl::StartAnimationWithCallback(
base::OnceClosure callback) {
aura::Window::Windows containers;
GetContainers(container_mask, &containers);
base::Closure animation_done_closure =
base::RepeatingClosure animation_done_closure =
base::BarrierClosure(containers.size(), std::move(callback));
for (aura::Window::Windows::const_iterator it = containers.begin();
it != containers.end(); ++it) {
......
......@@ -96,7 +96,7 @@ TEST_F(SessionStateAnimatiorImplContainersTest,
SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
SessionStateAnimator::ANIMATION_LIFT,
SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE,
base::Bind([](int* count) { ++(*count); }, &callback_count));
base::BindOnce([](int* count) { ++(*count); }, &callback_count));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, callback_count);
}
......
......@@ -393,10 +393,10 @@ void TabletModeController::MaybeObserveBoundsAnimation(aura::Window* window) {
}
destroy_observer_ = std::make_unique<DestroyObserver>(
window, base::Bind(&TabletModeController::StopObservingAnimation,
weak_factory_.GetWeakPtr(),
/*record_stats=*/false,
/*delete_screenshot=*/true));
window, base::BindOnce(&TabletModeController::StopObservingAnimation,
weak_factory_.GetWeakPtr(),
/*record_stats=*/false,
/*delete_screenshot=*/true));
animating_layer_ = window->layer();
animating_layer_->GetAnimator()->AddObserver(this);
}
......@@ -996,8 +996,8 @@ void TabletModeController::ResetDestroyObserver() {
void TabletModeController::TakeScreenshot(aura::Window* top_window) {
DCHECK(!top_window->IsRootWindow());
destroy_observer_ = std::make_unique<DestroyObserver>(
top_window, base::Bind(&TabletModeController::ResetDestroyObserver,
weak_factory_.GetWeakPtr()));
top_window, base::BindOnce(&TabletModeController::ResetDestroyObserver,
weak_factory_.GetWeakPtr()));
screenshot_set_callback_.Reset(base::BindOnce(
&TabletModeController::FinishInitTabletMode, weak_factory_.GetWeakPtr()));
......
......@@ -9,16 +9,11 @@
#include "base/barrier_closure.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/stl_util.h"
namespace ash {
namespace {
// A no-op callback that can be used when managing an animation that didn't
// actually have a callback given.
void DummyCallback() {}
} // namespace
const SessionStateAnimator::Container
TestSessionStateAnimator::kAllContainers[] = {
SessionStateAnimator::WALLPAPER,
......@@ -85,18 +80,22 @@ TestSessionStateAnimator::ActiveAnimation::ActiveAnimation(
SessionStateAnimator::Container container,
AnimationType type,
AnimationSpeed speed,
base::Closure success_callback,
base::Closure failed_callback)
base::OnceClosure success_callback,
base::OnceClosure failed_callback)
: animation_epoch(animation_epoch),
remaining_duration(duration),
container(container),
type(type),
speed(speed),
success_callback(success_callback),
failed_callback(failed_callback) {}
success_callback(std::move(success_callback)),
failed_callback(std::move(failed_callback)) {}
TestSessionStateAnimator::ActiveAnimation::ActiveAnimation(
const ActiveAnimation& other) = default;
ActiveAnimation&& other) = default;
TestSessionStateAnimator::ActiveAnimation&
TestSessionStateAnimator::ActiveAnimation::operator=(ActiveAnimation&& other) =
default;
TestSessionStateAnimator::ActiveAnimation::~ActiveAnimation() = default;
......@@ -121,7 +120,7 @@ void TestSessionStateAnimator::Advance(const base::TimeDelta& duration) {
ActiveAnimation& active_animation = *animation_iter;
active_animation.remaining_duration -= duration;
if (active_animation.remaining_duration <= base::TimeDelta()) {
active_animation.success_callback.Run();
std::move(active_animation.success_callback).Run();
animation_iter = (*container_iter).second.erase(animation_iter);
} else {
++animation_iter;
......@@ -137,12 +136,12 @@ void TestSessionStateAnimator::CompleteAnimations(int animation_epoch,
container_iter != active_animations_.end(); ++container_iter) {
AnimationList::iterator animation_iter = (*container_iter).second.begin();
while (animation_iter != (*container_iter).second.end()) {
ActiveAnimation active_animation = *animation_iter;
ActiveAnimation& active_animation = *animation_iter;
if (active_animation.animation_epoch <= animation_epoch) {
if (completed_successfully)
active_animation.success_callback.Run();
std::move(active_animation.success_callback).Run();
else
active_animation.failed_callback.Run();
std::move(active_animation.failed_callback).Run();
animation_iter = (*container_iter).second.erase(animation_iter);
} else {
++animation_iter;
......@@ -201,10 +200,8 @@ void TestSessionStateAnimator::StartAnimation(int container_mask,
++last_animation_epoch_;
for (size_t i = 0; i < base::size(kAllContainers); ++i) {
if (container_mask & kAllContainers[i]) {
// Use a dummy no-op callback because one isn't required by the client
// but one is required when completing or aborting animations.
base::Closure callback = base::Bind(&DummyCallback);
AddAnimation(kAllContainers[i], type, speed, callback, callback);
AddAnimation(kAllContainers[i], type, speed, base::DoNothing(),
base::DoNothing());
}
}
}
......@@ -259,15 +256,15 @@ void TestSessionStateAnimator::StartAnimationInSequence(
++last_animation_epoch_;
for (size_t i = 0; i < base::size(kAllContainers); ++i) {
if (container_mask & kAllContainers[i]) {
base::Closure success_callback =
base::Bind(&AnimationSequence::SequenceFinished,
base::Unretained(animation_sequence), true);
base::Closure failed_callback =
base::Bind(&AnimationSequence::SequenceFinished,
base::Unretained(animation_sequence), false);
base::OnceClosure success_callback =
base::BindOnce(&AnimationSequence::SequenceFinished,
base::Unretained(animation_sequence), true);
base::OnceClosure failed_callback =
base::BindOnce(&AnimationSequence::SequenceFinished,
base::Unretained(animation_sequence), false);
animation_sequence->SequenceAttached();
AddAnimation(kAllContainers[i], type, speed, success_callback,
failed_callback);
AddAnimation(kAllContainers[i], type, speed, std::move(success_callback),
std::move(failed_callback));
}
}
}
......@@ -276,16 +273,16 @@ void TestSessionStateAnimator::AddAnimation(
SessionStateAnimator::Container container,
AnimationType type,
AnimationSpeed speed,
base::Closure success_callback,
base::Closure failed_callback) {
base::OnceClosure success_callback,
base::OnceClosure failed_callback) {
base::TimeDelta duration = GetDuration(speed);
ActiveAnimation active_animation(last_animation_epoch_, duration, container,
type, speed, success_callback,
failed_callback);
type, speed, std::move(success_callback),
std::move(failed_callback));
// This test double is limited to only have one animation active for a given
// container at a time.
AbortAnimation(container);
active_animations_[container].push_back(active_animation);
active_animations_[container].push_back(std::move(active_animation));
}
void TestSessionStateAnimator::AbortAnimation(
......@@ -295,8 +292,8 @@ void TestSessionStateAnimator::AbortAnimation(
if (container_iter != active_animations_.end()) {
AnimationList::iterator animation_iter = (*container_iter).second.begin();
while (animation_iter != (*container_iter).second.end()) {
ActiveAnimation active_animation = *animation_iter;
active_animation.failed_callback.Run();
ActiveAnimation& active_animation = *animation_iter;
std::move(active_animation.failed_callback).Run();
animation_iter = (*container_iter).second.erase(animation_iter);
}
}
......
......@@ -88,9 +88,10 @@ class TestSessionStateAnimator : public SessionStateAnimator {
SessionStateAnimator::Container container,
AnimationType type,
AnimationSpeed speed,
base::Closure success_callback,
base::Closure failed_callback);
ActiveAnimation(const ActiveAnimation& other);
base::OnceClosure success_callback,
base::OnceClosure failed_callback);
ActiveAnimation(ActiveAnimation&& other);
ActiveAnimation& operator=(ActiveAnimation&& other);
virtual ~ActiveAnimation();
// The time epoch that this animation was scheduled.
......@@ -109,10 +110,10 @@ class TestSessionStateAnimator : public SessionStateAnimator {
AnimationSpeed speed;
// The callback to be invoked upon a successful completion.
base::Closure success_callback;
base::OnceClosure success_callback;
// The callback to be invoked upon an unsuccessful completion.
base::Closure failed_callback;
base::OnceClosure failed_callback;
};
typedef std::vector<ActiveAnimation> AnimationList;
......@@ -133,8 +134,8 @@ class TestSessionStateAnimator : public SessionStateAnimator {
void AddAnimation(SessionStateAnimator::Container container,
AnimationType type,
AnimationSpeed speed,
base::Closure success_callback,
base::Closure failed_callback);
base::OnceClosure success_callback,
base::OnceClosure failed_callback);
// If an animation is currently active for the given |container| it will be
// aborted by invoking OnAnimationAborted and removed from the list of active
......
......@@ -44,10 +44,11 @@ void WindowCycleEventFilter::OnKeyEvent(ui::KeyEvent* event) {
!repeat_timer_.IsRunning()) {
repeat_timer_.Start(
FROM_HERE, base::TimeDelta::FromMilliseconds(180),
base::Bind(&WindowCycleController::HandleCycleWindow,
base::Unretained(Shell::Get()->window_cycle_controller()),
event->IsShiftDown() ? WindowCycleController::BACKWARD
: WindowCycleController::FORWARD));
base::BindRepeating(
&WindowCycleController::HandleCycleWindow,
base::Unretained(Shell::Get()->window_cycle_controller()),
event->IsShiftDown() ? WindowCycleController::BACKWARD
: WindowCycleController::FORWARD));
}
} else if (event->key_code() == ui::VKEY_ESCAPE) {
Shell::Get()->window_cycle_controller()->CancelCycling();
......
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