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

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

Issue 10870014: Revert 152788 - Give access to browsers by Profile/HostDesktopType. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
« no previous file with comments | « chrome/browser/ui/browser_finder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // TODO(mad) eventually move this to host_desktop_type.h.
23 #if defined(OS_CHROMEOS)
24 chrome::HostDesktopType kDefaultHostDesktopType = chrome::HOST_DESKTOP_TYPE_ASH;
25 #else
26 chrome::HostDesktopType kDefaultHostDesktopType =
27 chrome::HOST_DESKTOP_TYPE_NATIVE;
28 #endif
29
30
31 // Type used to indicate to match anything. 22 // Type used to indicate to match anything.
32 const int kMatchAny = 0; 23 const int kMatchAny = 0;
33 24
34 // See BrowserMatches for details. 25 // See BrowserMatches for details.
35 const int kMatchOriginalProfile = 1 << 0; 26 const int kMatchOriginalProfile = 1 << 0;
36 const int kMatchCanSupportWindowFeature = 1 << 1; 27 const int kMatchCanSupportWindowFeature = 1 << 1;
37 const int kMatchTabbed = 1 << 2; 28 const int kMatchTabbed = 1 << 2;
38 29
39 // Returns true if the specified |browser| matches the specified arguments. 30 // Returns true if the specified |browser| matches the specified arguments.
40 // |match_types| is a bitmask dictating what parameters to match: 31 // |match_types| is a bitmask dictating what parameters to match:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 Browser::WindowFeature window_feature, 68 Browser::WindowFeature window_feature,
78 uint32 match_types) { 69 uint32 match_types) {
79 for (T i = begin; i != end; ++i) { 70 for (T i = begin; i != end; ++i) {
80 if (BrowserMatches(*i, profile, window_feature, match_types)) 71 if (BrowserMatches(*i, profile, window_feature, match_types))
81 return *i; 72 return *i;
82 } 73 }
83 return NULL; 74 return NULL;
84 } 75 }
85 76
86 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile, 77 Browser* FindBrowserWithTabbedOrAnyType(Profile* profile,
87 chrome::HostDesktopType desktop_type,
88 bool match_tabbed, 78 bool match_tabbed,
89 bool match_original_profiles) { 79 bool match_original_profiles) {
90 chrome::BrowserListImpl* browser_list_impl =
91 chrome::BrowserListImpl::GetInstance(desktop_type);
92 if (!browser_list_impl)
93 return NULL;
94 uint32 match_types = kMatchAny; 80 uint32 match_types = kMatchAny;
95 if (match_tabbed) 81 if (match_tabbed)
96 match_types |= kMatchTabbed; 82 match_types |= kMatchTabbed;
97 if (match_original_profiles) 83 if (match_original_profiles)
98 match_types |= kMatchOriginalProfile; 84 match_types |= kMatchOriginalProfile;
99 Browser* browser = FindBrowserMatching(browser_list_impl->begin_last_active(), 85 Browser* browser = FindBrowserMatching(
100 browser_list_impl->end_last_active(), 86 BrowserList::begin_last_active(), BrowserList::end_last_active(),
101 profile, 87 profile, Browser::FEATURE_NONE, match_types);
102 Browser::FEATURE_NONE,
103 match_types);
104 // Fall back to a forward scan of all Browsers if no active one was found. 88 // Fall back to a forward scan of all Browsers if no active one was found.
105 return browser ? browser : FindBrowserMatching(browser_list_impl->begin(), 89 return browser ? browser :
106 browser_list_impl->end(), 90 FindBrowserMatching(BrowserList::begin(), BrowserList::end(), profile,
107 profile, 91 Browser::FEATURE_NONE, match_types);
108 Browser::FEATURE_NONE,
109 match_types);
110 } 92 }
111 93
112 size_t GetBrowserCountImpl(Profile* profile, 94 size_t GetBrowserCountImpl(Profile* profile, uint32 match_types) {
113 chrome::HostDesktopType desktop_type,
114 uint32 match_types) {
115 chrome::BrowserListImpl* browser_list_impl =
116 chrome::BrowserListImpl::GetInstance(desktop_type);
117 size_t count = 0; 95 size_t count = 0;
118 if (browser_list_impl) { 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++;
123 }
124 } 100 }
125 return count; 101 return count;
126 } 102 }
127 103
128 } // namespace 104 } // namespace
129 105
130 Browser* FindTabbedBrowser(Profile* profile, bool match_original_profiles) { 106 Browser* FindTabbedBrowser(Profile* profile, bool match_original_profiles) {
131 return FindBrowserWithTabbedOrAnyType(profile, 107 return FindBrowserWithTabbedOrAnyType(profile,
132 kDefaultHostDesktopType,
133 true, 108 true,
134 match_original_profiles); 109 match_original_profiles);
135 } 110 }
136 111
137 Browser* FindOrCreateTabbedBrowser(Profile* profile) { 112 Browser* FindOrCreateTabbedBrowser(Profile* profile) {
138 Browser* browser = FindTabbedBrowser(profile, false); 113 Browser* browser = FindTabbedBrowser(profile, false);
139 if (!browser) 114 if (!browser)
140 browser = new Browser(Browser::CreateParams(profile)); 115 browser = new Browser(Browser::CreateParams(profile));
141 return browser; 116 return browser;
142 } 117 }
143 118
144 Browser* FindAnyBrowser(Profile* profile, bool match_original_profiles) { 119 Browser* FindAnyBrowser(Profile* profile, bool match_original_profiles) {
145 return FindBrowserWithTabbedOrAnyType(profile, 120 return FindBrowserWithTabbedOrAnyType(profile,
146 kDefaultHostDesktopType,
147 false, 121 false,
148 match_original_profiles); 122 match_original_profiles);
149 } 123 }
150 124
151 Browser* FindBrowserWithProfile(Profile* profile, 125 Browser* FindBrowserWithProfile(Profile* profile) {
152 chrome::HostDesktopType desktop_type) { 126 return FindAnyBrowser(profile, false);
153 return FindBrowserWithTabbedOrAnyType(profile, desktop_type, false, false);
154 } 127 }
155 128
156 Browser* FindBrowserWithID(SessionID::id_type desired_id) { 129 Browser* FindBrowserWithID(SessionID::id_type desired_id) {
157 for (BrowserList::const_iterator i = BrowserList::begin(); 130 for (BrowserList::const_iterator i = BrowserList::begin();
158 i != BrowserList::end(); ++i) { 131 i != BrowserList::end(); ++i) {
159 if ((*i)->session_id().id() == desired_id) 132 if ((*i)->session_id().id() == desired_id)
160 return *i; 133 return *i;
161 } 134 }
162 return NULL; 135 return NULL;
163 } 136 }
(...skipping 27 matching lines...) Expand all
191 164
192 Browser* FindLastActiveWithHostDesktopType(chrome::HostDesktopType type) { 165 Browser* FindLastActiveWithHostDesktopType(chrome::HostDesktopType type) {
193 chrome::BrowserListImpl* browser_list_impl = 166 chrome::BrowserListImpl* browser_list_impl =
194 chrome::BrowserListImpl::GetInstance(type); 167 chrome::BrowserListImpl::GetInstance(type);
195 if (browser_list_impl) 168 if (browser_list_impl)
196 return browser_list_impl->GetLastActive(); 169 return browser_list_impl->GetLastActive();
197 return NULL; 170 return NULL;
198 } 171 }
199 172
200 size_t GetBrowserCount(Profile* profile) { 173 size_t GetBrowserCount(Profile* profile) {
201 return GetBrowserCountImpl(profile, kDefaultHostDesktopType, kMatchAny); 174 return GetBrowserCountImpl(profile, kMatchAny);
202 } 175 }
203 176
204 size_t GetTabbedBrowserCount(Profile* profile) { 177 size_t GetTabbedBrowserCount(Profile* profile) {
205 return GetBrowserCountImpl(profile, kDefaultHostDesktopType, kMatchTabbed); 178 return GetBrowserCountImpl(profile, kMatchTabbed);
206 } 179 }
207 180
208 } // namespace browser 181 } // namespace browser
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_finder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698