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

Side by Side Diff: chrome/browser/ui/ash/session_state_delegate_chromeos.cc

Issue 1428213004: This CL replaces std::string user_id in ash/* with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 5 years, 1 month 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/ash/session_state_delegate_chromeos.h" 5 #include "chrome/browser/ui/ash/session_state_delegate_chromeos.h"
6 6
7 #include "ash/content/shell_content_state.h" 7 #include "ash/content/shell_content_state.h"
8 #include "ash/multi_profile_uma.h" 8 #include "ash/multi_profile_uma.h"
9 #include "ash/session/session_state_observer.h" 9 #include "ash/session/session_state_observer.h"
10 #include "ash/system/chromeos/multi_user/user_switch_util.h" 10 #include "ash/system/chromeos/multi_user/user_switch_util.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 151 }
152 152
153 gfx::ImageSkia SessionStateDelegateChromeos::GetAvatarImageForWindow( 153 gfx::ImageSkia SessionStateDelegateChromeos::GetAvatarImageForWindow(
154 aura::Window* window) const { 154 aura::Window* window) const {
155 content::BrowserContext* context = 155 content::BrowserContext* context =
156 ash::ShellContentState::GetInstance()->GetBrowserContextForWindow(window); 156 ash::ShellContentState::GetInstance()->GetBrowserContextForWindow(window);
157 return GetAvatarImageForContext(context); 157 return GetAvatarImageForContext(context);
158 } 158 }
159 159
160 void SessionStateDelegateChromeos::SwitchActiveUser( 160 void SessionStateDelegateChromeos::SwitchActiveUser(
161 const std::string& user_id) { 161 const AccountId& account_id) {
162 // Disallow switching to an already active user since that might crash. 162 // Disallow switching to an already active user since that might crash.
163 // Also check that we got a user id and not an email address. 163 // Also check that we got a user id and not an email address.
164 DCHECK_EQ(user_id, 164 DCHECK_EQ(
165 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id))); 165 account_id.GetUserEmail(),
166 if (user_id == user_manager::UserManager::Get()->GetActiveUser()->email()) 166 gaia::CanonicalizeEmail(gaia::SanitizeEmail(account_id.GetUserEmail())));
167 if (account_id ==
168 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId())
167 return; 169 return;
168 TryToSwitchUser(user_id); 170 TryToSwitchUser(account_id);
169 } 171 }
170 172
171 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { 173 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) {
172 // Make sure there is a user to switch to. 174 // Make sure there is a user to switch to.
173 if (NumberOfLoggedInUsers() <= 1) 175 if (NumberOfLoggedInUsers() <= 1)
174 return; 176 return;
175 177
176 const user_manager::UserList& logged_in_users = 178 const user_manager::UserList& logged_in_users =
177 user_manager::UserManager::Get()->GetLoggedInUsers(); 179 user_manager::UserManager::Get()->GetLoggedInUsers();
178 180
179 std::string user_id = 181 AccountId account_id =
180 user_manager::UserManager::Get()->GetActiveUser()->email(); 182 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId();
181 183
182 // Get an iterator positioned at the active user. 184 // Get an iterator positioned at the active user.
183 user_manager::UserList::const_iterator it; 185 user_manager::UserList::const_iterator it;
184 for (it = logged_in_users.begin(); 186 for (it = logged_in_users.begin();
185 it != logged_in_users.end(); ++it) { 187 it != logged_in_users.end(); ++it) {
186 if ((*it)->email() == user_id) 188 if ((*it)->GetAccountId() == account_id)
187 break; 189 break;
188 } 190 }
189 191
190 // Active user not found. 192 // Active user not found.
191 if (it == logged_in_users.end()) 193 if (it == logged_in_users.end())
192 return; 194 return;
193 195
194 // Get the user's email to select, wrapping to the start/end of the list if 196 // Get the user's email to select, wrapping to the start/end of the list if
195 // necessary. 197 // necessary.
196 switch (cycle_user) { 198 switch (cycle_user) {
197 case CYCLE_TO_NEXT_USER: 199 case CYCLE_TO_NEXT_USER:
198 if (++it == logged_in_users.end()) 200 if (++it == logged_in_users.end())
199 user_id = (*logged_in_users.begin())->email(); 201 account_id = (*logged_in_users.begin())->GetAccountId();
200 else 202 else
201 user_id = (*it)->email(); 203 account_id = (*it)->GetAccountId();
202 break; 204 break;
203 case CYCLE_TO_PREVIOUS_USER: 205 case CYCLE_TO_PREVIOUS_USER:
204 if (it == logged_in_users.begin()) 206 if (it == logged_in_users.begin())
205 it = logged_in_users.end(); 207 it = logged_in_users.end();
206 user_id = (*(--it))->email(); 208 account_id = (*(--it))->GetAccountId();
207 break; 209 break;
208 } 210 }
209 211
210 // Switch using the transformed |user_id|. 212 // Switch using the transformed |account_id|.
211 TryToSwitchUser(user_id); 213 TryToSwitchUser(account_id);
212 } 214 }
213 215
214 bool SessionStateDelegateChromeos::IsMultiProfileAllowedByPrimaryUserPolicy() 216 bool SessionStateDelegateChromeos::IsMultiProfileAllowedByPrimaryUserPolicy()
215 const { 217 const {
216 return chromeos::MultiProfileUserController::GetPrimaryUserPolicy() == 218 return chromeos::MultiProfileUserController::GetPrimaryUserPolicy() ==
217 chromeos::MultiProfileUserController::ALLOWED; 219 chromeos::MultiProfileUserController::ALLOWED;
218 } 220 }
219 221
220 void SessionStateDelegateChromeos::AddSessionStateObserver( 222 void SessionStateDelegateChromeos::AddSessionStateObserver(
221 ash::SessionStateObserver* observer) { 223 ash::SessionStateObserver* observer) {
222 session_state_observer_list_.AddObserver(observer); 224 session_state_observer_list_.AddObserver(observer);
223 } 225 }
224 226
225 void SessionStateDelegateChromeos::RemoveSessionStateObserver( 227 void SessionStateDelegateChromeos::RemoveSessionStateObserver(
226 ash::SessionStateObserver* observer) { 228 ash::SessionStateObserver* observer) {
227 session_state_observer_list_.RemoveObserver(observer); 229 session_state_observer_list_.RemoveObserver(observer);
228 } 230 }
229 231
230 void SessionStateDelegateChromeos::LoggedInStateChanged() { 232 void SessionStateDelegateChromeos::LoggedInStateChanged() {
231 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? 233 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ?
232 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, false); 234 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, false);
233 } 235 }
234 236
235 void SessionStateDelegateChromeos::ActiveUserChanged( 237 void SessionStateDelegateChromeos::ActiveUserChanged(
236 const user_manager::User* active_user) { 238 const user_manager::User* active_user) {
237 FOR_EACH_OBSERVER(ash::SessionStateObserver, 239 FOR_EACH_OBSERVER(ash::SessionStateObserver, session_state_observer_list_,
238 session_state_observer_list_, 240 ActiveUserChanged(active_user->GetAccountId()));
239 ActiveUserChanged(active_user->email()));
240 } 241 }
241 242
242 void SessionStateDelegateChromeos::UserAddedToSession( 243 void SessionStateDelegateChromeos::UserAddedToSession(
243 const user_manager::User* added_user) { 244 const user_manager::User* added_user) {
244 FOR_EACH_OBSERVER(ash::SessionStateObserver, 245 FOR_EACH_OBSERVER(ash::SessionStateObserver, session_state_observer_list_,
245 session_state_observer_list_, 246 UserAddedToSession(added_user->GetAccountId()));
246 UserAddedToSession(added_user->email()));
247 } 247 }
248 248
249 void SessionStateDelegateChromeos::OnUserAddingStarted() { 249 void SessionStateDelegateChromeos::OnUserAddingStarted() {
250 SetSessionState(SESSION_STATE_LOGIN_SECONDARY, false); 250 SetSessionState(SESSION_STATE_LOGIN_SECONDARY, false);
251 } 251 }
252 252
253 void SessionStateDelegateChromeos::OnUserAddingFinished() { 253 void SessionStateDelegateChromeos::OnUserAddingFinished() {
254 SetSessionState(SESSION_STATE_ACTIVE, false); 254 SetSessionState(SESSION_STATE_ACTIVE, false);
255 } 255 }
256 256
257 void SessionStateDelegateChromeos::SetSessionState(SessionState new_state, 257 void SessionStateDelegateChromeos::SetSessionState(SessionState new_state,
258 bool force) { 258 bool force) {
259 if (session_state_ == new_state && !force) 259 if (session_state_ == new_state && !force)
260 return; 260 return;
261 261
262 session_state_ = new_state; 262 session_state_ = new_state;
263 NotifySessionStateChanged(); 263 NotifySessionStateChanged();
264 } 264 }
265 265
266 void SessionStateDelegateChromeos::NotifySessionStateChanged() { 266 void SessionStateDelegateChromeos::NotifySessionStateChanged() {
267 FOR_EACH_OBSERVER(ash::SessionStateObserver, 267 FOR_EACH_OBSERVER(ash::SessionStateObserver,
268 session_state_observer_list_, 268 session_state_observer_list_,
269 SessionStateChanged(session_state_)); 269 SessionStateChanged(session_state_));
270 } 270 }
271 271
272 void DoSwitchUser(const std::string& user_id) { 272 void DoSwitchUser(const AccountId& account_id) {
273 user_manager::UserManager::Get()->SwitchActiveUser( 273 user_manager::UserManager::Get()->SwitchActiveUser(account_id);
274 AccountId::FromUserEmail(user_id));
275 } 274 }
276 275
277 void SessionStateDelegateChromeos::TryToSwitchUser( 276 void SessionStateDelegateChromeos::TryToSwitchUser(
278 const std::string& user_id) { 277 const AccountId& account_id) {
279 ash::TrySwitchingActiveUser(base::Bind(&DoSwitchUser, user_id)); 278 ash::TrySwitchingActiveUser(base::Bind(&DoSwitchUser, account_id));
280 } 279 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/session_state_delegate_chromeos.h ('k') | chrome/browser/ui/ash/session_state_delegate_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698