Commit 94c02046 authored by derat@chromium.org's avatar derat@chromium.org

aura: Reland r266681 to debug WindowObserver crashes.

Add code to make the aura::WindowObserver interface crash
when it's destroyed without having unregistered its interest
in all aura::Windows that it was observing. This will
hopefully help track down the source of crashes that are
seen when closing video windows on Google Play.

https://codereview.chromium.org/303163003/ hopefully fixes
the test crashes that resulted in this change being reverted
earlier.

BUG=365364

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274086 0039d316-1c4b-4281-b951-d872f2087c98
parent a82878d4
......@@ -72,6 +72,7 @@
'window_event_dispatcher.h',
'window_delegate.h',
'window_layer_type.h',
'window_observer.cc',
'window_observer.h',
'window_targeter.cc',
'window_targeter.h',
......
......@@ -644,10 +644,12 @@ gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const {
}
void Window::AddObserver(WindowObserver* observer) {
observer->OnObservingWindow(this);
observers_.AddObserver(observer);
}
void Window::RemoveObserver(WindowObserver* observer) {
observer->OnUnobservingWindow(this);
observers_.RemoveObserver(observer);
}
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/aura/window_observer.h"
#include "base/logging.h"
#include "ui/aura/window.h"
namespace aura {
WindowObserver::WindowObserver() : observing_(0) {
}
WindowObserver::~WindowObserver() {
// TODO(flackr): Remove this check and observing_ counter when the cause of
// http://crbug.com/365364 is discovered.
CHECK_EQ(0, observing_);
}
void WindowObserver::OnObservingWindow(aura::Window* window) {
if (!window->HasObserver(this))
observing_++;
}
void WindowObserver::OnUnobservingWindow(aura::Window* window) {
if (window->HasObserver(this))
observing_--;
}
} // namespace aura
......@@ -31,6 +31,8 @@ class AURA_EXPORT WindowObserver {
Window* receiver; // The window receiving the notification.
};
WindowObserver();
// Called when a window is added or removed. Notifications are sent to the
// following hierarchies in this order:
// 1. |target|.
......@@ -111,7 +113,22 @@ class AURA_EXPORT WindowObserver {
Window* new_root) {}
protected:
virtual ~WindowObserver() {}
virtual ~WindowObserver();
private:
friend class Window;
// Called when this is added as an observer on |window|.
void OnObservingWindow(Window* window);
// Called when this is removed from the observers on |window|.
void OnUnobservingWindow(Window* window);
// Tracks the number of windows being observed to track down
// http://crbug.com/365364.
int observing_;
DISALLOW_COPY_AND_ASSIGN(WindowObserver);
};
} // namespace aura
......
......@@ -2229,6 +2229,7 @@ TEST_F(WindowTest, RootWindowSetWhenReparenting) {
parent1.SetBounds(gfx::Rect(10, 10, 300, 300));
parent2.SetBounds(gfx::Rect(20, 20, 300, 300));
BoundsChangedWindowObserver observer;
Window child(NULL);
child.Init(aura::WINDOW_LAYER_NOT_DRAWN);
child.SetBounds(gfx::Rect(5, 5, 100, 100));
......@@ -2242,7 +2243,6 @@ TEST_F(WindowTest, RootWindowSetWhenReparenting) {
gfx::Rect new_bounds(gfx::Rect(35, 35, 50, 50));
child.SetBounds(new_bounds);
BoundsChangedWindowObserver observer;
child.AddObserver(&observer);
// Reparenting the |child| will cause it to get moved. During this move
......
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