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 "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/ui/browser_iterator.h" | 8 #include "chrome/browser/ui/browser_iterator.h" |
9 #include "chrome/browser/ui/browser_list.h" | 9 #include "chrome/browser/ui/browser_list.h" |
10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 Profile* profile, | 98 Profile* profile, |
99 Browser::WindowFeature window_feature, | 99 Browser::WindowFeature window_feature, |
100 uint32 match_types) { | 100 uint32 match_types) { |
101 for (T i = begin; i != end; ++i) { | 101 for (T i = begin; i != end; ++i) { |
102 if (BrowserMatches(*i, profile, window_feature, match_types)) | 102 if (BrowserMatches(*i, profile, window_feature, match_types)) |
103 return *i; | 103 return *i; |
104 } | 104 } |
105 return NULL; | 105 return NULL; |
106 } | 106 } |
107 | 107 |
108 // Returns all browsers in the specified iterator that returns true from | |
109 // |BrowserMatches|. See |BrowserMatches| for details on the arguments. | |
110 template <class T> | |
111 std::vector<Browser*> FindAllBrowsersMatching( | |
112 const T& begin, | |
113 const T& end, | |
114 Profile* profile, | |
115 Browser::WindowFeature window_feature, | |
116 uint32 match_types) { | |
117 std::vector<Browser*> matches; | |
118 for (T i = begin; i != end; ++i) { | |
119 if (BrowserMatches(*i, profile, window_feature, match_types)) | |
120 matches.push_back(*i); | |
121 } | |
122 return matches; | |
123 } | |
124 | |
108 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, | 125 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, |
109 chrome::HostDesktopType desktop_type, | 126 chrome::HostDesktopType desktop_type, |
110 bool match_tabbed, | 127 bool match_tabbed, |
111 bool match_original_profiles) { | 128 bool match_original_profiles) { |
112 BrowserList* browser_list_impl = BrowserList::GetInstance(desktop_type); | 129 BrowserList* browser_list_impl = BrowserList::GetInstance(desktop_type); |
113 if (!browser_list_impl) | 130 if (!browser_list_impl) |
114 return NULL; | 131 return NULL; |
115 uint32 match_types = kMatchAny; | 132 uint32 match_types = kMatchAny; |
116 if (match_tabbed) | 133 if (match_tabbed) |
117 match_types |= kMatchTabbed; | 134 match_types |= kMatchTabbed; |
118 if (match_original_profiles) | 135 if (match_original_profiles) |
119 match_types |= kMatchOriginalProfile; | 136 match_types |= kMatchOriginalProfile; |
120 Browser* browser = FindBrowserMatching(browser_list_impl->begin_last_active(), | 137 Browser* browser = FindBrowserMatching(browser_list_impl->begin_last_active(), |
121 browser_list_impl->end_last_active(), | 138 browser_list_impl->end_last_active(), |
122 profile, | 139 profile, |
123 Browser::FEATURE_NONE, | 140 Browser::FEATURE_NONE, |
124 match_types); | 141 match_types); |
125 // Fall back to a forward scan of all Browsers if no active one was found. | 142 // Fall back to a forward scan of all Browsers if no active one was found. |
126 return browser ? browser : FindBrowserMatching(browser_list_impl->begin(), | 143 return browser ? browser : FindBrowserMatching(browser_list_impl->begin(), |
127 browser_list_impl->end(), | 144 browser_list_impl->end(), |
128 profile, | 145 profile, |
129 Browser::FEATURE_NONE, | 146 Browser::FEATURE_NONE, |
130 match_types); | 147 match_types); |
131 } | 148 } |
132 | 149 |
150 std::vector<Browser*> FindAllBrowsersWithTabbedOrAnyType( | |
151 Profile* profile, | |
152 chrome::HostDesktopType desktop_type, | |
153 bool match_tabbed, | |
154 bool match_original_profiles) { | |
155 std::vector<Browser*> matches; | |
156 BrowserList* browser_list_impl = BrowserList::GetInstance(desktop_type); | |
157 if (!browser_list_impl) | |
158 return matches; | |
159 uint32 match_types = kMatchAny; | |
160 if (match_tabbed) | |
161 match_types |= kMatchTabbed; | |
162 if (match_original_profiles) | |
163 match_types |= kMatchOriginalProfile; | |
164 matches = | |
165 FindAllBrowsersMatching(browser_list_impl->begin_last_active(), | |
166 browser_list_impl->end_last_active(), profile, | |
167 Browser::FEATURE_NONE, match_types); | |
168 if (matches.size()) | |
msw
2015/12/15 21:30:09
nit: if (!matches.empty())
GeorgeZ
2015/12/16 00:07:39
Done.
| |
169 return matches; | |
170 | |
171 // Fall back to a forward scan of all Browsers if no active one was found. | |
172 matches = FindAllBrowsersMatching(browser_list_impl->begin(), | |
173 browser_list_impl->end(), profile, | |
174 Browser::FEATURE_NONE, match_types); | |
175 | |
176 return matches; | |
177 } | |
178 | |
133 size_t GetBrowserCountImpl(Profile* profile, | 179 size_t GetBrowserCountImpl(Profile* profile, |
134 chrome::HostDesktopType desktop_type, | 180 chrome::HostDesktopType desktop_type, |
135 uint32 match_types) { | 181 uint32 match_types) { |
136 BrowserList* browser_list_impl = BrowserList::GetInstance(desktop_type); | 182 BrowserList* browser_list_impl = BrowserList::GetInstance(desktop_type); |
137 size_t count = 0; | 183 size_t count = 0; |
138 if (browser_list_impl) { | 184 if (browser_list_impl) { |
139 for (BrowserList::const_iterator i = browser_list_impl->begin(); | 185 for (BrowserList::const_iterator i = browser_list_impl->begin(); |
140 i != browser_list_impl->end(); ++i) { | 186 i != browser_list_impl->end(); ++i) { |
141 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types)) | 187 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types)) |
142 count++; | 188 count++; |
(...skipping 22 matching lines...) Expand all Loading... | |
165 type, | 211 type, |
166 false, | 212 false, |
167 match_original_profiles); | 213 match_original_profiles); |
168 } | 214 } |
169 | 215 |
170 Browser* FindBrowserWithProfile(Profile* profile, | 216 Browser* FindBrowserWithProfile(Profile* profile, |
171 HostDesktopType desktop_type) { | 217 HostDesktopType desktop_type) { |
172 return FindBrowserWithTabbedOrAnyType(profile, desktop_type, false, false); | 218 return FindBrowserWithTabbedOrAnyType(profile, desktop_type, false, false); |
173 } | 219 } |
174 | 220 |
221 std::vector<Browser*> FindAllTabbedBrowsersWithProfile( | |
222 Profile* profile, | |
223 HostDesktopType desktop_type) { | |
224 return FindAllBrowsersWithTabbedOrAnyType(profile, desktop_type, true, false); | |
225 } | |
226 | |
175 Browser* FindBrowserWithID(SessionID::id_type desired_id) { | 227 Browser* FindBrowserWithID(SessionID::id_type desired_id) { |
176 for (BrowserIterator it; !it.done(); it.Next()) { | 228 for (BrowserIterator it; !it.done(); it.Next()) { |
177 if (it->session_id().id() == desired_id) | 229 if (it->session_id().id() == desired_id) |
178 return *it; | 230 return *it; |
179 } | 231 } |
180 return NULL; | 232 return NULL; |
181 } | 233 } |
182 | 234 |
183 Browser* FindBrowserWithWindow(gfx::NativeWindow window) { | 235 Browser* FindBrowserWithWindow(gfx::NativeWindow window) { |
184 if (!window) | 236 if (!window) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 | 287 |
236 size_t GetBrowserCount(Profile* profile, HostDesktopType type) { | 288 size_t GetBrowserCount(Profile* profile, HostDesktopType type) { |
237 return GetBrowserCountImpl(profile, type, kMatchAny); | 289 return GetBrowserCountImpl(profile, type, kMatchAny); |
238 } | 290 } |
239 | 291 |
240 size_t GetTabbedBrowserCount(Profile* profile, HostDesktopType type) { | 292 size_t GetTabbedBrowserCount(Profile* profile, HostDesktopType type) { |
241 return GetBrowserCountImpl(profile, type, kMatchTabbed); | 293 return GetBrowserCountImpl(profile, type, kMatchTabbed); |
242 } | 294 } |
243 | 295 |
244 } // namespace chrome | 296 } // namespace chrome |
OLD | NEW |