Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: chrome/browser/ui/browser_list.cc

Issue 1644773003: Remove BrowserIterator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@host-desktop-1
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/browser_iterator.cc ('k') | chrome/browser/ui/browser_tab_strip_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_iterator.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 "chrome/browser/ui/host_desktop.h" 21 #include "chrome/browser/ui/host_desktop.h"
22 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/user_metrics.h" 23 #include "content/public/browser/user_metrics.h"
24 24
25 using base::UserMetricsAction; 25 using base::UserMetricsAction;
26 using content::WebContents; 26 using content::WebContents;
27 27
28 // static 28 // static
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 // static 107 // static
108 void BrowserList::RemoveObserver(chrome::BrowserListObserver* observer) { 108 void BrowserList::RemoveObserver(chrome::BrowserListObserver* observer) {
109 observers_.Get().RemoveObserver(observer); 109 observers_.Get().RemoveObserver(observer);
110 } 110 }
111 111
112 // static 112 // static
113 void BrowserList::CloseAllBrowsersWithProfile(Profile* profile) { 113 void BrowserList::CloseAllBrowsersWithProfile(Profile* profile) {
114 BrowserVector browsers_to_close; 114 BrowserVector browsers_to_close;
115 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 115 for (auto* browser : *BrowserList::GetInstance()) {
116 if (it->profile()->GetOriginalProfile() == profile->GetOriginalProfile()) 116 if (browser->profile()->GetOriginalProfile() ==
117 browsers_to_close.push_back(*it); 117 profile->GetOriginalProfile())
118 browsers_to_close.push_back(browser);
118 } 119 }
119 120
120 for (BrowserVector::const_iterator it = browsers_to_close.begin(); 121 for (BrowserVector::const_iterator it = browsers_to_close.begin();
121 it != browsers_to_close.end(); ++it) { 122 it != browsers_to_close.end(); ++it) {
122 (*it)->window()->Close(); 123 (*it)->window()->Close();
123 } 124 }
124 } 125 }
125 126
126 // static 127 // static
127 void BrowserList::CloseAllBrowsersWithProfile(Profile* profile, 128 void BrowserList::CloseAllBrowsersWithProfile(Profile* profile,
128 const base::Callback<void(const base::FilePath&)>& on_close_success) { 129 const base::Callback<void(const base::FilePath&)>& on_close_success) {
129 BrowserVector browsers_to_close; 130 BrowserVector browsers_to_close;
130 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 131 for (auto* browser : *BrowserList::GetInstance()) {
131 if (it->profile()->GetOriginalProfile() == profile->GetOriginalProfile()) 132 if (browser->profile()->GetOriginalProfile() ==
132 browsers_to_close.push_back(*it); 133 profile->GetOriginalProfile())
134 browsers_to_close.push_back(browser);
133 } 135 }
134 136
135 TryToCloseBrowserList(browsers_to_close, 137 TryToCloseBrowserList(browsers_to_close,
136 on_close_success, 138 on_close_success,
137 profile->GetPath()); 139 profile->GetPath());
138 } 140 }
139 141
140 // static 142 // static
141 void BrowserList::TryToCloseBrowserList(const BrowserVector& browsers_to_close, 143 void BrowserList::TryToCloseBrowserList(const BrowserVector& browsers_to_close,
142 const base::Callback<void(const base::FilePath&)>& on_close_success, 144 const base::Callback<void(const base::FilePath&)>& on_close_success,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 192
191 RemoveBrowserFrom(browser, &GetInstance()->last_active_browsers_); 193 RemoveBrowserFrom(browser, &GetInstance()->last_active_browsers_);
192 GetInstance()->last_active_browsers_.push_back(browser); 194 GetInstance()->last_active_browsers_.push_back(browser);
193 195
194 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(), 196 FOR_EACH_OBSERVER(chrome::BrowserListObserver, observers_.Get(),
195 OnBrowserSetLastActive(browser)); 197 OnBrowserSetLastActive(browser));
196 } 198 }
197 199
198 // static 200 // static
199 bool BrowserList::IsOffTheRecordSessionActive() { 201 bool BrowserList::IsOffTheRecordSessionActive() {
200 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 202 for (auto* browser : *BrowserList::GetInstance()) {
201 if (it->profile()->IsOffTheRecord()) 203 if (browser->profile()->IsOffTheRecord())
202 return true; 204 return true;
203 } 205 }
204 return false; 206 return false;
205 } 207 }
206 208
207 // static 209 // static
208 bool BrowserList::IsOffTheRecordSessionActiveForProfile(Profile* profile) { 210 bool BrowserList::IsOffTheRecordSessionActiveForProfile(Profile* profile) {
209 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 211 for (auto* browser : *BrowserList::GetInstance()) {
210 if (it->profile()->IsSameProfile(profile) && 212 if (browser->profile()->IsSameProfile(profile) &&
211 it->profile()->IsOffTheRecord()) { 213 browser->profile()->IsOffTheRecord()) {
212 return true; 214 return true;
213 } 215 }
214 } 216 }
215 return false; 217 return false;
216 } 218 }
217 219
218 //////////////////////////////////////////////////////////////////////////////// 220 ////////////////////////////////////////////////////////////////////////////////
219 // BrowserList, private: 221 // BrowserList, private:
220 222
221 BrowserList::BrowserList() { 223 BrowserList::BrowserList() {
222 } 224 }
223 225
224 BrowserList::~BrowserList() { 226 BrowserList::~BrowserList() {
225 } 227 }
226 228
227 // static 229 // static
228 void BrowserList::RemoveBrowserFrom(Browser* browser, 230 void BrowserList::RemoveBrowserFrom(Browser* browser,
229 BrowserVector* browser_list) { 231 BrowserVector* browser_list) {
230 BrowserVector::iterator remove_browser = 232 BrowserVector::iterator remove_browser =
231 std::find(browser_list->begin(), browser_list->end(), browser); 233 std::find(browser_list->begin(), browser_list->end(), browser);
232 if (remove_browser != browser_list->end()) 234 if (remove_browser != browser_list->end())
233 browser_list->erase(remove_browser); 235 browser_list->erase(remove_browser);
234 } 236 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_iterator.cc ('k') | chrome/browser/ui/browser_tab_strip_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698