Remove window from observers when it's closed instead of deleted.

This commit is contained in:
Cheng Zhao 2014-04-23 09:25:04 +08:00
parent bccbc5e821
commit db39910455

View file

@ -75,8 +75,6 @@ Window::Window(base::DictionaryValue* options)
Window::~Window() { Window::~Window() {
Emit("destroyed"); Emit("destroyed");
window_->RemoveObserver(this);
} }
void Window::OnPageTitleUpdated(bool* prevent_default, void Window::OnPageTitleUpdated(bool* prevent_default,
@ -99,9 +97,13 @@ void Window::WillCloseWindow(bool* prevent_default) {
void Window::OnWindowClosed() { void Window::OnWindowClosed() {
Emit("closed"); Emit("closed");
// Free memory when native window is closed, the delete is delayed so other if (window_) {
// observers would not get a invalid pointer of NativeWindow. window_->RemoveObserver(this);
base::MessageLoop::current()->DeleteSoon(FROM_HERE, window_.release());
// Free memory when native window is closed, the delete is delayed so other
// observers would not get a invalid pointer of NativeWindow.
base::MessageLoop::current()->DeleteSoon(FROM_HERE, window_.release());
}
} }
void Window::OnWindowBlur() { void Window::OnWindowBlur() {