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 000c4c6210db311e0600ad9cac30d7a454e833c8..f4d86c383bed4039942f70de24944507d3204bfd 100644 |
| --- a/chrome/browser/ui/browser_list.cc |
| +++ b/chrome/browser/ui/browser_list.cc |
| @@ -12,6 +12,8 @@ |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/lifetime/application_lifetime.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_info_cache.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_finder.h" |
| #include "chrome/browser/ui/browser_iterator.h" |
| @@ -32,6 +34,10 @@ base::LazyInstance<ObserverList<chrome::BrowserListObserver> >::Leaky |
| BrowserList* BrowserList::native_instance_ = NULL; |
| BrowserList* BrowserList::ash_instance_ = NULL; |
| +// static |
| +// The current browser handling its OnBeforeUnload event before closing. |
| +Browser* current_closing_browser_; |
|
Peter Kasting
2014/08/26 20:26:15
Why do you actually need this? You only ever use
Mike Lerman
2014/08/27 14:11:38
This is done in BrowserCloseManager where I got th
Peter Kasting
2014/08/27 19:31:34
I'm never OK with landing code the author and revi
Mike Lerman
2014/08/28 15:06:52
Answer: If I have multiple browsers open, and acce
|
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // BrowserList, public: |
| @@ -116,6 +122,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 +137,75 @@ void BrowserList::CloseAllBrowsersWithProfile(Profile* profile) { |
| } |
| // static |
| +void BrowserList::CloseAllBrowsersWithProfile(Profile* profile, |
|
noms (inactive)
2014/08/26 20:17:32
I'm a little confused because CodeSearch still sho
Peter Kasting
2014/08/26 20:26:15
I think you're confused; that method is defined ju
Mike Lerman
2014/08/27 14:11:38
There is one place (Profile Deletion flow) that ca
Peter Kasting
2014/08/27 19:31:34
Can you do that in this CL? If not, don't worry a
Mike Lerman
2014/08/28 15:06:52
I'm going to see if the TPM's are okay with mergin
|
| + const base::Callback<void(size_t)>& on_close_success, |
| + const base::Callback<void(size_t)>& on_close_aborted) { |
| + current_closing_browser_ = NULL; |
| + BrowserVector browsers_to_close; |
| + for (chrome::BrowserIterator it; !it.done(); it.Next()) { |
| + if (it->profile()->GetOriginalProfile() == profile->GetOriginalProfile()) |
| + browsers_to_close.push_back(*it); |
| + } |
| + |
| + ProfileInfoCache& cache = |
|
Peter Kasting
2014/08/26 20:26:15
Nit: Prefer pointers or const refs to non-const re
Mike Lerman
2014/08/27 14:11:38
Inlined, since the ProfileInfoCache is only used o
|
| + g_browser_process->profile_manager()->GetProfileInfoCache(); |
| + size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| + |
| + TryToCloseBrowserList(browsers_to_close, on_close_success, |
|
noms (inactive)
2014/08/26 20:17:32
Hmm, can this and CloseAllBrowsers just get merged
Mike Lerman
2014/08/27 14:11:38
TryToCloseBrowserList is called in PostBeforeUnloa
|
| + on_close_aborted, profile_index); |
|
Peter Kasting
2014/08/26 20:26:15
Nit: All lines of args must be aligned
Mike Lerman
2014/08/27 14:11:38
No longer an issue.
|
| +} |
| + |
| +// static |
| +void BrowserList::TryToCloseBrowserList(const BrowserVector& browsers_to_close, |
| + const base::Callback<void(size_t)>& on_close_success, |
| + const base::Callback<void(size_t)>& on_close_aborted, |
| + const size_t profile_index) { |
| + 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_index))) { |
| + current_closing_browser_ = *it; |
| + return; |
| + } |
| + } |
| + |
| + on_close_success.Run(profile_index); |
| + |
| + // Close() can invalidate the std::vector::iterator, so use array indexing. |
| + Browser*const * browsers_ready_to_close = &browsers_to_close[0]; |
| + for (size_t i = 0; i < browsers_to_close.size(); i++) |
| + browsers_ready_to_close[i]->window()->Close(); |
|
noms (inactive)
2014/08/26 20:17:32
The original function in CodeSearch shows that an
Peter Kasting
2014/08/26 20:26:15
Yeah, the difference between this and the above sc
Mike Lerman
2014/08/27 14:11:38
Okay, I shall dig further into why the iterator ge
Mike Lerman
2014/08/28 15:06:53
The reason there's a difference between here and a
|
| +} |
| + |
| +// static |
| +void BrowserList::PostBeforeUnloadHandlers( |
| + const BrowserVector& browsers_to_close, |
| + const base::Callback<void(size_t)>& on_close_success, |
| + const base::Callback<void(size_t)>& on_close_aborted, |
| + const size_t profile_index, |
| + bool proceed) { |
| + if (!current_closing_browser_) |
| + return; |
| + |
| + current_closing_browser_ = NULL; |
| + |
| + if (proceed) { |
| + TryToCloseBrowserList(browsers_to_close, on_close_success, on_close_aborted, |
| + profile_index); |
| + } else { |
| + for (BrowserVector::const_iterator it = browsers_to_close.begin(); |
| + it != browsers_to_close.end(); ++it) { |
| + (*it)->ResetBeforeUnloadHandlers(); |
| + } |
| + on_close_aborted.Run(profile_index); |
| + } |
| +} |
| + |
| +// static |
| void BrowserList::SetLastActive(Browser* browser) { |
| content::RecordAction(UserMetricsAction("ActiveBrowserChanged")); |
| BrowserList* browser_list = GetInstance(browser->host_desktop_type()); |