Commit 371e6f63 authored by rouslan@chromium.org's avatar rouslan@chromium.org

Fix a leak in wm::AnimateOnChildWindowVisibilityChanged().

RotateHidingWindowAnimationObserver is leaking from
wm::AnimateOnChildWindowVisibilityChanged() because it's not observing
animation events. The fix is to make RotateHidingWindowAnimationObserver
observe the animation events.

BUG=389296
TEST=wm_unittests:WindowAnimationsTest.RotateHideNoLeak

Review URL: https://codereview.chromium.org/343753007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283970 0039d316-1c4b-4281-b951-d872f2087c98
parent b635d872
...@@ -58,7 +58,8 @@ const float kWindowAnimation_Vertical_TranslateY = 15.f; ...@@ -58,7 +58,8 @@ const float kWindowAnimation_Vertical_TranslateY = 15.f;
// The subclass will determine when the animation is completed. // The subclass will determine when the animation is completed.
class HidingWindowAnimationObserverBase : public aura::WindowObserver { class HidingWindowAnimationObserverBase : public aura::WindowObserver {
public: public:
HidingWindowAnimationObserverBase(aura::Window* window) : window_(window) { explicit HidingWindowAnimationObserverBase(aura::Window* window)
: window_(window) {
window_->AddObserver(this); window_->AddObserver(this);
} }
virtual ~HidingWindowAnimationObserverBase() { virtual ~HidingWindowAnimationObserverBase() {
...@@ -396,31 +397,29 @@ class RotateHidingWindowAnimationObserver ...@@ -396,31 +397,29 @@ class RotateHidingWindowAnimationObserver
: public HidingWindowAnimationObserverBase, : public HidingWindowAnimationObserverBase,
public ui::LayerAnimationObserver { public ui::LayerAnimationObserver {
public: public:
RotateHidingWindowAnimationObserver(aura::Window* window) explicit RotateHidingWindowAnimationObserver(aura::Window* window)
: HidingWindowAnimationObserverBase(window), last_sequence_(NULL) {} : HidingWindowAnimationObserverBase(window) {}
virtual ~RotateHidingWindowAnimationObserver() {} virtual ~RotateHidingWindowAnimationObserver() {}
void set_last_sequence(ui::LayerAnimationSequence* last_sequence) { // Destroys itself after |last_sequence| ends or is aborted. Does not take
last_sequence_ = last_sequence; // ownership of |last_sequence|, which should not be NULL.
void SetLastSequence(ui::LayerAnimationSequence* last_sequence) {
last_sequence->AddObserver(this);
} }
// ui::LayerAnimationObserver: // ui::LayerAnimationObserver:
virtual void OnLayerAnimationEnded( virtual void OnLayerAnimationEnded(
ui::LayerAnimationSequence* sequence) OVERRIDE { ui::LayerAnimationSequence* sequence) OVERRIDE {
if (last_sequence_ == sequence) OnAnimationCompleted();
OnAnimationCompleted();
} }
virtual void OnLayerAnimationAborted( virtual void OnLayerAnimationAborted(
ui::LayerAnimationSequence* sequence) OVERRIDE { ui::LayerAnimationSequence* sequence) OVERRIDE {
if (last_sequence_ == sequence) OnAnimationCompleted();
OnAnimationCompleted();
} }
virtual void OnLayerAnimationScheduled( virtual void OnLayerAnimationScheduled(
ui::LayerAnimationSequence* sequence) OVERRIDE {} ui::LayerAnimationSequence* sequence) OVERRIDE {}
private: private:
ui::LayerAnimationSequence* last_sequence_;
DISALLOW_COPY_AND_ASSIGN(RotateHidingWindowAnimationObserver); DISALLOW_COPY_AND_ASSIGN(RotateHidingWindowAnimationObserver);
}; };
...@@ -482,8 +481,9 @@ void AddLayerAnimationsForRotate(aura::Window* window, bool show) { ...@@ -482,8 +481,9 @@ void AddLayerAnimationsForRotate(aura::Window* window, bool show) {
ui::LayerAnimationSequence* last_sequence = ui::LayerAnimationSequence* last_sequence =
new ui::LayerAnimationSequence(transition.release()); new ui::LayerAnimationSequence(transition.release());
window->layer()->GetAnimator()->ScheduleAnimation(last_sequence); window->layer()->GetAnimator()->ScheduleAnimation(last_sequence);
if (observer) { if (observer) {
observer->set_last_sequence(last_sequence); observer->SetLastSequence(last_sequence);
observer->DetachAndRecreateLayers(); observer->DetachAndRecreateLayers();
} }
} }
......
...@@ -288,4 +288,21 @@ TEST_F(WindowAnimationsTest, NotifyHideCompleted) { ...@@ -288,4 +288,21 @@ TEST_F(WindowAnimationsTest, NotifyHideCompleted) {
EXPECT_TRUE(animation_host.hide_completed()); EXPECT_TRUE(animation_host.hide_completed());
} }
// The rotation animation for hiding a window should not leak the animation
// observer.
TEST_F(WindowAnimationsTest, RotateHideNoLeak) {
ui::ScopedAnimationDurationScaleMode scale_mode(
ui::ScopedAnimationDurationScaleMode::FAST_DURATION);
scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL));
ui::Layer* animating_layer = window->layer();
wm::SetWindowVisibilityAnimationType(window.get(),
WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE);
AnimateOnChildWindowVisibilityChanged(window.get(), true);
AnimateOnChildWindowVisibilityChanged(window.get(), false);
animating_layer->GetAnimator()->StopAnimating();
}
} // namespace wm } // namespace wm
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