| 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::PartitionByWorkspace(const std::string& new_workspace) { |
| 190 DCHECK(!new_workspace.empty()); |
| 191 |
| 192 BrowserList* instance = GetInstance(); |
| 193 |
| 194 Browser* old_last_active = instance->GetLastActive(); |
| 195 BrowserVector& last_active_browsers = instance->last_active_browsers_; |
| 196 |
| 197 // Perform a stable partition on the browsers in the list so that the browsers |
| 198 // in the new workspace appear after the browsers in the other workspaces. |
| 199 // |
| 200 // For example, if we have a list of browser-workspace pairs |
| 201 // [{b1, 0}, {b2, 1}, {b3, 0}, {b4, 1}] |
| 202 // and we switch to workspace 1, we want the resulting browser list to look |
| 203 // like [{b1, 0}, {b3, 0}, {b2, 1}, {b4, 1}]. |
| 204 std::stable_partition( |
| 205 last_active_browsers.begin(), last_active_browsers.end(), |
| 206 [&new_workspace](Browser* browser) { |
| 207 return browser->window()->GetWorkspace() != new_workspace; |
| 208 }); |
| 209 |
| 210 Browser* new_last_active = instance->GetLastActive(); |
| 211 if (old_last_active != new_last_active) { |
| 212 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(), |
| 213 OnBrowserSetLastActive(new_last_active)); |
| 214 } |
| 215 } |
| 216 |
| 217 // static |
| 189 void BrowserList::SetLastActive(Browser* browser) { | 218 void BrowserList::SetLastActive(Browser* browser) { |
| 190 content::RecordAction(UserMetricsAction("ActiveBrowserChanged")); | 219 content::RecordAction(UserMetricsAction("ActiveBrowserChanged")); |
| 191 | 220 |
| 192 RemoveBrowserFrom(browser, &GetInstance()->last_active_browsers_); | 221 RemoveBrowserFrom(browser, &GetInstance()->last_active_browsers_); |
| 193 GetInstance()->last_active_browsers_.push_back(browser); | 222 GetInstance()->last_active_browsers_.push_back(browser); |
| 194 | 223 |
| 195 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(), | 224 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(), |
| 196 OnBrowserSetLastActive(browser)); | 225 OnBrowserSetLastActive(browser)); |
| 197 } | 226 } |
| 198 | 227 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 226 } | 255 } |
| 227 | 256 |
| 228 // static | 257 // static |
| 229 void BrowserList::RemoveBrowserFrom(Browser* browser, | 258 void BrowserList::RemoveBrowserFrom(Browser* browser, |
| 230 BrowserVector* browser_list) { | 259 BrowserVector* browser_list) { |
| 231 BrowserVector::iterator remove_browser = | 260 BrowserVector::iterator remove_browser = |
| 232 std::find(browser_list->begin(), browser_list->end(), browser); | 261 std::find(browser_list->begin(), browser_list->end(), browser); |
| 233 if (remove_browser != browser_list->end()) | 262 if (remove_browser != browser_list->end()) |
| 234 browser_list->erase(remove_browser); | 263 browser_list->erase(remove_browser); |
| 235 } | 264 } |
| OLD | NEW |