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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 Browser::WindowFeature window_feature, | 97 Browser::WindowFeature window_feature, |
98 uint32 match_types) { | 98 uint32 match_types) { |
99 for (T i = begin; i != end; ++i) { | 99 for (T i = begin; i != end; ++i) { |
100 if (BrowserMatches(*i, profile, window_feature, match_types)) | 100 if (BrowserMatches(*i, profile, window_feature, match_types)) |
101 return *i; | 101 return *i; |
102 } | 102 } |
103 return NULL; | 103 return NULL; |
104 } | 104 } |
105 | 105 |
106 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, | 106 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, |
107 chrome::HostDesktopType desktop_type, | 107 ui::HostDesktopType desktop_type, |
108 bool match_tabbed, | 108 bool match_tabbed, |
109 bool match_original_profiles) { | 109 bool match_original_profiles) { |
110 BrowserList* browser_list_impl = BrowserList::GetInstance(desktop_type); | 110 BrowserList* browser_list_impl = BrowserList::GetInstance(desktop_type); |
111 if (!browser_list_impl) | 111 if (!browser_list_impl) |
112 return NULL; | 112 return NULL; |
113 uint32 match_types = kMatchAny; | 113 uint32 match_types = kMatchAny; |
114 if (match_tabbed) | 114 if (match_tabbed) |
115 match_types |= kMatchTabbed; | 115 match_types |= kMatchTabbed; |
116 if (match_original_profiles) | 116 if (match_original_profiles) |
117 match_types |= kMatchOriginalProfile; | 117 match_types |= kMatchOriginalProfile; |
118 Browser* browser = FindBrowserMatching(browser_list_impl->begin_last_active(), | 118 Browser* browser = FindBrowserMatching(browser_list_impl->begin_last_active(), |
119 browser_list_impl->end_last_active(), | 119 browser_list_impl->end_last_active(), |
120 profile, | 120 profile, |
121 Browser::FEATURE_NONE, | 121 Browser::FEATURE_NONE, |
122 match_types); | 122 match_types); |
123 // Fall back to a forward scan of all Browsers if no active one was found. | 123 // Fall back to a forward scan of all Browsers if no active one was found. |
124 return browser ? browser : FindBrowserMatching(browser_list_impl->begin(), | 124 return browser ? browser : FindBrowserMatching(browser_list_impl->begin(), |
125 browser_list_impl->end(), | 125 browser_list_impl->end(), |
126 profile, | 126 profile, |
127 Browser::FEATURE_NONE, | 127 Browser::FEATURE_NONE, |
128 match_types); | 128 match_types); |
129 } | 129 } |
130 | 130 |
131 size_t GetBrowserCountImpl(Profile* profile, | 131 size_t GetBrowserCountImpl(Profile* profile, |
132 chrome::HostDesktopType desktop_type, | 132 ui::HostDesktopType desktop_type, |
133 uint32 match_types) { | 133 uint32 match_types) { |
134 BrowserList* browser_list_impl = BrowserList::GetInstance(desktop_type); | 134 BrowserList* browser_list_impl = BrowserList::GetInstance(desktop_type); |
135 size_t count = 0; | 135 size_t count = 0; |
136 if (browser_list_impl) { | 136 if (browser_list_impl) { |
137 for (BrowserList::const_iterator i = browser_list_impl->begin(); | 137 for (BrowserList::const_iterator i = browser_list_impl->begin(); |
138 i != browser_list_impl->end(); ++i) { | 138 i != browser_list_impl->end(); ++i) { |
139 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types)) | 139 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types)) |
140 count++; | 140 count++; |
141 } | 141 } |
142 } | 142 } |
143 return count; | 143 return count; |
144 } | 144 } |
145 | 145 |
146 } // namespace | 146 } // namespace |
147 | 147 |
148 namespace chrome { | 148 namespace chrome { |
149 | 149 |
150 Browser* FindTabbedBrowser(Profile* profile, | 150 Browser* FindTabbedBrowser(Profile* profile, |
151 bool match_original_profiles, | 151 bool match_original_profiles, |
152 HostDesktopType type) { | 152 ui::HostDesktopType type) { |
153 return FindBrowserWithTabbedOrAnyType(profile, | 153 return FindBrowserWithTabbedOrAnyType(profile, |
154 type, | 154 type, |
155 true, | 155 true, |
156 match_original_profiles); | 156 match_original_profiles); |
157 } | 157 } |
158 | 158 |
159 Browser* FindAnyBrowser(Profile* profile, | 159 Browser* FindAnyBrowser(Profile* profile, |
160 bool match_original_profiles, | 160 bool match_original_profiles, |
161 HostDesktopType type) { | 161 ui::HostDesktopType type) { |
162 return FindBrowserWithTabbedOrAnyType(profile, | 162 return FindBrowserWithTabbedOrAnyType(profile, |
163 type, | 163 type, |
164 false, | 164 false, |
165 match_original_profiles); | 165 match_original_profiles); |
166 } | 166 } |
167 | 167 |
168 Browser* FindBrowserWithProfile(Profile* profile, | 168 Browser* FindBrowserWithProfile(Profile* profile, |
169 HostDesktopType desktop_type) { | 169 ui::HostDesktopType desktop_type) { |
170 return FindBrowserWithTabbedOrAnyType(profile, desktop_type, false, false); | 170 return FindBrowserWithTabbedOrAnyType(profile, desktop_type, false, false); |
171 } | 171 } |
172 | 172 |
173 Browser* FindBrowserWithID(SessionID::id_type desired_id) { | 173 Browser* FindBrowserWithID(SessionID::id_type desired_id) { |
174 for (BrowserIterator it; !it.done(); it.Next()) { | 174 for (BrowserIterator it; !it.done(); it.Next()) { |
175 if (it->session_id().id() == desired_id) | 175 if (it->session_id().id() == desired_id) |
176 return *it; | 176 return *it; |
177 } | 177 } |
178 return NULL; | 178 return NULL; |
179 } | 179 } |
(...skipping 11 matching lines...) Expand all Loading... |
191 | 191 |
192 Browser* FindBrowserWithWebContents(const WebContents* web_contents) { | 192 Browser* FindBrowserWithWebContents(const WebContents* web_contents) { |
193 DCHECK(web_contents); | 193 DCHECK(web_contents); |
194 for (TabContentsIterator it; !it.done(); it.Next()) { | 194 for (TabContentsIterator it; !it.done(); it.Next()) { |
195 if (*it == web_contents) | 195 if (*it == web_contents) |
196 return it.browser(); | 196 return it.browser(); |
197 } | 197 } |
198 return NULL; | 198 return NULL; |
199 } | 199 } |
200 | 200 |
201 Browser* FindLastActiveWithProfile(Profile* profile, HostDesktopType type) { | 201 Browser* FindLastActiveWithProfile(Profile* profile, ui::HostDesktopType type) { |
202 BrowserList* list = BrowserList::GetInstance(type); | 202 BrowserList* list = BrowserList::GetInstance(type); |
203 // We are only interested in last active browsers, so we don't fall back to | 203 // We are only interested in last active browsers, so we don't fall back to |
204 // all browsers like FindBrowserWith* do. | 204 // all browsers like FindBrowserWith* do. |
205 return FindBrowserMatching(list->begin_last_active(), list->end_last_active(), | 205 return FindBrowserMatching(list->begin_last_active(), list->end_last_active(), |
206 profile, Browser::FEATURE_NONE, kMatchAny); | 206 profile, Browser::FEATURE_NONE, kMatchAny); |
207 } | 207 } |
208 | 208 |
209 Browser* FindLastActiveWithHostDesktopType(HostDesktopType type) { | 209 Browser* FindLastActiveWithHostDesktopType(ui::HostDesktopType type) { |
210 BrowserList* browser_list_impl = BrowserList::GetInstance(type); | 210 BrowserList* browser_list_impl = BrowserList::GetInstance(type); |
211 if (browser_list_impl) | 211 if (browser_list_impl) |
212 return browser_list_impl->GetLastActive(); | 212 return browser_list_impl->GetLastActive(); |
213 return NULL; | 213 return NULL; |
214 } | 214 } |
215 | 215 |
216 size_t GetTotalBrowserCount() { | 216 size_t GetTotalBrowserCount() { |
217 size_t count = 0; | 217 size_t count = 0; |
218 for (HostDesktopType t = HOST_DESKTOP_TYPE_FIRST; t < HOST_DESKTOP_TYPE_COUNT; | 218 for (ui::HostDesktopType t = ui::HOST_DESKTOP_TYPE_FIRST; |
219 t = static_cast<HostDesktopType>(t + 1)) { | 219 t < ui::HOST_DESKTOP_TYPE_COUNT; |
| 220 t = static_cast<ui::HostDesktopType>(t + 1)) { |
220 count += BrowserList::GetInstance(t)->size(); | 221 count += BrowserList::GetInstance(t)->size(); |
221 } | 222 } |
222 return count; | 223 return count; |
223 } | 224 } |
224 | 225 |
225 size_t GetTotalBrowserCountForProfile(Profile* profile) { | 226 size_t GetTotalBrowserCountForProfile(Profile* profile) { |
226 size_t count = 0; | 227 size_t count = 0; |
227 for (HostDesktopType t = HOST_DESKTOP_TYPE_FIRST; t < HOST_DESKTOP_TYPE_COUNT; | 228 for (ui::HostDesktopType t = ui::HOST_DESKTOP_TYPE_FIRST; |
228 t = static_cast<HostDesktopType>(t + 1)) { | 229 t < ui::HOST_DESKTOP_TYPE_COUNT; |
| 230 t = static_cast<ui::HostDesktopType>(t + 1)) { |
229 count += GetBrowserCount(profile, t); | 231 count += GetBrowserCount(profile, t); |
230 } | 232 } |
231 return count; | 233 return count; |
232 } | 234 } |
233 | 235 |
234 size_t GetBrowserCount(Profile* profile, HostDesktopType type) { | 236 size_t GetBrowserCount(Profile* profile, ui::HostDesktopType type) { |
235 return GetBrowserCountImpl(profile, type, kMatchAny); | 237 return GetBrowserCountImpl(profile, type, kMatchAny); |
236 } | 238 } |
237 | 239 |
238 size_t GetTabbedBrowserCount(Profile* profile, HostDesktopType type) { | 240 size_t GetTabbedBrowserCount(Profile* profile, ui::HostDesktopType type) { |
239 return GetBrowserCountImpl(profile, type, kMatchTabbed); | 241 return GetBrowserCountImpl(profile, type, kMatchTabbed); |
240 } | 242 } |
241 | 243 |
242 } // namespace chrome | 244 } // namespace chrome |
OLD | NEW |