Index: chrome/browser/ui/browser_finder.cc |
diff --git a/chrome/browser/ui/browser_finder.cc b/chrome/browser/ui/browser_finder.cc |
index cd485eeff4cee19132e074146208d3eddd74fbfc..5c971cb2b584b2c69accd2ba9ce488aaf987c28f 100644 |
--- a/chrome/browser/ui/browser_finder.cc |
+++ b/chrome/browser/ui/browser_finder.cc |
@@ -105,6 +105,23 @@ Browser* FindBrowserMatching(const T& begin, |
return NULL; |
} |
+// Returns all browsers in the specified iterator that returns true from |
+// |BrowserMatches|. See |BrowserMatches| for details on the arguments. |
+template <class T> |
+std::vector<Browser*> FindAllBrowsersMatching( |
+ const T& begin, |
+ const T& end, |
+ Profile* profile, |
+ Browser::WindowFeature window_feature, |
+ uint32 match_types) { |
+ std::vector<Browser*> matches; |
+ for (T i = begin; i != end; ++i) { |
+ if (BrowserMatches(*i, profile, window_feature, match_types)) |
+ matches.push_back(*i); |
+ } |
+ return matches; |
+} |
+ |
Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, |
chrome::HostDesktopType desktop_type, |
bool match_tabbed, |
@@ -130,6 +147,35 @@ Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, |
match_types); |
} |
+std::vector<Browser*> FindAllBrowsersWithTabbedOrAnyType( |
+ Profile* profile, |
+ chrome::HostDesktopType desktop_type, |
+ bool match_tabbed, |
+ bool match_original_profiles) { |
+ std::vector<Browser*> matches; |
+ BrowserList* browser_list_impl = BrowserList::GetInstance(desktop_type); |
+ if (!browser_list_impl) |
+ return matches; |
+ uint32 match_types = kMatchAny; |
+ if (match_tabbed) |
+ match_types |= kMatchTabbed; |
+ if (match_original_profiles) |
+ match_types |= kMatchOriginalProfile; |
+ matches = |
+ FindAllBrowsersMatching(browser_list_impl->begin_last_active(), |
+ browser_list_impl->end_last_active(), profile, |
+ Browser::FEATURE_NONE, match_types); |
+ if (matches.size()) |
msw
2015/12/15 21:30:09
nit: if (!matches.empty())
GeorgeZ
2015/12/16 00:07:39
Done.
|
+ return matches; |
+ |
+ // Fall back to a forward scan of all Browsers if no active one was found. |
+ matches = FindAllBrowsersMatching(browser_list_impl->begin(), |
+ browser_list_impl->end(), profile, |
+ Browser::FEATURE_NONE, match_types); |
+ |
+ return matches; |
+} |
+ |
size_t GetBrowserCountImpl(Profile* profile, |
chrome::HostDesktopType desktop_type, |
uint32 match_types) { |
@@ -172,6 +218,12 @@ Browser* FindBrowserWithProfile(Profile* profile, |
return FindBrowserWithTabbedOrAnyType(profile, desktop_type, false, false); |
} |
+std::vector<Browser*> FindAllTabbedBrowsersWithProfile( |
+ Profile* profile, |
+ HostDesktopType desktop_type) { |
+ return FindAllBrowsersWithTabbedOrAnyType(profile, desktop_type, true, false); |
+} |
+ |
Browser* FindBrowserWithID(SessionID::id_type desired_id) { |
for (BrowserIterator it; !it.done(); it.Next()) { |
if (it->session_id().id() == desired_id) |