Chromium Code Reviews| 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) { |