From da5d7d72b034c4bd7f7b1dbdd2d4f6f4c8cd0fb6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 6 Apr 2017 14:43:37 -0700 Subject: [PATCH] Add GetWindows helper that returns a vector --- atom/browser/browser_linux.cc | 4 +--- atom/browser/browser_mac.mm | 5 ++--- atom/browser/native_window.cc | 3 +-- atom/browser/window_list.cc | 5 +++++ atom/browser/window_list.h | 15 ++------------- 5 files changed, 11 insertions(+), 21 deletions(-) diff --git a/atom/browser/browser_linux.cc b/atom/browser/browser_linux.cc index 4dd799dfaf02..f569040a2189 100644 --- a/atom/browser/browser_linux.cc +++ b/atom/browser/browser_linux.cc @@ -16,9 +16,7 @@ namespace atom { void Browser::Focus() { // Focus on the first visible window. - WindowList* list = WindowList::GetInstance(); - for (WindowList::iterator iter = list->begin(); iter != list->end(); ++iter) { - NativeWindow* window = *iter; + for (const auto& window : WindowList::GetWindows()) { if (window->IsVisible()) { window->Focus(true); break; diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index 51604e377cd6..38a0a003d968 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -204,9 +204,8 @@ std::string Browser::DockGetBadgeText() { } void Browser::DockHide() { - WindowList* list = WindowList::GetInstance(); - for (WindowList::iterator it = list->begin(); it != list->end(); ++it) - [(*it)->GetNativeWindow() setCanHide:NO]; + for (const auto& window : WindowList::GetWindows()) + [window->GetNativeWindow() setCanHide:NO]; ProcessSerialNumber psn = { 0, kCurrentProcess }; TransformProcessType(&psn, kProcessTransformToUIElementApplication); diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index af32a2e8a85a..316cc8dc2e3d 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -104,8 +104,7 @@ NativeWindow::~NativeWindow() { // static NativeWindow* NativeWindow::FromWebContents( content::WebContents* web_contents) { - WindowList& window_list = *WindowList::GetInstance(); - for (NativeWindow* window : window_list) { + for (const auto& window : WindowList::GetWindows()) { if (window->web_contents() == web_contents) return window; } diff --git a/atom/browser/window_list.cc b/atom/browser/window_list.cc index bcf4a9f1e2c0..8fa2ed67438e 100644 --- a/atom/browser/window_list.cc +++ b/atom/browser/window_list.cc @@ -26,6 +26,11 @@ WindowList* WindowList::GetInstance() { return instance_; } +// static +WindowList::WindowVector WindowList::GetWindows() { + return GetInstance()->windows_; +} + // static void WindowList::AddWindow(NativeWindow* window) { DCHECK(window); diff --git a/atom/browser/window_list.h b/atom/browser/window_list.h index 557a7969e59a..81ff5de10573 100644 --- a/atom/browser/window_list.h +++ b/atom/browser/window_list.h @@ -19,24 +19,13 @@ class WindowListObserver; class WindowList { public: typedef std::vector WindowVector; - typedef WindowVector::iterator iterator; - typedef WindowVector::const_iterator const_iterator; - - // Windows are added to the list before they have constructed windows, - // so the |window()| member function may return NULL. - const_iterator begin() const { return windows_.begin(); } - const_iterator end() const { return windows_.end(); } - - iterator begin() { return windows_.begin(); } - iterator end() { return windows_.end(); } bool empty() const { return windows_.empty(); } - size_t size() const { return windows_.size(); } - - NativeWindow* get(size_t index) const { return windows_[index]; } static WindowList* GetInstance(); + static WindowVector GetWindows(); + // Adds or removes |window| from the list it is associated with. static void AddWindow(NativeWindow* window); static void RemoveWindow(NativeWindow* window);