| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, | 111 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, |
| 112 chrome::HostDesktopType desktop_type, | 112 chrome::HostDesktopType desktop_type, |
| 113 bool match_tabbed, | 113 bool match_tabbed, |
| 114 bool match_original_profiles) { | 114 bool match_original_profiles) { |
| 115 BrowserList* browser_list_impl = BrowserList::GetInstance(desktop_type); | 115 BrowserList* browser_list_impl = BrowserList::GetInstance(); |
| 116 if (!browser_list_impl) | 116 if (!browser_list_impl) |
| 117 return NULL; | 117 return NULL; |
| 118 uint32_t match_types = kMatchAny; | 118 uint32_t match_types = kMatchAny; |
| 119 if (match_tabbed) | 119 if (match_tabbed) |
| 120 match_types |= kMatchTabbed; | 120 match_types |= kMatchTabbed; |
| 121 if (match_original_profiles) | 121 if (match_original_profiles) |
| 122 match_types |= kMatchOriginalProfile; | 122 match_types |= kMatchOriginalProfile; |
| 123 Browser* browser = FindBrowserMatching(browser_list_impl->begin_last_active(), | 123 Browser* browser = FindBrowserMatching(browser_list_impl->begin_last_active(), |
| 124 browser_list_impl->end_last_active(), | 124 browser_list_impl->end_last_active(), |
| 125 profile, | 125 profile, |
| 126 Browser::FEATURE_NONE, | 126 Browser::FEATURE_NONE, |
| 127 match_types); | 127 match_types); |
| 128 // Fall back to a forward scan of all Browsers if no active one was found. | 128 // Fall back to a forward scan of all Browsers if no active one was found. |
| 129 return browser ? browser : FindBrowserMatching(browser_list_impl->begin(), | 129 return browser ? browser : FindBrowserMatching(browser_list_impl->begin(), |
| 130 browser_list_impl->end(), | 130 browser_list_impl->end(), |
| 131 profile, | 131 profile, |
| 132 Browser::FEATURE_NONE, | 132 Browser::FEATURE_NONE, |
| 133 match_types); | 133 match_types); |
| 134 } | 134 } |
| 135 | 135 |
| 136 size_t GetBrowserCountImpl(Profile* profile, | 136 size_t GetBrowserCountImpl(Profile* profile, |
| 137 chrome::HostDesktopType desktop_type, | 137 chrome::HostDesktopType desktop_type, |
| 138 uint32_t match_types) { | 138 uint32_t match_types) { |
| 139 BrowserList* browser_list_impl = BrowserList::GetInstance(desktop_type); | 139 BrowserList* browser_list_impl = BrowserList::GetInstance(); |
| 140 size_t count = 0; | 140 size_t count = 0; |
| 141 if (browser_list_impl) { | 141 if (browser_list_impl) { |
| 142 for (BrowserList::const_iterator i = browser_list_impl->begin(); | 142 for (BrowserList::const_iterator i = browser_list_impl->begin(); |
| 143 i != browser_list_impl->end(); ++i) { | 143 i != browser_list_impl->end(); ++i) { |
| 144 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types)) | 144 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types)) |
| 145 count++; | 145 count++; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 return count; | 148 return count; |
| 149 } | 149 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 Browser* FindBrowserWithWebContents(const WebContents* web_contents) { | 197 Browser* FindBrowserWithWebContents(const WebContents* web_contents) { |
| 198 DCHECK(web_contents); | 198 DCHECK(web_contents); |
| 199 for (TabContentsIterator it; !it.done(); it.Next()) { | 199 for (TabContentsIterator it; !it.done(); it.Next()) { |
| 200 if (*it == web_contents) | 200 if (*it == web_contents) |
| 201 return it.browser(); | 201 return it.browser(); |
| 202 } | 202 } |
| 203 return NULL; | 203 return NULL; |
| 204 } | 204 } |
| 205 | 205 |
| 206 Browser* FindLastActiveWithProfile(Profile* profile, HostDesktopType type) { | 206 Browser* FindLastActiveWithProfile(Profile* profile, HostDesktopType type) { |
| 207 BrowserList* list = BrowserList::GetInstance(type); | 207 BrowserList* list = BrowserList::GetInstance(); |
| 208 // We are only interested in last active browsers, so we don't fall back to | 208 // We are only interested in last active browsers, so we don't fall back to |
| 209 // all browsers like FindBrowserWith* do. | 209 // all browsers like FindBrowserWith* do. |
| 210 return FindBrowserMatching(list->begin_last_active(), list->end_last_active(), | 210 return FindBrowserMatching(list->begin_last_active(), list->end_last_active(), |
| 211 profile, Browser::FEATURE_NONE, kMatchAny); | 211 profile, Browser::FEATURE_NONE, kMatchAny); |
| 212 } | 212 } |
| 213 | 213 |
| 214 Browser* FindLastActiveWithHostDesktopType(HostDesktopType type) { | 214 Browser* FindLastActiveWithHostDesktopType(HostDesktopType type) { |
| 215 BrowserList* browser_list_impl = BrowserList::GetInstance(type); | 215 BrowserList* browser_list_impl = BrowserList::GetInstance(); |
| 216 if (browser_list_impl) | 216 if (browser_list_impl) |
| 217 return browser_list_impl->GetLastActive(); | 217 return browser_list_impl->GetLastActive(); |
| 218 return NULL; | 218 return NULL; |
| 219 } | 219 } |
| 220 | 220 |
| 221 size_t GetTotalBrowserCount() { | 221 size_t GetTotalBrowserCount() { |
| 222 size_t count = 0; | 222 return BrowserList::GetInstance()->size(); |
| 223 for (HostDesktopType t = HOST_DESKTOP_TYPE_FIRST; t < HOST_DESKTOP_TYPE_COUNT; | |
| 224 t = static_cast<HostDesktopType>(t + 1)) { | |
| 225 count += BrowserList::GetInstance(t)->size(); | |
| 226 } | |
| 227 return count; | |
| 228 } | 223 } |
| 229 | 224 |
| 230 size_t GetTotalBrowserCountForProfile(Profile* profile) { | 225 size_t GetTotalBrowserCountForProfile(Profile* profile) { |
| 231 size_t count = 0; | 226 size_t count = 0; |
| 232 for (HostDesktopType t = HOST_DESKTOP_TYPE_FIRST; t < HOST_DESKTOP_TYPE_COUNT; | 227 for (HostDesktopType t = HOST_DESKTOP_TYPE_FIRST; t < HOST_DESKTOP_TYPE_COUNT; |
| 233 t = static_cast<HostDesktopType>(t + 1)) { | 228 t = static_cast<HostDesktopType>(t + 1)) { |
| 234 count += GetBrowserCount(profile, t); | 229 count += GetBrowserCount(profile, t); |
| 235 } | 230 } |
| 236 return count; | 231 return count; |
| 237 } | 232 } |
| 238 | 233 |
| 239 size_t GetBrowserCount(Profile* profile, HostDesktopType type) { | 234 size_t GetBrowserCount(Profile* profile, HostDesktopType type) { |
| 240 return GetBrowserCountImpl(profile, type, kMatchAny); | 235 return GetBrowserCountImpl(profile, type, kMatchAny); |
| 241 } | 236 } |
| 242 | 237 |
| 243 size_t GetTabbedBrowserCount(Profile* profile, HostDesktopType type) { | 238 size_t GetTabbedBrowserCount(Profile* profile, HostDesktopType type) { |
| 244 return GetBrowserCountImpl(profile, type, kMatchTabbed); | 239 return GetBrowserCountImpl(profile, type, kMatchTabbed); |
| 245 } | 240 } |
| 246 | 241 |
| 247 } // namespace chrome | 242 } // namespace chrome |
| OLD | NEW |