summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-28 22:41:06 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-28 22:41:06 +0000
commitecd789dad7def3a6bac31c343b30e28315e6f231 (patch)
treec9235ddc4f97a2365493827661badfcc2eaeea9b
parenta3372c7d55fb9912b6e062e417473b8df7e495ae (diff)
downloadchromium_src-ecd789dad7def3a6bac31c343b30e28315e6f231.zip
chromium_src-ecd789dad7def3a6bac31c343b30e28315e6f231.tar.gz
chromium_src-ecd789dad7def3a6bac31c343b30e28315e6f231.tar.bz2
Adds back some debugging code
We're getting another crash that looks like an observer is being destroyed before removing itself. BUG=365364 TEST=none R=flackr@chromium.org Review URL: https://codereview.chromium.org/257023002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266681 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/aura/aura.gyp1
-rw-r--r--ui/aura/window.cc2
-rw-r--r--ui/aura/window_observer.cc31
-rw-r--r--ui/aura/window_observer.h19
-rw-r--r--ui/aura/window_unittest.cc2
5 files changed, 53 insertions, 2 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index 9ddb104..676bbd5 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -73,6 +73,7 @@
'window_event_dispatcher.h',
'window_delegate.h',
'window_layer_type.h',
+ 'window_observer.cc',
'window_observer.h',
'window_targeter.cc',
'window_targeter.h',
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index 98808dd..36a305f 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -636,10 +636,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);
}
diff --git a/ui/aura/window_observer.cc b/ui/aura/window_observer.cc
new file mode 100644
index 0000000..8f87826
--- /dev/null
+++ b/ui/aura/window_observer.cc
@@ -0,0 +1,31 @@
+// Copyright (c) 2013 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
diff --git a/ui/aura/window_observer.h b/ui/aura/window_observer.h
index 926e5c4..ef1259a 100644
--- a/ui/aura/window_observer.h
+++ b/ui/aura/window_observer.h
@@ -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
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index c0bb6a5..96cd670 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -2231,6 +2231,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));
@@ -2244,7 +2245,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