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

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

Issue 375413002: Replace chromeos::UserManager::Get() with chromeos::GetUserManager(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 6 years, 5 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/session_state_observer.h" 8 #include "ash/session/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/lock/screen_locker.h" 12 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
13 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" 13 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
14 #include "chrome/browser/chromeos/login/users/user.h" 14 #include "chrome/browser/chromeos/login/users/user.h"
15 #include "chrome/browser/chromeos/login/users/user_manager.h" 15 #include "chrome/browser/chromeos/login/users/user_manager.h"
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" 16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
19 #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"
20 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "chromeos/chromeos_switches.h" 21 #include "chromeos/chromeos_switches.h"
22 #include "chromeos/dbus/dbus_thread_manager.h" 22 #include "chromeos/dbus/dbus_thread_manager.h"
23 #include "chromeos/dbus/session_manager_client.h" 23 #include "chromeos/dbus/session_manager_client.h"
24 #include "chromeos/login/login_state.h" 24 #include "chromeos/login/login_state.h"
25 #include "google_apis/gaia/gaia_auth_util.h" 25 #include "google_apis/gaia/gaia_auth_util.h"
26 26
27 SessionStateDelegateChromeos::SessionStateDelegateChromeos() 27 SessionStateDelegateChromeos::SessionStateDelegateChromeos()
28 : session_state_(SESSION_STATE_LOGIN_PRIMARY) { 28 : session_state_(SESSION_STATE_LOGIN_PRIMARY) {
29 chromeos::UserManager::Get()->AddSessionStateObserver(this); 29 chromeos::GetUserManager()->AddSessionStateObserver(this);
30 chromeos::UserAddingScreen::Get()->AddObserver(this); 30 chromeos::UserAddingScreen::Get()->AddObserver(this);
31 31
32 // LoginState is not initialized in unit_tests. 32 // LoginState is not initialized in unit_tests.
33 if (chromeos::LoginState::IsInitialized()) { 33 if (chromeos::LoginState::IsInitialized()) {
34 chromeos::LoginState::Get()->AddObserver(this); 34 chromeos::LoginState::Get()->AddObserver(this);
35 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ? 35 SetSessionState(chromeos::LoginState::Get()->IsUserLoggedIn() ?
36 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, true); 36 SESSION_STATE_ACTIVE : SESSION_STATE_LOGIN_PRIMARY, true);
37 } 37 }
38 } 38 }
39 39
40 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { 40 SessionStateDelegateChromeos::~SessionStateDelegateChromeos() {
41 chromeos::UserManager::Get()->RemoveSessionStateObserver(this); 41 chromeos::GetUserManager()->RemoveSessionStateObserver(this);
42 chromeos::UserAddingScreen::Get()->RemoveObserver(this); 42 chromeos::UserAddingScreen::Get()->RemoveObserver(this);
43 43
44 // LoginState is not initialized in unit_tests. 44 // LoginState is not initialized in unit_tests.
45 if (chromeos::LoginState::IsInitialized()) 45 if (chromeos::LoginState::IsInitialized())
46 chromeos::LoginState::Get()->RemoveObserver(this); 46 chromeos::LoginState::Get()->RemoveObserver(this);
47 } 47 }
48 48
49 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex( 49 content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex(
50 ash::MultiProfileIndex index) { 50 ash::MultiProfileIndex index) {
51 DCHECK_LT(index, NumberOfLoggedInUsers()); 51 DCHECK_LT(index, NumberOfLoggedInUsers());
52 chromeos::User* user = 52 chromeos::User* user =
53 chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]; 53 chromeos::GetUserManager()->GetLRULoggedInUsers()[index];
54 DCHECK(user); 54 DCHECK(user);
55 return chromeos::ProfileHelper::Get()->GetProfileByUser(user); 55 return chromeos::ProfileHelper::Get()->GetProfileByUser(user);
56 } 56 }
57 57
58 content::BrowserContext* 58 content::BrowserContext*
59 SessionStateDelegateChromeos::GetBrowserContextForWindow( 59 SessionStateDelegateChromeos::GetBrowserContextForWindow(
60 aura::Window* window) { 60 aura::Window* window) {
61 const std::string& user_id = 61 const std::string& user_id =
62 chrome::MultiUserWindowManager::GetInstance()->GetWindowOwner(window); 62 chrome::MultiUserWindowManager::GetInstance()->GetWindowOwner(window);
63 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(user_id); 63 const chromeos::User* user = chromeos::GetUserManager()->FindUser(user_id);
64 DCHECK(user); 64 DCHECK(user);
65 return chromeos::ProfileHelper::Get()->GetProfileByUser(user); 65 return chromeos::ProfileHelper::Get()->GetProfileByUser(user);
66 } 66 }
67 67
68 int SessionStateDelegateChromeos::GetMaximumNumberOfLoggedInUsers() const { 68 int SessionStateDelegateChromeos::GetMaximumNumberOfLoggedInUsers() const {
69 // We limit list of logged in users to 10 due to memory constraints. 69 // We limit list of logged in users to 10 due to memory constraints.
70 // Note that 10 seems excessive, but we want to test how many users are 70 // Note that 10 seems excessive, but we want to test how many users are
71 // actually added to a session. 71 // actually added to a session.
72 // TODO(nkostylev): Adjust this limitation based on device capabilites. 72 // TODO(nkostylev): Adjust this limitation based on device capabilites.
73 // http://crbug.com/230865 73 // http://crbug.com/230865
74 return 10; 74 return 10;
75 } 75 }
76 76
77 int SessionStateDelegateChromeos::NumberOfLoggedInUsers() const { 77 int SessionStateDelegateChromeos::NumberOfLoggedInUsers() const {
78 return chromeos::UserManager::Get()->GetLoggedInUsers().size(); 78 return chromeos::GetUserManager()->GetLoggedInUsers().size();
79 } 79 }
80 80
81 bool SessionStateDelegateChromeos::IsActiveUserSessionStarted() const { 81 bool SessionStateDelegateChromeos::IsActiveUserSessionStarted() const {
82 return chromeos::UserManager::Get()->IsSessionStarted(); 82 return chromeos::GetUserManager()->IsSessionStarted();
83 } 83 }
84 84
85 bool SessionStateDelegateChromeos::CanLockScreen() const { 85 bool SessionStateDelegateChromeos::CanLockScreen() const {
86 const chromeos::UserList unlock_users = 86 const chromeos::UserList unlock_users =
87 chromeos::UserManager::Get()->GetUnlockUsers(); 87 chromeos::GetUserManager()->GetUnlockUsers();
88 return !unlock_users.empty(); 88 return !unlock_users.empty();
89 } 89 }
90 90
91 bool SessionStateDelegateChromeos::IsScreenLocked() const { 91 bool SessionStateDelegateChromeos::IsScreenLocked() const {
92 return chromeos::ScreenLocker::default_screen_locker() && 92 return chromeos::ScreenLocker::default_screen_locker() &&
93 chromeos::ScreenLocker::default_screen_locker()->locked(); 93 chromeos::ScreenLocker::default_screen_locker()->locked();
94 } 94 }
95 95
96 bool SessionStateDelegateChromeos::ShouldLockScreenBeforeSuspending() const { 96 bool SessionStateDelegateChromeos::ShouldLockScreenBeforeSuspending() const {
97 const chromeos::UserList logged_in_users = 97 const chromeos::UserList logged_in_users =
98 chromeos::UserManager::Get()->GetLoggedInUsers(); 98 chromeos::GetUserManager()->GetLoggedInUsers();
99 for (chromeos::UserList::const_iterator it = logged_in_users.begin(); 99 for (chromeos::UserList::const_iterator it = logged_in_users.begin();
100 it != logged_in_users.end(); ++it) { 100 it != logged_in_users.end(); ++it) {
101 chromeos::User* user = (*it); 101 chromeos::User* user = (*it);
102 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user); 102 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user);
103 if (profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock)) 103 if (profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock))
104 return true; 104 return true;
105 } 105 }
106 return false; 106 return false;
107 } 107 }
108 108
(...skipping 20 matching lines...) Expand all
129 } 129 }
130 130
131 ash::SessionStateDelegate::SessionState 131 ash::SessionStateDelegate::SessionState
132 SessionStateDelegateChromeos::GetSessionState() const { 132 SessionStateDelegateChromeos::GetSessionState() const {
133 return session_state_; 133 return session_state_;
134 } 134 }
135 135
136 const ash::UserInfo* SessionStateDelegateChromeos::GetUserInfo( 136 const ash::UserInfo* SessionStateDelegateChromeos::GetUserInfo(
137 ash::MultiProfileIndex index) const { 137 ash::MultiProfileIndex index) const {
138 DCHECK_LT(index, NumberOfLoggedInUsers()); 138 DCHECK_LT(index, NumberOfLoggedInUsers());
139 return chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]; 139 return chromeos::GetUserManager()->GetLRULoggedInUsers()[index];
140 } 140 }
141 141
142 const ash::UserInfo* SessionStateDelegateChromeos::GetUserInfo( 142 const ash::UserInfo* SessionStateDelegateChromeos::GetUserInfo(
143 content::BrowserContext* context) const { 143 content::BrowserContext* context) const {
144 DCHECK(context); 144 DCHECK(context);
145 return chromeos::ProfileHelper::Get()->GetUserByProfile( 145 return chromeos::ProfileHelper::Get()->GetUserByProfile(
146 Profile::FromBrowserContext(context)); 146 Profile::FromBrowserContext(context));
147 } 147 }
148 148
149 bool SessionStateDelegateChromeos::ShouldShowAvatar( 149 bool SessionStateDelegateChromeos::ShouldShowAvatar(
150 aura::Window* window) const { 150 aura::Window* window) const {
151 return chrome::MultiUserWindowManager::GetInstance()-> 151 return chrome::MultiUserWindowManager::GetInstance()->
152 ShouldShowAvatar(window); 152 ShouldShowAvatar(window);
153 } 153 }
154 154
155 void SessionStateDelegateChromeos::SwitchActiveUser( 155 void SessionStateDelegateChromeos::SwitchActiveUser(
156 const std::string& user_id) { 156 const std::string& user_id) {
157 // Disallow switching to an already active user since that might crash. 157 // Disallow switching to an already active user since that might crash.
158 // Also check that we got a user id and not an email address. 158 // Also check that we got a user id and not an email address.
159 DCHECK_EQ(user_id, 159 DCHECK_EQ(user_id,
160 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id))); 160 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id)));
161 if (user_id == chromeos::UserManager::Get()->GetActiveUser()->email()) 161 if (user_id == chromeos::GetUserManager()->GetActiveUser()->email())
162 return; 162 return;
163 chromeos::UserManager::Get()->SwitchActiveUser(user_id); 163 chromeos::GetUserManager()->SwitchActiveUser(user_id);
164 } 164 }
165 165
166 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) { 166 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) {
167 // Make sure there is a user to switch to. 167 // Make sure there is a user to switch to.
168 if (NumberOfLoggedInUsers() <= 1) 168 if (NumberOfLoggedInUsers() <= 1)
169 return; 169 return;
170 170
171 const chromeos::UserList& logged_in_users = 171 const chromeos::UserList& logged_in_users =
172 chromeos::UserManager::Get()->GetLoggedInUsers(); 172 chromeos::GetUserManager()->GetLoggedInUsers();
173 173
174 std::string user_id = chromeos::UserManager::Get()->GetActiveUser()->email(); 174 std::string user_id = chromeos::GetUserManager()->GetActiveUser()->email();
175 175
176 // Get an iterator positioned at the active user. 176 // Get an iterator positioned at the active user.
177 chromeos::UserList::const_iterator it; 177 chromeos::UserList::const_iterator it;
178 for (it = logged_in_users.begin(); 178 for (it = logged_in_users.begin();
179 it != logged_in_users.end(); ++it) { 179 it != logged_in_users.end(); ++it) {
180 if ((*it)->email() == user_id) 180 if ((*it)->email() == user_id)
181 break; 181 break;
182 } 182 }
183 183
184 // Active user not found. 184 // Active user not found.
(...skipping 10 matching lines...) Expand all
195 user_id = (*it)->email(); 195 user_id = (*it)->email();
196 break; 196 break;
197 case CYCLE_TO_PREVIOUS_USER: 197 case CYCLE_TO_PREVIOUS_USER:
198 if (it == logged_in_users.begin()) 198 if (it == logged_in_users.begin())
199 it = logged_in_users.end(); 199 it = logged_in_users.end();
200 user_id = (*(--it))->email(); 200 user_id = (*(--it))->email();
201 break; 201 break;
202 } 202 }
203 203
204 // Switch using the transformed |user_id|. 204 // Switch using the transformed |user_id|.
205 chromeos::UserManager::Get()->SwitchActiveUser(user_id); 205 chromeos::GetUserManager()->SwitchActiveUser(user_id);
206 } 206 }
207 207
208 void SessionStateDelegateChromeos::AddSessionStateObserver( 208 void SessionStateDelegateChromeos::AddSessionStateObserver(
209 ash::SessionStateObserver* observer) { 209 ash::SessionStateObserver* observer) {
210 session_state_observer_list_.AddObserver(observer); 210 session_state_observer_list_.AddObserver(observer);
211 } 211 }
212 212
213 void SessionStateDelegateChromeos::RemoveSessionStateObserver( 213 void SessionStateDelegateChromeos::RemoveSessionStateObserver(
214 ash::SessionStateObserver* observer) { 214 ash::SessionStateObserver* observer) {
215 session_state_observer_list_.RemoveObserver(observer); 215 session_state_observer_list_.RemoveObserver(observer);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 249
250 session_state_ = new_state; 250 session_state_ = new_state;
251 NotifySessionStateChanged(); 251 NotifySessionStateChanged();
252 } 252 }
253 253
254 void SessionStateDelegateChromeos::NotifySessionStateChanged() { 254 void SessionStateDelegateChromeos::NotifySessionStateChanged() {
255 FOR_EACH_OBSERVER(ash::SessionStateObserver, 255 FOR_EACH_OBSERVER(ash::SessionStateObserver,
256 session_state_observer_list_, 256 session_state_observer_list_,
257 SessionStateChanged(session_state_)); 257 SessionStateChanged(session_state_));
258 } 258 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/multi_user/multi_user_util.cc ('k') | chrome/browser/ui/ash/session_state_delegate_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698