Index: chrome/browser/ui/browser_list.cc |
diff --git a/chrome/browser/ui/browser_list.cc b/chrome/browser/ui/browser_list.cc |
index 000c4c6210db311e0600ad9cac30d7a454e833c8..c00ddbc205223dc8e5cb372a4d4e8fdd8c68c054 100644 |
--- a/chrome/browser/ui/browser_list.cc |
+++ b/chrome/browser/ui/browser_list.cc |
@@ -6,6 +6,7 @@ |
#include <algorithm> |
+#include "base/auto_reset.h" |
#include "base/logging.h" |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/browser_shutdown.h" |
@@ -116,6 +117,7 @@ void BrowserList::RemoveObserver(chrome::BrowserListObserver* observer) { |
observers_.Get().RemoveObserver(observer); |
} |
+// static |
void BrowserList::CloseAllBrowsersWithProfile(Profile* profile) { |
BrowserVector browsers_to_close; |
for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
@@ -130,6 +132,64 @@ void BrowserList::CloseAllBrowsersWithProfile(Profile* profile) { |
} |
// static |
+void BrowserList::CloseAllBrowsersWithProfile(Profile* profile, |
+ const base::Callback<void(const base::FilePath&)>& on_close_success) { |
+ BrowserVector browsers_to_close; |
+ for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
+ if (it->profile()->GetOriginalProfile() == profile->GetOriginalProfile()) |
+ browsers_to_close.push_back(*it); |
+ } |
+ |
+ TryToCloseBrowserList(browsers_to_close, |
+ on_close_success, |
+ profile->GetPath()); |
+} |
+ |
+// static |
+void BrowserList::TryToCloseBrowserList(const BrowserVector& browsers_to_close, |
+ const base::Callback<void(const base::FilePath&)>& on_close_success, |
+ const base::FilePath& profile_path) { |
+ for (BrowserVector::const_iterator it = browsers_to_close.begin(); |
+ it != browsers_to_close.end(); ++it) { |
+ if ((*it)->CallBeforeUnloadHandlers( |
+ base::Bind(&BrowserList::PostBeforeUnloadHandlers, |
+ browsers_to_close, |
+ on_close_success, |
+ profile_path))) { |
+ return; |
+ } |
+ } |
+ |
+ for (BrowserVector::const_iterator it = browsers_to_close.begin(); |
+ it != browsers_to_close.end(); ++it) |
+ (*it)->window()->Close(); |
+ |
+ on_close_success.Run(profile_path); |
+} |
+ |
+// static |
+void BrowserList::PostBeforeUnloadHandlers( |
+ const BrowserVector& browsers_to_close, |
+ const base::Callback<void(const base::FilePath&)>& on_close_success, |
+ const base::FilePath& profile_path, |
+ bool tab_close_confirmed) { |
+ // We need this bool to avoid infinite recursion when resetting the |
+ // BeforeUnload handlers, since doing that will trigger calls back to this |
+ // method for each affected window. |
+ static bool resetting_handlers = false; |
+ |
+ if (tab_close_confirmed) { |
+ TryToCloseBrowserList(browsers_to_close, on_close_success, profile_path); |
+ } else if (!resetting_handlers) { |
+ base::AutoReset<bool> resetting_handlers_scoper(&resetting_handlers, true); |
+ for (BrowserVector::const_iterator it = browsers_to_close.begin(); |
+ it != browsers_to_close.end(); ++it) { |
Peter Kasting
2014/09/02 19:40:34
Nit: Indent one more
Mike Lerman
2014/09/03 15:28:34
Done.
|
+ (*it)->ResetBeforeUnloadHandlers(); |
+ } |
+ } |
+} |
+ |
+// static |
void BrowserList::SetLastActive(Browser* browser) { |
content::RecordAction(UserMetricsAction("ActiveBrowserChanged")); |
BrowserList* browser_list = GetInstance(browser->host_desktop_type()); |