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

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

Issue 1198313003: Fix the browser match rules. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
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_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 24 matching lines...) Expand all
35 // . If it contains kMatchOriginalProfile then the original profile of the 35 // . If it contains kMatchOriginalProfile then the original profile of the
36 // browser must match |profile->GetOriginalProfile()|. This is used to match 36 // browser must match |profile->GetOriginalProfile()|. This is used to match
37 // incognito windows. 37 // incognito windows.
38 // . If it contains kMatchCanSupportWindowFeature 38 // . If it contains kMatchCanSupportWindowFeature
39 // |CanSupportWindowFeature(window_feature)| must return true. 39 // |CanSupportWindowFeature(window_feature)| must return true.
40 // . If it contains kMatchTabbed, the browser must be a tabbed browser. 40 // . If it contains kMatchTabbed, the browser must be a tabbed browser.
41 bool BrowserMatches(Browser* browser, 41 bool BrowserMatches(Browser* browser,
42 Profile* profile, 42 Profile* profile,
43 Browser::WindowFeature window_feature, 43 Browser::WindowFeature window_feature,
44 uint32 match_types) { 44 uint32 match_types) {
45 if (match_types & kMatchCanSupportWindowFeature && 45 if ((match_types & kMatchCanSupportWindowFeature) &&
46 !browser->CanSupportWindowFeature(window_feature)) { 46 !browser->CanSupportWindowFeature(window_feature)) {
47 return false; 47 return false;
48 } 48 }
49 49
50 bool matches_profile = browser->profile() == profile;
51 #if defined(OS_CHROMEOS) 50 #if defined(OS_CHROMEOS)
52 // Get the profile on which the window is currently shown. 51 // Get the profile on which the window is currently shown.
53 // MultiUserWindowManager might be NULL under test scenario. 52 // MultiUserWindowManager might be NULL under test scenario.
54 chrome::MultiUserWindowManager* const window_manager = 53 chrome::MultiUserWindowManager* const window_manager =
55 chrome::MultiUserWindowManager::GetInstance(); 54 chrome::MultiUserWindowManager::GetInstance();
55 Profile* shown_profile = nullptr;
56 if (window_manager) { 56 if (window_manager) {
57 const std::string& shown_user_id = window_manager->GetUserPresentingWindow( 57 const std::string& shown_user_id = window_manager->GetUserPresentingWindow(
58 browser->window()->GetNativeWindow()); 58 browser->window()->GetNativeWindow());
59 Profile* shown_profile = 59 shown_profile = shown_user_id.empty()
60 shown_user_id.empty() 60 ? nullptr
61 ? nullptr 61 : multi_user_util::GetProfileFromUserID(shown_user_id);
62 : multi_user_util::GetProfileFromUserID(shown_user_id);
63 matches_profile &= !shown_profile || shown_profile == profile;
64 } 62 }
65 #endif 63 #endif
66 64
67 if (match_types & kMatchOriginalProfile) { 65 if (match_types & kMatchOriginalProfile) {
68 if (browser->profile()->GetOriginalProfile() != 66 if (browser->profile()->GetOriginalProfile() !=
69 profile->GetOriginalProfile()) 67 profile->GetOriginalProfile())
70 return false; 68 return false;
71 } else if (!matches_profile) { 69 #if defined(OS_CHROMEOS)
72 return false; 70 if (shown_profile &&
71 shown_profile->GetOriginalProfile() != profile->GetOriginalProfile()) {
72 return false;
73 }
74 #endif
75 } else {
76 if (browser->profile() != profile)
77 return false;
78 #if defined(OS_CHROMEOS)
79 if (shown_profile && shown_profile != profile)
80 return false;
81 #endif
73 } 82 }
74 83
75 if (match_types & kMatchTabbed) 84 if (match_types & kMatchTabbed)
76 return browser->is_type_tabbed(); 85 return browser->is_type_tabbed();
77 86
78 return true; 87 return true;
79 } 88 }
80 89
81 // Returns the first browser in the specified iterator that returns true from 90 // Returns the first browser in the specified iterator that returns true from
82 // |BrowserMatches|, or null if no browsers match the arguments. See 91 // |BrowserMatches|, or null if no browsers match the arguments. See
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 233
225 size_t GetBrowserCount(Profile* profile, HostDesktopType type) { 234 size_t GetBrowserCount(Profile* profile, HostDesktopType type) {
226 return GetBrowserCountImpl(profile, type, kMatchAny); 235 return GetBrowserCountImpl(profile, type, kMatchAny);
227 } 236 }
228 237
229 size_t GetTabbedBrowserCount(Profile* profile, HostDesktopType type) { 238 size_t GetTabbedBrowserCount(Profile* profile, HostDesktopType type) {
230 return GetBrowserCountImpl(profile, type, kMatchTabbed); 239 return GetBrowserCountImpl(profile, type, kMatchTabbed);
231 } 240 }
232 241
233 } // namespace chrome 242 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698