blob: 42b26e0078a5cf25707f4f629ec762bbaf7792bb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/browser_list_impl.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/host_desktop.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/user_manager.h"
#endif
using content::WebContents;
namespace {
chrome::BrowserListImpl* GetNativeList() {
return chrome::BrowserListImpl::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
}
} // namespace
// static
void BrowserList::AddBrowser(Browser* browser) {
chrome::BrowserListImpl::GetInstance(browser->host_desktop_type())->
AddBrowser(browser);
}
// static
void BrowserList::RemoveBrowser(Browser* browser) {
chrome::BrowserListImpl::GetInstance(browser->host_desktop_type())->
RemoveBrowser(browser);
}
// static
void BrowserList::AddObserver(chrome::BrowserListObserver* observer) {
for (chrome::HostDesktopType t = chrome::HOST_DESKTOP_TYPE_FIRST;
t < chrome::HOST_DESKTOP_TYPE_COUNT;
t = static_cast<chrome::HostDesktopType>(t + 1)) {
chrome::BrowserListImpl::GetInstance(t)->AddObserver(observer);
}
}
// static
void BrowserList::RemoveObserver(chrome::BrowserListObserver* observer) {
for (chrome::HostDesktopType t = chrome::HOST_DESKTOP_TYPE_FIRST;
t < chrome::HOST_DESKTOP_TYPE_COUNT;
t = static_cast<chrome::HostDesktopType>(t + 1)) {
chrome::BrowserListImpl::GetInstance(t)->RemoveObserver(observer);
}
}
void BrowserList::CloseAllBrowsersWithProfile(Profile* profile) {
BrowserVector browsers_to_close;
for (chrome::BrowserIterator it; !it.done(); it.Next()) {
if (it->profile()->GetOriginalProfile() == profile->GetOriginalProfile())
browsers_to_close.push_back(*it);
}
for (BrowserVector::const_iterator it = browsers_to_close.begin();
it != browsers_to_close.end(); ++it) {
(*it)->window()->Close();
}
}
// static
void BrowserList::SetLastActive(Browser* browser) {
chrome::BrowserListImpl::GetInstance(browser->host_desktop_type())->
SetLastActive(browser);
}
// static
bool BrowserList::IsOffTheRecordSessionActive() {
for (chrome::BrowserIterator it; !it.done(); it.Next()) {
if (it->profile()->IsOffTheRecord())
return true;
}
return false;
}
// static
bool BrowserList::IsOffTheRecordSessionActiveForProfile(Profile* profile) {
#if defined(OS_CHROMEOS)
// In ChromeOS, we assume that the default profile is always valid, so if
// we are in guest mode, keep the OTR profile active so it won't be deleted.
if (chromeos::UserManager::Get()->IsLoggedInAsGuest())
return true;
#endif
for (chrome::BrowserIterator it; !it.done(); it.Next()) {
if (it->profile()->IsSameProfile(profile) &&
it->profile()->IsOffTheRecord()) {
return true;
}
}
return false;
}
|