Chromium Code Reviews| Index: ash/mus/window_manager.cc |
| diff --git a/ash/mus/window_manager.cc b/ash/mus/window_manager.cc |
| index 69a2992a7c08fb222113a7bf0d9fe96b2881f42e..eb9ce110142030f24df31d9fdf2abc3c17e80e1d 100644 |
| --- a/ash/mus/window_manager.cc |
| +++ b/ash/mus/window_manager.cc |
| @@ -181,6 +181,21 @@ RootWindowController* WindowManager::CreateRootWindowController( |
| return root_window_controller; |
| } |
| +void WindowManager::RemoveDisplay(ui::Window* window) { |
|
msw
2016/09/12 22:01:51
q: just window->Destroy and let OnWindowDestroy[in
sky
2016/09/12 23:11:27
Indeed. I want to move away from the observer and
|
| + // TODO(sky): WindowManager shouldn't need to observer the windows. Instead |
|
msw
2016/09/12 22:01:51
nit: "observer"
sky
2016/09/12 23:11:27
Done.
|
| + // WindowManager should have a specific API that is called when a display is |
| + // removed. |
| + auto it = FindRootWindowControllerByWindow(window); |
| + DCHECK(it != root_window_controllers_.end()); |
| + FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| + OnWillDestroyRootWindowController((*it).get())); |
| + root_window_controllers_.erase(it); |
| + // Remove the observer so we don't see the OnWindowDestroying/Destroyed as we |
| + // already handled it here. |
| + window->RemoveObserver(this); |
| + window->Destroy(); |
| +} |
| + |
| void WindowManager::Shutdown() { |
| if (!window_tree_client_) |
| return; |
| @@ -206,28 +221,28 @@ void WindowManager::Shutdown() { |
| window_manager_client_ = nullptr; |
| } |
| -void WindowManager::OnWindowDestroying(ui::Window* window) { |
| +WindowManager::RootWindowControllers::iterator |
| +WindowManager::FindRootWindowControllerByWindow(ui::Window* window) { |
| for (auto it = root_window_controllers_.begin(); |
|
msw
2016/09/12 22:01:51
optional nit: for (auto it : root_window_controlle
sky
2016/09/12 23:11:27
That'll give me a std::unique_ptr<RootWindowContro
|
| it != root_window_controllers_.end(); ++it) { |
| - if ((*it)->root() == window) { |
| - FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| - OnWillDestroyRootWindowController((*it).get())); |
| - return; |
| - } |
| + if ((*it)->root() == window) |
| + return it; |
| } |
| - NOTREACHED(); |
| + return root_window_controllers_.end(); |
| +} |
| + |
| +void WindowManager::OnWindowDestroying(ui::Window* window) { |
| + auto it = FindRootWindowControllerByWindow(window); |
| + DCHECK(it != root_window_controllers_.end()); |
| + FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| + OnWillDestroyRootWindowController((*it).get())); |
| } |
| void WindowManager::OnWindowDestroyed(ui::Window* window) { |
| + auto it = FindRootWindowControllerByWindow(window); |
| + DCHECK(it != root_window_controllers_.end()); |
| window->RemoveObserver(this); |
| - for (auto it = root_window_controllers_.begin(); |
| - it != root_window_controllers_.end(); ++it) { |
| - if ((*it)->root() == window) { |
| - root_window_controllers_.erase(it); |
| - return; |
| - } |
| - } |
| - NOTREACHED(); |
| + root_window_controllers_.erase(it); |
| } |
| void WindowManager::OnEmbed(ui::Window* root) { |