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

Side by Side Diff: chrome/browser/ui/ash/multi_user/multi_user_context_menu_chromeos.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/ash/multi_user/multi_user_context_menu.h" 5 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
6 6
7 #include "ash/common/multi_profile_uma.h" 7 #include "ash/common/multi_profile_uma.h"
8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/wm_shell.h"
10 #include "base/bind.h" 8 #include "base/bind.h"
11 #include "base/callback.h" 9 #include "base/callback.h"
12 #include "base/macros.h" 10 #include "base/macros.h"
13 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/app/chrome_command_ids.h" 12 #include "chrome/app/chrome_command_ids.h"
15 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 15 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
18 #include "chrome/browser/ui/ash/multi_user/multi_user_warning_dialog.h" 16 #include "chrome/browser/ui/ash/multi_user/multi_user_warning_dialog.h"
19 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 void MultiUserContextMenuChromeos::ExecuteCommand(int command_id, 55 void MultiUserContextMenuChromeos::ExecuteCommand(int command_id,
58 int event_flags) { 56 int event_flags) {
59 ExecuteVisitDesktopCommand(command_id, window_); 57 ExecuteVisitDesktopCommand(command_id, window_);
60 } 58 }
61 } // namespace 59 } // namespace
62 } // namespace chromeos 60 } // namespace chromeos
63 61
64 std::unique_ptr<ui::MenuModel> CreateMultiUserContextMenu( 62 std::unique_ptr<ui::MenuModel> CreateMultiUserContextMenu(
65 aura::Window* window) { 63 aura::Window* window) {
66 std::unique_ptr<ui::MenuModel> model; 64 std::unique_ptr<ui::MenuModel> model;
67 ash::SessionStateDelegate* delegate = 65 const user_manager::UserList logged_in_users =
68 ash::WmShell::Get()->GetSessionStateDelegate(); 66 user_manager::UserManager::Get()->GetLRULoggedInUsers();
69 if (!delegate)
70 return model;
71 67
72 int logged_in_users = delegate->NumberOfLoggedInUsers(); 68 if (logged_in_users.size() > 1u) {
73 if (logged_in_users > 1) {
74 // If this window is not owned, we don't show the menu addition. 69 // If this window is not owned, we don't show the menu addition.
75 chrome::MultiUserWindowManager* manager = 70 chrome::MultiUserWindowManager* manager =
76 chrome::MultiUserWindowManager::GetInstance(); 71 chrome::MultiUserWindowManager::GetInstance();
77 const AccountId& account_id = manager->GetWindowOwner(window); 72 const AccountId& account_id = manager->GetWindowOwner(window);
78 if (!account_id.is_valid() || !window) 73 if (!account_id.is_valid() || !window)
79 return model; 74 return model;
80 chromeos::MultiUserContextMenuChromeos* menu = 75 chromeos::MultiUserContextMenuChromeos* menu =
81 new chromeos::MultiUserContextMenuChromeos(window); 76 new chromeos::MultiUserContextMenuChromeos(window);
82 model.reset(menu); 77 model.reset(menu);
83 for (int user_index = 1; user_index < logged_in_users; ++user_index) { 78 for (size_t user_index = 1; user_index < logged_in_users.size();
84 const user_manager::UserInfo* user_info = 79 ++user_index) {
85 delegate->GetUserInfo(user_index); 80 const user_manager::UserInfo* user_info = logged_in_users[user_index];
86 menu->AddItem( 81 menu->AddItem(
87 user_index == 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2 82 user_index == 1 ? IDC_VISIT_DESKTOP_OF_LRU_USER_2
88 : IDC_VISIT_DESKTOP_OF_LRU_USER_3, 83 : IDC_VISIT_DESKTOP_OF_LRU_USER_3,
89 l10n_util::GetStringFUTF16( 84 l10n_util::GetStringFUTF16(
90 IDS_VISIT_DESKTOP_OF_LRU_USER, user_info->GetDisplayName(), 85 IDS_VISIT_DESKTOP_OF_LRU_USER, user_info->GetDisplayName(),
91 base::ASCIIToUTF16(user_info->GetDisplayEmail()))); 86 base::ASCIIToUTF16(user_info->GetDisplayEmail())));
92 } 87 }
93 } 88 }
94 return model; 89 return model;
95 } 90 }
96 91
97 void OnAcceptTeleportWarning(const AccountId& account_id, 92 void OnAcceptTeleportWarning(const AccountId& account_id,
98 aura::Window* window_, 93 aura::Window* window_,
99 bool no_show_again) { 94 bool no_show_again) {
100 PrefService* pref = ProfileManager::GetActiveUserProfile()->GetPrefs(); 95 PrefService* pref = ProfileManager::GetActiveUserProfile()->GetPrefs();
101 pref->SetBoolean(prefs::kMultiProfileWarningShowDismissed, no_show_again); 96 pref->SetBoolean(prefs::kMultiProfileWarningShowDismissed, no_show_again);
102 97
103 ash::MultiProfileUMA::RecordTeleportAction( 98 ash::MultiProfileUMA::RecordTeleportAction(
104 ash::MultiProfileUMA::TELEPORT_WINDOW_CAPTION_MENU); 99 ash::MultiProfileUMA::TELEPORT_WINDOW_CAPTION_MENU);
105 100
106 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(window_, 101 chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(window_,
107 account_id); 102 account_id);
108 } 103 }
109 104
110 void ExecuteVisitDesktopCommand(int command_id, aura::Window* window) { 105 void ExecuteVisitDesktopCommand(int command_id, aura::Window* window) {
111 switch (command_id) { 106 switch (command_id) {
112 case IDC_VISIT_DESKTOP_OF_LRU_USER_2: 107 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
113 case IDC_VISIT_DESKTOP_OF_LRU_USER_3: { 108 case IDC_VISIT_DESKTOP_OF_LRU_USER_3: {
109 const user_manager::UserList logged_in_users =
110 user_manager::UserManager::Get()->GetLRULoggedInUsers();
114 // When running the multi user mode on Chrome OS, windows can "visit" 111 // When running the multi user mode on Chrome OS, windows can "visit"
115 // another user's desktop. 112 // another user's desktop.
116 const AccountId account_id = 113 const AccountId account_id =
117 ash::WmShell::Get() 114 logged_in_users[IDC_VISIT_DESKTOP_OF_LRU_USER_2 == command_id ? 1 : 2]
118 ->GetSessionStateDelegate()
119 ->GetUserInfo(IDC_VISIT_DESKTOP_OF_LRU_USER_2 == command_id ? 1
120 : 2)
121 ->GetAccountId(); 115 ->GetAccountId();
122 base::Callback<void(bool)> on_accept = 116 base::Callback<void(bool)> on_accept =
123 base::Bind(&OnAcceptTeleportWarning, account_id, window); 117 base::Bind(&OnAcceptTeleportWarning, account_id, window);
124 118
125 // Don't show warning dialog if any logged in user in multi-profiles 119 // Don't show warning dialog if any logged in user in multi-profiles
126 // session dismissed it. 120 // session dismissed it.
127 const user_manager::UserList logged_in_users =
128 user_manager::UserManager::Get()->GetLoggedInUsers();
129 for (user_manager::UserList::const_iterator it = logged_in_users.begin(); 121 for (user_manager::UserList::const_iterator it = logged_in_users.begin();
130 it != logged_in_users.end(); 122 it != logged_in_users.end();
131 ++it) { 123 ++it) {
132 if (multi_user_util::GetProfileFromAccountId((*it)->GetAccountId()) 124 if (multi_user_util::GetProfileFromAccountId((*it)->GetAccountId())
133 ->GetPrefs() 125 ->GetPrefs()
134 ->GetBoolean(prefs::kMultiProfileWarningShowDismissed)) { 126 ->GetBoolean(prefs::kMultiProfileWarningShowDismissed)) {
135 bool active_user_show_option = 127 bool active_user_show_option =
136 ProfileManager::GetActiveUserProfile()-> 128 ProfileManager::GetActiveUserProfile()->
137 GetPrefs()->GetBoolean(prefs::kMultiProfileWarningShowDismissed); 129 GetPrefs()->GetBoolean(prefs::kMultiProfileWarningShowDismissed);
138 on_accept.Run(active_user_show_option); 130 on_accept.Run(active_user_show_option);
139 return; 131 return;
140 } 132 }
141 } 133 }
142 chromeos::ShowMultiprofilesWarningDialog(on_accept); 134 chromeos::ShowMultiprofilesWarningDialog(on_accept);
143 return; 135 return;
144 } 136 }
145 default: 137 default:
146 NOTREACHED(); 138 NOTREACHED();
147 } 139 }
148 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698