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_finder.h" | 5 #include "chrome/browser/ui/browser_finder.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 Browser::WindowFeature window_feature, | 101 Browser::WindowFeature window_feature, |
102 uint32_t match_types) { | 102 uint32_t match_types) { |
103 for (T i = begin; i != end; ++i) { | 103 for (T i = begin; i != end; ++i) { |
104 if (BrowserMatches(*i, profile, window_feature, match_types)) | 104 if (BrowserMatches(*i, profile, window_feature, match_types)) |
105 return *i; | 105 return *i; |
106 } | 106 } |
107 return NULL; | 107 return NULL; |
108 } | 108 } |
109 | 109 |
110 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, | 110 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, |
111 chrome::HostDesktopType desktop_type, | |
112 bool match_tabbed, | 111 bool match_tabbed, |
113 bool match_original_profiles) { | 112 bool match_original_profiles) { |
114 BrowserList* browser_list_impl = BrowserList::GetInstance(); | 113 BrowserList* browser_list_impl = BrowserList::GetInstance(); |
115 if (!browser_list_impl) | 114 if (!browser_list_impl) |
116 return NULL; | 115 return NULL; |
117 uint32_t match_types = kMatchAny; | 116 uint32_t match_types = kMatchAny; |
118 if (match_tabbed) | 117 if (match_tabbed) |
119 match_types |= kMatchTabbed; | 118 match_types |= kMatchTabbed; |
120 if (match_original_profiles) | 119 if (match_original_profiles) |
121 match_types |= kMatchOriginalProfile; | 120 match_types |= kMatchOriginalProfile; |
122 Browser* browser = FindBrowserMatching(browser_list_impl->begin_last_active(), | 121 Browser* browser = FindBrowserMatching(browser_list_impl->begin_last_active(), |
123 browser_list_impl->end_last_active(), | 122 browser_list_impl->end_last_active(), |
124 profile, | 123 profile, |
125 Browser::FEATURE_NONE, | 124 Browser::FEATURE_NONE, |
126 match_types); | 125 match_types); |
127 // Fall back to a forward scan of all Browsers if no active one was found. | 126 // Fall back to a forward scan of all Browsers if no active one was found. |
128 return browser ? browser : FindBrowserMatching(browser_list_impl->begin(), | 127 return browser ? browser : FindBrowserMatching(browser_list_impl->begin(), |
129 browser_list_impl->end(), | 128 browser_list_impl->end(), |
130 profile, | 129 profile, |
131 Browser::FEATURE_NONE, | 130 Browser::FEATURE_NONE, |
132 match_types); | 131 match_types); |
133 } | 132 } |
134 | 133 |
135 size_t GetBrowserCountImpl(Profile* profile, | 134 size_t GetBrowserCountImpl(Profile* profile, |
136 chrome::HostDesktopType desktop_type, | |
137 uint32_t match_types) { | 135 uint32_t match_types) { |
138 BrowserList* browser_list_impl = BrowserList::GetInstance(); | 136 BrowserList* browser_list_impl = BrowserList::GetInstance(); |
139 size_t count = 0; | 137 size_t count = 0; |
140 if (browser_list_impl) { | 138 if (browser_list_impl) { |
141 for (BrowserList::const_iterator i = browser_list_impl->begin(); | 139 for (BrowserList::const_iterator i = browser_list_impl->begin(); |
142 i != browser_list_impl->end(); ++i) { | 140 i != browser_list_impl->end(); ++i) { |
143 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types)) | 141 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types)) |
144 count++; | 142 count++; |
145 } | 143 } |
146 } | 144 } |
147 return count; | 145 return count; |
148 } | 146 } |
149 | 147 |
150 } // namespace | 148 } // namespace |
151 | 149 |
152 namespace chrome { | 150 namespace chrome { |
153 | 151 |
154 Browser* FindTabbedBrowser(Profile* profile, | 152 Browser* FindTabbedBrowser(Profile* profile, |
155 bool match_original_profiles, | 153 bool match_original_profiles) { |
156 HostDesktopType type) { | 154 return FindBrowserWithTabbedOrAnyType(profile, true, match_original_profiles); |
157 return FindBrowserWithTabbedOrAnyType(profile, | |
158 type, | |
159 true, | |
160 match_original_profiles); | |
161 } | 155 } |
162 | 156 |
163 Browser* FindAnyBrowser(Profile* profile, | 157 Browser* FindAnyBrowser(Profile* profile, |
164 bool match_original_profiles, | 158 bool match_original_profiles) { |
165 HostDesktopType type) { | |
166 return FindBrowserWithTabbedOrAnyType(profile, | 159 return FindBrowserWithTabbedOrAnyType(profile, |
167 type, | |
168 false, | 160 false, |
169 match_original_profiles); | 161 match_original_profiles); |
170 } | 162 } |
171 | 163 |
172 Browser* FindBrowserWithProfile(Profile* profile, | 164 Browser* FindBrowserWithProfile(Profile* profile) { |
173 HostDesktopType desktop_type) { | 165 return FindBrowserWithTabbedOrAnyType(profile, false, false); |
174 return FindBrowserWithTabbedOrAnyType(profile, desktop_type, false, false); | |
175 } | 166 } |
176 | 167 |
177 Browser* FindBrowserWithID(SessionID::id_type desired_id) { | 168 Browser* FindBrowserWithID(SessionID::id_type desired_id) { |
178 for (auto* browser : *BrowserList::GetInstance()) { | 169 for (auto* browser : *BrowserList::GetInstance()) { |
179 if (browser->session_id().id() == desired_id) | 170 if (browser->session_id().id() == desired_id) |
180 return browser; | 171 return browser; |
181 } | 172 } |
182 return NULL; | 173 return NULL; |
183 } | 174 } |
184 | 175 |
(...skipping 28 matching lines...) Expand all Loading... |
213 BrowserList* browser_list_impl = BrowserList::GetInstance(); | 204 BrowserList* browser_list_impl = BrowserList::GetInstance(); |
214 if (browser_list_impl) | 205 if (browser_list_impl) |
215 return browser_list_impl->GetLastActive(); | 206 return browser_list_impl->GetLastActive(); |
216 return NULL; | 207 return NULL; |
217 } | 208 } |
218 | 209 |
219 size_t GetTotalBrowserCount() { | 210 size_t GetTotalBrowserCount() { |
220 return BrowserList::GetInstance()->size(); | 211 return BrowserList::GetInstance()->size(); |
221 } | 212 } |
222 | 213 |
223 size_t GetTotalBrowserCountForProfile(Profile* profile) { | 214 size_t GetBrowserCount(Profile* profile) { |
224 size_t count = 0; | 215 return GetBrowserCountImpl(profile, kMatchAny); |
225 for (HostDesktopType t = HOST_DESKTOP_TYPE_FIRST; t < HOST_DESKTOP_TYPE_COUNT; | |
226 t = static_cast<HostDesktopType>(t + 1)) { | |
227 count += GetBrowserCount(profile, t); | |
228 } | |
229 return count; | |
230 } | 216 } |
231 | 217 |
232 size_t GetBrowserCount(Profile* profile, HostDesktopType type) { | 218 size_t GetTabbedBrowserCount(Profile* profile) { |
233 return GetBrowserCountImpl(profile, type, kMatchAny); | 219 return GetBrowserCountImpl(profile, kMatchTabbed); |
234 } | |
235 | |
236 size_t GetTabbedBrowserCount(Profile* profile, HostDesktopType type) { | |
237 return GetBrowserCountImpl(profile, type, kMatchTabbed); | |
238 } | 220 } |
239 | 221 |
240 } // namespace chrome | 222 } // namespace chrome |
OLD | NEW |