Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_BROWSER_LIST_H_ | 5 #ifndef CHROME_BROWSER_UI_BROWSER_LIST_H_ |
| 6 #define CHROME_BROWSER_UI_BROWSER_LIST_H_ | 6 #define CHROME_BROWSER_UI_BROWSER_LIST_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "chrome/browser/ui/host_desktop.h" | 13 #include "chrome/browser/ui/host_desktop.h" |
| 14 | 14 |
| 15 class Browser; | 15 class Browser; |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 namespace chrome { | 18 namespace chrome { |
| 19 class BrowserListObserver; | 19 class BrowserListObserver; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace base { | |
| 23 class FilePath; | |
| 24 } | |
| 25 | |
| 22 // Maintains a list of Browser objects present in a given HostDesktop (see | 26 // Maintains a list of Browser objects present in a given HostDesktop (see |
| 23 // HostDesktopType). | 27 // HostDesktopType). |
| 24 class BrowserList { | 28 class BrowserList { |
| 25 public: | 29 public: |
| 26 typedef std::vector<Browser*> BrowserVector; | 30 typedef std::vector<Browser*> BrowserVector; |
| 27 typedef BrowserVector::const_iterator const_iterator; | 31 typedef BrowserVector::const_iterator const_iterator; |
| 28 typedef BrowserVector::const_reverse_iterator const_reverse_iterator; | 32 typedef BrowserVector::const_reverse_iterator const_reverse_iterator; |
| 29 | 33 |
| 30 // Returns the last active browser for this list. | 34 // Returns the last active browser for this list. |
| 31 Browser* GetLastActive() const; | 35 Browser* GetLastActive() const; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 static void AddObserver(chrome::BrowserListObserver* observer); | 69 static void AddObserver(chrome::BrowserListObserver* observer); |
| 66 static void RemoveObserver(chrome::BrowserListObserver* observer); | 70 static void RemoveObserver(chrome::BrowserListObserver* observer); |
| 67 | 71 |
| 68 // Called by Browser objects when their window is activated (focused). This | 72 // Called by Browser objects when their window is activated (focused). This |
| 69 // allows us to determine what the last active Browser was on each desktop. | 73 // allows us to determine what the last active Browser was on each desktop. |
| 70 // Note: This only takes effect on the appropriate browser list as determined | 74 // Note: This only takes effect on the appropriate browser list as determined |
| 71 // by |browser->host_desktop_type()|. | 75 // by |browser->host_desktop_type()|. |
| 72 static void SetLastActive(Browser* browser); | 76 static void SetLastActive(Browser* browser); |
| 73 | 77 |
| 74 // Closes all browsers for |profile| across all desktops. | 78 // Closes all browsers for |profile| across all desktops. |
| 79 // TODO(mlerman): Move the Profile Deletion flow to use the overloaded | |
| 80 // version of this method with a callback, then remove this method. | |
| 75 static void CloseAllBrowsersWithProfile(Profile* profile); | 81 static void CloseAllBrowsersWithProfile(Profile* profile); |
| 76 | 82 |
| 83 // Closes all browsers for |profile| across all desktops. This method is | |
| 84 // called once and will defer to TryToCloseBrowserList to handle each | |
| 85 // OnBeforeUnload event. If all OnBeforeUnload events are confirmed, | |
|
Peter Kasting
2014/08/29 21:30:25
Nit: Second sentence might be clearer as:
Uses
Mike Lerman
2014/09/02 15:15:41
Done.
| |
| 86 // |on_close_success| is called. | |
| 87 static void CloseAllBrowsersWithProfile( | |
| 88 Profile* profile, | |
| 89 const base::Callback<void(const base::FilePath&)>& on_close_success); | |
| 90 | |
| 77 // Returns true if at least one incognito session is active across all | 91 // Returns true if at least one incognito session is active across all |
| 78 // desktops. | 92 // desktops. |
| 79 static bool IsOffTheRecordSessionActive(); | 93 static bool IsOffTheRecordSessionActive(); |
| 80 | 94 |
| 81 // Returns true if at least one incognito session is active for |profile| | 95 // Returns true if at least one incognito session is active for |profile| |
| 82 // across all desktops. | 96 // across all desktops. |
| 83 static bool IsOffTheRecordSessionActiveForProfile(Profile* profile); | 97 static bool IsOffTheRecordSessionActiveForProfile(Profile* profile); |
| 84 | 98 |
| 85 private: | 99 private: |
| 86 BrowserList(); | 100 BrowserList(); |
| 87 ~BrowserList(); | 101 ~BrowserList(); |
| 88 | 102 |
| 89 // Helper method to remove a browser instance from a list of browsers | 103 // Helper method to remove a browser instance from a list of browsers |
| 90 static void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list); | 104 static void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list); |
| 91 | 105 |
| 106 // Attempts to close |browsers_to_close| while respecting OnBeforeUnload | |
| 107 // events. If there are no OnBeforeUnload events to be called, | |
| 108 // |on_close_confirmed| will be called, with a parameter of |profile_path|. | |
| 109 // If at least one unfired OnBeforeUnload event is found, handle it with a | |
| 110 // callback to PostBeforeUnloadHandlers, which upon success will recursively | |
| 111 // call this method to handle any other OnBeforeUnload events. | |
| 112 static void TryToCloseBrowserList( | |
| 113 const BrowserVector& browsers_to_close, | |
| 114 const base::Callback<void(const base::FilePath&)>& on_close_success, | |
| 115 const base::FilePath& profile_path); | |
| 116 | |
| 117 // Called after handling an OnBeforeUnload event. If |tab_close_confirmed| is | |
| 118 // true, call |TryToCloseBrowserList|, passing the parameters | |
|
Peter Kasting
2014/08/29 21:30:26
Nit: call |TryToCloseBrowserList| -> calls TryToCl
Mike Lerman
2014/09/02 15:15:41
Done.
| |
| 119 // |browsers_to_close|, |on_close_confirmed|, and |profile_path|. Otherwise, | |
| 120 // reset all the OnBeforeUnload event handlers and processing ends. | |
|
Peter Kasting
2014/08/29 21:30:25
Nit: reset -> resets; remove "and processing ends"
Mike Lerman
2014/09/02 15:15:40
Done.
| |
| 121 static void PostBeforeUnloadHandlers( | |
| 122 const BrowserVector& browsers_to_close, | |
| 123 const base::Callback<void(const base::FilePath&)>& on_close_success, | |
| 124 const base::FilePath& profile_path, | |
| 125 bool tab_close_confirmed); | |
| 126 | |
| 92 // A vector of the browsers in this list, in the order they were added. | 127 // A vector of the browsers in this list, in the order they were added. |
| 93 BrowserVector browsers_; | 128 BrowserVector browsers_; |
| 94 // A vector of the browsers in this list that have been activated, in the | 129 // A vector of the browsers in this list that have been activated, in the |
| 95 // reverse order in which they were last activated. | 130 // reverse order in which they were last activated. |
| 96 BrowserVector last_active_browsers_; | 131 BrowserVector last_active_browsers_; |
| 97 | 132 |
| 98 // A list of observers which will be notified of every browser addition and | 133 // A list of observers which will be notified of every browser addition and |
| 99 // removal across all BrowserLists. | 134 // removal across all BrowserLists. |
| 100 static base::LazyInstance<ObserverList<chrome::BrowserListObserver> >::Leaky | 135 static base::LazyInstance<ObserverList<chrome::BrowserListObserver> >::Leaky |
| 101 observers_; | 136 observers_; |
| 102 | 137 |
| 103 // Nothing fancy, since we only have two HDTs. | 138 // Nothing fancy, since we only have two HDTs. |
| 104 static BrowserList* native_instance_; | 139 static BrowserList* native_instance_; |
| 105 static BrowserList* ash_instance_; | 140 static BrowserList* ash_instance_; |
| 106 | 141 |
| 107 DISALLOW_COPY_AND_ASSIGN(BrowserList); | 142 DISALLOW_COPY_AND_ASSIGN(BrowserList); |
| 108 }; | 143 }; |
| 109 | 144 |
| 110 #endif // CHROME_BROWSER_UI_BROWSER_LIST_H_ | 145 #endif // CHROME_BROWSER_UI_BROWSER_LIST_H_ |
| OLD | NEW |