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

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

Issue 2867673004: Use OnceCallback on Mojo interfaces in //ash (Closed)
Patch Set: rebase. +#include 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
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_;
218
219 int count = 0;
James Cook 2017/05/09 18:30:40 nit: |container_count| or similar
tzik 2017/05/11 08:15:21 Done.
215 for (size_t i = 0; i < arraysize(kAllContainers); ++i) 220 for (size_t i = 0; i < arraysize(kAllContainers); ++i)
James Cook 2017/05/09 18:30:40 nit: {}
tzik 2017/05/11 08:15:21 Done.
221 if (container_mask & kAllContainers[i])
222 ++count;
223
224 base::RepeatingClosure completion_callback =
225 base::BarrierClosure(count, std::move(callback));
226 for (size_t i = 0; i < arraysize(kAllContainers); ++i) {
216 if (container_mask & kAllContainers[i]) { 227 if (container_mask & kAllContainers[i]) {
217 // ash::SessionStateAnimatorImpl invokes the callback whether or not the 228 // ash::SessionStateAnimatorImpl invokes the callback whether or not the
218 // animation was completed successfully or not. 229 // animation was completed successfully or not.
219 AddAnimation(kAllContainers[i], type, speed, callback, callback); 230 AddAnimation(kAllContainers[i], type, speed, completion_callback,
231 completion_callback);
220 } 232 }
233 }
221 } 234 }
222 235
223 ash::SessionStateAnimator::AnimationSequence* 236 ash::SessionStateAnimator::AnimationSequence*
224 TestSessionStateAnimator::BeginAnimationSequence(base::Closure callback) { 237 TestSessionStateAnimator::BeginAnimationSequence(base::OnceClosure callback) {
225 return new AnimationSequence(callback, this); 238 return new AnimationSequence(std::move(callback), this);
226 } 239 }
227 240
228 bool TestSessionStateAnimator::IsWallpaperHidden() const { 241 bool TestSessionStateAnimator::IsWallpaperHidden() const {
229 return is_wallpaper_hidden_; 242 return is_wallpaper_hidden_;
230 } 243 }
231 244
232 void TestSessionStateAnimator::ShowWallpaper() { 245 void TestSessionStateAnimator::ShowWallpaper() {
233 is_wallpaper_hidden_ = false; 246 is_wallpaper_hidden_ = false;
234 } 247 }
235 248
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 while (animation_iter != (*container_iter).second.end()) { 296 while (animation_iter != (*container_iter).second.end()) {
284 ActiveAnimation active_animation = *animation_iter; 297 ActiveAnimation active_animation = *animation_iter;
285 active_animation.failed_callback.Run(); 298 active_animation.failed_callback.Run();
286 animation_iter = (*container_iter).second.erase(animation_iter); 299 animation_iter = (*container_iter).second.erase(animation_iter);
287 } 300 }
288 } 301 }
289 } 302 }
290 303
291 } // namespace test 304 } // namespace test
292 } // namespace ash 305 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698