Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/ui/browser_finder.cc

Issue 10855183: Give access to browsers by Profile/HostDesktopType. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Isolated brwoser_finder changes, task manager changes moved to another CL. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_list.h" 8 #include "chrome/browser/ui/browser_list.h"
9 #include "chrome/browser/ui/browser_list_impl.h" 9 #include "chrome/browser/ui/browser_list_impl.h"
10 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" 11 #include "chrome/browser/ui/tab_contents/tab_contents.h"
12 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 12 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "content/public/browser/navigation_controller.h" 14 #include "content/public/browser/navigation_controller.h"
15 15
16 using content::WebContents; 16 using content::WebContents;
17 17
18 namespace browser { 18 namespace browser {
19 19
20 namespace { 20 namespace {
21 21
22 #if defined(OS_CHROMEOS)
23 chrome::HostDesktopType kDefaultHostDesktopType = chrome::HOST_DESKTOP_TYPE_ASH;
24 #else
25 chrome::HostDesktopType kDefaultHostDesktopType =
26 chrome::HOST_DESKTOP_TYPE_NATIVE;
27 #endif
28
29
22 // Type used to indicate to match anything. 30 // Type used to indicate to match anything.
23 const int kMatchAny = 0; 31 const int kMatchAny = 0;
24 32
25 // See BrowserMatches for details. 33 // See BrowserMatches for details.
26 const int kMatchOriginalProfile = 1 << 0; 34 const int kMatchOriginalProfile = 1 << 0;
27 const int kMatchCanSupportWindowFeature = 1 << 1; 35 const int kMatchCanSupportWindowFeature = 1 << 1;
28 const int kMatchTabbed = 1 << 2; 36 const int kMatchTabbed = 1 << 2;
29 37
30 // Returns true if the specified |browser| matches the specified arguments. 38 // Returns true if the specified |browser| matches the specified arguments.
31 // |match_types| is a bitmask dictating what parameters to match: 39 // |match_types| is a bitmask dictating what parameters to match:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 Browser::WindowFeature window_feature, 76 Browser::WindowFeature window_feature,
69 uint32 match_types) { 77 uint32 match_types) {
70 for (T i = begin; i != end; ++i) { 78 for (T i = begin; i != end; ++i) {
71 if (BrowserMatches(*i, profile, window_feature, match_types)) 79 if (BrowserMatches(*i, profile, window_feature, match_types))
72 return *i; 80 return *i;
73 } 81 }
74 return NULL; 82 return NULL;
75 } 83 }
76 84
77 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, 85 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile,
86 chrome::HostDesktopType desktop_type,
78 bool match_tabbed, 87 bool match_tabbed,
79 bool match_original_profiles) { 88 bool match_original_profiles) {
89 chrome::BrowserListImpl* browser_list_impl =
90 chrome::BrowserListImpl::GetInstance(desktop_type);
91 if (!browser_list_impl)
92 return NULL;
80 uint32 match_types = kMatchAny; 93 uint32 match_types = kMatchAny;
81 if (match_tabbed) 94 if (match_tabbed)
82 match_types |= kMatchTabbed; 95 match_types |= kMatchTabbed;
83 if (match_original_profiles) 96 if (match_original_profiles)
84 match_types |= kMatchOriginalProfile; 97 match_types |= kMatchOriginalProfile;
85 Browser* browser = FindBrowserMatching( 98 Browser* browser = FindBrowserMatching(browser_list_impl->begin_last_active(),
86 BrowserList::begin_last_active(), BrowserList::end_last_active(), 99 browser_list_impl->end_last_active(),
87 profile, Browser::FEATURE_NONE, match_types); 100 profile,
101 Browser::FEATURE_NONE,
102 match_types);
88 // Fall back to a forward scan of all Browsers if no active one was found. 103 // Fall back to a forward scan of all Browsers if no active one was found.
89 return browser ? browser : 104 return browser ? browser : FindBrowserMatching(browser_list_impl->begin(),
90 FindBrowserMatching(BrowserList::begin(), BrowserList::end(), profile, 105 browser_list_impl->end(),
91 Browser::FEATURE_NONE, match_types); 106 profile,
107 Browser::FEATURE_NONE,
108 match_types);
92 } 109 }
93 110
94 size_t GetBrowserCountImpl(Profile* profile, uint32 match_types) { 111 size_t GetBrowserCountImpl(Profile* profile,
112 chrome::HostDesktopType desktop_type,
113 uint32 match_types) {
114 chrome::BrowserListImpl* browser_list_impl =
115 chrome::BrowserListImpl::GetInstance(desktop_type);
116 if (!browser_list_impl)
117 return NULL;
95 size_t count = 0; 118 size_t count = 0;
96 for (BrowserList::const_iterator i = BrowserList::begin(); 119 for (BrowserList::const_iterator i = browser_list_impl->begin();
97 i != BrowserList::end(); ++i) { 120 i != browser_list_impl->end(); ++i) {
98 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types)) 121 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types))
99 count++; 122 count++;
100 } 123 }
101 return count; 124 return count;
102 } 125 }
103 126
104 } // namespace 127 } // namespace
105 128
106 Browser* FindTabbedBrowser(Profile* profile, bool match_original_profiles) { 129 Browser* FindTabbedBrowser(Profile* profile, bool match_original_profiles) {
107 return FindBrowserWithTabbedOrAnyType(profile, 130 return FindBrowserWithTabbedOrAnyType(profile,
131 kDefaultHostDesktopType,
108 true, 132 true,
109 match_original_profiles); 133 match_original_profiles);
110 } 134 }
135
136 Browser* FindDesktopTabbedBrowser(Profile* profile,
137 chrome::HostDesktopType desktop_type,
138 bool match_original_profiles) {
139 return FindBrowserWithTabbedOrAnyType(profile,
140 desktop_type,
141 true,
142 match_original_profiles);
143 }
111 144
112 Browser* FindOrCreateTabbedBrowser(Profile* profile) { 145 Browser* FindOrCreateTabbedBrowser(Profile* profile) {
113 Browser* browser = FindTabbedBrowser(profile, false); 146 Browser* browser = FindTabbedBrowser(profile, false);
114 if (!browser) 147 if (!browser)
115 browser = new Browser(Browser::CreateParams(profile)); 148 browser = new Browser(Browser::CreateParams(Browser::TYPE_TABBED, profile));
robertshield 2012/08/16 21:05:16 why do we add TYPE_TABBED here?
MAD 2012/08/17 12:45:51 Because I wanted to be more explicit that it's the
149 return browser;
150 }
151
152 Browser* FindOrCreateDesktopTabbedBrowser(
153 Profile* profile, chrome::HostDesktopType desktop_type) {
154 Browser* browser = FindDesktopTabbedBrowser(profile, desktop_type, false);
155 if (!browser)
156 browser = new Browser(Browser::CreateParams(Browser::TYPE_TABBED,
157 profile,
158 desktop_type));
116 return browser; 159 return browser;
117 } 160 }
118 161
119 Browser* FindAnyBrowser(Profile* profile, bool match_original_profiles) { 162 Browser* FindAnyBrowser(Profile* profile, bool match_original_profiles) {
120 return FindBrowserWithTabbedOrAnyType(profile, 163 return FindBrowserWithTabbedOrAnyType(profile,
164 kDefaultHostDesktopType,
121 false, 165 false,
122 match_original_profiles); 166 match_original_profiles);
123 } 167 }
168
169 Browser* FindDesktopBrowser(Profile* profile,
170 chrome::HostDesktopType desktop_type,
171 bool match_original_profiles) {
172 return FindBrowserWithTabbedOrAnyType(profile,
173 desktop_type,
174 false,
175 match_original_profiles);
176 }
124 177
125 Browser* FindBrowserWithProfile(Profile* profile) { 178 Browser* FindBrowserWithProfile(Profile* profile) {
126 return FindAnyBrowser(profile, false); 179 return FindAnyBrowser(profile, false);
127 } 180 }
128 181
182 Browser* FindDesktopBrowserWithProfile(Profile* profile,
183 chrome::HostDesktopType desktop_type) {
184 return FindDesktopBrowser(profile, desktop_type, false);
185 }
186
129 Browser* FindBrowserWithID(SessionID::id_type desired_id) { 187 Browser* FindBrowserWithID(SessionID::id_type desired_id) {
130 for (BrowserList::const_iterator i = BrowserList::begin(); 188 for (BrowserList::const_iterator i = BrowserList::begin();
131 i != BrowserList::end(); ++i) { 189 i != BrowserList::end(); ++i) {
132 if ((*i)->session_id().id() == desired_id) 190 if ((*i)->session_id().id() == desired_id)
133 return *i; 191 return *i;
134 } 192 }
135 return NULL; 193 return NULL;
136 } 194 }
137 195
138 Browser* FindBrowserWithWindow(gfx::NativeWindow window) { 196 Browser* FindBrowserWithWindow(gfx::NativeWindow window) {
(...skipping 16 matching lines...) Expand all
155 } 213 }
156 214
157 Browser* FindLastActiveWithProfile(Profile* profile) { 215 Browser* FindLastActiveWithProfile(Profile* profile) {
158 // We are only interested in last active browsers, so we don't fall back to 216 // We are only interested in last active browsers, so we don't fall back to
159 // all browsers like FindBrowserWith* do. 217 // all browsers like FindBrowserWith* do.
160 return FindBrowserMatching( 218 return FindBrowserMatching(
161 BrowserList::begin_last_active(), BrowserList::end_last_active(), profile, 219 BrowserList::begin_last_active(), BrowserList::end_last_active(), profile,
162 Browser::FEATURE_NONE, kMatchAny); 220 Browser::FEATURE_NONE, kMatchAny);
163 } 221 }
164 222
165 Browser* FindLastActiveWithHostDesktopType(chrome::HostDesktopType type) { 223 Browser* FindLastActiveWithHostDesktopType(
224 chrome::HostDesktopType desktop_type) {
166 chrome::BrowserListImpl* browser_list_impl = 225 chrome::BrowserListImpl* browser_list_impl =
167 chrome::BrowserListImpl::GetInstance(type); 226 chrome::BrowserListImpl::GetInstance(desktop_type);
168 if (browser_list_impl) 227 if (browser_list_impl)
169 return browser_list_impl->GetLastActive(); 228 return browser_list_impl->GetLastActive();
170 return NULL; 229 return NULL;
171 } 230 }
172 231
173 size_t GetBrowserCount(Profile* profile) { 232 size_t GetBrowserCount(Profile* profile) {
174 return GetBrowserCountImpl(profile, kMatchAny); 233 return GetBrowserCountImpl(profile, kDefaultHostDesktopType, kMatchAny);
175 } 234 }
176 235
177 size_t GetTabbedBrowserCount(Profile* profile) { 236 size_t GetTabbedBrowserCount(Profile* profile) {
178 return GetBrowserCountImpl(profile, kMatchTabbed); 237 return GetBrowserCountImpl(profile, kDefaultHostDesktopType, kMatchTabbed);
179 } 238 }
180 239
181 } // namespace browser 240 } // namespace browser
OLDNEW
« chrome/browser/ui/browser_finder.h ('K') | « chrome/browser/ui/browser_finder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698