|
10 | 10 | #include "shell/browser/native_window.h"
|
11 | 11 | #include "shell/browser/window_list_observer.h"
|
12 | 12 |
|
| 13 | +namespace { |
| 14 | +template <typename T> |
| 15 | +std::vector<base::WeakPtr<T>> ConvertToWeakPtrVector(std::vector<T*> raw_ptrs) { |
| 16 | + std::vector<base::WeakPtr<T>> converted_to_weak; |
| 17 | + converted_to_weak.reserve(raw_ptrs.size()); |
| 18 | + for (auto* raw_ptr : raw_ptrs) { |
| 19 | + converted_to_weak.push_back(raw_ptr->GetWeakPtr()); |
| 20 | + } |
| 21 | + return converted_to_weak; |
| 22 | +} |
| 23 | +} // namespace |
| 24 | + |
13 | 25 | namespace electron {
|
14 | 26 |
|
15 | 27 | // static
|
@@ -80,20 +92,26 @@ void WindowList::RemoveObserver(WindowListObserver* observer) {
|
80 | 92 |
|
81 | 93 | // static
|
82 | 94 | void WindowList::CloseAllWindows() {
|
83 |
| - WindowVector windows = GetInstance()->windows_; |
| 95 | + std::vector<base::WeakPtr<NativeWindow>> weak_windows = |
| 96 | + ConvertToWeakPtrVector(GetInstance()->windows_); |
84 | 97 | #if defined(OS_MACOSX)
|
85 |
| - std::reverse(windows.begin(), windows.end()); |
| 98 | + std::reverse(weak_windows.begin(), weak_windows.end()); |
86 | 99 | #endif
|
87 |
| - for (auto* const& window : windows) |
88 |
| - if (!window->IsClosed()) |
| 100 | + for (const auto& window : weak_windows) { |
| 101 | + if (window && !window->IsClosed()) |
89 | 102 | window->Close();
|
| 103 | + } |
90 | 104 | }
|
91 | 105 |
|
92 | 106 | // static
|
93 | 107 | void WindowList::DestroyAllWindows() {
|
94 |
| - WindowVector windows = GetInstance()->windows_; |
95 |
| - for (auto* const& window : windows) |
96 |
| - window->CloseImmediately(); // e.g. Destroy() |
| 108 | + std::vector<base::WeakPtr<NativeWindow>> weak_windows = |
| 109 | + ConvertToWeakPtrVector(GetInstance()->windows_); |
| 110 | + |
| 111 | + for (const auto& window : weak_windows) { |
| 112 | + if (window) |
| 113 | + window->CloseImmediately(); |
| 114 | + } |
97 | 115 | }
|
98 | 116 |
|
99 | 117 | WindowList::WindowList() = default;
|
|
0 commit comments