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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/browser_list.h" 5 #include "chrome/browser/ui/browser_list.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 for (auto* browser : *BrowserList::GetInstance()) { 210 for (auto* browser : *BrowserList::GetInstance()) {
211 if (browser->profile()->IsSameProfile(profile) && 211 if (browser->profile()->IsSameProfile(profile) &&
212 browser->profile()->IsOffTheRecord()) { 212 browser->profile()->IsOffTheRecord()) {
213 return true; 213 return true;
214 } 214 }
215 } 215 }
216 return false; 216 return false;
217 } 217 }
218 218
219 //////////////////////////////////////////////////////////////////////////////// 219 ////////////////////////////////////////////////////////////////////////////////
220 // BrowserList, display::DesktopObserver implementation:
221
222 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
223 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.
224
225 Browser* old_last_active = GetLastActive();
226
227 // Reorder the browsers in the list so that the browsers in the new workspace
228 // appear before the browsers in the other workspaces.
229 //
230 // For example, if we have a list of browser-workspace pairs
231 // [{b1, 0}, {b2, 1}, {b3, 0}, {b4, 1}]
232 // and we switch to workspace 1, we want the resulting browser list to look
233 // like [{b2, 1}, {b4, 1}, {b1, 0}, {b3, 0}].
234 BrowserVector in_this_workspace;
235 BrowserVector in_different_workspace;
236 for (Browser* browser : last_active_browsers_) {
237 if (browser->window()->GetWorkspace() == new_workspace)
238 in_this_workspace.push_back(browser);
239 else
240 in_different_workspace.push_back(browser);
241 }
242 last_active_browsers_.clear();
243 last_active_browsers_.insert(last_active_browsers_.end(),
244 in_different_workspace.begin(),
245 in_different_workspace.end());
246 last_active_browsers_.insert(last_active_browsers_.end(),
247 in_this_workspace.begin(),
248 in_this_workspace.end());
249
250 Browser* new_last_active = GetLastActive();
251 if (old_last_active != new_last_active) {
252 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(),
253 OnBrowserSetLastActive(new_last_active));
254 }
255 }
256
257 ////////////////////////////////////////////////////////////////////////////////
220 // BrowserList, private: 258 // BrowserList, private:
221 259
222 BrowserList::BrowserList() { 260 BrowserList::BrowserList() {
261 display::g_desktop_observer_list.AddObserver(this);
223 } 262 }
224 263
225 BrowserList::~BrowserList() { 264 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.
226 } 265 }
227 266
228 // static 267 // static
229 void BrowserList::RemoveBrowserFrom(Browser* browser, 268 void BrowserList::RemoveBrowserFrom(Browser* browser,
230 BrowserVector* browser_list) { 269 BrowserVector* browser_list) {
231 BrowserVector::iterator remove_browser = 270 BrowserVector::iterator remove_browser =
232 std::find(browser_list->begin(), browser_list->end(), browser); 271 std::find(browser_list->begin(), browser_list->end(), browser);
233 if (remove_browser != browser_list->end()) 272 if (remove_browser != browser_list->end())
234 browser_list->erase(remove_browser); 273 browser_list->erase(remove_browser);
235 } 274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698