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

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

Powered by Google App Engine
This is Rietveld 408576698