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

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: Sync'd to Tip Of Tree. 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 #if defined(OS_CHROMEOS)
23 chrome::HostDesktopType kDefaultHostDesktopType = chrome::HOST_DESKTOP_TYPE_ASH;
Ben Goodger (Google) 2012/08/21 21:47:20 my theory is that this will have to go in host_des
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);
95 size_t count = 0; 116 size_t count = 0;
96 for (BrowserList::const_iterator i = BrowserList::begin(); 117 if (browser_list_impl) {
97 i != BrowserList::end(); ++i) { 118 for (BrowserList::const_iterator i = browser_list_impl->begin();
98 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types)) 119 i != browser_list_impl->end(); ++i) {
99 count++; 120 if (BrowserMatches(*i, profile, Browser::FEATURE_NONE, match_types))
121 count++;
122 }
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 }
111 135
112 Browser* FindOrCreateTabbedBrowser(Profile* profile) { 136 Browser* FindOrCreateTabbedBrowser(Profile* profile) {
113 Browser* browser = FindTabbedBrowser(profile, false); 137 Browser* browser = FindTabbedBrowser(profile, false);
114 if (!browser) 138 if (!browser)
115 browser = new Browser(Browser::CreateParams(profile)); 139 browser = new Browser(Browser::CreateParams(profile));
116 return browser; 140 return browser;
117 } 141 }
118 142
119 Browser* FindAnyBrowser(Profile* profile, bool match_original_profiles) { 143 Browser* FindAnyBrowser(Profile* profile, bool match_original_profiles) {
120 return FindBrowserWithTabbedOrAnyType(profile, 144 return FindBrowserWithTabbedOrAnyType(profile,
145 kDefaultHostDesktopType,
121 false, 146 false,
122 match_original_profiles); 147 match_original_profiles);
123 } 148 }
124 149
125 Browser* FindBrowserWithProfile(Profile* profile) { 150 Browser* FindBrowserWithProfile(Profile* profile,
126 return FindAnyBrowser(profile, false); 151 chrome::HostDesktopType desktop_type) {
152 return FindBrowserWithTabbedOrAnyType(profile, desktop_type, false, false);
127 } 153 }
128 154
129 Browser* FindBrowserWithID(SessionID::id_type desired_id) { 155 Browser* FindBrowserWithID(SessionID::id_type desired_id) {
130 for (BrowserList::const_iterator i = BrowserList::begin(); 156 for (BrowserList::const_iterator i = BrowserList::begin();
131 i != BrowserList::end(); ++i) { 157 i != BrowserList::end(); ++i) {
132 if ((*i)->session_id().id() == desired_id) 158 if ((*i)->session_id().id() == desired_id)
133 return *i; 159 return *i;
134 } 160 }
135 return NULL; 161 return NULL;
136 } 162 }
(...skipping 27 matching lines...) Expand all
164 190
165 Browser* FindLastActiveWithHostDesktopType(chrome::HostDesktopType type) { 191 Browser* FindLastActiveWithHostDesktopType(chrome::HostDesktopType type) {
166 chrome::BrowserListImpl* browser_list_impl = 192 chrome::BrowserListImpl* browser_list_impl =
167 chrome::BrowserListImpl::GetInstance(type); 193 chrome::BrowserListImpl::GetInstance(type);
168 if (browser_list_impl) 194 if (browser_list_impl)
169 return browser_list_impl->GetLastActive(); 195 return browser_list_impl->GetLastActive();
170 return NULL; 196 return NULL;
171 } 197 }
172 198
173 size_t GetBrowserCount(Profile* profile) { 199 size_t GetBrowserCount(Profile* profile) {
174 return GetBrowserCountImpl(profile, kMatchAny); 200 return GetBrowserCountImpl(profile, kDefaultHostDesktopType, kMatchAny);
175 } 201 }
176 202
177 size_t GetTabbedBrowserCount(Profile* profile) { 203 size_t GetTabbedBrowserCount(Profile* profile) {
178 return GetBrowserCountImpl(profile, kMatchTabbed); 204 return GetBrowserCountImpl(profile, kDefaultHostDesktopType, kMatchTabbed);
179 } 205 }
180 206
181 } // namespace browser 207 } // 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