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