Chromium Code Reviews| Index: chrome/browser/ui/browser_list.cc |
| diff --git a/chrome/browser/ui/browser_list.cc b/chrome/browser/ui/browser_list.cc |
| index 74260b4be30b5aebefe0d0c5ce67ea3b75862136..81b4fc4966f1121969e201ac0878a320ab1bd3d9 100644 |
| --- a/chrome/browser/ui/browser_list.cc |
| +++ b/chrome/browser/ui/browser_list.cc |
| @@ -15,7 +15,6 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_finder.h" |
| -#include "chrome/browser/ui/browser_list.h" |
| #include "chrome/browser/ui/browser_list_observer.h" |
| #include "chrome/browser/ui/browser_window.h" |
| #include "content/public/browser/notification_service.h" |
| @@ -24,6 +23,20 @@ |
| using base::UserMetricsAction; |
| using content::WebContents; |
| +namespace { |
| + |
| +BrowserList::BrowserVector GetBrowserToClose(Profile* profile) { |
|
Charlie Reis
2017/02/27 21:47:51
GetBrowsersToClose (plural)
zmin
2017/03/06 23:58:08
Done.
|
| + BrowserList::BrowserVector browsers_to_close; |
| + for (auto* browser : *BrowserList::GetInstance()) { |
| + if (browser->profile()->GetOriginalProfile() == |
| + profile->GetOriginalProfile()) |
| + browsers_to_close.push_back(browser); |
| + } |
| + return browsers_to_close; |
| +} |
| + |
| +} // namespace |
| + |
| // static |
| base::LazyInstance<base::ObserverList<chrome::BrowserListObserver>>::Leaky |
| BrowserList::observers_ = LAZY_INSTANCE_INITIALIZER; |
| @@ -124,33 +137,27 @@ void BrowserList::CloseAllBrowsersWithProfile(Profile* profile) { |
| } |
| // static |
| -void BrowserList::CloseAllBrowsersWithProfile(Profile* profile, |
| +void BrowserList::CloseAllBrowsersWithProfile( |
| + Profile* profile, |
| const CloseCallback& on_close_success, |
| - const CloseCallback& on_close_aborted) { |
| - BrowserVector browsers_to_close; |
| - for (auto* browser : *BrowserList::GetInstance()) { |
| - if (browser->profile()->GetOriginalProfile() == |
| - profile->GetOriginalProfile()) |
| - browsers_to_close.push_back(browser); |
| - } |
| - |
| - TryToCloseBrowserList(browsers_to_close, on_close_success, on_close_aborted, |
| - profile->GetPath()); |
| + const CloseCallback& on_close_aborted, |
| + bool is_force) { |
| + TryToCloseBrowserList(GetBrowserToClose(profile), on_close_success, |
| + on_close_aborted, profile->GetPath(), is_force); |
| } |
| // static |
| void BrowserList::TryToCloseBrowserList(const BrowserVector& browsers_to_close, |
| - const CloseCallback& on_close_success, |
| - const CloseCallback& on_close_aborted, |
| - const base::FilePath& profile_path) { |
| + const CloseCallback& on_close_success, |
| + const CloseCallback& on_close_aborted, |
| + const base::FilePath& profile_path, |
| + const bool is_force) { |
| 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, |
| - on_close_aborted, |
| - profile_path))) { |
| + if ((*it)->TryToCloseWindow( |
| + is_force, base::Bind(&BrowserList::PostTryToCloseBrowserWindow, |
| + browsers_to_close, on_close_success, |
| + on_close_aborted, profile_path, is_force))) { |
| return; |
| } |
| } |
| @@ -166,11 +173,12 @@ void BrowserList::TryToCloseBrowserList(const BrowserVector& browsers_to_close, |
| } |
| // static |
| -void BrowserList::PostBeforeUnloadHandlers( |
| +void BrowserList::PostTryToCloseBrowserWindow( |
| const BrowserVector& browsers_to_close, |
| const CloseCallback& on_close_success, |
| const CloseCallback& on_close_aborted, |
| const base::FilePath& profile_path, |
| + const bool is_force, |
| 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 |
| @@ -179,12 +187,12 @@ void BrowserList::PostBeforeUnloadHandlers( |
| if (tab_close_confirmed) { |
| TryToCloseBrowserList(browsers_to_close, on_close_success, on_close_aborted, |
| - profile_path); |
| + profile_path, is_force); |
| } 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) { |
| - (*it)->ResetBeforeUnloadHandlers(); |
| + (*it)->ResetTryToCloseWindow(); |
| } |
| on_close_aborted.Run(profile_path); |
| } |