Add IsEmpty helper and remove GetInstance public usage
authorKevin Sawicki <kevinsawicki@gmail.com>
Thu, 6 Apr 2017 21:48:58 +0000 (14:48 -0700)
committerKevin Sawicki <kevinsawicki@gmail.com>
Tue, 11 Apr 2017 16:09:17 +0000 (09:09 -0700)
atom/browser/api/atom_api_auto_updater.cc
atom/browser/browser.cc
atom/browser/window_list.cc
atom/browser/window_list.h

index 60bbcbd..ea30241 100644 (file)
@@ -87,14 +87,13 @@ void AutoUpdater::SetFeedURL(const std::string& url, mate::Arguments* args) {
 
 void AutoUpdater::QuitAndInstall() {
   // If we don't have any window then quitAndInstall immediately.
-  WindowList* window_list = WindowList::GetInstance();
-  if (window_list->empty()) {
+  if (WindowList::IsEmpty()) {
     auto_updater::AutoUpdater::QuitAndInstall();
     return;
   }
 
   // Otherwise do the restart after all windows have been closed.
-  window_list->AddObserver(this);
+  WindowList::AddObserver(this);
   WindowList::CloseAllWindows();
 }
 
index 1df1f31..b2900a3 100644 (file)
@@ -43,11 +43,10 @@ void Browser::Quit() {
   if (!is_quiting_)
     return;
 
-  atom::WindowList* window_list = atom::WindowList::GetInstance();
-  if (window_list->empty())
+  if (atom::WindowList::IsEmpty())
     NotifyAndShutdown();
-
-  window_list->CloseAllWindows();
+  else
+    atom::WindowList::CloseAllWindows();
 }
 
 void Browser::Exit(mate::Arguments* args) {
@@ -65,8 +64,7 @@ void Browser::Exit(mate::Arguments* args) {
     is_exiting_ = true;
 
     // Must destroy windows before quitting, otherwise bad things can happen.
-    atom::WindowList* window_list = atom::WindowList::GetInstance();
-    if (window_list->empty()) {
+    if (atom::WindowList::IsEmpty()) {
       Shutdown();
     } else {
       // Unlike Quit(), we do not ask to close window, but destroy the window
index 8fa2ed6..374389e 100644 (file)
@@ -32,6 +32,11 @@ WindowList::WindowVector WindowList::GetWindows() {
 }
 
 // static
+bool WindowList::IsEmpty() {
+  return GetInstance()->windows_.empty();
+}
+
+// static
 void WindowList::AddWindow(NativeWindow* window) {
   DCHECK(window);
   // Push |window| on the appropriate list instance.
index 81ff5de..e336c80 100644 (file)
@@ -20,11 +20,8 @@ class WindowList {
  public:
   typedef std::vector<NativeWindow*> WindowVector;
 
-  bool empty() const { return windows_.empty(); }
-
-  static WindowList* GetInstance();
-
   static WindowVector GetWindows();
+  static bool IsEmpty();
 
   // Adds or removes |window| from the list it is associated with.
   static void AddWindow(NativeWindow* window);
@@ -44,6 +41,8 @@ class WindowList {
   static void DestroyAllWindows();
 
  private:
+  static WindowList* GetInstance();
+
   WindowList();
   ~WindowList();