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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) { |
| 223 DCHECK(!new_workspace.empty()); |
| 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 after 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 [{b1, 0}, {b3, 0}, {b2, 1}, {b4, 1}]. |
| 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::desktop::AddObserver(this); |
223 } | 262 } |
224 | 263 |
225 BrowserList::~BrowserList() { | 264 BrowserList::~BrowserList() { |
| 265 display::desktop::RemoveObserver(this); |
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 } |
OLD | NEW |