OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/login/users/user_manager_base.h" | 5 #include "components/user_manager/user_manager_base.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/format_macros.h" | 14 #include "base/format_macros.h" |
| 15 #include "base/location.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" |
16 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
17 #include "base/prefs/pref_registry_simple.h" | 19 #include "base/prefs/pref_registry_simple.h" |
18 #include "base/prefs/pref_service.h" | 20 #include "base/prefs/pref_service.h" |
19 #include "base/prefs/scoped_user_pref_update.h" | 21 #include "base/prefs/scoped_user_pref_update.h" |
20 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
21 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
22 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 25 #include "base/task_runner.h" |
23 #include "base/values.h" | 26 #include "base/values.h" |
24 #include "chrome/browser/chromeos/login/users/remove_user_delegate.h" | |
25 #include "chromeos/chromeos_switches.h" | 27 #include "chromeos/chromeos_switches.h" |
26 #include "chromeos/cryptohome/async_method_caller.h" | 28 #include "chromeos/cryptohome/async_method_caller.h" |
27 #include "chromeos/login/login_state.h" | 29 #include "chromeos/login/login_state.h" |
28 #include "chromeos/login/user_names.h" | 30 #include "chromeos/login/user_names.h" |
29 #include "components/session_manager/core/session_manager.h" | 31 #include "components/session_manager/core/session_manager.h" |
| 32 #include "components/user_manager/remove_user_delegate.h" |
30 #include "components/user_manager/user_type.h" | 33 #include "components/user_manager/user_type.h" |
31 #include "content/public/browser/browser_thread.h" | |
32 #include "google_apis/gaia/gaia_auth_util.h" | 34 #include "google_apis/gaia/gaia_auth_util.h" |
33 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
34 | 36 |
35 using content::BrowserThread; | 37 namespace user_manager { |
36 | |
37 namespace chromeos { | |
38 namespace { | 38 namespace { |
39 | 39 |
40 // A vector pref of the the regular users known on this device, arranged in LRU | 40 // A vector pref of the the regular users known on this device, arranged in LRU |
41 // order. | 41 // order. |
42 const char kRegularUsers[] = "LoggedInUsers"; | 42 const char kRegularUsers[] = "LoggedInUsers"; |
43 | 43 |
44 // A dictionary that maps user IDs to the displayed name. | 44 // A dictionary that maps user IDs to the displayed name. |
45 const char kUserDisplayName[] = "UserDisplayName"; | 45 const char kUserDisplayName[] = "UserDisplayName"; |
46 | 46 |
47 // A dictionary that maps user IDs to the user's given name. | 47 // A dictionary that maps user IDs to the user's given name. |
(...skipping 22 matching lines...) Expand all Loading... |
70 void OnRemoveUserComplete(const std::string& user_email, | 70 void OnRemoveUserComplete(const std::string& user_email, |
71 bool success, | 71 bool success, |
72 cryptohome::MountError return_code) { | 72 cryptohome::MountError return_code) { |
73 // Log the error, but there's not much we can do. | 73 // Log the error, but there's not much we can do. |
74 if (!success) { | 74 if (!success) { |
75 LOG(ERROR) << "Removal of cryptohome for " << user_email | 75 LOG(ERROR) << "Removal of cryptohome for " << user_email |
76 << " failed, return code: " << return_code; | 76 << " failed, return code: " << return_code; |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 // Runs on SequencedWorkerPool thread. Passes resolved locale to | |
81 // |on_resolve_callback| on UI thread. | |
82 void ResolveLocale( | |
83 const std::string& raw_locale, | |
84 base::Callback<void(const std::string&)> on_resolve_callback) { | |
85 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
86 std::string resolved_locale; | |
87 // Ignore result | |
88 l10n_util::CheckAndResolveLocale(raw_locale, &resolved_locale); | |
89 BrowserThread::PostTask(BrowserThread::UI, | |
90 FROM_HERE, | |
91 base::Bind(on_resolve_callback, resolved_locale)); | |
92 } | |
93 | |
94 } // namespace | 80 } // namespace |
95 | 81 |
96 // static | 82 // static |
97 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { | 83 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { |
98 registry->RegisterListPref(kRegularUsers); | 84 registry->RegisterListPref(kRegularUsers); |
99 registry->RegisterStringPref(kLastLoggedInRegularUser, std::string()); | 85 registry->RegisterStringPref(kLastLoggedInRegularUser, std::string()); |
100 registry->RegisterDictionaryPref(kUserDisplayName); | 86 registry->RegisterDictionaryPref(kUserDisplayName); |
101 registry->RegisterDictionaryPref(kUserGivenName); | 87 registry->RegisterDictionaryPref(kUserGivenName); |
102 registry->RegisterDictionaryPref(kUserDisplayEmail); | 88 registry->RegisterDictionaryPref(kUserDisplayEmail); |
103 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); | 89 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); |
104 registry->RegisterDictionaryPref(kUserForceOnlineSignin); | 90 registry->RegisterDictionaryPref(kUserForceOnlineSignin); |
105 } | 91 } |
106 | 92 |
107 UserManagerBase::UserManagerBase() | 93 UserManagerBase::UserManagerBase( |
| 94 scoped_refptr<base::TaskRunner> task_runner, |
| 95 scoped_refptr<base::TaskRunner> blocking_task_runner) |
108 : active_user_(NULL), | 96 : active_user_(NULL), |
109 primary_user_(NULL), | 97 primary_user_(NULL), |
110 user_loading_stage_(STAGE_NOT_LOADED), | 98 user_loading_stage_(STAGE_NOT_LOADED), |
111 session_started_(false), | 99 session_started_(false), |
112 is_current_user_owner_(false), | 100 is_current_user_owner_(false), |
113 is_current_user_new_(false), | 101 is_current_user_new_(false), |
114 is_current_user_ephemeral_regular_user_(false), | 102 is_current_user_ephemeral_regular_user_(false), |
115 ephemeral_users_enabled_(false), | 103 ephemeral_users_enabled_(false), |
116 manager_creation_time_(base::TimeTicks::Now()), | 104 manager_creation_time_(base::TimeTicks::Now()), |
| 105 task_runner_(task_runner), |
| 106 blocking_task_runner_(blocking_task_runner), |
117 weak_factory_(this) { | 107 weak_factory_(this) { |
118 // UserManager instance should be used only on UI thread. | |
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
120 UpdateLoginState(); | 108 UpdateLoginState(); |
121 } | 109 } |
122 | 110 |
123 UserManagerBase::~UserManagerBase() { | 111 UserManagerBase::~UserManagerBase() { |
124 // Can't use STLDeleteElements because of the private destructor of User. | 112 // Can't use STLDeleteElements because of the private destructor of User. |
125 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); | 113 for (UserList::iterator it = users_.begin(); it != users_.end(); |
126 it = users_.erase(it)) { | 114 it = users_.erase(it)) { |
127 DeleteUser(*it); | 115 DeleteUser(*it); |
128 } | 116 } |
129 // These are pointers to the same User instances that were in users_ list. | 117 // These are pointers to the same User instances that were in users_ list. |
130 logged_in_users_.clear(); | 118 logged_in_users_.clear(); |
131 lru_logged_in_users_.clear(); | 119 lru_logged_in_users_.clear(); |
132 | 120 |
133 DeleteUser(active_user_); | 121 DeleteUser(active_user_); |
134 } | 122 } |
135 | 123 |
136 void UserManagerBase::Shutdown() { | 124 void UserManagerBase::Shutdown() { |
137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 125 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
138 } | 126 } |
139 | 127 |
140 const user_manager::UserList& UserManagerBase::GetUsers() const { | 128 const UserList& UserManagerBase::GetUsers() const { |
141 const_cast<UserManagerBase*>(this)->EnsureUsersLoaded(); | 129 const_cast<UserManagerBase*>(this)->EnsureUsersLoaded(); |
142 return users_; | 130 return users_; |
143 } | 131 } |
144 | 132 |
145 const user_manager::UserList& UserManagerBase::GetLoggedInUsers() const { | 133 const UserList& UserManagerBase::GetLoggedInUsers() const { |
146 return logged_in_users_; | 134 return logged_in_users_; |
147 } | 135 } |
148 | 136 |
149 const user_manager::UserList& UserManagerBase::GetLRULoggedInUsers() const { | 137 const UserList& UserManagerBase::GetLRULoggedInUsers() const { |
150 return lru_logged_in_users_; | 138 return lru_logged_in_users_; |
151 } | 139 } |
152 | 140 |
153 const std::string& UserManagerBase::GetOwnerEmail() const { | 141 const std::string& UserManagerBase::GetOwnerEmail() const { |
154 return owner_email_; | 142 return owner_email_; |
155 } | 143 } |
156 | 144 |
157 void UserManagerBase::UserLoggedIn(const std::string& user_id, | 145 void UserManagerBase::UserLoggedIn(const std::string& user_id, |
158 const std::string& username_hash, | 146 const std::string& username_hash, |
159 bool browser_restart) { | 147 bool browser_restart) { |
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 148 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
161 | 149 |
162 user_manager::User* user = FindUserInListAndModify(user_id); | 150 User* user = FindUserInListAndModify(user_id); |
163 if (active_user_ && user) { | 151 if (active_user_ && user) { |
164 user->set_is_logged_in(true); | 152 user->set_is_logged_in(true); |
165 user->set_username_hash(username_hash); | 153 user->set_username_hash(username_hash); |
166 logged_in_users_.push_back(user); | 154 logged_in_users_.push_back(user); |
167 lru_logged_in_users_.push_back(user); | 155 lru_logged_in_users_.push_back(user); |
168 | 156 |
169 // Reset the new user flag if the user already exists. | 157 // Reset the new user flag if the user already exists. |
170 SetIsCurrentUserNew(false); | 158 SetIsCurrentUserNew(false); |
171 NotifyUserAddedToSession(user, true /* user switch pending */); | 159 NotifyUserAddedToSession(user, true /* user switch pending */); |
172 | 160 |
173 return; | 161 return; |
174 } | 162 } |
175 | 163 |
176 if (user_id == chromeos::login::kGuestUserName) { | 164 if (user_id == chromeos::login::kGuestUserName) { |
177 GuestUserLoggedIn(); | 165 GuestUserLoggedIn(); |
178 } else if (user_id == chromeos::login::kRetailModeUserName) { | 166 } else if (user_id == chromeos::login::kRetailModeUserName) { |
179 RetailModeUserLoggedIn(); | 167 RetailModeUserLoggedIn(); |
180 } else if (IsKioskApp(user_id)) { | 168 } else if (IsKioskApp(user_id)) { |
181 KioskAppLoggedIn(user_id); | 169 KioskAppLoggedIn(user_id); |
182 } else if (IsDemoApp(user_id)) { | 170 } else if (IsDemoApp(user_id)) { |
183 DemoAccountLoggedIn(); | 171 DemoAccountLoggedIn(); |
184 } else { | 172 } else { |
185 EnsureUsersLoaded(); | 173 EnsureUsersLoaded(); |
186 | 174 |
187 if (user && user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { | 175 if (user && user->GetType() == USER_TYPE_PUBLIC_ACCOUNT) { |
188 PublicAccountUserLoggedIn(user); | 176 PublicAccountUserLoggedIn(user); |
189 } else if ((user && | 177 } else if ((user && user->GetType() == USER_TYPE_SUPERVISED) || |
190 user->GetType() == user_manager::USER_TYPE_SUPERVISED) || | |
191 (!user && | 178 (!user && |
192 gaia::ExtractDomainName(user_id) == | 179 gaia::ExtractDomainName(user_id) == |
193 chromeos::login::kSupervisedUserDomain)) { | 180 chromeos::login::kSupervisedUserDomain)) { |
194 SupervisedUserLoggedIn(user_id); | 181 SupervisedUserLoggedIn(user_id); |
195 } else if (browser_restart && IsPublicAccountMarkedForRemoval(user_id)) { | 182 } else if (browser_restart && IsPublicAccountMarkedForRemoval(user_id)) { |
196 PublicAccountUserLoggedIn( | 183 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(user_id)); |
197 user_manager::User::CreatePublicAccountUser(user_id)); | |
198 } else if (user_id != GetOwnerEmail() && !user && | 184 } else if (user_id != GetOwnerEmail() && !user && |
199 (AreEphemeralUsersEnabled() || browser_restart)) { | 185 (AreEphemeralUsersEnabled() || browser_restart)) { |
200 RegularUserLoggedInAsEphemeral(user_id); | 186 RegularUserLoggedInAsEphemeral(user_id); |
201 } else { | 187 } else { |
202 RegularUserLoggedIn(user_id); | 188 RegularUserLoggedIn(user_id); |
203 } | 189 } |
204 } | 190 } |
205 | 191 |
206 DCHECK(active_user_); | 192 DCHECK(active_user_); |
207 active_user_->set_is_logged_in(true); | 193 active_user_->set_is_logged_in(true); |
208 active_user_->set_is_active(true); | 194 active_user_->set_is_active(true); |
209 active_user_->set_username_hash(username_hash); | 195 active_user_->set_username_hash(username_hash); |
210 | 196 |
211 // Place user who just signed in to the top of the logged in users. | 197 // Place user who just signed in to the top of the logged in users. |
212 logged_in_users_.insert(logged_in_users_.begin(), active_user_); | 198 logged_in_users_.insert(logged_in_users_.begin(), active_user_); |
213 SetLRUUser(active_user_); | 199 SetLRUUser(active_user_); |
214 | 200 |
215 if (!primary_user_) { | 201 if (!primary_user_) { |
216 primary_user_ = active_user_; | 202 primary_user_ = active_user_; |
217 if (primary_user_->GetType() == user_manager::USER_TYPE_REGULAR) | 203 if (primary_user_->GetType() == USER_TYPE_REGULAR) |
218 SendRegularUserLoginMetrics(user_id); | 204 SendRegularUserLoginMetrics(user_id); |
219 } | 205 } |
220 | 206 |
221 UMA_HISTOGRAM_ENUMERATION("UserManager.LoginUserType", | 207 UMA_HISTOGRAM_ENUMERATION( |
222 active_user_->GetType(), | 208 "UserManager.LoginUserType", active_user_->GetType(), NUM_USER_TYPES); |
223 user_manager::NUM_USER_TYPES); | |
224 | 209 |
225 GetLocalState()->SetString( | 210 GetLocalState()->SetString( |
226 kLastLoggedInRegularUser, | 211 kLastLoggedInRegularUser, |
227 (active_user_->GetType() == user_manager::USER_TYPE_REGULAR) ? user_id | 212 (active_user_->GetType() == USER_TYPE_REGULAR) ? user_id : ""); |
228 : ""); | |
229 | 213 |
230 NotifyOnLogin(); | 214 NotifyOnLogin(); |
231 PerformPostUserLoggedInActions(browser_restart); | 215 PerformPostUserLoggedInActions(browser_restart); |
232 } | 216 } |
233 | 217 |
234 void UserManagerBase::SwitchActiveUser(const std::string& user_id) { | 218 void UserManagerBase::SwitchActiveUser(const std::string& user_id) { |
235 user_manager::User* user = FindUserAndModify(user_id); | 219 User* user = FindUserAndModify(user_id); |
236 if (!user) { | 220 if (!user) { |
237 NOTREACHED() << "Switching to a non-existing user"; | 221 NOTREACHED() << "Switching to a non-existing user"; |
238 return; | 222 return; |
239 } | 223 } |
240 if (user == active_user_) { | 224 if (user == active_user_) { |
241 NOTREACHED() << "Switching to a user who is already active"; | 225 NOTREACHED() << "Switching to a user who is already active"; |
242 return; | 226 return; |
243 } | 227 } |
244 if (!user->is_logged_in()) { | 228 if (!user->is_logged_in()) { |
245 NOTREACHED() << "Switching to a user that is not logged in"; | 229 NOTREACHED() << "Switching to a user that is not logged in"; |
246 return; | 230 return; |
247 } | 231 } |
248 if (user->GetType() != user_manager::USER_TYPE_REGULAR) { | 232 if (user->GetType() != USER_TYPE_REGULAR) { |
249 NOTREACHED() << "Switching to a non-regular user"; | 233 NOTREACHED() << "Switching to a non-regular user"; |
250 return; | 234 return; |
251 } | 235 } |
252 if (user->username_hash().empty()) { | 236 if (user->username_hash().empty()) { |
253 NOTREACHED() << "Switching to a user that doesn't have username_hash set"; | 237 NOTREACHED() << "Switching to a user that doesn't have username_hash set"; |
254 return; | 238 return; |
255 } | 239 } |
256 | 240 |
257 DCHECK(active_user_); | 241 DCHECK(active_user_); |
258 active_user_->set_is_active(false); | 242 active_user_->set_is_active(false); |
259 user->set_is_active(true); | 243 user->set_is_active(true); |
260 active_user_ = user; | 244 active_user_ = user; |
261 | 245 |
262 // Move the user to the front. | 246 // Move the user to the front. |
263 SetLRUUser(active_user_); | 247 SetLRUUser(active_user_); |
264 | 248 |
265 NotifyActiveUserHashChanged(active_user_->username_hash()); | 249 NotifyActiveUserHashChanged(active_user_->username_hash()); |
266 NotifyActiveUserChanged(active_user_); | 250 NotifyActiveUserChanged(active_user_); |
267 } | 251 } |
268 | 252 |
269 void UserManagerBase::SessionStarted() { | 253 void UserManagerBase::SessionStarted() { |
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 254 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
271 session_started_ = true; | 255 session_started_ = true; |
272 | 256 |
273 UpdateLoginState(); | 257 UpdateLoginState(); |
274 session_manager::SessionManager::Get()->SetSessionState( | 258 session_manager::SessionManager::Get()->SetSessionState( |
275 session_manager::SESSION_STATE_ACTIVE); | 259 session_manager::SESSION_STATE_ACTIVE); |
276 | 260 |
277 if (IsCurrentUserNew()) { | 261 if (IsCurrentUserNew()) { |
278 // Make sure that the new user's data is persisted to Local State. | 262 // Make sure that the new user's data is persisted to Local State. |
279 GetLocalState()->CommitPendingWrite(); | 263 GetLocalState()->CommitPendingWrite(); |
280 } | 264 } |
281 } | 265 } |
282 | 266 |
283 void UserManagerBase::RemoveUser(const std::string& user_id, | 267 void UserManagerBase::RemoveUser(const std::string& user_id, |
284 RemoveUserDelegate* delegate) { | 268 RemoveUserDelegate* delegate) { |
285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 269 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
286 | 270 |
287 if (!CanUserBeRemoved(FindUser(user_id))) | 271 if (!CanUserBeRemoved(FindUser(user_id))) |
288 return; | 272 return; |
289 | 273 |
290 RemoveUserInternal(user_id, delegate); | 274 RemoveUserInternal(user_id, delegate); |
291 } | 275 } |
292 | 276 |
293 void UserManagerBase::RemoveUserInternal(const std::string& user_email, | 277 void UserManagerBase::RemoveUserInternal(const std::string& user_email, |
294 RemoveUserDelegate* delegate) { | 278 RemoveUserDelegate* delegate) { |
295 RemoveNonOwnerUserInternal(user_email, delegate); | 279 RemoveNonOwnerUserInternal(user_email, delegate); |
296 } | 280 } |
297 | 281 |
298 void UserManagerBase::RemoveNonOwnerUserInternal(const std::string& user_email, | 282 void UserManagerBase::RemoveNonOwnerUserInternal(const std::string& user_email, |
299 RemoveUserDelegate* delegate) { | 283 RemoveUserDelegate* delegate) { |
300 if (delegate) | 284 if (delegate) |
301 delegate->OnBeforeUserRemoved(user_email); | 285 delegate->OnBeforeUserRemoved(user_email); |
302 RemoveUserFromList(user_email); | 286 RemoveUserFromList(user_email); |
303 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( | 287 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
304 user_email, base::Bind(&OnRemoveUserComplete, user_email)); | 288 user_email, base::Bind(&OnRemoveUserComplete, user_email)); |
305 | 289 |
306 if (delegate) | 290 if (delegate) |
307 delegate->OnUserRemoved(user_email); | 291 delegate->OnUserRemoved(user_email); |
308 } | 292 } |
309 | 293 |
310 void UserManagerBase::RemoveUserFromList(const std::string& user_id) { | 294 void UserManagerBase::RemoveUserFromList(const std::string& user_id) { |
311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 295 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
312 RemoveNonCryptohomeData(user_id); | 296 RemoveNonCryptohomeData(user_id); |
313 if (user_loading_stage_ == STAGE_LOADED) { | 297 if (user_loading_stage_ == STAGE_LOADED) { |
314 DeleteUser(RemoveRegularOrSupervisedUserFromList(user_id)); | 298 DeleteUser(RemoveRegularOrSupervisedUserFromList(user_id)); |
315 } else if (user_loading_stage_ == STAGE_LOADING) { | 299 } else if (user_loading_stage_ == STAGE_LOADING) { |
316 DCHECK(gaia::ExtractDomainName(user_id) == | 300 DCHECK(gaia::ExtractDomainName(user_id) == |
317 chromeos::login::kSupervisedUserDomain); | 301 chromeos::login::kSupervisedUserDomain); |
318 // Special case, removing partially-constructed supervised user during user | 302 // Special case, removing partially-constructed supervised user during user |
319 // list loading. | 303 // list loading. |
320 ListPrefUpdate users_update(GetLocalState(), kRegularUsers); | 304 ListPrefUpdate users_update(GetLocalState(), kRegularUsers); |
321 users_update->Remove(base::StringValue(user_id), NULL); | 305 users_update->Remove(base::StringValue(user_id), NULL); |
322 } else { | 306 } else { |
323 NOTREACHED() << "Users are not loaded yet."; | 307 NOTREACHED() << "Users are not loaded yet."; |
324 return; | 308 return; |
325 } | 309 } |
326 | 310 |
327 // Make sure that new data is persisted to Local State. | 311 // Make sure that new data is persisted to Local State. |
328 GetLocalState()->CommitPendingWrite(); | 312 GetLocalState()->CommitPendingWrite(); |
329 } | 313 } |
330 | 314 |
331 bool UserManagerBase::IsKnownUser(const std::string& user_id) const { | 315 bool UserManagerBase::IsKnownUser(const std::string& user_id) const { |
332 return FindUser(user_id) != NULL; | 316 return FindUser(user_id) != NULL; |
333 } | 317 } |
334 | 318 |
335 const user_manager::User* UserManagerBase::FindUser( | 319 const User* UserManagerBase::FindUser(const std::string& user_id) const { |
336 const std::string& user_id) const { | 320 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
338 if (active_user_ && active_user_->email() == user_id) | 321 if (active_user_ && active_user_->email() == user_id) |
339 return active_user_; | 322 return active_user_; |
340 return FindUserInList(user_id); | 323 return FindUserInList(user_id); |
341 } | 324 } |
342 | 325 |
343 user_manager::User* UserManagerBase::FindUserAndModify( | 326 User* UserManagerBase::FindUserAndModify(const std::string& user_id) { |
344 const std::string& user_id) { | 327 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
346 if (active_user_ && active_user_->email() == user_id) | 328 if (active_user_ && active_user_->email() == user_id) |
347 return active_user_; | 329 return active_user_; |
348 return FindUserInListAndModify(user_id); | 330 return FindUserInListAndModify(user_id); |
349 } | 331 } |
350 | 332 |
351 const user_manager::User* UserManagerBase::GetLoggedInUser() const { | 333 const User* UserManagerBase::GetLoggedInUser() const { |
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 334 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
353 return active_user_; | 335 return active_user_; |
354 } | 336 } |
355 | 337 |
356 user_manager::User* UserManagerBase::GetLoggedInUser() { | 338 User* UserManagerBase::GetLoggedInUser() { |
357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 339 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
358 return active_user_; | 340 return active_user_; |
359 } | 341 } |
360 | 342 |
361 const user_manager::User* UserManagerBase::GetActiveUser() const { | 343 const User* UserManagerBase::GetActiveUser() const { |
362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 344 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
363 return active_user_; | 345 return active_user_; |
364 } | 346 } |
365 | 347 |
366 user_manager::User* UserManagerBase::GetActiveUser() { | 348 User* UserManagerBase::GetActiveUser() { |
367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 349 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
368 return active_user_; | 350 return active_user_; |
369 } | 351 } |
370 | 352 |
371 const user_manager::User* UserManagerBase::GetPrimaryUser() const { | 353 const User* UserManagerBase::GetPrimaryUser() const { |
372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 354 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
373 return primary_user_; | 355 return primary_user_; |
374 } | 356 } |
375 | 357 |
376 void UserManagerBase::SaveUserOAuthStatus( | 358 void UserManagerBase::SaveUserOAuthStatus( |
377 const std::string& user_id, | 359 const std::string& user_id, |
378 user_manager::User::OAuthTokenStatus oauth_token_status) { | 360 User::OAuthTokenStatus oauth_token_status) { |
379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 361 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
380 | 362 |
381 DVLOG(1) << "Saving user OAuth token status in Local State"; | 363 DVLOG(1) << "Saving user OAuth token status in Local State"; |
382 user_manager::User* user = FindUserAndModify(user_id); | 364 User* user = FindUserAndModify(user_id); |
383 if (user) | 365 if (user) |
384 user->set_oauth_token_status(oauth_token_status); | 366 user->set_oauth_token_status(oauth_token_status); |
385 | 367 |
386 // Do not update local state if data stored or cached outside the user's | 368 // Do not update local state if data stored or cached outside the user's |
387 // cryptohome is to be treated as ephemeral. | 369 // cryptohome is to be treated as ephemeral. |
388 if (IsUserNonCryptohomeDataEphemeral(user_id)) | 370 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
389 return; | 371 return; |
390 | 372 |
391 DictionaryPrefUpdate oauth_status_update(GetLocalState(), | 373 DictionaryPrefUpdate oauth_status_update(GetLocalState(), |
392 kUserOAuthTokenStatus); | 374 kUserOAuthTokenStatus); |
393 oauth_status_update->SetWithoutPathExpansion( | 375 oauth_status_update->SetWithoutPathExpansion( |
394 user_id, | 376 user_id, |
395 new base::FundamentalValue(static_cast<int>(oauth_token_status))); | 377 new base::FundamentalValue(static_cast<int>(oauth_token_status))); |
396 } | 378 } |
397 | 379 |
398 void UserManagerBase::SaveForceOnlineSignin(const std::string& user_id, | 380 void UserManagerBase::SaveForceOnlineSignin(const std::string& user_id, |
399 bool force_online_signin) { | 381 bool force_online_signin) { |
400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 382 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
401 | 383 |
402 // Do not update local state if data stored or cached outside the user's | 384 // Do not update local state if data stored or cached outside the user's |
403 // cryptohome is to be treated as ephemeral. | 385 // cryptohome is to be treated as ephemeral. |
404 if (IsUserNonCryptohomeDataEphemeral(user_id)) | 386 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
405 return; | 387 return; |
406 | 388 |
407 DictionaryPrefUpdate force_online_update(GetLocalState(), | 389 DictionaryPrefUpdate force_online_update(GetLocalState(), |
408 kUserForceOnlineSignin); | 390 kUserForceOnlineSignin); |
409 force_online_update->SetBooleanWithoutPathExpansion(user_id, | 391 force_online_update->SetBooleanWithoutPathExpansion(user_id, |
410 force_online_signin); | 392 force_online_signin); |
411 } | 393 } |
412 | 394 |
413 void UserManagerBase::SaveUserDisplayName(const std::string& user_id, | 395 void UserManagerBase::SaveUserDisplayName(const std::string& user_id, |
414 const base::string16& display_name) { | 396 const base::string16& display_name) { |
415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 397 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
416 | 398 |
417 if (user_manager::User* user = FindUserAndModify(user_id)) { | 399 if (User* user = FindUserAndModify(user_id)) { |
418 user->set_display_name(display_name); | 400 user->set_display_name(display_name); |
419 | 401 |
420 // Do not update local state if data stored or cached outside the user's | 402 // Do not update local state if data stored or cached outside the user's |
421 // cryptohome is to be treated as ephemeral. | 403 // cryptohome is to be treated as ephemeral. |
422 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { | 404 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { |
423 DictionaryPrefUpdate display_name_update(GetLocalState(), | 405 DictionaryPrefUpdate display_name_update(GetLocalState(), |
424 kUserDisplayName); | 406 kUserDisplayName); |
425 display_name_update->SetWithoutPathExpansion( | 407 display_name_update->SetWithoutPathExpansion( |
426 user_id, new base::StringValue(display_name)); | 408 user_id, new base::StringValue(display_name)); |
427 } | 409 } |
428 } | 410 } |
429 } | 411 } |
430 | 412 |
431 base::string16 UserManagerBase::GetUserDisplayName( | 413 base::string16 UserManagerBase::GetUserDisplayName( |
432 const std::string& user_id) const { | 414 const std::string& user_id) const { |
433 const user_manager::User* user = FindUser(user_id); | 415 const User* user = FindUser(user_id); |
434 return user ? user->display_name() : base::string16(); | 416 return user ? user->display_name() : base::string16(); |
435 } | 417 } |
436 | 418 |
437 void UserManagerBase::SaveUserDisplayEmail(const std::string& user_id, | 419 void UserManagerBase::SaveUserDisplayEmail(const std::string& user_id, |
438 const std::string& display_email) { | 420 const std::string& display_email) { |
439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 421 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
440 | 422 |
441 user_manager::User* user = FindUserAndModify(user_id); | 423 User* user = FindUserAndModify(user_id); |
442 if (!user) | 424 if (!user) |
443 return; // Ignore if there is no such user. | 425 return; // Ignore if there is no such user. |
444 | 426 |
445 user->set_display_email(display_email); | 427 user->set_display_email(display_email); |
446 | 428 |
447 // Do not update local state if data stored or cached outside the user's | 429 // Do not update local state if data stored or cached outside the user's |
448 // cryptohome is to be treated as ephemeral. | 430 // cryptohome is to be treated as ephemeral. |
449 if (IsUserNonCryptohomeDataEphemeral(user_id)) | 431 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
450 return; | 432 return; |
451 | 433 |
452 DictionaryPrefUpdate display_email_update(GetLocalState(), kUserDisplayEmail); | 434 DictionaryPrefUpdate display_email_update(GetLocalState(), kUserDisplayEmail); |
453 display_email_update->SetWithoutPathExpansion( | 435 display_email_update->SetWithoutPathExpansion( |
454 user_id, new base::StringValue(display_email)); | 436 user_id, new base::StringValue(display_email)); |
455 } | 437 } |
456 | 438 |
457 std::string UserManagerBase::GetUserDisplayEmail( | 439 std::string UserManagerBase::GetUserDisplayEmail( |
458 const std::string& user_id) const { | 440 const std::string& user_id) const { |
459 const user_manager::User* user = FindUser(user_id); | 441 const User* user = FindUser(user_id); |
460 return user ? user->display_email() : user_id; | 442 return user ? user->display_email() : user_id; |
461 } | 443 } |
462 | 444 |
463 void UserManagerBase::UpdateUserAccountData( | 445 void UserManagerBase::UpdateUserAccountData( |
464 const std::string& user_id, | 446 const std::string& user_id, |
465 const UserAccountData& account_data) { | 447 const UserAccountData& account_data) { |
466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 448 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
467 | 449 |
468 SaveUserDisplayName(user_id, account_data.display_name()); | 450 SaveUserDisplayName(user_id, account_data.display_name()); |
469 | 451 |
470 if (user_manager::User* user = FindUserAndModify(user_id)) { | 452 if (User* user = FindUserAndModify(user_id)) { |
471 base::string16 given_name = account_data.given_name(); | 453 base::string16 given_name = account_data.given_name(); |
472 user->set_given_name(given_name); | 454 user->set_given_name(given_name); |
473 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { | 455 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { |
474 DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName); | 456 DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName); |
475 given_name_update->SetWithoutPathExpansion( | 457 given_name_update->SetWithoutPathExpansion( |
476 user_id, new base::StringValue(given_name)); | 458 user_id, new base::StringValue(given_name)); |
477 } | 459 } |
478 } | 460 } |
479 | 461 |
480 UpdateUserAccountLocale(user_id, account_data.locale()); | 462 UpdateUserAccountLocale(user_id, account_data.locale()); |
(...skipping 15 matching lines...) Expand all Loading... |
496 if (existing_users.find(email) != existing_users.end() || | 478 if (existing_users.find(email) != existing_users.end() || |
497 !users_set->insert(email).second) { | 479 !users_set->insert(email).second) { |
498 LOG(ERROR) << "Duplicate user: " << email; | 480 LOG(ERROR) << "Duplicate user: " << email; |
499 continue; | 481 continue; |
500 } | 482 } |
501 users_vector->push_back(email); | 483 users_vector->push_back(email); |
502 } | 484 } |
503 } | 485 } |
504 | 486 |
505 bool UserManagerBase::IsCurrentUserOwner() const { | 487 bool UserManagerBase::IsCurrentUserOwner() const { |
506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 488 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
507 base::AutoLock lk(is_current_user_owner_lock_); | 489 base::AutoLock lk(is_current_user_owner_lock_); |
508 return is_current_user_owner_; | 490 return is_current_user_owner_; |
509 } | 491 } |
510 | 492 |
511 void UserManagerBase::SetCurrentUserIsOwner(bool is_current_user_owner) { | 493 void UserManagerBase::SetCurrentUserIsOwner(bool is_current_user_owner) { |
512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 494 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
513 { | 495 { |
514 base::AutoLock lk(is_current_user_owner_lock_); | 496 base::AutoLock lk(is_current_user_owner_lock_); |
515 is_current_user_owner_ = is_current_user_owner; | 497 is_current_user_owner_ = is_current_user_owner; |
516 } | 498 } |
517 UpdateLoginState(); | 499 UpdateLoginState(); |
518 } | 500 } |
519 | 501 |
520 bool UserManagerBase::IsCurrentUserNew() const { | 502 bool UserManagerBase::IsCurrentUserNew() const { |
521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 503 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
522 return is_current_user_new_; | 504 return is_current_user_new_; |
523 } | 505 } |
524 | 506 |
525 bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const { | 507 bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const { |
526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 508 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
527 return IsUserLoggedIn() && | 509 return IsUserLoggedIn() && |
528 IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->email()); | 510 IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->email()); |
529 } | 511 } |
530 | 512 |
531 bool UserManagerBase::CanCurrentUserLock() const { | 513 bool UserManagerBase::CanCurrentUserLock() const { |
532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 514 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
533 return IsUserLoggedIn() && active_user_->can_lock(); | 515 return IsUserLoggedIn() && active_user_->can_lock(); |
534 } | 516 } |
535 | 517 |
536 bool UserManagerBase::IsUserLoggedIn() const { | 518 bool UserManagerBase::IsUserLoggedIn() const { |
537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 519 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
538 return active_user_; | 520 return active_user_; |
539 } | 521 } |
540 | 522 |
541 bool UserManagerBase::IsLoggedInAsRegularUser() const { | 523 bool UserManagerBase::IsLoggedInAsRegularUser() const { |
542 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 524 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
543 return IsUserLoggedIn() && | 525 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_REGULAR; |
544 active_user_->GetType() == user_manager::USER_TYPE_REGULAR; | |
545 } | 526 } |
546 | 527 |
547 bool UserManagerBase::IsLoggedInAsDemoUser() const { | 528 bool UserManagerBase::IsLoggedInAsDemoUser() const { |
548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 529 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
549 return IsUserLoggedIn() && | 530 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_RETAIL_MODE; |
550 active_user_->GetType() == user_manager::USER_TYPE_RETAIL_MODE; | |
551 } | 531 } |
552 | 532 |
553 bool UserManagerBase::IsLoggedInAsPublicAccount() const { | 533 bool UserManagerBase::IsLoggedInAsPublicAccount() const { |
554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 534 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
555 return IsUserLoggedIn() && | 535 return IsUserLoggedIn() && |
556 active_user_->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT; | 536 active_user_->GetType() == USER_TYPE_PUBLIC_ACCOUNT; |
557 } | 537 } |
558 | 538 |
559 bool UserManagerBase::IsLoggedInAsGuest() const { | 539 bool UserManagerBase::IsLoggedInAsGuest() const { |
560 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 540 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
561 return IsUserLoggedIn() && | 541 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_GUEST; |
562 active_user_->GetType() == user_manager::USER_TYPE_GUEST; | |
563 } | 542 } |
564 | 543 |
565 bool UserManagerBase::IsLoggedInAsSupervisedUser() const { | 544 bool UserManagerBase::IsLoggedInAsSupervisedUser() const { |
566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 545 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
567 return IsUserLoggedIn() && | 546 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_SUPERVISED; |
568 active_user_->GetType() == user_manager::USER_TYPE_SUPERVISED; | |
569 } | 547 } |
570 | 548 |
571 bool UserManagerBase::IsLoggedInAsKioskApp() const { | 549 bool UserManagerBase::IsLoggedInAsKioskApp() const { |
572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 550 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
573 return IsUserLoggedIn() && | 551 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_KIOSK_APP; |
574 active_user_->GetType() == user_manager::USER_TYPE_KIOSK_APP; | |
575 } | 552 } |
576 | 553 |
577 bool UserManagerBase::IsLoggedInAsStub() const { | 554 bool UserManagerBase::IsLoggedInAsStub() const { |
578 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 555 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
579 return IsUserLoggedIn() && active_user_->email() == login::kStubUser; | 556 return IsUserLoggedIn() && |
| 557 active_user_->email() == chromeos::login::kStubUser; |
580 } | 558 } |
581 | 559 |
582 bool UserManagerBase::IsSessionStarted() const { | 560 bool UserManagerBase::IsSessionStarted() const { |
583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 561 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
584 return session_started_; | 562 return session_started_; |
585 } | 563 } |
586 | 564 |
587 bool UserManagerBase::IsUserNonCryptohomeDataEphemeral( | 565 bool UserManagerBase::IsUserNonCryptohomeDataEphemeral( |
588 const std::string& user_id) const { | 566 const std::string& user_id) const { |
589 // Data belonging to the guest, retail mode and stub users is always | 567 // Data belonging to the guest, retail mode and stub users is always |
590 // ephemeral. | 568 // ephemeral. |
591 if (user_id == login::kGuestUserName || | 569 if (user_id == chromeos::login::kGuestUserName || |
592 user_id == login::kRetailModeUserName || user_id == login::kStubUser) { | 570 user_id == chromeos::login::kRetailModeUserName || |
| 571 user_id == chromeos::login::kStubUser) { |
593 return true; | 572 return true; |
594 } | 573 } |
595 | 574 |
596 // Data belonging to the owner, anyone found on the user list and obsolete | 575 // Data belonging to the owner, anyone found on the user list and obsolete |
597 // public accounts whose data has not been removed yet is not ephemeral. | 576 // public accounts whose data has not been removed yet is not ephemeral. |
598 if (user_id == GetOwnerEmail() || UserExistsInList(user_id) || | 577 if (user_id == GetOwnerEmail() || UserExistsInList(user_id) || |
599 IsPublicAccountMarkedForRemoval(user_id)) { | 578 IsPublicAccountMarkedForRemoval(user_id)) { |
600 return false; | 579 return false; |
601 } | 580 } |
602 | 581 |
(...skipping 10 matching lines...) Expand all Loading... |
613 // Data belonging to any other user is ephemeral when: | 592 // Data belonging to any other user is ephemeral when: |
614 // a) Going through the regular login flow and the ephemeral users policy is | 593 // a) Going through the regular login flow and the ephemeral users policy is |
615 // enabled. | 594 // enabled. |
616 // - or - | 595 // - or - |
617 // b) The browser is restarting after a crash. | 596 // b) The browser is restarting after a crash. |
618 return AreEphemeralUsersEnabled() || | 597 return AreEphemeralUsersEnabled() || |
619 session_manager::SessionManager::HasBrowserRestarted(); | 598 session_manager::SessionManager::HasBrowserRestarted(); |
620 } | 599 } |
621 | 600 |
622 void UserManagerBase::AddObserver(UserManager::Observer* obs) { | 601 void UserManagerBase::AddObserver(UserManager::Observer* obs) { |
623 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 602 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
624 observer_list_.AddObserver(obs); | 603 observer_list_.AddObserver(obs); |
625 } | 604 } |
626 | 605 |
627 void UserManagerBase::RemoveObserver(UserManager::Observer* obs) { | 606 void UserManagerBase::RemoveObserver(UserManager::Observer* obs) { |
628 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 607 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
629 observer_list_.RemoveObserver(obs); | 608 observer_list_.RemoveObserver(obs); |
630 } | 609 } |
631 | 610 |
632 void UserManagerBase::AddSessionStateObserver( | 611 void UserManagerBase::AddSessionStateObserver( |
633 UserManager::UserSessionStateObserver* obs) { | 612 UserManager::UserSessionStateObserver* obs) { |
634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 613 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
635 session_state_observer_list_.AddObserver(obs); | 614 session_state_observer_list_.AddObserver(obs); |
636 } | 615 } |
637 | 616 |
638 void UserManagerBase::RemoveSessionStateObserver( | 617 void UserManagerBase::RemoveSessionStateObserver( |
639 UserManager::UserSessionStateObserver* obs) { | 618 UserManager::UserSessionStateObserver* obs) { |
640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 619 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
641 session_state_observer_list_.RemoveObserver(obs); | 620 session_state_observer_list_.RemoveObserver(obs); |
642 } | 621 } |
643 | 622 |
644 void UserManagerBase::NotifyLocalStateChanged() { | 623 void UserManagerBase::NotifyLocalStateChanged() { |
645 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 624 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
646 FOR_EACH_OBSERVER( | 625 FOR_EACH_OBSERVER( |
647 UserManager::Observer, observer_list_, LocalStateChanged(this)); | 626 UserManager::Observer, observer_list_, LocalStateChanged(this)); |
648 } | 627 } |
649 | 628 |
650 bool UserManagerBase::CanUserBeRemoved(const user_manager::User* user) const { | 629 bool UserManagerBase::CanUserBeRemoved(const User* user) const { |
651 // Only regular and supervised users are allowed to be manually removed. | 630 // Only regular and supervised users are allowed to be manually removed. |
652 if (!user || (user->GetType() != user_manager::USER_TYPE_REGULAR && | 631 if (!user || (user->GetType() != USER_TYPE_REGULAR && |
653 user->GetType() != user_manager::USER_TYPE_SUPERVISED)) { | 632 user->GetType() != USER_TYPE_SUPERVISED)) { |
654 return false; | 633 return false; |
655 } | 634 } |
656 | 635 |
657 // Sanity check: we must not remove single user unless it's an enterprise | 636 // Sanity check: we must not remove single user unless it's an enterprise |
658 // device. This check may seem redundant at a first sight because | 637 // device. This check may seem redundant at a first sight because |
659 // this single user must be an owner and we perform special check later | 638 // this single user must be an owner and we perform special check later |
660 // in order not to remove an owner. However due to non-instant nature of | 639 // in order not to remove an owner. However due to non-instant nature of |
661 // ownership assignment this later check may sometimes fail. | 640 // ownership assignment this later check may sometimes fail. |
662 // See http://crosbug.com/12723 | 641 // See http://crosbug.com/12723 |
663 if (users_.size() < 2 && !IsEnterpriseManaged()) | 642 if (users_.size() < 2 && !IsEnterpriseManaged()) |
664 return false; | 643 return false; |
665 | 644 |
666 // Sanity check: do not allow any of the the logged in users to be removed. | 645 // Sanity check: do not allow any of the the logged in users to be removed. |
667 for (user_manager::UserList::const_iterator it = logged_in_users_.begin(); | 646 for (UserList::const_iterator it = logged_in_users_.begin(); |
668 it != logged_in_users_.end(); | 647 it != logged_in_users_.end(); |
669 ++it) { | 648 ++it) { |
670 if ((*it)->email() == user->email()) | 649 if ((*it)->email() == user->email()) |
671 return false; | 650 return false; |
672 } | 651 } |
673 | 652 |
674 return true; | 653 return true; |
675 } | 654 } |
676 | 655 |
677 bool UserManagerBase::GetEphemeralUsersEnabled() const { | 656 bool UserManagerBase::GetEphemeralUsersEnabled() const { |
(...skipping 14 matching lines...) Expand all Loading... |
692 | 671 |
693 const std::string& UserManagerBase::GetPendingUserSwitchID() const { | 672 const std::string& UserManagerBase::GetPendingUserSwitchID() const { |
694 return pending_user_switch_; | 673 return pending_user_switch_; |
695 } | 674 } |
696 | 675 |
697 void UserManagerBase::SetPendingUserSwitchID(std::string user_id) { | 676 void UserManagerBase::SetPendingUserSwitchID(std::string user_id) { |
698 pending_user_switch_ = user_id; | 677 pending_user_switch_ = user_id; |
699 } | 678 } |
700 | 679 |
701 void UserManagerBase::EnsureUsersLoaded() { | 680 void UserManagerBase::EnsureUsersLoaded() { |
702 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 681 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
703 if (!GetLocalState()) | 682 if (!GetLocalState()) |
704 return; | 683 return; |
705 | 684 |
706 if (user_loading_stage_ != STAGE_NOT_LOADED) | 685 if (user_loading_stage_ != STAGE_NOT_LOADED) |
707 return; | 686 return; |
708 user_loading_stage_ = STAGE_LOADING; | 687 user_loading_stage_ = STAGE_LOADING; |
709 | 688 |
710 PerformPreUserListLoadingActions(); | 689 PerformPreUserListLoadingActions(); |
711 | 690 |
712 PrefService* local_state = GetLocalState(); | 691 PrefService* local_state = GetLocalState(); |
(...skipping 14 matching lines...) Expand all Loading... |
727 // Load regular users and supervised users. | 706 // Load regular users and supervised users. |
728 std::vector<std::string> regular_users; | 707 std::vector<std::string> regular_users; |
729 std::set<std::string> regular_users_set; | 708 std::set<std::string> regular_users_set; |
730 ParseUserList(*prefs_regular_users, | 709 ParseUserList(*prefs_regular_users, |
731 public_sessions_set, | 710 public_sessions_set, |
732 ®ular_users, | 711 ®ular_users, |
733 ®ular_users_set); | 712 ®ular_users_set); |
734 for (std::vector<std::string>::const_iterator it = regular_users.begin(); | 713 for (std::vector<std::string>::const_iterator it = regular_users.begin(); |
735 it != regular_users.end(); | 714 it != regular_users.end(); |
736 ++it) { | 715 ++it) { |
737 user_manager::User* user = NULL; | 716 User* user = NULL; |
738 const std::string domain = gaia::ExtractDomainName(*it); | 717 const std::string domain = gaia::ExtractDomainName(*it); |
739 if (domain == chromeos::login::kSupervisedUserDomain) | 718 if (domain == chromeos::login::kSupervisedUserDomain) |
740 user = user_manager::User::CreateSupervisedUser(*it); | 719 user = User::CreateSupervisedUser(*it); |
741 else | 720 else |
742 user = user_manager::User::CreateRegularUser(*it); | 721 user = User::CreateRegularUser(*it); |
743 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); | 722 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); |
744 user->set_force_online_signin(LoadForceOnlineSignin(*it)); | 723 user->set_force_online_signin(LoadForceOnlineSignin(*it)); |
745 users_.push_back(user); | 724 users_.push_back(user); |
746 | 725 |
747 base::string16 display_name; | 726 base::string16 display_name; |
748 if (prefs_display_names->GetStringWithoutPathExpansion(*it, | 727 if (prefs_display_names->GetStringWithoutPathExpansion(*it, |
749 &display_name)) { | 728 &display_name)) { |
750 user->set_display_name(display_name); | 729 user->set_display_name(display_name); |
751 } | 730 } |
752 | 731 |
753 base::string16 given_name; | 732 base::string16 given_name; |
754 if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) { | 733 if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) { |
755 user->set_given_name(given_name); | 734 user->set_given_name(given_name); |
756 } | 735 } |
757 | 736 |
758 std::string display_email; | 737 std::string display_email; |
759 if (prefs_display_emails->GetStringWithoutPathExpansion(*it, | 738 if (prefs_display_emails->GetStringWithoutPathExpansion(*it, |
760 &display_email)) { | 739 &display_email)) { |
761 user->set_display_email(display_email); | 740 user->set_display_email(display_email); |
762 } | 741 } |
763 } | 742 } |
764 | 743 |
765 user_loading_stage_ = STAGE_LOADED; | 744 user_loading_stage_ = STAGE_LOADED; |
766 | 745 |
767 PerformPostUserListLoadingActions(); | 746 PerformPostUserListLoadingActions(); |
768 } | 747 } |
769 | 748 |
770 user_manager::UserList& UserManagerBase::GetUsersAndModify() { | 749 UserList& UserManagerBase::GetUsersAndModify() { |
771 EnsureUsersLoaded(); | 750 EnsureUsersLoaded(); |
772 return users_; | 751 return users_; |
773 } | 752 } |
774 | 753 |
775 const user_manager::User* UserManagerBase::FindUserInList( | 754 const User* UserManagerBase::FindUserInList(const std::string& user_id) const { |
776 const std::string& user_id) const { | 755 const UserList& users = GetUsers(); |
777 const user_manager::UserList& users = GetUsers(); | 756 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
778 for (user_manager::UserList::const_iterator it = users.begin(); | |
779 it != users.end(); | |
780 ++it) { | |
781 if ((*it)->email() == user_id) | 757 if ((*it)->email() == user_id) |
782 return *it; | 758 return *it; |
783 } | 759 } |
784 return NULL; | 760 return NULL; |
785 } | 761 } |
786 | 762 |
787 const bool UserManagerBase::UserExistsInList(const std::string& user_id) const { | 763 const bool UserManagerBase::UserExistsInList(const std::string& user_id) const { |
788 const base::ListValue* user_list = GetLocalState()->GetList(kRegularUsers); | 764 const base::ListValue* user_list = GetLocalState()->GetList(kRegularUsers); |
789 for (size_t i = 0; i < user_list->GetSize(); ++i) { | 765 for (size_t i = 0; i < user_list->GetSize(); ++i) { |
790 std::string email; | 766 std::string email; |
791 if (user_list->GetString(i, &email) && (user_id == email)) | 767 if (user_list->GetString(i, &email) && (user_id == email)) |
792 return true; | 768 return true; |
793 } | 769 } |
794 return false; | 770 return false; |
795 } | 771 } |
796 | 772 |
797 user_manager::User* UserManagerBase::FindUserInListAndModify( | 773 User* UserManagerBase::FindUserInListAndModify(const std::string& user_id) { |
798 const std::string& user_id) { | 774 UserList& users = GetUsersAndModify(); |
799 user_manager::UserList& users = GetUsersAndModify(); | 775 for (UserList::iterator it = users.begin(); it != users.end(); ++it) { |
800 for (user_manager::UserList::iterator it = users.begin(); it != users.end(); | |
801 ++it) { | |
802 if ((*it)->email() == user_id) | 776 if ((*it)->email() == user_id) |
803 return *it; | 777 return *it; |
804 } | 778 } |
805 return NULL; | 779 return NULL; |
806 } | 780 } |
807 | 781 |
808 void UserManagerBase::GuestUserLoggedIn() { | 782 void UserManagerBase::GuestUserLoggedIn() { |
809 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 783 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
810 active_user_ = user_manager::User::CreateGuestUser(); | 784 active_user_ = User::CreateGuestUser(); |
811 } | 785 } |
812 | 786 |
813 void UserManagerBase::AddUserRecord(user_manager::User* user) { | 787 void UserManagerBase::AddUserRecord(User* user) { |
814 // Add the user to the front of the user list. | 788 // Add the user to the front of the user list. |
815 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); | 789 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); |
816 prefs_users_update->Insert(0, new base::StringValue(user->email())); | 790 prefs_users_update->Insert(0, new base::StringValue(user->email())); |
817 users_.insert(users_.begin(), user); | 791 users_.insert(users_.begin(), user); |
818 } | 792 } |
819 | 793 |
820 void UserManagerBase::RegularUserLoggedIn(const std::string& user_id) { | 794 void UserManagerBase::RegularUserLoggedIn(const std::string& user_id) { |
821 // Remove the user from the user list. | 795 // Remove the user from the user list. |
822 active_user_ = RemoveRegularOrSupervisedUserFromList(user_id); | 796 active_user_ = RemoveRegularOrSupervisedUserFromList(user_id); |
823 | 797 |
824 // If the user was not found on the user list, create a new user. | 798 // If the user was not found on the user list, create a new user. |
825 SetIsCurrentUserNew(!active_user_); | 799 SetIsCurrentUserNew(!active_user_); |
826 if (IsCurrentUserNew()) { | 800 if (IsCurrentUserNew()) { |
827 active_user_ = user_manager::User::CreateRegularUser(user_id); | 801 active_user_ = User::CreateRegularUser(user_id); |
828 active_user_->set_oauth_token_status(LoadUserOAuthStatus(user_id)); | 802 active_user_->set_oauth_token_status(LoadUserOAuthStatus(user_id)); |
829 SaveUserDisplayName(active_user_->email(), | 803 SaveUserDisplayName(active_user_->email(), |
830 base::UTF8ToUTF16(active_user_->GetAccountName(true))); | 804 base::UTF8ToUTF16(active_user_->GetAccountName(true))); |
831 } | 805 } |
832 | 806 |
833 AddUserRecord(active_user_); | 807 AddUserRecord(active_user_); |
834 | 808 |
835 // Make sure that new data is persisted to Local State. | 809 // Make sure that new data is persisted to Local State. |
836 GetLocalState()->CommitPendingWrite(); | 810 GetLocalState()->CommitPendingWrite(); |
837 } | 811 } |
838 | 812 |
839 void UserManagerBase::RegularUserLoggedInAsEphemeral( | 813 void UserManagerBase::RegularUserLoggedInAsEphemeral( |
840 const std::string& user_id) { | 814 const std::string& user_id) { |
841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 815 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
842 SetIsCurrentUserNew(true); | 816 SetIsCurrentUserNew(true); |
843 is_current_user_ephemeral_regular_user_ = true; | 817 is_current_user_ephemeral_regular_user_ = true; |
844 active_user_ = user_manager::User::CreateRegularUser(user_id); | 818 active_user_ = User::CreateRegularUser(user_id); |
845 } | 819 } |
846 | 820 |
847 void UserManagerBase::NotifyOnLogin() { | 821 void UserManagerBase::NotifyOnLogin() { |
848 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 822 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
849 | 823 |
850 NotifyActiveUserHashChanged(active_user_->username_hash()); | 824 NotifyActiveUserHashChanged(active_user_->username_hash()); |
851 NotifyActiveUserChanged(active_user_); | 825 NotifyActiveUserChanged(active_user_); |
852 UpdateLoginState(); | 826 UpdateLoginState(); |
853 } | 827 } |
854 | 828 |
855 user_manager::User::OAuthTokenStatus UserManagerBase::LoadUserOAuthStatus( | 829 User::OAuthTokenStatus UserManagerBase::LoadUserOAuthStatus( |
856 const std::string& user_id) const { | 830 const std::string& user_id) const { |
857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 831 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
858 | 832 |
859 const base::DictionaryValue* prefs_oauth_status = | 833 const base::DictionaryValue* prefs_oauth_status = |
860 GetLocalState()->GetDictionary(kUserOAuthTokenStatus); | 834 GetLocalState()->GetDictionary(kUserOAuthTokenStatus); |
861 int oauth_token_status = user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; | 835 int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN; |
862 if (prefs_oauth_status && | 836 if (prefs_oauth_status && |
863 prefs_oauth_status->GetIntegerWithoutPathExpansion(user_id, | 837 prefs_oauth_status->GetIntegerWithoutPathExpansion(user_id, |
864 &oauth_token_status)) { | 838 &oauth_token_status)) { |
865 user_manager::User::OAuthTokenStatus result = | 839 User::OAuthTokenStatus status = |
866 static_cast<user_manager::User::OAuthTokenStatus>(oauth_token_status); | 840 static_cast<User::OAuthTokenStatus>(oauth_token_status); |
867 if (result == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) | 841 HandleUserOAuthTokenStatusChange(user_id, status); |
868 GetUserFlow(user_id)->HandleOAuthTokenStatusChange(result); | 842 |
869 return result; | 843 return status; |
870 } | 844 } |
871 return user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; | 845 return User::OAUTH_TOKEN_STATUS_UNKNOWN; |
872 } | 846 } |
873 | 847 |
874 bool UserManagerBase::LoadForceOnlineSignin(const std::string& user_id) const { | 848 bool UserManagerBase::LoadForceOnlineSignin(const std::string& user_id) const { |
875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 849 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
876 | 850 |
877 const base::DictionaryValue* prefs_force_online = | 851 const base::DictionaryValue* prefs_force_online = |
878 GetLocalState()->GetDictionary(kUserForceOnlineSignin); | 852 GetLocalState()->GetDictionary(kUserForceOnlineSignin); |
879 bool force_online_signin = false; | 853 bool force_online_signin = false; |
880 if (prefs_force_online) { | 854 if (prefs_force_online) { |
881 prefs_force_online->GetBooleanWithoutPathExpansion(user_id, | 855 prefs_force_online->GetBooleanWithoutPathExpansion(user_id, |
882 &force_online_signin); | 856 &force_online_signin); |
883 } | 857 } |
884 return force_online_signin; | 858 return force_online_signin; |
885 } | 859 } |
886 | 860 |
887 void UserManagerBase::RemoveNonCryptohomeData(const std::string& user_id) { | 861 void UserManagerBase::RemoveNonCryptohomeData(const std::string& user_id) { |
888 PrefService* prefs = GetLocalState(); | 862 PrefService* prefs = GetLocalState(); |
889 DictionaryPrefUpdate prefs_display_name_update(prefs, kUserDisplayName); | 863 DictionaryPrefUpdate prefs_display_name_update(prefs, kUserDisplayName); |
890 prefs_display_name_update->RemoveWithoutPathExpansion(user_id, NULL); | 864 prefs_display_name_update->RemoveWithoutPathExpansion(user_id, NULL); |
891 | 865 |
892 DictionaryPrefUpdate prefs_given_name_update(prefs, kUserGivenName); | 866 DictionaryPrefUpdate prefs_given_name_update(prefs, kUserGivenName); |
893 prefs_given_name_update->RemoveWithoutPathExpansion(user_id, NULL); | 867 prefs_given_name_update->RemoveWithoutPathExpansion(user_id, NULL); |
894 | 868 |
895 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); | 869 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); |
896 prefs_display_email_update->RemoveWithoutPathExpansion(user_id, NULL); | 870 prefs_display_email_update->RemoveWithoutPathExpansion(user_id, NULL); |
897 | 871 |
898 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | 872 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); |
899 prefs_oauth_update->RemoveWithoutPathExpansion(user_id, NULL); | 873 prefs_oauth_update->RemoveWithoutPathExpansion(user_id, NULL); |
900 | 874 |
901 DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin); | 875 DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin); |
902 prefs_force_online_update->RemoveWithoutPathExpansion(user_id, NULL); | 876 prefs_force_online_update->RemoveWithoutPathExpansion(user_id, NULL); |
903 } | 877 } |
904 | 878 |
905 user_manager::User* UserManagerBase::RemoveRegularOrSupervisedUserFromList( | 879 User* UserManagerBase::RemoveRegularOrSupervisedUserFromList( |
906 const std::string& user_id) { | 880 const std::string& user_id) { |
907 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); | 881 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); |
908 prefs_users_update->Clear(); | 882 prefs_users_update->Clear(); |
909 user_manager::User* user = NULL; | 883 User* user = NULL; |
910 for (user_manager::UserList::iterator it = users_.begin(); | 884 for (UserList::iterator it = users_.begin(); it != users_.end();) { |
911 it != users_.end();) { | |
912 const std::string user_email = (*it)->email(); | 885 const std::string user_email = (*it)->email(); |
913 if (user_email == user_id) { | 886 if (user_email == user_id) { |
914 user = *it; | 887 user = *it; |
915 it = users_.erase(it); | 888 it = users_.erase(it); |
916 } else { | 889 } else { |
917 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR || | 890 if ((*it)->GetType() == USER_TYPE_REGULAR || |
918 (*it)->GetType() == user_manager::USER_TYPE_SUPERVISED) { | 891 (*it)->GetType() == USER_TYPE_SUPERVISED) { |
919 prefs_users_update->Append(new base::StringValue(user_email)); | 892 prefs_users_update->Append(new base::StringValue(user_email)); |
920 } | 893 } |
921 ++it; | 894 ++it; |
922 } | 895 } |
923 } | 896 } |
924 return user; | 897 return user; |
925 } | 898 } |
926 | 899 |
927 void UserManagerBase::NotifyActiveUserChanged( | 900 void UserManagerBase::NotifyActiveUserChanged(const User* active_user) { |
928 const user_manager::User* active_user) { | 901 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
929 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
930 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 902 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
931 session_state_observer_list_, | 903 session_state_observer_list_, |
932 ActiveUserChanged(active_user)); | 904 ActiveUserChanged(active_user)); |
933 } | 905 } |
934 | 906 |
935 void UserManagerBase::NotifyUserAddedToSession( | 907 void UserManagerBase::NotifyUserAddedToSession(const User* added_user, |
936 const user_manager::User* added_user, | 908 bool user_switch_pending) { |
937 bool user_switch_pending) { | 909 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
939 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 910 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
940 session_state_observer_list_, | 911 session_state_observer_list_, |
941 UserAddedToSession(added_user)); | 912 UserAddedToSession(added_user)); |
942 } | 913 } |
943 | 914 |
944 void UserManagerBase::NotifyActiveUserHashChanged(const std::string& hash) { | 915 void UserManagerBase::NotifyActiveUserHashChanged(const std::string& hash) { |
945 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 916 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
946 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 917 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
947 session_state_observer_list_, | 918 session_state_observer_list_, |
948 ActiveUserHashChanged(hash)); | 919 ActiveUserHashChanged(hash)); |
949 } | 920 } |
950 | 921 |
951 void UserManagerBase::UpdateLoginState() { | 922 void UserManagerBase::UpdateLoginState() { |
952 if (!LoginState::IsInitialized()) | 923 if (!chromeos::LoginState::IsInitialized()) |
953 return; // LoginState may not be intialized in tests. | 924 return; // LoginState may not be intialized in tests. |
954 | 925 |
955 LoginState::LoggedInState logged_in_state; | 926 chromeos::LoginState::LoggedInState logged_in_state; |
956 logged_in_state = | 927 logged_in_state = active_user_ ? chromeos::LoginState::LOGGED_IN_ACTIVE |
957 active_user_ ? LoginState::LOGGED_IN_ACTIVE : LoginState::LOGGED_IN_NONE; | 928 : chromeos::LoginState::LOGGED_IN_NONE; |
958 | 929 |
959 LoginState::LoggedInUserType login_user_type; | 930 chromeos::LoginState::LoggedInUserType login_user_type; |
960 if (logged_in_state == LoginState::LOGGED_IN_NONE) | 931 if (logged_in_state == chromeos::LoginState::LOGGED_IN_NONE) |
961 login_user_type = LoginState::LOGGED_IN_USER_NONE; | 932 login_user_type = chromeos::LoginState::LOGGED_IN_USER_NONE; |
962 else if (is_current_user_owner_) | 933 else if (is_current_user_owner_) |
963 login_user_type = LoginState::LOGGED_IN_USER_OWNER; | 934 login_user_type = chromeos::LoginState::LOGGED_IN_USER_OWNER; |
964 else if (active_user_->GetType() == user_manager::USER_TYPE_GUEST) | 935 else if (active_user_->GetType() == USER_TYPE_GUEST) |
965 login_user_type = LoginState::LOGGED_IN_USER_GUEST; | 936 login_user_type = chromeos::LoginState::LOGGED_IN_USER_GUEST; |
966 else if (active_user_->GetType() == user_manager::USER_TYPE_RETAIL_MODE) | 937 else if (active_user_->GetType() == USER_TYPE_RETAIL_MODE) |
967 login_user_type = LoginState::LOGGED_IN_USER_RETAIL_MODE; | 938 login_user_type = chromeos::LoginState::LOGGED_IN_USER_RETAIL_MODE; |
968 else if (active_user_->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) | 939 else if (active_user_->GetType() == USER_TYPE_PUBLIC_ACCOUNT) |
969 login_user_type = LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT; | 940 login_user_type = chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT; |
970 else if (active_user_->GetType() == user_manager::USER_TYPE_SUPERVISED) | 941 else if (active_user_->GetType() == USER_TYPE_SUPERVISED) |
971 login_user_type = LoginState::LOGGED_IN_USER_SUPERVISED; | 942 login_user_type = chromeos::LoginState::LOGGED_IN_USER_SUPERVISED; |
972 else if (active_user_->GetType() == user_manager::USER_TYPE_KIOSK_APP) | 943 else if (active_user_->GetType() == USER_TYPE_KIOSK_APP) |
973 login_user_type = LoginState::LOGGED_IN_USER_KIOSK_APP; | 944 login_user_type = chromeos::LoginState::LOGGED_IN_USER_KIOSK_APP; |
974 else | 945 else |
975 login_user_type = LoginState::LOGGED_IN_USER_REGULAR; | 946 login_user_type = chromeos::LoginState::LOGGED_IN_USER_REGULAR; |
976 | 947 |
977 if (primary_user_) { | 948 if (primary_user_) { |
978 LoginState::Get()->SetLoggedInStateAndPrimaryUser( | 949 chromeos::LoginState::Get()->SetLoggedInStateAndPrimaryUser( |
979 logged_in_state, login_user_type, primary_user_->username_hash()); | 950 logged_in_state, login_user_type, primary_user_->username_hash()); |
980 } else { | 951 } else { |
981 LoginState::Get()->SetLoggedInState(logged_in_state, login_user_type); | 952 chromeos::LoginState::Get()->SetLoggedInState(logged_in_state, |
| 953 login_user_type); |
982 } | 954 } |
983 } | 955 } |
984 | 956 |
985 void UserManagerBase::SetLRUUser(user_manager::User* user) { | 957 void UserManagerBase::SetLRUUser(User* user) { |
986 user_manager::UserList::iterator it = | 958 UserList::iterator it = |
987 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); | 959 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); |
988 if (it != lru_logged_in_users_.end()) | 960 if (it != lru_logged_in_users_.end()) |
989 lru_logged_in_users_.erase(it); | 961 lru_logged_in_users_.erase(it); |
990 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); | 962 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); |
991 } | 963 } |
992 | 964 |
993 void UserManagerBase::SendRegularUserLoginMetrics(const std::string& user_id) { | 965 void UserManagerBase::SendRegularUserLoginMetrics(const std::string& user_id) { |
994 // If this isn't the first time Chrome was run after the system booted, | 966 // If this isn't the first time Chrome was run after the system booted, |
995 // assume that Chrome was restarted because a previous session ended. | 967 // assume that Chrome was restarted because a previous session ended. |
996 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 968 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
997 switches::kFirstExecAfterBoot)) { | 969 chromeos::switches::kFirstExecAfterBoot)) { |
998 const std::string last_email = | 970 const std::string last_email = |
999 GetLocalState()->GetString(kLastLoggedInRegularUser); | 971 GetLocalState()->GetString(kLastLoggedInRegularUser); |
1000 const base::TimeDelta time_to_login = | 972 const base::TimeDelta time_to_login = |
1001 base::TimeTicks::Now() - manager_creation_time_; | 973 base::TimeTicks::Now() - manager_creation_time_; |
1002 if (!last_email.empty() && user_id != last_email && | 974 if (!last_email.empty() && user_id != last_email && |
1003 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { | 975 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { |
1004 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", | 976 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", |
1005 time_to_login.InSeconds(), | 977 time_to_login.InSeconds(), |
1006 0, | 978 0, |
1007 kLogoutToLoginDelayMaxSec, | 979 kLogoutToLoginDelayMaxSec, |
1008 50); | 980 50); |
1009 } | 981 } |
1010 } | 982 } |
1011 } | 983 } |
1012 | 984 |
1013 void UserManagerBase::UpdateUserAccountLocale(const std::string& user_id, | 985 void UserManagerBase::UpdateUserAccountLocale(const std::string& user_id, |
1014 const std::string& locale) { | 986 const std::string& locale) { |
1015 if (!locale.empty() && locale != GetApplicationLocale()) { | 987 if (!locale.empty() && locale != GetApplicationLocale()) { |
1016 base::Callback<void(const std::string&)> on_resolve_callback = | 988 base::Callback<void(const std::string&)> on_resolve_callback = |
1017 base::Bind(&UserManagerBase::DoUpdateAccountLocale, | 989 base::Bind(&UserManagerBase::DoUpdateAccountLocale, |
1018 weak_factory_.GetWeakPtr(), | 990 weak_factory_.GetWeakPtr(), |
1019 user_id); | 991 user_id); |
1020 BrowserThread::PostBlockingPoolTask(FROM_HERE, | 992 blocking_task_runner_->PostTask(FROM_HERE, |
1021 base::Bind(ResolveLocale, | 993 base::Bind(&UserManagerBase::ResolveLocale, |
1022 locale, | 994 weak_factory_.GetWeakPtr(), |
1023 on_resolve_callback)); | 995 locale, |
| 996 on_resolve_callback)); |
1024 } else { | 997 } else { |
1025 DoUpdateAccountLocale(user_id, locale); | 998 DoUpdateAccountLocale(user_id, locale); |
1026 } | 999 } |
1027 } | 1000 } |
1028 | 1001 |
| 1002 void UserManagerBase::ResolveLocale( |
| 1003 const std::string& raw_locale, |
| 1004 base::Callback<void(const std::string&)> on_resolve_callback) { |
| 1005 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 1006 std::string resolved_locale; |
| 1007 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, &resolved_locale)); |
| 1008 task_runner_->PostTask(FROM_HERE, |
| 1009 base::Bind(on_resolve_callback, resolved_locale)); |
| 1010 } |
| 1011 |
1029 void UserManagerBase::DoUpdateAccountLocale( | 1012 void UserManagerBase::DoUpdateAccountLocale( |
1030 const std::string& user_id, | 1013 const std::string& user_id, |
1031 const std::string& resolved_locale) { | 1014 const std::string& resolved_locale) { |
1032 if (user_manager::User* user = FindUserAndModify(user_id)) | 1015 if (User* user = FindUserAndModify(user_id)) |
1033 user->SetAccountLocale(resolved_locale); | 1016 user->SetAccountLocale(resolved_locale); |
1034 } | 1017 } |
1035 | 1018 |
1036 void UserManagerBase::DeleteUser(user_manager::User* user) { | 1019 void UserManagerBase::DeleteUser(User* user) { |
1037 const bool is_active_user = (user == active_user_); | 1020 const bool is_active_user = (user == active_user_); |
1038 delete user; | 1021 delete user; |
1039 if (is_active_user) | 1022 if (is_active_user) |
1040 active_user_ = NULL; | 1023 active_user_ = NULL; |
1041 } | 1024 } |
1042 | 1025 |
1043 } // namespace chromeos | 1026 } // namespace user_manager |
OLD | NEW |