| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 // Notifies the observers when the current active browser becomes not active. | 82 // Notifies the observers when the current active browser becomes not active. |
| 83 static void NotifyBrowserNoLongerActive(Browser* browser); | 83 static void NotifyBrowserNoLongerActive(Browser* browser); |
| 84 | 84 |
| 85 // Closes all browsers for |profile| across all desktops. | 85 // Closes all browsers for |profile| across all desktops. |
| 86 // TODO(mlerman): Move the Profile Deletion flow to use the overloaded | 86 // TODO(mlerman): Move the Profile Deletion flow to use the overloaded |
| 87 // version of this method with a callback, then remove this method. | 87 // version of this method with a callback, then remove this method. |
| 88 static void CloseAllBrowsersWithProfile(Profile* profile); | 88 static void CloseAllBrowsersWithProfile(Profile* profile); |
| 89 | 89 |
| 90 // Closes all browsers for |profile| across all desktops. Uses | 90 // Closes all browsers for |profile| across all desktops. Uses |
| 91 // TryToCloseBrowserList() to do the actual closing and trigger any | 91 // TryToCloseBrowserList() to do the actual closing. Trigger any |
| 92 // OnBeforeUnload events. If all OnBeforeUnload events are confirmed, | 92 // OnBeforeUnload events if |if_force| is false. If all OnBeforeUnload events |
| 93 // |on_close_success| is called, otherwise |on_close_aborted| is called. | 93 // are confirmed or |skip_beforeunload| is true, |on_close_success| is called, |
| 94 static void CloseAllBrowsersWithProfile( | 94 // otherwise |on_close_aborted| is called. |
| 95 Profile* profile, | 95 // Note that if there is any browser window has been used before, user |
| 96 const CloseCallback& on_close_success, | 96 // should always has a chance to save his or her work before closing windows |
| 97 const CloseCallback& on_close_aborted); | 97 // without trigger beforeunload event. |
| 98 static void CloseAllBrowsersWithProfile(Profile* profile, |
| 99 const CloseCallback& on_close_success, |
| 100 const CloseCallback& on_close_aborted, |
| 101 bool skip_beforeunload); |
| 98 | 102 |
| 99 // Returns true if at least one incognito session is active across all | 103 // Returns true if at least one incognito session is active across all |
| 100 // desktops. | 104 // desktops. |
| 101 static bool IsIncognitoSessionActive(); | 105 static bool IsIncognitoSessionActive(); |
| 102 | 106 |
| 103 // Returns true if at least one incognito session is active for |profile| | 107 // Returns true if at least one incognito session is active for |profile| |
| 104 // across all desktops. | 108 // across all desktops. |
| 105 static bool IsIncognitoSessionActiveForProfile(Profile* profile); | 109 static bool IsIncognitoSessionActiveForProfile(Profile* profile); |
| 106 | 110 |
| 107 private: | 111 private: |
| 108 BrowserList(); | 112 BrowserList(); |
| 109 ~BrowserList(); | 113 ~BrowserList(); |
| 110 | 114 |
| 111 // Helper method to remove a browser instance from a list of browsers | 115 // Helper method to remove a browser instance from a list of browsers |
| 112 static void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list); | 116 static void RemoveBrowserFrom(Browser* browser, BrowserVector* browser_list); |
| 113 | 117 |
| 114 // Attempts to close |browsers_to_close| while respecting OnBeforeUnload | 118 // Attempts to close |browsers_to_close| while respecting OnBeforeUnload |
| 115 // events. If there are no OnBeforeUnload events to be called, | 119 // events. If there are no OnBeforeUnload events to be called, |
| 116 // |on_close_success| will be called, with a parameter of |profile_path|, | 120 // |on_close_success| will be called, with a parameter of |profile_path|, |
| 117 // and the Browsers will then be closed. If at least one unfired | 121 // and the Browsers will then be closed. If at least one unfired |
| 118 // OnBeforeUnload event is found, handle it with a callback to | 122 // OnBeforeUnload event is found, handle it with a callback to |
| 119 // PostBeforeUnloadHandlers, which upon success will recursively call this | 123 // PostTryToCloseBrowserWindow, which upon success will recursively call this |
| 120 // method to handle any other OnBeforeUnload events. If aborted in the | 124 // method to handle any other OnBeforeUnload events. If aborted in the |
| 121 // OnBeforeUnload event, PostBeforeUnloadHandlers will call |on_close_aborted| | 125 // OnBeforeUnload event, PostTryToCloseBrowserWindow will call |
| 122 // instead and reset all OnBeforeUnload event handlers. | 126 // |on_close_aborted| instead and reset all OnBeforeUnload event handlers. |
| 123 static void TryToCloseBrowserList( | 127 static void TryToCloseBrowserList(const BrowserVector& browsers_to_close, |
| 124 const BrowserVector& browsers_to_close, | 128 const CloseCallback& on_close_success, |
| 125 const CloseCallback& on_close_success, | 129 const CloseCallback& on_close_aborted, |
| 126 const CloseCallback& on_close_aborted, | 130 const base::FilePath& profile_path, |
| 127 const base::FilePath& profile_path); | 131 const bool skip_beforeunload); |
| 128 | 132 |
| 129 // Called after handling an OnBeforeUnload event. If |tab_close_confirmed| is | 133 // Called after handling an OnBeforeUnload event. If |tab_close_confirmed| is |
| 130 // true, calls |TryToCloseBrowserList()|, passing the parameters | 134 // true, calls |TryToCloseBrowserList()|, passing the parameters |
| 131 // |browsers_to_close|, |on_close_success|, |on_close_aborted|, and | 135 // |browsers_to_close|, |on_close_success|, |on_close_aborted|, and |
| 132 // |profile_path|. Otherwise, resets all the OnBeforeUnload event handlers and | 136 // |profile_path|. Otherwise, resets all the OnBeforeUnload event handlers and |
| 133 // calls |on_close_aborted|. | 137 // calls |on_close_aborted|. |
| 134 static void PostBeforeUnloadHandlers( | 138 static void PostTryToCloseBrowserWindow( |
| 135 const BrowserVector& browsers_to_close, | 139 const BrowserVector& browsers_to_close, |
| 136 const CloseCallback& on_close_success, | 140 const CloseCallback& on_close_success, |
| 137 const CloseCallback& on_close_aborted, | 141 const CloseCallback& on_close_aborted, |
| 138 const base::FilePath& profile_path, | 142 const base::FilePath& profile_path, |
| 143 const bool skip_beforeunload, |
| 139 bool tab_close_confirmed); | 144 bool tab_close_confirmed); |
| 140 | 145 |
| 141 // A vector of the browsers in this list, in the order they were added. | 146 // A vector of the browsers in this list, in the order they were added. |
| 142 BrowserVector browsers_; | 147 BrowserVector browsers_; |
| 143 // A vector of the browsers in this list that have been activated, in the | 148 // A vector of the browsers in this list that have been activated, in the |
| 144 // reverse order in which they were last activated. | 149 // reverse order in which they were last activated. |
| 145 BrowserVector last_active_browsers_; | 150 BrowserVector last_active_browsers_; |
| 146 | 151 |
| 147 // A list of observers which will be notified of every browser addition and | 152 // A list of observers which will be notified of every browser addition and |
| 148 // removal across all BrowserLists. | 153 // removal across all BrowserLists. |
| 149 static base::LazyInstance< | 154 static base::LazyInstance< |
| 150 base::ObserverList<chrome::BrowserListObserver>>::Leaky observers_; | 155 base::ObserverList<chrome::BrowserListObserver>>::Leaky observers_; |
| 151 | 156 |
| 152 static BrowserList* instance_; | 157 static BrowserList* instance_; |
| 153 | 158 |
| 154 DISALLOW_COPY_AND_ASSIGN(BrowserList); | 159 DISALLOW_COPY_AND_ASSIGN(BrowserList); |
| 155 }; | 160 }; |
| 156 | 161 |
| 157 #endif // CHROME_BROWSER_UI_BROWSER_LIST_H_ | 162 #endif // CHROME_BROWSER_UI_BROWSER_LIST_H_ |
| OLD | NEW |