OLD | NEW |
---|---|
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 Loading... | |
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 std::stable_sort(last_active_browsers.begin(), last_active_browsers.end(), | |
206 [](Browser* b1, Browser* b2) { | |
207 return b1->window()->GetWorkspace() != | |
sky
2016/07/07 03:23:27
Don't you want < ?
Tom (Use chromium acct)
2016/07/07 19:12:10
actually wanted stable_partition
| |
208 b2->window()->GetWorkspace(); | |
209 }); | |
210 | |
211 Browser* new_last_active = instance->GetLastActive(); | |
212 if (old_last_active != new_last_active) { | |
213 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(), | |
214 OnBrowserSetLastActive(new_last_active)); | |
215 } | |
216 } | |
217 | |
218 // static | |
189 void BrowserList::SetLastActive(Browser* browser) { | 219 void BrowserList::SetLastActive(Browser* browser) { |
190 content::RecordAction(UserMetricsAction("ActiveBrowserChanged")); | 220 content::RecordAction(UserMetricsAction("ActiveBrowserChanged")); |
191 | 221 |
192 RemoveBrowserFrom(browser, &GetInstance()->last_active_browsers_); | 222 RemoveBrowserFrom(browser, &GetInstance()->last_active_browsers_); |
193 GetInstance()->last_active_browsers_.push_back(browser); | 223 GetInstance()->last_active_browsers_.push_back(browser); |
194 | 224 |
195 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(), | 225 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(), |
196 OnBrowserSetLastActive(browser)); | 226 OnBrowserSetLastActive(browser)); |
197 } | 227 } |
198 | 228 |
(...skipping 27 matching lines...) Expand all Loading... | |
226 } | 256 } |
227 | 257 |
228 // static | 258 // static |
229 void BrowserList::RemoveBrowserFrom(Browser* browser, | 259 void BrowserList::RemoveBrowserFrom(Browser* browser, |
230 BrowserVector* browser_list) { | 260 BrowserVector* browser_list) { |
231 BrowserVector::iterator remove_browser = | 261 BrowserVector::iterator remove_browser = |
232 std::find(browser_list->begin(), browser_list->end(), browser); | 262 std::find(browser_list->begin(), browser_list->end(), browser); |
233 if (remove_browser != browser_list->end()) | 263 if (remove_browser != browser_list->end()) |
234 browser_list->erase(remove_browser); | 264 browser_list->erase(remove_browser); |
235 } | 265 } |
OLD | NEW |