| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/mus/ws/display_manager.h" | 5 #include "components/mus/ws/display_manager.h" |
| 6 | 6 |
| 7 #include "components/mus/ws/display.h" | 7 #include "components/mus/ws/display.h" |
| 8 #include "components/mus/ws/display_manager_delegate.h" | 8 #include "components/mus/ws/display_manager_delegate.h" |
| 9 #include "components/mus/ws/server_window.h" | 9 #include "components/mus/ws/server_window.h" |
| 10 #include "components/mus/ws/user_display_manager.h" | 10 #include "components/mus/ws/user_display_manager.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 | 35 |
| 36 void DisplayManager::AddDisplay(Display* display) { | 36 void DisplayManager::AddDisplay(Display* display) { |
| 37 DCHECK_EQ(0u, pending_displays_.count(display)); | 37 DCHECK_EQ(0u, pending_displays_.count(display)); |
| 38 pending_displays_.insert(display); | 38 pending_displays_.insert(display); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void DisplayManager::DestroyDisplay(Display* display) { | 41 void DisplayManager::DestroyDisplay(Display* display) { |
| 42 if (pending_displays_.count(display)) { | 42 if (pending_displays_.count(display)) { |
| 43 pending_displays_.erase(display); | 43 pending_displays_.erase(display); |
| 44 } else { | 44 } else if (displays_.count(display)) { |
| 45 for (const auto& pair : user_display_managers_) | 45 for (const auto& pair : user_display_managers_) |
| 46 pair.second->OnWillDestroyDisplay(display); | 46 pair.second->OnWillDestroyDisplay(display); |
| 47 displays_.erase(display); |
| 48 } else { |
| 49 // NOTE: This may fuction may be re-entered with the same |display| in which |
| 50 // case we need to avoid a double-free. This should probably be considered a |
| 51 // bug. This was hidden before due to the fact that the mus app exited |
| 52 // uncleanly in tests. |
| 53 DLOG(WARNING) << "Trying to destroy the same display twice."; |
| 54 return; |
| 55 } |
| 47 | 56 |
| 48 DCHECK(displays_.count(display)); | |
| 49 displays_.erase(display); | |
| 50 } | |
| 51 delete display; | 57 delete display; |
| 52 | 58 |
| 53 // If we have no more roots left, let the app know so it can terminate. | 59 // If we have no more roots left, let the app know so it can terminate. |
| 54 // TODO(sky): move to delegate/observer. | 60 // TODO(sky): move to delegate/observer. |
| 55 if (!displays_.size() && !pending_displays_.size()) | 61 if (!displays_.size() && !pending_displays_.size()) |
| 56 delegate_->OnNoMoreDisplays(); | 62 delegate_->OnNoMoreDisplays(); |
| 57 } | 63 } |
| 58 | 64 |
| 59 void DisplayManager::DestroyAllDisplays() { | 65 void DisplayManager::DestroyAllDisplays() { |
| 60 while (!pending_displays_.empty()) | 66 while (!pending_displays_.empty()) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 DCHECK_EQ(0u, displays_.count(display)); | 143 DCHECK_EQ(0u, displays_.count(display)); |
| 138 const bool is_first_display = displays_.empty(); | 144 const bool is_first_display = displays_.empty(); |
| 139 displays_.insert(display); | 145 displays_.insert(display); |
| 140 pending_displays_.erase(display); | 146 pending_displays_.erase(display); |
| 141 if (is_first_display) | 147 if (is_first_display) |
| 142 delegate_->OnFirstDisplayReady(); | 148 delegate_->OnFirstDisplayReady(); |
| 143 } | 149 } |
| 144 | 150 |
| 145 } // namespace ws | 151 } // namespace ws |
| 146 } // namespace mus | 152 } // namespace mus |
| OLD | NEW |