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" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/browser_shutdown.h" | 12 #include "chrome/browser/browser_shutdown.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/lifetime/application_lifetime.h" | 14 #include "chrome/browser/lifetime/application_lifetime.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_finder.h" | 17 #include "chrome/browser/ui/browser_finder.h" |
18 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
19 #include "chrome/browser/ui/browser_list_observer.h" | 19 #include "chrome/browser/ui/browser_list_observer.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/user_metrics.h" | 22 #include "content/public/browser/user_metrics.h" |
| 23 #include "ui/display/desktop.h" |
23 | 24 |
24 using base::UserMetricsAction; | 25 using base::UserMetricsAction; |
25 using content::WebContents; | 26 using content::WebContents; |
26 | 27 |
27 // static | 28 // static |
28 base::LazyInstance<base::ObserverList<chrome::BrowserListObserver>>::Leaky | 29 base::LazyInstance<base::ObserverList<chrome::BrowserListObserver>>::Leaky |
29 BrowserList::observers_ = LAZY_INSTANCE_INITIALIZER; | 30 BrowserList::observers_ = LAZY_INSTANCE_INITIALIZER; |
30 | 31 |
31 // static | 32 // static |
32 BrowserList* BrowserList::instance_ = NULL; | 33 BrowserList* BrowserList::instance_ = NULL; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 for (auto* browser : *BrowserList::GetInstance()) { | 211 for (auto* browser : *BrowserList::GetInstance()) { |
211 if (browser->profile()->IsSameProfile(profile) && | 212 if (browser->profile()->IsSameProfile(profile) && |
212 browser->profile()->IsOffTheRecord()) { | 213 browser->profile()->IsOffTheRecord()) { |
213 return true; | 214 return true; |
214 } | 215 } |
215 } | 216 } |
216 return false; | 217 return false; |
217 } | 218 } |
218 | 219 |
219 //////////////////////////////////////////////////////////////////////////////// | 220 //////////////////////////////////////////////////////////////////////////////// |
| 221 // BrowserList, display::DesktopObserver implementation: |
| 222 |
| 223 void BrowserList::OnWorkspaceChanged(const std::string& new_workspace) { |
| 224 DCHECK(!new_workspace.empty()); |
| 225 |
| 226 Browser* old_last_active = GetLastActive(); |
| 227 |
| 228 // Reorder the browsers in the list so that the browsers in the new workspace |
| 229 // appear after the browsers in the other workspaces. |
| 230 // |
| 231 // For example, if we have a list of browser-workspace pairs |
| 232 // [{b1, 0}, {b2, 1}, {b3, 0}, {b4, 1}] |
| 233 // and we switch to workspace 1, we want the resulting browser list to look |
| 234 // like [{b1, 0}, {b3, 0}, {b2, 1}, {b4, 1}]. |
| 235 BrowserVector in_this_workspace; |
| 236 BrowserVector in_different_workspace; |
| 237 for (Browser* browser : last_active_browsers_) { |
| 238 if (browser->window()->GetWorkspace() == new_workspace) |
| 239 in_this_workspace.push_back(browser); |
| 240 else |
| 241 in_different_workspace.push_back(browser); |
| 242 } |
| 243 last_active_browsers_.clear(); |
| 244 last_active_browsers_.insert(last_active_browsers_.end(), |
| 245 in_different_workspace.begin(), |
| 246 in_different_workspace.end()); |
| 247 last_active_browsers_.insert(last_active_browsers_.end(), |
| 248 in_this_workspace.begin(), |
| 249 in_this_workspace.end()); |
| 250 |
| 251 Browser* new_last_active = GetLastActive(); |
| 252 if (old_last_active != new_last_active) { |
| 253 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(), |
| 254 OnBrowserSetLastActive(new_last_active)); |
| 255 } |
| 256 } |
| 257 |
| 258 //////////////////////////////////////////////////////////////////////////////// |
220 // BrowserList, private: | 259 // BrowserList, private: |
221 | 260 |
222 BrowserList::BrowserList() { | 261 BrowserList::BrowserList() { |
| 262 display::Desktop::AddObserver(this); |
223 } | 263 } |
224 | 264 |
225 BrowserList::~BrowserList() { | 265 BrowserList::~BrowserList() { |
| 266 display::Desktop::RemoveObserver(this); |
226 } | 267 } |
227 | 268 |
228 // static | 269 // static |
229 void BrowserList::RemoveBrowserFrom(Browser* browser, | 270 void BrowserList::RemoveBrowserFrom(Browser* browser, |
230 BrowserVector* browser_list) { | 271 BrowserVector* browser_list) { |
231 BrowserVector::iterator remove_browser = | 272 BrowserVector::iterator remove_browser = |
232 std::find(browser_list->begin(), browser_list->end(), browser); | 273 std::find(browser_list->begin(), browser_list->end(), browser); |
233 if (remove_browser != browser_list->end()) | 274 if (remove_browser != browser_list->end()) |
234 browser_list->erase(remove_browser); | 275 browser_list->erase(remove_browser); |
235 } | 276 } |
OLD | NEW |