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

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: 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/chrome_notification_types.h"
12 #include "chrome/browser/chromeos/login/screen_locker.h" 13 #include "chrome/browser/chromeos/login/screen_locker.h"
13 #include "chrome/browser/chromeos/login/user.h" 14 #include "chrome/browser/chromeos/login/user.h"
14 #include "chrome/browser/chromeos/login/user_adding_screen.h" 15 #include "chrome/browser/chromeos/login/user_adding_screen.h"
15 #include "chrome/browser/chromeos/login/user_manager.h" 16 #include "chrome/browser/chromeos/login/user_manager.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 19 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "chromeos/chromeos_switches.h" 21 #include "chromeos/chromeos_switches.h"
21 #include "chromeos/dbus/dbus_thread_manager.h" 22 #include "chromeos/dbus/dbus_thread_manager.h"
22 #include "chromeos/dbus/session_manager_client.h" 23 #include "chromeos/dbus/session_manager_client.h"
24 #include "chromeos/login/login_state.h"
25 #include "content/public/browser/notification_details.h"
26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_source.h"
23 #include "google_apis/gaia/gaia_auth_util.h" 28 #include "google_apis/gaia/gaia_auth_util.h"
24 29
25 SessionStateDelegateChromeos::SessionStateDelegateChromeos() { 30 SessionStateDelegateChromeos::SessionStateDelegateChromeos()
31 : session_state_(STATE_UNKNOWN) {
Daniel Erat 2014/04/10 16:30:32 it'd be better to have a separate "initialized" me
Nikita (slow) 2014/04/10 17:22:51 Done.
32 chromeos::LoginState::Get()->AddObserver(this);
33 chromeos::DBusThreadManager::Get()->
34 GetSessionManagerClient()->AddObserver(this);
26 chromeos::UserManager::Get()->AddSessionStateObserver(this); 35 chromeos::UserManager::Get()->AddSessionStateObserver(this);
36 chromeos::UserAddingScreen::Get()->AddObserver(this);
37 notification_registrar_.Add(this,
38 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
39 content::NotificationService::AllSources());
40 LoggedInStateChanged();
27 } 41 }
28 42
29 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { 43 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() {
44 chromeos::LoginState::Get()->RemoveObserver(this);
45 chromeos::DBusThreadManager::Get()->
46 GetSessionManagerClient()->RemoveObserver(this);
47 chromeos::UserManager::Get()->RemoveSessionStateObserver(this);
48 chromeos::UserAddingScreen::Get()->RemoveObserver(this);
30 } 49 }
31 50
32 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex( 51 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex(
33 ash::MultiProfileIndex index) { 52 ash::MultiProfileIndex index) {
34 DCHECK_LT(index, NumberOfLoggedInUsers()); 53 DCHECK_LT(index, NumberOfLoggedInUsers());
35 chromeos::User* user = 54 chromeos::User* user =
36 chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]; 55 chromeos::UserManager::Get()->GetLRULoggedInUsers()[index];
37 DCHECK(user); 56 DCHECK(user);
38 return chromeos::UserManager::Get()->GetProfileByUser(user); 57 return chromeos::UserManager::Get()->GetProfileByUser(user);
39 } 58 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 123 }
105 124
106 bool SessionStateDelegateChromeos::IsUserSessionBlocked() const { 125 bool SessionStateDelegateChromeos::IsUserSessionBlocked() const {
107 bool has_login_manager = CommandLine::ForCurrentProcess()->HasSwitch( 126 bool has_login_manager = CommandLine::ForCurrentProcess()->HasSwitch(
108 chromeos::switches::kLoginManager); 127 chromeos::switches::kLoginManager);
109 return (has_login_manager && !IsActiveUserSessionStarted()) || 128 return (has_login_manager && !IsActiveUserSessionStarted()) ||
110 IsScreenLocked() || 129 IsScreenLocked() ||
111 chromeos::UserAddingScreen::Get()->IsRunning(); 130 chromeos::UserAddingScreen::Get()->IsRunning();
112 } 131 }
113 132
133 ash::SessionStateDelegate::SessionState
134 SessionStateDelegateChromeos::GetSessionState() const {
135 return session_state_;
136 }
137
114 const base::string16 SessionStateDelegateChromeos::GetUserDisplayName( 138 const base::string16 SessionStateDelegateChromeos::GetUserDisplayName(
115 ash::MultiProfileIndex index) const { 139 ash::MultiProfileIndex index) const {
116 DCHECK_LT(index, NumberOfLoggedInUsers()); 140 DCHECK_LT(index, NumberOfLoggedInUsers());
117 return chromeos::UserManager::Get()-> 141 return chromeos::UserManager::Get()->
118 GetLRULoggedInUsers()[index]->display_name(); 142 GetLRULoggedInUsers()[index]->display_name();
119 } 143 }
120 144
121 const std::string SessionStateDelegateChromeos::GetUserEmail( 145 const std::string SessionStateDelegateChromeos::GetUserEmail(
122 ash::MultiProfileIndex index) const { 146 ash::MultiProfileIndex index) const {
123 DCHECK_LT(index, NumberOfLoggedInUsers()); 147 DCHECK_LT(index, NumberOfLoggedInUsers());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 void SessionStateDelegateChromeos::AddSessionStateObserver( 225 void SessionStateDelegateChromeos::AddSessionStateObserver(
202 ash::SessionStateObserver* observer) { 226 ash::SessionStateObserver* observer) {
203 session_state_observer_list_.AddObserver(observer); 227 session_state_observer_list_.AddObserver(observer);
204 } 228 }
205 229
206 void SessionStateDelegateChromeos::RemoveSessionStateObserver( 230 void SessionStateDelegateChromeos::RemoveSessionStateObserver(
207 ash::SessionStateObserver* observer) { 231 ash::SessionStateObserver* observer) {
208 session_state_observer_list_.RemoveObserver(observer); 232 session_state_observer_list_.RemoveObserver(observer);
209 } 233 }
210 234
235 void SessionStateDelegateChromeos::LoggedInStateChanged() {
236 if (chromeos::LoginState::Get()->IsUserLoggedIn())
237 SetSessionState(STATE_SESSION);
Daniel Erat 2014/04/10 16:30:32 nit: SetSessionState(chromeos::LoginState::Get(
Nikita (slow) 2014/04/10 17:22:51 Done.
238 else
239 SetSessionState(STATE_LOGIN_PRIMARY);
240 }
241
242 void SessionStateDelegateChromeos::ScreenIsLocked() {
243 SetSessionState(STATE_LOCK);
244 }
245
246 void SessionStateDelegateChromeos::ScreenIsUnlocked() {
247 SetSessionState(STATE_SESSION);
248 }
249
211 void SessionStateDelegateChromeos::ActiveUserChanged( 250 void SessionStateDelegateChromeos::ActiveUserChanged(
212 const chromeos::User* active_user) { 251 const chromeos::User* active_user) {
252 SetSessionState(STATE_SESSION);
Daniel Erat 2014/04/10 16:30:32 why is this necessary? shouldn't LoggedInStateChan
Nikita (slow) 2014/04/10 17:22:51 Done.
Nikita (slow) 2014/04/10 17:22:51 Done.
213 FOR_EACH_OBSERVER(ash::SessionStateObserver, 253 FOR_EACH_OBSERVER(ash::SessionStateObserver,
214 session_state_observer_list_, 254 session_state_observer_list_,
215 ActiveUserChanged(active_user->email())); 255 ActiveUserChanged(active_user->email()));
216 } 256 }
217 257
218 void SessionStateDelegateChromeos::UserAddedToSession( 258 void SessionStateDelegateChromeos::UserAddedToSession(
219 const chromeos::User* added_user) { 259 const chromeos::User* added_user) {
260 SetSessionState(STATE_SESSION);
Daniel Erat 2014/04/10 16:30:32 why is this necessary? shouldn't OnUserAddingFinis
Nikita (slow) 2014/04/10 17:22:51 Done.
220 FOR_EACH_OBSERVER(ash::SessionStateObserver, 261 FOR_EACH_OBSERVER(ash::SessionStateObserver,
221 session_state_observer_list_, 262 session_state_observer_list_,
222 UserAddedToSession(added_user->email())); 263 UserAddedToSession(added_user->email()));
223 } 264 }
265
266 void SessionStateDelegateChromeos::OnUserAddingStarted() {
267 SetSessionState(STATE_LOGIN_SECONDARY);
268 }
269
270 void SessionStateDelegateChromeos::OnUserAddingFinished() {
271 SetSessionState(STATE_SESSION);
272 }
273
274 void SessionStateDelegateChromeos::Observe(
275 int type,
276 const content::NotificationSource& source,
277 const content::NotificationDetails& details) {
278 switch (type) {
279 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: {
Daniel Erat 2014/04/10 16:30:32 this seems ugly. do we really need to watch for bo
Nikita (slow) 2014/04/10 17:22:51 Turns out ScreenLockerTest only creates ScreenLock
280 bool locked = *content::Details<bool>(details).ptr();
281 SetSessionState(locked ? STATE_LOCK : STATE_SESSION);
282 break;
283 }
284 default: {
285 NOTREACHED() << "Unknown notification type";
286 break;
287 }
288 }
289 }
290
291 void SessionStateDelegateChromeos::SetSessionState(SessionState new_state) {
292 if (session_state_ == new_state)
293 return;
294
295 session_state_ = new_state;
296 NotifySessionStateChanged();
297 }
298
299 void SessionStateDelegateChromeos::NotifySessionStateChanged() {
300 FOR_EACH_OBSERVER(ash::SessionStateObserver,
301 session_state_observer_list_,
302 SessionStateChanged(session_state_));
303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698