window_list.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef SHELL_BROWSER_WINDOW_LIST_H_
  5. #define SHELL_BROWSER_WINDOW_LIST_H_
  6. #include <vector>
  7. #include "base/lazy_instance.h"
  8. #include "base/macros.h"
  9. #include "base/observer_list.h"
  10. namespace electron {
  11. class NativeWindow;
  12. class WindowListObserver;
  13. class WindowList {
  14. public:
  15. typedef std::vector<NativeWindow*> WindowVector;
  16. static WindowVector GetWindows();
  17. static bool IsEmpty();
  18. // Adds or removes |window| from the list it is associated with.
  19. static void AddWindow(NativeWindow* window);
  20. static void RemoveWindow(NativeWindow* window);
  21. // Called by window when a close is cancelled by beforeunload handler.
  22. static void WindowCloseCancelled(NativeWindow* window);
  23. // Adds and removes |observer| from the observer list.
  24. static void AddObserver(WindowListObserver* observer);
  25. static void RemoveObserver(WindowListObserver* observer);
  26. // Closes all windows.
  27. static void CloseAllWindows();
  28. // Destroy all windows.
  29. static void DestroyAllWindows();
  30. private:
  31. static WindowList* GetInstance();
  32. WindowList();
  33. ~WindowList();
  34. // A vector of the windows in this list, in the order they were added.
  35. WindowVector windows_;
  36. // A list of observers which will be notified of every window addition and
  37. // removal across all WindowLists.
  38. static base::LazyInstance<base::ObserverList<WindowListObserver>>::Leaky
  39. observers_;
  40. static WindowList* instance_;
  41. DISALLOW_COPY_AND_ASSIGN(WindowList);
  42. };
  43. } // namespace electron
  44. #endif // SHELL_BROWSER_WINDOW_LIST_H_