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

Side by Side Diff: chrome/browser/ui/views/frame/system_menu_model_builder.cc

Issue 2661283002: cros: Clean up SessionStateDelegate refs in Chrome (Closed)
Patch Set: update browser_finder_chromeos_unittest Created 3 years, 9 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/views/frame/system_menu_model_builder.h" 5 #include "chrome/browser/ui/views/frame/system_menu_model_builder.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/ui/browser_commands.h" 11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/browser/ui/toolbar/app_menu_model.h" 13 #include "chrome/browser/ui/toolbar/app_menu_model.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/url_constants.h" 15 #include "chrome/common/url_constants.h"
16 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
17 #include "components/strings/grit/components_strings.h" 17 #include "components/strings/grit/components_strings.h"
18 #include "ui/base/accelerators/accelerator.h" 18 #include "ui/base/accelerators/accelerator.h"
19 #include "ui/base/models/simple_menu_model.h" 19 #include "ui/base/models/simple_menu_model.h"
20 20
21 #if defined(OS_CHROMEOS) 21 #if defined(OS_CHROMEOS)
22 #include "ash/common/session/session_state_delegate.h" // nogncheck
23 #include "ash/common/wm_shell.h" // nogncheck
24 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 22 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
25 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 23 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
26 #include "chrome/browser/ui/browser_window.h" 24 #include "chrome/browser/ui/browser_window.h"
27 #include "components/signin/core/account_id/account_id.h" 25 #include "components/signin/core/account_id/account_id.h"
28 #include "components/user_manager/user_info.h" 26 #include "components/user_manager/user_info.h"
27 #include "components/user_manager/user_manager.h"
29 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
30 #endif 29 #endif
31 30
32 namespace { 31 namespace {
33 32
34 // Given a |browser| that's an app or popup window, checks if it's hosting the 33 // Given a |browser| that's an app or popup window, checks if it's hosting the
35 // settings page. 34 // settings page.
36 bool IsChromeSettingsAppOrPopupWindow(Browser* browser) { 35 bool IsChromeSettingsAppOrPopupWindow(Browser* browser) {
37 DCHECK(browser); 36 DCHECK(browser);
38 TabStripModel* tab_strip = browser->tab_strip_model(); 37 TabStripModel* tab_strip = browser->tab_strip_model();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // If there is no manager, we are not in the proper multi user mode. 147 // If there is no manager, we are not in the proper multi user mode.
149 if (chrome::MultiUserWindowManager::GetMultiProfileMode() != 148 if (chrome::MultiUserWindowManager::GetMultiProfileMode() !=
150 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) 149 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED)
151 return; 150 return;
152 151
153 // Don't show the menu for incognito windows. 152 // Don't show the menu for incognito windows.
154 if (browser()->profile()->IsOffTheRecord()) 153 if (browser()->profile()->IsOffTheRecord())
155 return; 154 return;
156 155
157 // To show the menu we need at least two logged in users. 156 // To show the menu we need at least two logged in users.
158 ash::SessionStateDelegate* delegate = 157 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
159 ash::WmShell::Get()->GetSessionStateDelegate(); 158 const user_manager::UserList logged_in_users =
160 int logged_in_users = delegate->NumberOfLoggedInUsers(); 159 user_manager->GetLRULoggedInUsers();
161 if (logged_in_users <= 1) 160 if (logged_in_users.size() <= 1u)
162 return; 161 return;
163 162
164 // If this does not belong to a profile or there is no window, or the window 163 // If this does not belong to a profile or there is no window, or the window
165 // is not owned by anyone, we don't show the menu addition. 164 // is not owned by anyone, we don't show the menu addition.
166 chrome::MultiUserWindowManager* manager = 165 chrome::MultiUserWindowManager* manager =
167 chrome::MultiUserWindowManager::GetInstance(); 166 chrome::MultiUserWindowManager::GetInstance();
168 const AccountId account_id = 167 const AccountId account_id =
169 multi_user_util::GetAccountIdFromProfile(browser()->profile()); 168 multi_user_util::GetAccountIdFromProfile(browser()->profile());
170 aura::Window* window = browser()->window()->GetNativeWindow(); 169 aura::Window* window = browser()->window()->GetNativeWindow();
171 if (!account_id.is_valid() || !window || 170 if (!account_id.is_valid() || !window ||
172 !manager->GetWindowOwner(window).is_valid()) 171 !manager->GetWindowOwner(window).is_valid())
173 return; 172 return;
174 173
175 model->AddSeparator(ui::NORMAL_SEPARATOR); 174 model->AddSeparator(ui::NORMAL_SEPARATOR);
176 DCHECK(logged_in_users <= 3); 175 DCHECK_LE(logged_in_users.size(), 3u);
177 for (int user_index = 1; user_index < logged_in_users; ++user_index) { 176 for (size_t user_index = 1; user_index < logged_in_users.size();
178 const user_manager::UserInfo* user_info = delegate->GetUserInfo(user_index); 177 ++user_index) {
178 const user_manager::UserInfo* user_info = logged_in_users[user_index];
179 model->AddItem( 179 model->AddItem(
180 user_index == 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2 180 user_index == 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2
181 : IDC_VISIT_DESKTOP_OF_LRU_USER_3, 181 : IDC_VISIT_DESKTOP_OF_LRU_USER_3,
182 l10n_util::GetStringFUTF16( 182 l10n_util::GetStringFUTF16(
183 IDS_VISIT_DESKTOP_OF_LRU_USER, user_info->GetDisplayName(), 183 IDS_VISIT_DESKTOP_OF_LRU_USER, user_info->GetDisplayName(),
184 base::ASCIIToUTF16(user_info->GetDisplayEmail()))); 184 base::ASCIIToUTF16(user_info->GetDisplayEmail())));
185 } 185 }
186 #endif 186 #endif
187 } 187 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_frame.cc ('k') | chrome/browser/ui/webui/chromeos/login/signin_screen_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698