Index: chrome/browser/ui/browser_list.cc |
diff --git a/chrome/browser/ui/browser_list.cc b/chrome/browser/ui/browser_list.cc |
index 5516e79a2d661b03360ed12af48582c656e1ed4b..2f578b6978d705cd46144e051c5418452a7a200a 100644 |
--- a/chrome/browser/ui/browser_list.cc |
+++ b/chrome/browser/ui/browser_list.cc |
@@ -186,6 +186,46 @@ void BrowserList::PostBeforeUnloadHandlers( |
} |
// static |
+void BrowserList::ReorderAfterWorkspaceChange( |
+ const std::string& new_workspace) { |
+ DCHECK(!new_workspace.empty()); |
+ |
+ BrowserList* instance = GetInstance(); |
+ |
+ Browser* old_last_active = instance->GetLastActive(); |
+ BrowserVector& last_active_browsers = instance->last_active_browsers_; |
+ |
+ // Perform a stable partition on the browsers in the list so that the browsers |
+ // in the new workspace appear after the browsers in the other workspaces. |
+ // |
+ // For example, if we have a list of browser-workspace pairs |
+ // [{b1, 0}, {b2, 1}, {b3, 0}, {b4, 1}] |
+ // and we switch to workspace 1, we want the resulting browser list to look |
+ // like [{b1, 0}, {b3, 0}, {b2, 1}, {b4, 1}]. |
+ BrowserVector in_this_workspace; |
sky
2016/07/06 20:33:05
Isn't this the same as a sort with a comparator th
Tom (Use chromium acct)
2016/07/06 22:29:16
Nice catch. stable_sort is much cleaner
|
+ BrowserVector in_different_workspace; |
+ for (Browser* browser : last_active_browsers) { |
+ if (browser->window()->GetWorkspace() == new_workspace) |
+ in_this_workspace.push_back(browser); |
+ else |
+ in_different_workspace.push_back(browser); |
+ } |
+ last_active_browsers.clear(); |
+ last_active_browsers.insert(last_active_browsers.end(), |
+ in_different_workspace.begin(), |
+ in_different_workspace.end()); |
+ last_active_browsers.insert(last_active_browsers.end(), |
+ in_this_workspace.begin(), |
+ in_this_workspace.end()); |
+ |
+ Browser* new_last_active = instance->GetLastActive(); |
+ if (old_last_active != new_last_active) { |
+ FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(), |
+ OnBrowserSetLastActive(new_last_active)); |
+ } |
+} |
+ |
+// static |
void BrowserList::SetLastActive(Browser* browser) { |
content::RecordAction(UserMetricsAction("ActiveBrowserChanged")); |