Commit 9104f917 authored by sky@chromium.org's avatar sky@chromium.org

Nukes aura::WindowDestructionObserver. It's effectively the same as

WindowTracker.

BUG=none
TEST=none
R=sadrul@chromium.org

Review URL: https://chromiumcodereview.appspot.com/22254003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215821 0039d316-1c4b-4281-b951-d872f2087c98
parent 64b0860b
......@@ -54,7 +54,6 @@
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/aura/window_destruction_observer.h"
#include "ui/aura/window_observer.h"
#include "ui/aura/window_tracker.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
......@@ -2481,12 +2480,13 @@ void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) {
aura::Window* host = *(host_tracker_->windows().begin());
aura::client::FocusClient* client = aura::client::GetFocusClient(host);
if (client) {
// Calling host->Focus() may delete |this|. We create a local
// observer for that. In that case we exit without further
// access to any members.
aura::WindowDestructionObserver destruction_observer(window_);
// Calling host->Focus() may delete |this|. We create a local observer
// for that. In that case we exit without further access to any members.
aura::WindowTracker tracker;
aura::Window* window = window_;
tracker.Add(window);
host->Focus();
if (destruction_observer.destroyed()) {
if (!tracker.Contains(window)) {
event->SetHandled();
return;
}
......
......@@ -101,8 +101,6 @@
'window.cc',
'window.h',
'window_delegate.h',
'window_destruction_observer.cc',
'window_destruction_observer.h',
'window_observer.h',
'window_tracker.cc',
'window_tracker.h',
......
......@@ -23,8 +23,8 @@
#include "ui/aura/layout_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_destruction_observer.h"
#include "ui/aura/window_observer.h"
#include "ui/aura/window_tracker.h"
#include "ui/base/animation/multi_animation.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
......@@ -1027,13 +1027,14 @@ void Window::NotifyWindowVisibilityChanged(aura::Window* target,
bool Window::NotifyWindowVisibilityChangedAtReceiver(aura::Window* target,
bool visible) {
// |this| may be deleted during a call to OnWindowVisibilityChanged
// on one of the observers. We create an local observer for that. In
// that case we exit without further access to any members.
WindowDestructionObserver destruction_observer(this);
// |this| may be deleted during a call to OnWindowVisibilityChanged() on one
// of the observers. We create an local observer for that. In that case we
// exit without further access to any members.
WindowTracker tracker;
tracker.Add(this);
FOR_EACH_OBSERVER(WindowObserver, observers_,
OnWindowVisibilityChanged(target, visible));
return !destruction_observer.destroyed();
return tracker.Contains(this);
}
bool Window::NotifyWindowVisibilityChangedDown(aura::Window* target,
......
// Copyright 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_destruction_observer.h"
namespace aura {
WindowDestructionObserver::WindowDestructionObserver(Window* window)
: window_(window), destroyed_(false) {
DCHECK(window_);
window_->AddObserver(this);
}
WindowDestructionObserver::~WindowDestructionObserver() {
if (!destroyed_)
window_->RemoveObserver(this);
}
void WindowDestructionObserver::OnWindowDestroyed(Window* window) {
if (window == window_)
destroyed_ = true;
}
} // namespace aura
// Copyright 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.
#ifndef UI_AURA_WINDOW_DESTRUCTION_OBSERVER_H_
#define UI_AURA_WINDOW_DESTRUCTION_OBSERVER_H_
#include <set>
#include "ui/aura/aura_export.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
namespace aura {
// A class for observing window (self) destruction. A side effect of a
// window member funtion may be that the object, i.e. |this|, gets
// deleted. This class can be used to detect such cases and to exit
// the member function without any further access to member data. See
// for example: aura::Window::NotifyWindowVisibilityChangedAtReceiver.
class AURA_EXPORT WindowDestructionObserver : public WindowObserver {
public:
// Addes this observer to window.
explicit WindowDestructionObserver(aura::Window* window);
// Removes this observer from |window_| unless |window_| has been
// observed to be destroyed.
virtual ~WindowDestructionObserver();
// Returns true if |window_| has been observed to be destroyed.
bool destroyed() const { return destroyed_; }
private:
// aura::WindowObserver overrides:
virtual void OnWindowDestroyed(Window* window) OVERRIDE;
Window* window_;
bool destroyed_;
DISALLOW_COPY_AND_ASSIGN(WindowDestructionObserver);
};
} // namespace aura
#endif
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