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

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

Issue 2416253004: ash: Use session_manager::SessionState (Closed)
Patch Set: add comment about session state in SessionStaetDelegateChromeos Created 4 years, 2 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/ash/session_state_delegate_chromeos.h" 5 #include "chrome/browser/ui/ash/session_state_delegate_chromeos.h"
6 6
7 #include "ash/aura/wm_window_aura.h" 7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/session/session_state_observer.h" 8 #include "ash/common/session/session_state_observer.h"
9 #include "ash/content/shell_content_state.h" 9 #include "ash/content/shell_content_state.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 16 matching lines...) Expand all
27 #include "chromeos/login/login_state.h" 27 #include "chromeos/login/login_state.h"
28 #include "components/prefs/pref_service.h" 28 #include "components/prefs/pref_service.h"
29 #include "components/signin/core/account_id/account_id.h" 29 #include "components/signin/core/account_id/account_id.h"
30 #include "components/user_manager/user.h" 30 #include "components/user_manager/user.h"
31 #include "components/user_manager/user_info.h" 31 #include "components/user_manager/user_info.h"
32 #include "components/user_manager/user_manager.h" 32 #include "components/user_manager/user_manager.h"
33 #include "google_apis/gaia/gaia_auth_util.h" 33 #include "google_apis/gaia/gaia_auth_util.h"
34 #include "ui/gfx/image/image_skia.h" 34 #include "ui/gfx/image/image_skia.h"
35 35
36 SessionStateDelegateChromeos::SessionStateDelegateChromeos() 36 SessionStateDelegateChromeos::SessionStateDelegateChromeos()
37 : session_state_(SESSION_STATE_LOGIN_PRIMARY) { 37 : session_state_(session_manager::SessionState::LOGIN_PRIMARY) {
38 user_manager::UserManager::Get()->AddSessionStateObserver(this); 38 user_manager::UserManager::Get()->AddSessionStateObserver(this);
39 chromeos::UserAddingScreen::Get()->AddObserver(this); 39 chromeos::UserAddingScreen::Get()->AddObserver(this);
40 40
41 // LoginState is not initialized in unit_tests. 41 // LoginState is not initialized in unit_tests.
42 if (chromeos::LoginState::IsInitialized()) { 42 if (chromeos::LoginState::IsInitialized()) {
43 chromeos::LoginState::Get()->AddObserver(this); 43 chromeos::LoginState::Get()->AddObserver(this);
44 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? 44 // Note that the session state is only set to ACTIVE or LOGIN_PRIMARY
45 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, true); 45 // instead of using SessionManager::Get()->session_state(). This is
46 // an intermediate state of replacing SessionStateDelegate with
47 // mojo interfaces. The replacement mojo interface would reflect
48 // real session state in SessionManager and have getters to translate
49 // them in a sensible way to ash code.
50 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn()
51 ? session_manager::SessionState::ACTIVE
52 : session_manager::SessionState::LOGIN_PRIMARY,
53 true);
46 } 54 }
47 } 55 }
48 56
49 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { 57 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() {
50 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); 58 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
51 chromeos::UserAddingScreen::Get()->RemoveObserver(this); 59 chromeos::UserAddingScreen::Get()->RemoveObserver(this);
52 60
53 // LoginState is not initialized in unit_tests. 61 // LoginState is not initialized in unit_tests.
54 if (chromeos::LoginState::IsInitialized()) 62 if (chromeos::LoginState::IsInitialized())
55 chromeos::LoginState::Get()->RemoveObserver(this); 63 chromeos::LoginState::Get()->RemoveObserver(this);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 134 }
127 135
128 bool SessionStateDelegateChromeos::IsUserSessionBlocked() const { 136 bool SessionStateDelegateChromeos::IsUserSessionBlocked() const {
129 bool has_login_manager = base::CommandLine::ForCurrentProcess()->HasSwitch( 137 bool has_login_manager = base::CommandLine::ForCurrentProcess()->HasSwitch(
130 chromeos::switches::kLoginManager); 138 chromeos::switches::kLoginManager);
131 return (has_login_manager && !IsActiveUserSessionStarted()) || 139 return (has_login_manager && !IsActiveUserSessionStarted()) ||
132 IsScreenLocked() || 140 IsScreenLocked() ||
133 chromeos::UserAddingScreen::Get()->IsRunning(); 141 chromeos::UserAddingScreen::Get()->IsRunning();
134 } 142 }
135 143
136 ash::SessionStateDelegate::SessionState 144 session_manager::SessionState SessionStateDelegateChromeos::GetSessionState()
137 SessionStateDelegateChromeos::GetSessionState() const { 145 const {
138 return session_state_; 146 return session_state_;
139 } 147 }
140 148
141 const user_manager::UserInfo* SessionStateDelegateChromeos::GetUserInfo( 149 const user_manager::UserInfo* SessionStateDelegateChromeos::GetUserInfo(
142 ash::UserIndex index) const { 150 ash::UserIndex index) const {
143 DCHECK_LT(index, NumberOfLoggedInUsers()); 151 DCHECK_LT(index, NumberOfLoggedInUsers());
144 return user_manager::UserManager::Get()->GetLRULoggedInUsers()[index]; 152 return user_manager::UserManager::Get()->GetLRULoggedInUsers()[index];
145 } 153 }
146 154
147 bool SessionStateDelegateChromeos::ShouldShowAvatar( 155 bool SessionStateDelegateChromeos::ShouldShowAvatar(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 ash::SessionStateObserver* observer) { 232 ash::SessionStateObserver* observer) {
225 session_state_observer_list_.AddObserver(observer); 233 session_state_observer_list_.AddObserver(observer);
226 } 234 }
227 235
228 void SessionStateDelegateChromeos::RemoveSessionStateObserver( 236 void SessionStateDelegateChromeos::RemoveSessionStateObserver(
229 ash::SessionStateObserver* observer) { 237 ash::SessionStateObserver* observer) {
230 session_state_observer_list_.RemoveObserver(observer); 238 session_state_observer_list_.RemoveObserver(observer);
231 } 239 }
232 240
233 void SessionStateDelegateChromeos::LoggedInStateChanged() { 241 void SessionStateDelegateChromeos::LoggedInStateChanged() {
234 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? 242 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn()
235 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, false); 243 ? session_manager::SessionState::ACTIVE
244 : session_manager::SessionState::LOGIN_PRIMARY,
245 false);
236 } 246 }
237 247
238 void SessionStateDelegateChromeos::ActiveUserChanged( 248 void SessionStateDelegateChromeos::ActiveUserChanged(
239 const user_manager::User* active_user) { 249 const user_manager::User* active_user) {
240 FOR_EACH_OBSERVER(ash::SessionStateObserver, session_state_observer_list_, 250 FOR_EACH_OBSERVER(ash::SessionStateObserver, session_state_observer_list_,
241 ActiveUserChanged(active_user->GetAccountId())); 251 ActiveUserChanged(active_user->GetAccountId()));
242 } 252 }
243 253
244 void SessionStateDelegateChromeos::UserAddedToSession( 254 void SessionStateDelegateChromeos::UserAddedToSession(
245 const user_manager::User* added_user) { 255 const user_manager::User* added_user) {
246 FOR_EACH_OBSERVER(ash::SessionStateObserver, session_state_observer_list_, 256 FOR_EACH_OBSERVER(ash::SessionStateObserver, session_state_observer_list_,
247 UserAddedToSession(added_user->GetAccountId())); 257 UserAddedToSession(added_user->GetAccountId()));
248 } 258 }
249 259
250 void SessionStateDelegateChromeos::OnUserAddingStarted() { 260 void SessionStateDelegateChromeos::OnUserAddingStarted() {
251 SetSessionState(SESSION_STATE_LOGIN_SECONDARY, false); 261 SetSessionState(session_manager::SessionState::LOGIN_SECONDARY, false);
252 } 262 }
253 263
254 void SessionStateDelegateChromeos::OnUserAddingFinished() { 264 void SessionStateDelegateChromeos::OnUserAddingFinished() {
255 SetSessionState(SESSION_STATE_ACTIVE, false); 265 SetSessionState(session_manager::SessionState::ACTIVE, false);
256 } 266 }
257 267
258 void SessionStateDelegateChromeos::SetSessionState(SessionState new_state, 268 void SessionStateDelegateChromeos::SetSessionState(
259 bool force) { 269 session_manager::SessionState new_state,
270 bool force) {
260 if (session_state_ == new_state && !force) 271 if (session_state_ == new_state && !force)
261 return; 272 return;
262 273
263 session_state_ = new_state; 274 session_state_ = new_state;
264 NotifySessionStateChanged(); 275 NotifySessionStateChanged();
265 } 276 }
266 277
267 void SessionStateDelegateChromeos::NotifySessionStateChanged() { 278 void SessionStateDelegateChromeos::NotifySessionStateChanged() {
268 FOR_EACH_OBSERVER(ash::SessionStateObserver, 279 FOR_EACH_OBSERVER(ash::SessionStateObserver,
269 session_state_observer_list_, 280 session_state_observer_list_,
270 SessionStateChanged(session_state_)); 281 SessionStateChanged(session_state_));
271 } 282 }
272 283
273 void DoSwitchUser(const AccountId& account_id) { 284 void DoSwitchUser(const AccountId& account_id) {
274 user_manager::UserManager::Get()->SwitchActiveUser(account_id); 285 user_manager::UserManager::Get()->SwitchActiveUser(account_id);
275 } 286 }
276 287
277 void SessionStateDelegateChromeos::TryToSwitchUser( 288 void SessionStateDelegateChromeos::TryToSwitchUser(
278 const AccountId& account_id) { 289 const AccountId& account_id) {
279 TrySwitchingActiveUser(base::Bind(&DoSwitchUser, account_id)); 290 TrySwitchingActiveUser(base::Bind(&DoSwitchUser, account_id));
280 } 291 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698