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

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

Issue 231123002: Notify about major session changes events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit_tests Created 6 years, 8 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 | Annotate | Revision Log
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/multi_profile_uma.h" 7 #include "ash/multi_profile_uma.h"
8 #include "ash/session_state_observer.h" 8 #include "ash/session_state_observer.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "chrome/browser/chromeos/login/screen_locker.h" 12 #include "chrome/browser/chromeos/login/screen_locker.h"
13 #include "chrome/browser/chromeos/login/user.h" 13 #include "chrome/browser/chromeos/login/user.h"
14 #include "chrome/browser/chromeos/login/user_adding_screen.h" 14 #include "chrome/browser/chromeos/login/user_adding_screen.h"
15 #include "chrome/browser/chromeos/login/user_manager.h" 15 #include "chrome/browser/chromeos/login/user_manager.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 18 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chromeos/chromeos_switches.h" 20 #include "chromeos/chromeos_switches.h"
21 #include "chromeos/dbus/dbus_thread_manager.h" 21 #include "chromeos/dbus/dbus_thread_manager.h"
22 #include "chromeos/dbus/session_manager_client.h" 22 #include "chromeos/dbus/session_manager_client.h"
23 #include "chromeos/login/login_state.h"
23 #include "google_apis/gaia/gaia_auth_util.h" 24 #include "google_apis/gaia/gaia_auth_util.h"
24 25
25 SessionStateDelegateChromeos::SessionStateDelegateChromeos() { 26 SessionStateDelegateChromeos::SessionStateDelegateChromeos()
27 : session_state_(SESSION_STATE_LOGIN_PRIMARY) {
26 chromeos::UserManager::Get()->AddSessionStateObserver(this); 28 chromeos::UserManager::Get()->AddSessionStateObserver(this);
29 chromeos::UserAddingScreen::Get()->AddObserver(this);
30
31 // LoginState is not initialized in unit_tests.
32 if (chromeos::LoginState::IsInitialized()) {
33 chromeos::LoginState::Get()->AddObserver(this);
34 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ?
35 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, true);
36 }
27 } 37 }
28 38
29 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { 39 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() {
40 chromeos::UserManager::Get()->RemoveSessionStateObserver(this);
41 chromeos::UserAddingScreen::Get()->RemoveObserver(this);
42
43 // LoginState is not initialized in unit_tests.
44 if (chromeos::LoginState::IsInitialized())
45 chromeos::LoginState::Get()->RemoveObserver(this);
30 } 46 }
31 47
32 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex( 48 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex(
33 ash::MultiProfileIndex index) { 49 ash::MultiProfileIndex index) {
34 DCHECK_LT(index, NumberOfLoggedInUsers()); 50 DCHECK_LT(index, NumberOfLoggedInUsers());
35 chromeos::User* user = 51 chromeos::User* user =
36 chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]; 52 chromeos::UserManager::Get()->GetLRULoggedInUsers()[index];
37 DCHECK(user); 53 DCHECK(user);
38 return chromeos::UserManager::Get()->GetProfileByUser(user); 54 return chromeos::UserManager::Get()->GetProfileByUser(user);
39 } 55 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 120 }
105 121
106 bool SessionStateDelegateChromeos::IsUserSessionBlocked() const { 122 bool SessionStateDelegateChromeos::IsUserSessionBlocked() const {
107 bool has_login_manager = CommandLine::ForCurrentProcess()->HasSwitch( 123 bool has_login_manager = CommandLine::ForCurrentProcess()->HasSwitch(
108 chromeos::switches::kLoginManager); 124 chromeos::switches::kLoginManager);
109 return (has_login_manager && !IsActiveUserSessionStarted()) || 125 return (has_login_manager && !IsActiveUserSessionStarted()) ||
110 IsScreenLocked() || 126 IsScreenLocked() ||
111 chromeos::UserAddingScreen::Get()->IsRunning(); 127 chromeos::UserAddingScreen::Get()->IsRunning();
112 } 128 }
113 129
130 ash::SessionStateDelegate::SessionState
131 SessionStateDelegateChromeos::GetSessionState() const {
132 return session_state_;
133 }
134
114 const base::string16 SessionStateDelegateChromeos::GetUserDisplayName( 135 const base::string16 SessionStateDelegateChromeos::GetUserDisplayName(
115 ash::MultiProfileIndex index) const { 136 ash::MultiProfileIndex index) const {
116 DCHECK_LT(index, NumberOfLoggedInUsers()); 137 DCHECK_LT(index, NumberOfLoggedInUsers());
117 return chromeos::UserManager::Get()-> 138 return chromeos::UserManager::Get()->
118 GetLRULoggedInUsers()[index]->display_name(); 139 GetLRULoggedInUsers()[index]->display_name();
119 } 140 }
120 141
121 const base::string16 SessionStateDelegateChromeos::GetUserGivenName( 142 const base::string16 SessionStateDelegateChromeos::GetUserGivenName(
122 ash::MultiProfileIndex index) const { 143 ash::MultiProfileIndex index) const {
123 DCHECK_LT(index, NumberOfLoggedInUsers()); 144 DCHECK_LT(index, NumberOfLoggedInUsers());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 void SessionStateDelegateChromeos::AddSessionStateObserver( 230 void SessionStateDelegateChromeos::AddSessionStateObserver(
210 ash::SessionStateObserver* observer) { 231 ash::SessionStateObserver* observer) {
211 session_state_observer_list_.AddObserver(observer); 232 session_state_observer_list_.AddObserver(observer);
212 } 233 }
213 234
214 void SessionStateDelegateChromeos::RemoveSessionStateObserver( 235 void SessionStateDelegateChromeos::RemoveSessionStateObserver(
215 ash::SessionStateObserver* observer) { 236 ash::SessionStateObserver* observer) {
216 session_state_observer_list_.RemoveObserver(observer); 237 session_state_observer_list_.RemoveObserver(observer);
217 } 238 }
218 239
240 void SessionStateDelegateChromeos::LoggedInStateChanged() {
241 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ?
242 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, false);
243 }
244
219 void SessionStateDelegateChromeos::ActiveUserChanged( 245 void SessionStateDelegateChromeos::ActiveUserChanged(
220 const chromeos::User* active_user) { 246 const chromeos::User* active_user) {
221 FOR_EACH_OBSERVER(ash::SessionStateObserver, 247 FOR_EACH_OBSERVER(ash::SessionStateObserver,
222 session_state_observer_list_, 248 session_state_observer_list_,
223 ActiveUserChanged(active_user->email())); 249 ActiveUserChanged(active_user->email()));
224 } 250 }
225 251
226 void SessionStateDelegateChromeos::UserAddedToSession( 252 void SessionStateDelegateChromeos::UserAddedToSession(
227 const chromeos::User* added_user) { 253 const chromeos::User* added_user) {
228 FOR_EACH_OBSERVER(ash::SessionStateObserver, 254 FOR_EACH_OBSERVER(ash::SessionStateObserver,
229 session_state_observer_list_, 255 session_state_observer_list_,
230 UserAddedToSession(added_user->email())); 256 UserAddedToSession(added_user->email()));
231 } 257 }
258
259 void SessionStateDelegateChromeos::OnUserAddingStarted() {
260 SetSessionState(SESSION_STATE_LOGIN_SECONDARY, false);
261 }
262
263 void SessionStateDelegateChromeos::OnUserAddingFinished() {
264 SetSessionState(SESSION_STATE_ACTIVE, false);
265 }
266
267 void SessionStateDelegateChromeos::SetSessionState(SessionState new_state,
268 bool force) {
269 if (session_state_ == new_state && !force)
270 return;
271
272 session_state_ = new_state;
273 NotifySessionStateChanged();
274 }
275
276 void SessionStateDelegateChromeos::NotifySessionStateChanged() {
277 FOR_EACH_OBSERVER(ash::SessionStateObserver,
278 session_state_observer_list_,
279 SessionStateChanged(session_state_));
280 }
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