Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(747)

Unified Diff: mash/wm/user_window_controller_impl.cc

Issue 1988153003: Fix dangling observer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mash/wm/user_window_controller_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mash/wm/user_window_controller_impl.cc
diff --git a/mash/wm/user_window_controller_impl.cc b/mash/wm/user_window_controller_impl.cc
index 1201d0bdbb88367ad311f5a5d6534bfdee3f5b66..de983c7c325de710937992044c3fcca234b080de 100644
--- a/mash/wm/user_window_controller_impl.cc
+++ b/mash/wm/user_window_controller_impl.cc
@@ -89,15 +89,11 @@ UserWindowControllerImpl::~UserWindowControllerImpl() {
if (!root_controller_)
return;
- // TODO(msw): should really listen for user window container being destroyed
- // and cleanup there.
mus::Window* user_container = GetUserWindowContainer();
if (!user_container)
msw 2016/05/18 17:36:56 optional nit: invert and nest the RemoveObservers
return;
- user_container->RemoveObserver(this);
- for (auto iter : user_container->children())
- iter->RemoveObserver(window_property_observer_.get());
+ RemoveObservers(user_container);
}
void UserWindowControllerImpl::Initialize(
@@ -119,6 +115,13 @@ void UserWindowControllerImpl::AssignIdIfNecessary(mus::Window* window) {
window->SetLocalProperty(kUserWindowIdKey, next_id_++);
}
+void UserWindowControllerImpl::RemoveObservers(mus::Window* user_container) {
+ user_container->RemoveObserver(this);
+ user_container->connection()->RemoveObserver(this);
+ for (auto iter : user_container->children())
+ iter->RemoveObserver(window_property_observer_.get());
+}
+
mus::Window* UserWindowControllerImpl::GetUserWindowById(uint32_t id) {
for (mus::Window* window : GetUserWindowContainer()->children()) {
if (window->GetLocalProperty(kUserWindowIdKey) == id)
@@ -147,6 +150,11 @@ void UserWindowControllerImpl::OnTreeChanging(const TreeChangeParams& params) {
}
}
+void UserWindowControllerImpl::OnWindowDestroying(mus::Window* window) {
+ if (window == GetUserWindowContainer())
+ RemoveObservers(window);
+}
+
void UserWindowControllerImpl::OnWindowTreeFocusChanged(
mus::Window* gained_focus,
mus::Window* lost_focus) {
« no previous file with comments | « mash/wm/user_window_controller_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698