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

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: Moved code into ChromeBrowserMainExtraPartsX11 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } else if (!resetting_handlers) { 179 } else if (!resetting_handlers) {
180 base::AutoReset<bool> resetting_handlers_scoper(&resetting_handlers, true); 180 base::AutoReset<bool> resetting_handlers_scoper(&resetting_handlers, true);
181 for (BrowserVector::const_iterator it = browsers_to_close.begin(); 181 for (BrowserVector::const_iterator it = browsers_to_close.begin();
182 it != browsers_to_close.end(); ++it) { 182 it != browsers_to_close.end(); ++it) {
183 (*it)->ResetBeforeUnloadHandlers(); 183 (*it)->ResetBeforeUnloadHandlers();
184 } 184 }
185 } 185 }
186 } 186 }
187 187
188 // static 188 // static
189 void BrowserList::ReorderAfterWorkspaceChange(
190 const std::string& new_workspace) {
191 DCHECK(!new_workspace.empty());
192
193 BrowserList* instance = GetInstance();
194
195 Browser* old_last_active = instance->GetLastActive();
196 BrowserVector& last_active_browsers = instance->last_active_browsers_;
197
198 // Perform a stable partition on the browsers in the list so that the browsers
199 // in the new workspace appear after the browsers in the other workspaces.
200 //
201 // For example, if we have a list of browser-workspace pairs
202 // [{b1, 0}, {b2, 1}, {b3, 0}, {b4, 1}]
203 // and we switch to workspace 1, we want the resulting browser list to look
204 // like [{b1, 0}, {b3, 0}, {b2, 1}, {b4, 1}].
205 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
206 BrowserVector in_different_workspace;
207 for (Browser* browser : last_active_browsers) {
208 if (browser->window()->GetWorkspace() == new_workspace)
209 in_this_workspace.push_back(browser);
210 else
211 in_different_workspace.push_back(browser);
212 }
213 last_active_browsers.clear();
214 last_active_browsers.insert(last_active_browsers.end(),
215 in_different_workspace.begin(),
216 in_different_workspace.end());
217 last_active_browsers.insert(last_active_browsers.end(),
218 in_this_workspace.begin(),
219 in_this_workspace.end());
220
221 Browser* new_last_active = instance->GetLastActive();
222 if (old_last_active != new_last_active) {
223 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(),
224 OnBrowserSetLastActive(new_last_active));
225 }
226 }
227
228 // static
189 void BrowserList::SetLastActive(Browser* browser) { 229 void BrowserList::SetLastActive(Browser* browser) {
190 content::RecordAction(UserMetricsAction("ActiveBrowserChanged")); 230 content::RecordAction(UserMetricsAction("ActiveBrowserChanged"));
191 231
192 RemoveBrowserFrom(browser, &GetInstance()->last_active_browsers_); 232 RemoveBrowserFrom(browser, &GetInstance()->last_active_browsers_);
193 GetInstance()->last_active_browsers_.push_back(browser); 233 GetInstance()->last_active_browsers_.push_back(browser);
194 234
195 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(), 235 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(),
196 OnBrowserSetLastActive(browser)); 236 OnBrowserSetLastActive(browser));
197 } 237 }
198 238
(...skipping 27 matching lines...) Expand all
226 } 266 }
227 267
228 // static 268 // static
229 void BrowserList::RemoveBrowserFrom(Browser* browser, 269 void BrowserList::RemoveBrowserFrom(Browser* browser,
230 BrowserVector* browser_list) { 270 BrowserVector* browser_list) {
231 BrowserVector::iterator remove_browser = 271 BrowserVector::iterator remove_browser =
232 std::find(browser_list->begin(), browser_list->end(), browser); 272 std::find(browser_list->begin(), browser_list->end(), browser);
233 if (remove_browser != browser_list->end()) 273 if (remove_browser != browser_list->end())
234 browser_list->erase(remove_browser); 274 browser_list->erase(remove_browser);
235 } 275 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698