Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: ash/test/test_session_state_animator.cc

Issue 2867673004: Use OnceCallback on Mojo interfaces in //ash (Closed)
Patch Set: count -> container_count Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/test/test_session_state_animator.h ('k') | ash/wm/lock_state_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/test/test_session_state_animator.h" 5 #include "ash/test/test_session_state_animator.h"
6 6
7 #include <utility>
7 #include <vector> 8 #include <vector>
8 9
10 #include "base/barrier_closure.h"
9 #include "base/bind.h" 11 #include "base/bind.h"
10 12
11 namespace ash { 13 namespace ash {
12 namespace test { 14 namespace test {
13 15
14 namespace { 16 namespace {
15 // A no-op callback that can be used when managing an animation that didn't 17 // A no-op callback that can be used when managing an animation that didn't
16 // actually have a callback given. 18 // actually have a callback given.
17 void DummyCallback() {} 19 void DummyCallback() {}
18 } 20 }
19 21
20 const SessionStateAnimator::Container 22 const SessionStateAnimator::Container
21 TestSessionStateAnimator::kAllContainers[] = { 23 TestSessionStateAnimator::kAllContainers[] = {
22 SessionStateAnimator::WALLPAPER, 24 SessionStateAnimator::WALLPAPER,
23 SessionStateAnimator::LAUNCHER, 25 SessionStateAnimator::LAUNCHER,
24 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, 26 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
25 SessionStateAnimator::LOCK_SCREEN_WALLPAPER, 27 SessionStateAnimator::LOCK_SCREEN_WALLPAPER,
26 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, 28 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
27 SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS, 29 SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS,
28 SessionStateAnimator::ROOT_CONTAINER}; 30 SessionStateAnimator::ROOT_CONTAINER};
29 31
30 // A simple SessionStateAnimator::AnimationSequence that tracks the number of 32 // A simple SessionStateAnimator::AnimationSequence that tracks the number of
31 // attached sequences. The callback will be invoked if all animations complete 33 // attached sequences. The callback will be invoked if all animations complete
32 // successfully. 34 // successfully.
33 class TestSessionStateAnimator::AnimationSequence 35 class TestSessionStateAnimator::AnimationSequence
34 : public SessionStateAnimator::AnimationSequence { 36 : public SessionStateAnimator::AnimationSequence {
35 public: 37 public:
36 AnimationSequence(base::Closure callback, TestSessionStateAnimator* animator) 38 AnimationSequence(base::OnceClosure callback,
37 : SessionStateAnimator::AnimationSequence(callback), 39 TestSessionStateAnimator* animator)
40 : SessionStateAnimator::AnimationSequence(std::move(callback)),
38 sequence_count_(0), 41 sequence_count_(0),
39 sequence_aborted_(false), 42 sequence_aborted_(false),
40 animator_(animator) {} 43 animator_(animator) {}
41 44
42 ~AnimationSequence() override {} 45 ~AnimationSequence() override {}
43 46
44 virtual void SequenceAttached() { ++sequence_count_; } 47 virtual void SequenceAttached() { ++sequence_count_; }
45 48
46 // Notify the sequence that is has completed. 49 // Notify the sequence that is has completed.
47 virtual void SequenceFinished(bool successfully) { 50 virtual void SequenceFinished(bool successfully) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 base::Closure callback = base::Bind(&DummyCallback); 206 base::Closure callback = base::Bind(&DummyCallback);
204 AddAnimation(kAllContainers[i], type, speed, callback, callback); 207 AddAnimation(kAllContainers[i], type, speed, callback, callback);
205 } 208 }
206 } 209 }
207 } 210 }
208 211
209 void TestSessionStateAnimator::StartAnimationWithCallback( 212 void TestSessionStateAnimator::StartAnimationWithCallback(
210 int container_mask, 213 int container_mask,
211 AnimationType type, 214 AnimationType type,
212 AnimationSpeed speed, 215 AnimationSpeed speed,
213 base::Closure callback) { 216 base::OnceClosure callback) {
214 ++last_animation_epoch_; 217 ++last_animation_epoch_;
215 for (size_t i = 0; i < arraysize(kAllContainers); ++i) 218
219 int container_count = 0;
220 for (size_t i = 0; i < arraysize(kAllContainers); ++i) {
221 if (container_mask & kAllContainers[i])
222 ++container_count;
223 }
224
225 base::RepeatingClosure completion_callback =
226 base::BarrierClosure(container_count, std::move(callback));
227 for (size_t i = 0; i < arraysize(kAllContainers); ++i) {
216 if (container_mask & kAllContainers[i]) { 228 if (container_mask & kAllContainers[i]) {
217 // ash::SessionStateAnimatorImpl invokes the callback whether or not the 229 // ash::SessionStateAnimatorImpl invokes the callback whether or not the
218 // animation was completed successfully or not. 230 // animation was completed successfully or not.
219 AddAnimation(kAllContainers[i], type, speed, callback, callback); 231 AddAnimation(kAllContainers[i], type, speed, completion_callback,
232 completion_callback);
220 } 233 }
234 }
221 } 235 }
222 236
223 ash::SessionStateAnimator::AnimationSequence* 237 ash::SessionStateAnimator::AnimationSequence*
224 TestSessionStateAnimator::BeginAnimationSequence(base::Closure callback) { 238 TestSessionStateAnimator::BeginAnimationSequence(base::OnceClosure callback) {
225 return new AnimationSequence(callback, this); 239 return new AnimationSequence(std::move(callback), this);
226 } 240 }
227 241
228 bool TestSessionStateAnimator::IsWallpaperHidden() const { 242 bool TestSessionStateAnimator::IsWallpaperHidden() const {
229 return is_wallpaper_hidden_; 243 return is_wallpaper_hidden_;
230 } 244 }
231 245
232 void TestSessionStateAnimator::ShowWallpaper() { 246 void TestSessionStateAnimator::ShowWallpaper() {
233 is_wallpaper_hidden_ = false; 247 is_wallpaper_hidden_ = false;
234 } 248 }
235 249
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 while (animation_iter != (*container_iter).second.end()) { 297 while (animation_iter != (*container_iter).second.end()) {
284 ActiveAnimation active_animation = *animation_iter; 298 ActiveAnimation active_animation = *animation_iter;
285 active_animation.failed_callback.Run(); 299 active_animation.failed_callback.Run();
286 animation_iter = (*container_iter).second.erase(animation_iter); 300 animation_iter = (*container_iter).second.erase(animation_iter);
287 } 301 }
288 } 302 }
289 } 303 }
290 304
291 } // namespace test 305 } // namespace test
292 } // namespace ash 306 } // namespace ash
OLDNEW
« no previous file with comments | « ash/test/test_session_state_animator.h ('k') | ash/wm/lock_state_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698