Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2694)

Unified Diff: chrome/browser/ui/browser_list.cc

Issue 2108933003: Reorder browser list on workspace switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Set a browser as last active on workspace change Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3dee769bb4259b714792dc3e78c686c072635170 100644
--- a/chrome/browser/ui/browser_list.cc
+++ b/chrome/browser/ui/browser_list.cc
@@ -217,9 +217,48 @@ bool BrowserList::IsOffTheRecordSessionActiveForProfile(Profile* profile) {
}
////////////////////////////////////////////////////////////////////////////////
+// BrowserList, display::DesktopObserver implementation:
+
+void BrowserList::OnWorkspaceChanged(const std::string& new_workspace) {
Lei Zhang 2016/06/29 18:30:53 Isn't BrowserList cross-platform? How does this af
Tom (Use chromium acct) 2016/06/29 20:16:04 It won't get called, until we eventually add suppo
+ DCHECK_NE(new_workspace, "");
Lei Zhang 2016/06/29 18:30:53 DCHECK(!new_workspace.empty()) ?
Tom (Use chromium acct) 2016/06/29 20:16:04 Done.
+
+ Browser* old_last_active = GetLastActive();
+
+ // Reorder the browsers in the list so that the browsers in the new workspace
+ // appear before 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 [{b2, 1}, {b4, 1}, {b1, 0}, {b3, 0}].
+ BrowserVector in_this_workspace;
+ 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 = GetLastActive();
+ if (old_last_active != new_last_active) {
+ FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(),
+ OnBrowserSetLastActive(new_last_active));
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
// BrowserList, private:
BrowserList::BrowserList() {
+ display::g_desktop_observer_list.AddObserver(this);
}
BrowserList::~BrowserList() {
Elliot Glaysher 2016/06/29 18:21:09 Do you need a matched RemoveObserver?
Tom (Use chromium acct) 2016/06/29 20:16:04 Done.

Powered by Google App Engine
This is Rietveld 408576698