Chromium Code Reviews| 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/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/prefs/pref_registry_simple.h" | 17 #include "base/prefs/pref_registry_simple.h" |
| 18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 19 #include "base/prefs/scoped_user_pref_update.h" | 19 #include "base/prefs/scoped_user_pref_update.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/values.h" | 23 #include "base/values.h" |
| 24 #include "chrome/browser/chromeos/login/users/remove_user_delegate.h" | |
| 25 #include "chromeos/chromeos_switches.h" | 24 #include "chromeos/chromeos_switches.h" |
| 26 #include "chromeos/cryptohome/async_method_caller.h" | 25 #include "chromeos/cryptohome/async_method_caller.h" |
| 27 #include "chromeos/login/login_state.h" | 26 #include "chromeos/login/login_state.h" |
| 28 #include "chromeos/login/user_names.h" | 27 #include "chromeos/login/user_names.h" |
| 29 #include "components/session_manager/core/session_manager.h" | 28 #include "components/session_manager/core/session_manager.h" |
| 29 #include "components/user_manager/remove_user_delegate.h" | |
| 30 #include "components/user_manager/user_type.h" | 30 #include "components/user_manager/user_type.h" |
| 31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 32 #include "google_apis/gaia/gaia_auth_util.h" | 32 #include "google_apis/gaia/gaia_auth_util.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 34 | 34 |
| 35 using content::BrowserThread; | 35 using content::BrowserThread; |
| 36 | 36 |
| 37 namespace chromeos { | 37 namespace user_manager { |
| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 : active_user_(NULL), | 108 : active_user_(NULL), |
| 109 primary_user_(NULL), | 109 primary_user_(NULL), |
| 110 user_loading_stage_(STAGE_NOT_LOADED), | 110 user_loading_stage_(STAGE_NOT_LOADED), |
| 111 session_started_(false), | 111 session_started_(false), |
| 112 is_current_user_owner_(false), | 112 is_current_user_owner_(false), |
| 113 is_current_user_new_(false), | 113 is_current_user_new_(false), |
| 114 is_current_user_ephemeral_regular_user_(false), | 114 is_current_user_ephemeral_regular_user_(false), |
| 115 ephemeral_users_enabled_(false), | 115 ephemeral_users_enabled_(false), |
| 116 manager_creation_time_(base::TimeTicks::Now()), | 116 manager_creation_time_(base::TimeTicks::Now()), |
| 117 weak_factory_(this) { | 117 weak_factory_(this) { |
| 118 // UserManager instance should be used only on UI thread. | |
| 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
|
Dmitry Polukhin
2014/08/12 09:03:13
Why did you remove it?
Nikita (slow)
2014/08/12 09:34:42
unit_tests now use this class through
FakeUserMan
| |
| 120 UpdateLoginState(); | 118 UpdateLoginState(); |
| 121 } | 119 } |
| 122 | 120 |
| 123 UserManagerBase::~UserManagerBase() { | 121 UserManagerBase::~UserManagerBase() { |
| 124 // Can't use STLDeleteElements because of the private destructor of User. | 122 // Can't use STLDeleteElements because of the private destructor of User. |
| 125 for (user_manager::UserList::iterator it = users_.begin(); it != users_.end(); | 123 for (UserList::iterator it = users_.begin(); it != users_.end(); |
| 126 it = users_.erase(it)) { | 124 it = users_.erase(it)) { |
| 127 DeleteUser(*it); | 125 DeleteUser(*it); |
| 128 } | 126 } |
| 129 // These are pointers to the same User instances that were in users_ list. | 127 // These are pointers to the same User instances that were in users_ list. |
| 130 logged_in_users_.clear(); | 128 logged_in_users_.clear(); |
| 131 lru_logged_in_users_.clear(); | 129 lru_logged_in_users_.clear(); |
| 132 | 130 |
| 133 DeleteUser(active_user_); | 131 DeleteUser(active_user_); |
| 134 } | 132 } |
| 135 | 133 |
| 136 void UserManagerBase::Shutdown() { | 134 void UserManagerBase::Shutdown() { |
| 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 138 } | 136 } |
| 139 | 137 |
| 140 const user_manager::UserList& UserManagerBase::GetUsers() const { | 138 const UserList& UserManagerBase::GetUsers() const { |
| 141 const_cast<UserManagerBase*>(this)->EnsureUsersLoaded(); | 139 const_cast<UserManagerBase*>(this)->EnsureUsersLoaded(); |
| 142 return users_; | 140 return users_; |
| 143 } | 141 } |
| 144 | 142 |
| 145 const user_manager::UserList& UserManagerBase::GetLoggedInUsers() const { | 143 const UserList& UserManagerBase::GetLoggedInUsers() const { |
| 146 return logged_in_users_; | 144 return logged_in_users_; |
| 147 } | 145 } |
| 148 | 146 |
| 149 const user_manager::UserList& UserManagerBase::GetLRULoggedInUsers() const { | 147 const UserList& UserManagerBase::GetLRULoggedInUsers() const { |
| 150 return lru_logged_in_users_; | 148 return lru_logged_in_users_; |
| 151 } | 149 } |
| 152 | 150 |
| 153 const std::string& UserManagerBase::GetOwnerEmail() const { | 151 const std::string& UserManagerBase::GetOwnerEmail() const { |
| 154 return owner_email_; | 152 return owner_email_; |
| 155 } | 153 } |
| 156 | 154 |
| 157 void UserManagerBase::UserLoggedIn(const std::string& user_id, | 155 void UserManagerBase::UserLoggedIn(const std::string& user_id, |
| 158 const std::string& username_hash, | 156 const std::string& username_hash, |
| 159 bool browser_restart) { | 157 bool browser_restart) { |
| 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 161 | 159 |
| 162 user_manager::User* user = FindUserInListAndModify(user_id); | 160 User* user = FindUserInListAndModify(user_id); |
| 163 if (active_user_ && user) { | 161 if (active_user_ && user) { |
| 164 user->set_is_logged_in(true); | 162 user->set_is_logged_in(true); |
| 165 user->set_username_hash(username_hash); | 163 user->set_username_hash(username_hash); |
| 166 logged_in_users_.push_back(user); | 164 logged_in_users_.push_back(user); |
| 167 lru_logged_in_users_.push_back(user); | 165 lru_logged_in_users_.push_back(user); |
| 168 | 166 |
| 169 // Reset the new user flag if the user already exists. | 167 // Reset the new user flag if the user already exists. |
| 170 SetIsCurrentUserNew(false); | 168 SetIsCurrentUserNew(false); |
| 171 NotifyUserAddedToSession(user, true /* user switch pending */); | 169 NotifyUserAddedToSession(user, true /* user switch pending */); |
| 172 | 170 |
| 173 return; | 171 return; |
| 174 } | 172 } |
| 175 | 173 |
| 176 if (user_id == chromeos::login::kGuestUserName) { | 174 if (user_id == chromeos::login::kGuestUserName) { |
| 177 GuestUserLoggedIn(); | 175 GuestUserLoggedIn(); |
| 178 } else if (user_id == chromeos::login::kRetailModeUserName) { | 176 } else if (user_id == chromeos::login::kRetailModeUserName) { |
| 179 RetailModeUserLoggedIn(); | 177 RetailModeUserLoggedIn(); |
| 180 } else if (IsKioskApp(user_id)) { | 178 } else if (IsKioskApp(user_id)) { |
| 181 KioskAppLoggedIn(user_id); | 179 KioskAppLoggedIn(user_id); |
| 182 } else if (IsDemoApp(user_id)) { | 180 } else if (IsDemoApp(user_id)) { |
| 183 DemoAccountLoggedIn(); | 181 DemoAccountLoggedIn(); |
| 184 } else { | 182 } else { |
| 185 EnsureUsersLoaded(); | 183 EnsureUsersLoaded(); |
| 186 | 184 |
| 187 if (user && user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { | 185 if (user && user->GetType() == USER_TYPE_PUBLIC_ACCOUNT) { |
| 188 PublicAccountUserLoggedIn(user); | 186 PublicAccountUserLoggedIn(user); |
| 189 } else if ((user && | 187 } else if ((user && user->GetType() == USER_TYPE_SUPERVISED) || |
| 190 user->GetType() == user_manager::USER_TYPE_SUPERVISED) || | |
| 191 (!user && | 188 (!user && |
| 192 gaia::ExtractDomainName(user_id) == | 189 gaia::ExtractDomainName(user_id) == |
| 193 chromeos::login::kSupervisedUserDomain)) { | 190 chromeos::login::kSupervisedUserDomain)) { |
| 194 SupervisedUserLoggedIn(user_id); | 191 SupervisedUserLoggedIn(user_id); |
| 195 } else if (browser_restart && IsPublicAccountMarkedForRemoval(user_id)) { | 192 } else if (browser_restart && IsPublicAccountMarkedForRemoval(user_id)) { |
| 196 PublicAccountUserLoggedIn( | 193 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(user_id)); |
| 197 user_manager::User::CreatePublicAccountUser(user_id)); | |
| 198 } else if (user_id != GetOwnerEmail() && !user && | 194 } else if (user_id != GetOwnerEmail() && !user && |
| 199 (AreEphemeralUsersEnabled() || browser_restart)) { | 195 (AreEphemeralUsersEnabled() || browser_restart)) { |
| 200 RegularUserLoggedInAsEphemeral(user_id); | 196 RegularUserLoggedInAsEphemeral(user_id); |
| 201 } else { | 197 } else { |
| 202 RegularUserLoggedIn(user_id); | 198 RegularUserLoggedIn(user_id); |
| 203 } | 199 } |
| 204 } | 200 } |
| 205 | 201 |
| 206 DCHECK(active_user_); | 202 DCHECK(active_user_); |
| 207 active_user_->set_is_logged_in(true); | 203 active_user_->set_is_logged_in(true); |
| 208 active_user_->set_is_active(true); | 204 active_user_->set_is_active(true); |
| 209 active_user_->set_username_hash(username_hash); | 205 active_user_->set_username_hash(username_hash); |
| 210 | 206 |
| 211 // Place user who just signed in to the top of the logged in users. | 207 // 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_); | 208 logged_in_users_.insert(logged_in_users_.begin(), active_user_); |
| 213 SetLRUUser(active_user_); | 209 SetLRUUser(active_user_); |
| 214 | 210 |
| 215 if (!primary_user_) { | 211 if (!primary_user_) { |
| 216 primary_user_ = active_user_; | 212 primary_user_ = active_user_; |
| 217 if (primary_user_->GetType() == user_manager::USER_TYPE_REGULAR) | 213 if (primary_user_->GetType() == USER_TYPE_REGULAR) |
| 218 SendRegularUserLoginMetrics(user_id); | 214 SendRegularUserLoginMetrics(user_id); |
| 219 } | 215 } |
| 220 | 216 |
| 221 UMA_HISTOGRAM_ENUMERATION("UserManager.LoginUserType", | 217 UMA_HISTOGRAM_ENUMERATION( |
| 222 active_user_->GetType(), | 218 "UserManager.LoginUserType", active_user_->GetType(), NUM_USER_TYPES); |
| 223 user_manager::NUM_USER_TYPES); | |
| 224 | 219 |
| 225 GetLocalState()->SetString( | 220 GetLocalState()->SetString( |
| 226 kLastLoggedInRegularUser, | 221 kLastLoggedInRegularUser, |
| 227 (active_user_->GetType() == user_manager::USER_TYPE_REGULAR) ? user_id | 222 (active_user_->GetType() == USER_TYPE_REGULAR) ? user_id : ""); |
| 228 : ""); | |
| 229 | 223 |
| 230 NotifyOnLogin(); | 224 NotifyOnLogin(); |
| 231 PerformPostUserLoggedInActions(browser_restart); | 225 PerformPostUserLoggedInActions(browser_restart); |
| 232 } | 226 } |
| 233 | 227 |
| 234 void UserManagerBase::SwitchActiveUser(const std::string& user_id) { | 228 void UserManagerBase::SwitchActiveUser(const std::string& user_id) { |
| 235 user_manager::User* user = FindUserAndModify(user_id); | 229 User* user = FindUserAndModify(user_id); |
| 236 if (!user) { | 230 if (!user) { |
| 237 NOTREACHED() << "Switching to a non-existing user"; | 231 NOTREACHED() << "Switching to a non-existing user"; |
| 238 return; | 232 return; |
| 239 } | 233 } |
| 240 if (user == active_user_) { | 234 if (user == active_user_) { |
| 241 NOTREACHED() << "Switching to a user who is already active"; | 235 NOTREACHED() << "Switching to a user who is already active"; |
| 242 return; | 236 return; |
| 243 } | 237 } |
| 244 if (!user->is_logged_in()) { | 238 if (!user->is_logged_in()) { |
| 245 NOTREACHED() << "Switching to a user that is not logged in"; | 239 NOTREACHED() << "Switching to a user that is not logged in"; |
| 246 return; | 240 return; |
| 247 } | 241 } |
| 248 if (user->GetType() != user_manager::USER_TYPE_REGULAR) { | 242 if (user->GetType() != USER_TYPE_REGULAR) { |
| 249 NOTREACHED() << "Switching to a non-regular user"; | 243 NOTREACHED() << "Switching to a non-regular user"; |
| 250 return; | 244 return; |
| 251 } | 245 } |
| 252 if (user->username_hash().empty()) { | 246 if (user->username_hash().empty()) { |
| 253 NOTREACHED() << "Switching to a user that doesn't have username_hash set"; | 247 NOTREACHED() << "Switching to a user that doesn't have username_hash set"; |
| 254 return; | 248 return; |
| 255 } | 249 } |
| 256 | 250 |
| 257 DCHECK(active_user_); | 251 DCHECK(active_user_); |
| 258 active_user_->set_is_active(false); | 252 active_user_->set_is_active(false); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 } | 319 } |
| 326 | 320 |
| 327 // Make sure that new data is persisted to Local State. | 321 // Make sure that new data is persisted to Local State. |
| 328 GetLocalState()->CommitPendingWrite(); | 322 GetLocalState()->CommitPendingWrite(); |
| 329 } | 323 } |
| 330 | 324 |
| 331 bool UserManagerBase::IsKnownUser(const std::string& user_id) const { | 325 bool UserManagerBase::IsKnownUser(const std::string& user_id) const { |
| 332 return FindUser(user_id) != NULL; | 326 return FindUser(user_id) != NULL; |
| 333 } | 327 } |
| 334 | 328 |
| 335 const user_manager::User* UserManagerBase::FindUser( | 329 const User* UserManagerBase::FindUser(const std::string& user_id) const { |
| 336 const std::string& user_id) const { | |
| 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 338 if (active_user_ && active_user_->email() == user_id) | 331 if (active_user_ && active_user_->email() == user_id) |
| 339 return active_user_; | 332 return active_user_; |
| 340 return FindUserInList(user_id); | 333 return FindUserInList(user_id); |
| 341 } | 334 } |
| 342 | 335 |
| 343 user_manager::User* UserManagerBase::FindUserAndModify( | 336 User* UserManagerBase::FindUserAndModify(const std::string& user_id) { |
| 344 const std::string& user_id) { | |
| 345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 346 if (active_user_ && active_user_->email() == user_id) | 338 if (active_user_ && active_user_->email() == user_id) |
| 347 return active_user_; | 339 return active_user_; |
| 348 return FindUserInListAndModify(user_id); | 340 return FindUserInListAndModify(user_id); |
| 349 } | 341 } |
| 350 | 342 |
| 351 const user_manager::User* UserManagerBase::GetLoggedInUser() const { | 343 const User* UserManagerBase::GetLoggedInUser() const { |
| 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 353 return active_user_; | 345 return active_user_; |
| 354 } | 346 } |
| 355 | 347 |
| 356 user_manager::User* UserManagerBase::GetLoggedInUser() { | 348 User* UserManagerBase::GetLoggedInUser() { |
| 357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 358 return active_user_; | 350 return active_user_; |
| 359 } | 351 } |
| 360 | 352 |
| 361 const user_manager::User* UserManagerBase::GetActiveUser() const { | 353 const User* UserManagerBase::GetActiveUser() const { |
| 362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 363 return active_user_; | 355 return active_user_; |
| 364 } | 356 } |
| 365 | 357 |
| 366 user_manager::User* UserManagerBase::GetActiveUser() { | 358 User* UserManagerBase::GetActiveUser() { |
| 367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 368 return active_user_; | 360 return active_user_; |
| 369 } | 361 } |
| 370 | 362 |
| 371 const user_manager::User* UserManagerBase::GetPrimaryUser() const { | 363 const User* UserManagerBase::GetPrimaryUser() const { |
| 372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 373 return primary_user_; | 365 return primary_user_; |
| 374 } | 366 } |
| 375 | 367 |
| 376 void UserManagerBase::SaveUserOAuthStatus( | 368 void UserManagerBase::SaveUserOAuthStatus( |
| 377 const std::string& user_id, | 369 const std::string& user_id, |
| 378 user_manager::User::OAuthTokenStatus oauth_token_status) { | 370 User::OAuthTokenStatus oauth_token_status) { |
| 379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 380 | 372 |
| 381 DVLOG(1) << "Saving user OAuth token status in Local State"; | 373 DVLOG(1) << "Saving user OAuth token status in Local State"; |
| 382 user_manager::User* user = FindUserAndModify(user_id); | 374 User* user = FindUserAndModify(user_id); |
| 383 if (user) | 375 if (user) |
| 384 user->set_oauth_token_status(oauth_token_status); | 376 user->set_oauth_token_status(oauth_token_status); |
| 385 | 377 |
| 386 // Do not update local state if data stored or cached outside the user's | 378 // Do not update local state if data stored or cached outside the user's |
| 387 // cryptohome is to be treated as ephemeral. | 379 // cryptohome is to be treated as ephemeral. |
| 388 if (IsUserNonCryptohomeDataEphemeral(user_id)) | 380 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
| 389 return; | 381 return; |
| 390 | 382 |
| 391 DictionaryPrefUpdate oauth_status_update(GetLocalState(), | 383 DictionaryPrefUpdate oauth_status_update(GetLocalState(), |
| 392 kUserOAuthTokenStatus); | 384 kUserOAuthTokenStatus); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 407 DictionaryPrefUpdate force_online_update(GetLocalState(), | 399 DictionaryPrefUpdate force_online_update(GetLocalState(), |
| 408 kUserForceOnlineSignin); | 400 kUserForceOnlineSignin); |
| 409 force_online_update->SetBooleanWithoutPathExpansion(user_id, | 401 force_online_update->SetBooleanWithoutPathExpansion(user_id, |
| 410 force_online_signin); | 402 force_online_signin); |
| 411 } | 403 } |
| 412 | 404 |
| 413 void UserManagerBase::SaveUserDisplayName(const std::string& user_id, | 405 void UserManagerBase::SaveUserDisplayName(const std::string& user_id, |
| 414 const base::string16& display_name) { | 406 const base::string16& display_name) { |
| 415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 416 | 408 |
| 417 if (user_manager::User* user = FindUserAndModify(user_id)) { | 409 if (User* user = FindUserAndModify(user_id)) { |
| 418 user->set_display_name(display_name); | 410 user->set_display_name(display_name); |
| 419 | 411 |
| 420 // Do not update local state if data stored or cached outside the user's | 412 // Do not update local state if data stored or cached outside the user's |
| 421 // cryptohome is to be treated as ephemeral. | 413 // cryptohome is to be treated as ephemeral. |
| 422 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { | 414 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { |
| 423 DictionaryPrefUpdate display_name_update(GetLocalState(), | 415 DictionaryPrefUpdate display_name_update(GetLocalState(), |
| 424 kUserDisplayName); | 416 kUserDisplayName); |
| 425 display_name_update->SetWithoutPathExpansion( | 417 display_name_update->SetWithoutPathExpansion( |
| 426 user_id, new base::StringValue(display_name)); | 418 user_id, new base::StringValue(display_name)); |
| 427 } | 419 } |
| 428 } | 420 } |
| 429 } | 421 } |
| 430 | 422 |
| 431 base::string16 UserManagerBase::GetUserDisplayName( | 423 base::string16 UserManagerBase::GetUserDisplayName( |
| 432 const std::string& user_id) const { | 424 const std::string& user_id) const { |
| 433 const user_manager::User* user = FindUser(user_id); | 425 const User* user = FindUser(user_id); |
| 434 return user ? user->display_name() : base::string16(); | 426 return user ? user->display_name() : base::string16(); |
| 435 } | 427 } |
| 436 | 428 |
| 437 void UserManagerBase::SaveUserDisplayEmail(const std::string& user_id, | 429 void UserManagerBase::SaveUserDisplayEmail(const std::string& user_id, |
| 438 const std::string& display_email) { | 430 const std::string& display_email) { |
| 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 440 | 432 |
| 441 user_manager::User* user = FindUserAndModify(user_id); | 433 User* user = FindUserAndModify(user_id); |
| 442 if (!user) | 434 if (!user) |
| 443 return; // Ignore if there is no such user. | 435 return; // Ignore if there is no such user. |
| 444 | 436 |
| 445 user->set_display_email(display_email); | 437 user->set_display_email(display_email); |
| 446 | 438 |
| 447 // Do not update local state if data stored or cached outside the user's | 439 // Do not update local state if data stored or cached outside the user's |
| 448 // cryptohome is to be treated as ephemeral. | 440 // cryptohome is to be treated as ephemeral. |
| 449 if (IsUserNonCryptohomeDataEphemeral(user_id)) | 441 if (IsUserNonCryptohomeDataEphemeral(user_id)) |
| 450 return; | 442 return; |
| 451 | 443 |
| 452 DictionaryPrefUpdate display_email_update(GetLocalState(), kUserDisplayEmail); | 444 DictionaryPrefUpdate display_email_update(GetLocalState(), kUserDisplayEmail); |
| 453 display_email_update->SetWithoutPathExpansion( | 445 display_email_update->SetWithoutPathExpansion( |
| 454 user_id, new base::StringValue(display_email)); | 446 user_id, new base::StringValue(display_email)); |
| 455 } | 447 } |
| 456 | 448 |
| 457 std::string UserManagerBase::GetUserDisplayEmail( | 449 std::string UserManagerBase::GetUserDisplayEmail( |
| 458 const std::string& user_id) const { | 450 const std::string& user_id) const { |
| 459 const user_manager::User* user = FindUser(user_id); | 451 const User* user = FindUser(user_id); |
| 460 return user ? user->display_email() : user_id; | 452 return user ? user->display_email() : user_id; |
| 461 } | 453 } |
| 462 | 454 |
| 463 void UserManagerBase::UpdateUserAccountData( | 455 void UserManagerBase::UpdateUserAccountData( |
| 464 const std::string& user_id, | 456 const std::string& user_id, |
| 465 const UserAccountData& account_data) { | 457 const UserAccountData& account_data) { |
| 466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 467 | 459 |
| 468 SaveUserDisplayName(user_id, account_data.display_name()); | 460 SaveUserDisplayName(user_id, account_data.display_name()); |
| 469 | 461 |
| 470 if (user_manager::User* user = FindUserAndModify(user_id)) { | 462 if (User* user = FindUserAndModify(user_id)) { |
| 471 base::string16 given_name = account_data.given_name(); | 463 base::string16 given_name = account_data.given_name(); |
| 472 user->set_given_name(given_name); | 464 user->set_given_name(given_name); |
| 473 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { | 465 if (!IsUserNonCryptohomeDataEphemeral(user_id)) { |
| 474 DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName); | 466 DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName); |
| 475 given_name_update->SetWithoutPathExpansion( | 467 given_name_update->SetWithoutPathExpansion( |
| 476 user_id, new base::StringValue(given_name)); | 468 user_id, new base::StringValue(given_name)); |
| 477 } | 469 } |
| 478 } | 470 } |
| 479 | 471 |
| 480 UpdateUserAccountLocale(user_id, account_data.locale()); | 472 UpdateUserAccountLocale(user_id, account_data.locale()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 return IsUserLoggedIn() && active_user_->can_lock(); | 525 return IsUserLoggedIn() && active_user_->can_lock(); |
| 534 } | 526 } |
| 535 | 527 |
| 536 bool UserManagerBase::IsUserLoggedIn() const { | 528 bool UserManagerBase::IsUserLoggedIn() const { |
| 537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 538 return active_user_; | 530 return active_user_; |
| 539 } | 531 } |
| 540 | 532 |
| 541 bool UserManagerBase::IsLoggedInAsRegularUser() const { | 533 bool UserManagerBase::IsLoggedInAsRegularUser() const { |
| 542 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 543 return IsUserLoggedIn() && | 535 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_REGULAR; |
| 544 active_user_->GetType() == user_manager::USER_TYPE_REGULAR; | |
| 545 } | 536 } |
| 546 | 537 |
| 547 bool UserManagerBase::IsLoggedInAsDemoUser() const { | 538 bool UserManagerBase::IsLoggedInAsDemoUser() const { |
| 548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 539 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 549 return IsUserLoggedIn() && | 540 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_RETAIL_MODE; |
| 550 active_user_->GetType() == user_manager::USER_TYPE_RETAIL_MODE; | |
| 551 } | 541 } |
| 552 | 542 |
| 553 bool UserManagerBase::IsLoggedInAsPublicAccount() const { | 543 bool UserManagerBase::IsLoggedInAsPublicAccount() const { |
| 554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 555 return IsUserLoggedIn() && | 545 return IsUserLoggedIn() && |
| 556 active_user_->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT; | 546 active_user_->GetType() == USER_TYPE_PUBLIC_ACCOUNT; |
| 557 } | 547 } |
| 558 | 548 |
| 559 bool UserManagerBase::IsLoggedInAsGuest() const { | 549 bool UserManagerBase::IsLoggedInAsGuest() const { |
| 560 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 561 return IsUserLoggedIn() && | 551 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_GUEST; |
| 562 active_user_->GetType() == user_manager::USER_TYPE_GUEST; | |
| 563 } | 552 } |
| 564 | 553 |
| 565 bool UserManagerBase::IsLoggedInAsSupervisedUser() const { | 554 bool UserManagerBase::IsLoggedInAsSupervisedUser() const { |
| 566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 567 return IsUserLoggedIn() && | 556 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_SUPERVISED; |
| 568 active_user_->GetType() == user_manager::USER_TYPE_SUPERVISED; | |
| 569 } | 557 } |
| 570 | 558 |
| 571 bool UserManagerBase::IsLoggedInAsKioskApp() const { | 559 bool UserManagerBase::IsLoggedInAsKioskApp() const { |
| 572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 560 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 573 return IsUserLoggedIn() && | 561 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_KIOSK_APP; |
| 574 active_user_->GetType() == user_manager::USER_TYPE_KIOSK_APP; | |
| 575 } | 562 } |
| 576 | 563 |
| 577 bool UserManagerBase::IsLoggedInAsStub() const { | 564 bool UserManagerBase::IsLoggedInAsStub() const { |
| 578 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 565 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 579 return IsUserLoggedIn() && active_user_->email() == login::kStubUser; | 566 return IsUserLoggedIn() && |
| 567 active_user_->email() == chromeos::login::kStubUser; | |
| 580 } | 568 } |
| 581 | 569 |
| 582 bool UserManagerBase::IsSessionStarted() const { | 570 bool UserManagerBase::IsSessionStarted() const { |
| 583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 584 return session_started_; | 572 return session_started_; |
| 585 } | 573 } |
| 586 | 574 |
| 587 bool UserManagerBase::IsUserNonCryptohomeDataEphemeral( | 575 bool UserManagerBase::IsUserNonCryptohomeDataEphemeral( |
| 588 const std::string& user_id) const { | 576 const std::string& user_id) const { |
| 589 // Data belonging to the guest, retail mode and stub users is always | 577 // Data belonging to the guest, retail mode and stub users is always |
| 590 // ephemeral. | 578 // ephemeral. |
| 591 if (user_id == login::kGuestUserName || | 579 if (user_id == chromeos::login::kGuestUserName || |
| 592 user_id == login::kRetailModeUserName || user_id == login::kStubUser) { | 580 user_id == chromeos::login::kRetailModeUserName || |
| 581 user_id == chromeos::login::kStubUser) { | |
| 593 return true; | 582 return true; |
| 594 } | 583 } |
| 595 | 584 |
| 596 // Data belonging to the owner, anyone found on the user list and obsolete | 585 // 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. | 586 // public accounts whose data has not been removed yet is not ephemeral. |
| 598 if (user_id == GetOwnerEmail() || UserExistsInList(user_id) || | 587 if (user_id == GetOwnerEmail() || UserExistsInList(user_id) || |
| 599 IsPublicAccountMarkedForRemoval(user_id)) { | 588 IsPublicAccountMarkedForRemoval(user_id)) { |
| 600 return false; | 589 return false; |
| 601 } | 590 } |
| 602 | 591 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 641 session_state_observer_list_.RemoveObserver(obs); | 630 session_state_observer_list_.RemoveObserver(obs); |
| 642 } | 631 } |
| 643 | 632 |
| 644 void UserManagerBase::NotifyLocalStateChanged() { | 633 void UserManagerBase::NotifyLocalStateChanged() { |
| 645 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 646 FOR_EACH_OBSERVER( | 635 FOR_EACH_OBSERVER( |
| 647 UserManager::Observer, observer_list_, LocalStateChanged(this)); | 636 UserManager::Observer, observer_list_, LocalStateChanged(this)); |
| 648 } | 637 } |
| 649 | 638 |
| 650 bool UserManagerBase::CanUserBeRemoved(const user_manager::User* user) const { | 639 bool UserManagerBase::CanUserBeRemoved(const User* user) const { |
| 651 // Only regular and supervised users are allowed to be manually removed. | 640 // Only regular and supervised users are allowed to be manually removed. |
| 652 if (!user || (user->GetType() != user_manager::USER_TYPE_REGULAR && | 641 if (!user || (user->GetType() != USER_TYPE_REGULAR && |
| 653 user->GetType() != user_manager::USER_TYPE_SUPERVISED)) { | 642 user->GetType() != USER_TYPE_SUPERVISED)) { |
| 654 return false; | 643 return false; |
| 655 } | 644 } |
| 656 | 645 |
| 657 // Sanity check: we must not remove single user unless it's an enterprise | 646 // 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 | 647 // 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 | 648 // 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 | 649 // in order not to remove an owner. However due to non-instant nature of |
| 661 // ownership assignment this later check may sometimes fail. | 650 // ownership assignment this later check may sometimes fail. |
| 662 // See http://crosbug.com/12723 | 651 // See http://crosbug.com/12723 |
| 663 if (users_.size() < 2 && !IsEnterpriseManaged()) | 652 if (users_.size() < 2 && !IsEnterpriseManaged()) |
| 664 return false; | 653 return false; |
| 665 | 654 |
| 666 // Sanity check: do not allow any of the the logged in users to be removed. | 655 // 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(); | 656 for (UserList::const_iterator it = logged_in_users_.begin(); |
| 668 it != logged_in_users_.end(); | 657 it != logged_in_users_.end(); |
| 669 ++it) { | 658 ++it) { |
| 670 if ((*it)->email() == user->email()) | 659 if ((*it)->email() == user->email()) |
| 671 return false; | 660 return false; |
| 672 } | 661 } |
| 673 | 662 |
| 674 return true; | 663 return true; |
| 675 } | 664 } |
| 676 | 665 |
| 677 bool UserManagerBase::GetEphemeralUsersEnabled() const { | 666 bool UserManagerBase::GetEphemeralUsersEnabled() const { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 // Load regular users and supervised users. | 716 // Load regular users and supervised users. |
| 728 std::vector<std::string> regular_users; | 717 std::vector<std::string> regular_users; |
| 729 std::set<std::string> regular_users_set; | 718 std::set<std::string> regular_users_set; |
| 730 ParseUserList(*prefs_regular_users, | 719 ParseUserList(*prefs_regular_users, |
| 731 public_sessions_set, | 720 public_sessions_set, |
| 732 ®ular_users, | 721 ®ular_users, |
| 733 ®ular_users_set); | 722 ®ular_users_set); |
| 734 for (std::vector<std::string>::const_iterator it = regular_users.begin(); | 723 for (std::vector<std::string>::const_iterator it = regular_users.begin(); |
| 735 it != regular_users.end(); | 724 it != regular_users.end(); |
| 736 ++it) { | 725 ++it) { |
| 737 user_manager::User* user = NULL; | 726 User* user = NULL; |
| 738 const std::string domain = gaia::ExtractDomainName(*it); | 727 const std::string domain = gaia::ExtractDomainName(*it); |
| 739 if (domain == chromeos::login::kSupervisedUserDomain) | 728 if (domain == chromeos::login::kSupervisedUserDomain) |
| 740 user = user_manager::User::CreateSupervisedUser(*it); | 729 user = User::CreateSupervisedUser(*it); |
| 741 else | 730 else |
| 742 user = user_manager::User::CreateRegularUser(*it); | 731 user = User::CreateRegularUser(*it); |
| 743 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); | 732 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); |
| 744 user->set_force_online_signin(LoadForceOnlineSignin(*it)); | 733 user->set_force_online_signin(LoadForceOnlineSignin(*it)); |
| 745 users_.push_back(user); | 734 users_.push_back(user); |
| 746 | 735 |
| 747 base::string16 display_name; | 736 base::string16 display_name; |
| 748 if (prefs_display_names->GetStringWithoutPathExpansion(*it, | 737 if (prefs_display_names->GetStringWithoutPathExpansion(*it, |
| 749 &display_name)) { | 738 &display_name)) { |
| 750 user->set_display_name(display_name); | 739 user->set_display_name(display_name); |
| 751 } | 740 } |
| 752 | 741 |
| 753 base::string16 given_name; | 742 base::string16 given_name; |
| 754 if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) { | 743 if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) { |
| 755 user->set_given_name(given_name); | 744 user->set_given_name(given_name); |
| 756 } | 745 } |
| 757 | 746 |
| 758 std::string display_email; | 747 std::string display_email; |
| 759 if (prefs_display_emails->GetStringWithoutPathExpansion(*it, | 748 if (prefs_display_emails->GetStringWithoutPathExpansion(*it, |
| 760 &display_email)) { | 749 &display_email)) { |
| 761 user->set_display_email(display_email); | 750 user->set_display_email(display_email); |
| 762 } | 751 } |
| 763 } | 752 } |
| 764 | 753 |
| 765 user_loading_stage_ = STAGE_LOADED; | 754 user_loading_stage_ = STAGE_LOADED; |
| 766 | 755 |
| 767 PerformPostUserListLoadingActions(); | 756 PerformPostUserListLoadingActions(); |
| 768 } | 757 } |
| 769 | 758 |
| 770 user_manager::UserList& UserManagerBase::GetUsersAndModify() { | 759 UserList& UserManagerBase::GetUsersAndModify() { |
| 771 EnsureUsersLoaded(); | 760 EnsureUsersLoaded(); |
| 772 return users_; | 761 return users_; |
| 773 } | 762 } |
| 774 | 763 |
| 775 const user_manager::User* UserManagerBase::FindUserInList( | 764 const User* UserManagerBase::FindUserInList(const std::string& user_id) const { |
| 776 const std::string& user_id) const { | 765 const UserList& users = GetUsers(); |
| 777 const user_manager::UserList& users = GetUsers(); | 766 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) | 767 if ((*it)->email() == user_id) |
| 782 return *it; | 768 return *it; |
| 783 } | 769 } |
| 784 return NULL; | 770 return NULL; |
| 785 } | 771 } |
| 786 | 772 |
| 787 const bool UserManagerBase::UserExistsInList(const std::string& user_id) const { | 773 const bool UserManagerBase::UserExistsInList(const std::string& user_id) const { |
| 788 const base::ListValue* user_list = GetLocalState()->GetList(kRegularUsers); | 774 const base::ListValue* user_list = GetLocalState()->GetList(kRegularUsers); |
| 789 for (size_t i = 0; i < user_list->GetSize(); ++i) { | 775 for (size_t i = 0; i < user_list->GetSize(); ++i) { |
| 790 std::string email; | 776 std::string email; |
| 791 if (user_list->GetString(i, &email) && (user_id == email)) | 777 if (user_list->GetString(i, &email) && (user_id == email)) |
| 792 return true; | 778 return true; |
| 793 } | 779 } |
| 794 return false; | 780 return false; |
| 795 } | 781 } |
| 796 | 782 |
| 797 user_manager::User* UserManagerBase::FindUserInListAndModify( | 783 User* UserManagerBase::FindUserInListAndModify(const std::string& user_id) { |
| 798 const std::string& user_id) { | 784 UserList& users = GetUsersAndModify(); |
| 799 user_manager::UserList& users = GetUsersAndModify(); | 785 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) | 786 if ((*it)->email() == user_id) |
| 803 return *it; | 787 return *it; |
| 804 } | 788 } |
| 805 return NULL; | 789 return NULL; |
| 806 } | 790 } |
| 807 | 791 |
| 808 void UserManagerBase::GuestUserLoggedIn() { | 792 void UserManagerBase::GuestUserLoggedIn() { |
| 809 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 793 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 810 active_user_ = user_manager::User::CreateGuestUser(); | 794 active_user_ = User::CreateGuestUser(); |
| 811 } | 795 } |
| 812 | 796 |
| 813 void UserManagerBase::AddUserRecord(user_manager::User* user) { | 797 void UserManagerBase::AddUserRecord(User* user) { |
| 814 // Add the user to the front of the user list. | 798 // Add the user to the front of the user list. |
| 815 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); | 799 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); |
| 816 prefs_users_update->Insert(0, new base::StringValue(user->email())); | 800 prefs_users_update->Insert(0, new base::StringValue(user->email())); |
| 817 users_.insert(users_.begin(), user); | 801 users_.insert(users_.begin(), user); |
| 818 } | 802 } |
| 819 | 803 |
| 820 void UserManagerBase::RegularUserLoggedIn(const std::string& user_id) { | 804 void UserManagerBase::RegularUserLoggedIn(const std::string& user_id) { |
| 821 // Remove the user from the user list. | 805 // Remove the user from the user list. |
| 822 active_user_ = RemoveRegularOrSupervisedUserFromList(user_id); | 806 active_user_ = RemoveRegularOrSupervisedUserFromList(user_id); |
| 823 | 807 |
| 824 // If the user was not found on the user list, create a new user. | 808 // If the user was not found on the user list, create a new user. |
| 825 SetIsCurrentUserNew(!active_user_); | 809 SetIsCurrentUserNew(!active_user_); |
| 826 if (IsCurrentUserNew()) { | 810 if (IsCurrentUserNew()) { |
| 827 active_user_ = user_manager::User::CreateRegularUser(user_id); | 811 active_user_ = User::CreateRegularUser(user_id); |
| 828 active_user_->set_oauth_token_status(LoadUserOAuthStatus(user_id)); | 812 active_user_->set_oauth_token_status(LoadUserOAuthStatus(user_id)); |
| 829 SaveUserDisplayName(active_user_->email(), | 813 SaveUserDisplayName(active_user_->email(), |
| 830 base::UTF8ToUTF16(active_user_->GetAccountName(true))); | 814 base::UTF8ToUTF16(active_user_->GetAccountName(true))); |
| 831 } | 815 } |
| 832 | 816 |
| 833 AddUserRecord(active_user_); | 817 AddUserRecord(active_user_); |
| 834 | 818 |
| 835 // Make sure that new data is persisted to Local State. | 819 // Make sure that new data is persisted to Local State. |
| 836 GetLocalState()->CommitPendingWrite(); | 820 GetLocalState()->CommitPendingWrite(); |
| 837 } | 821 } |
| 838 | 822 |
| 839 void UserManagerBase::RegularUserLoggedInAsEphemeral( | 823 void UserManagerBase::RegularUserLoggedInAsEphemeral( |
| 840 const std::string& user_id) { | 824 const std::string& user_id) { |
| 841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 825 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 842 SetIsCurrentUserNew(true); | 826 SetIsCurrentUserNew(true); |
| 843 is_current_user_ephemeral_regular_user_ = true; | 827 is_current_user_ephemeral_regular_user_ = true; |
| 844 active_user_ = user_manager::User::CreateRegularUser(user_id); | 828 active_user_ = User::CreateRegularUser(user_id); |
| 845 } | 829 } |
| 846 | 830 |
| 847 void UserManagerBase::NotifyOnLogin() { | 831 void UserManagerBase::NotifyOnLogin() { |
| 848 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 832 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 849 | 833 |
| 850 NotifyActiveUserHashChanged(active_user_->username_hash()); | 834 NotifyActiveUserHashChanged(active_user_->username_hash()); |
| 851 NotifyActiveUserChanged(active_user_); | 835 NotifyActiveUserChanged(active_user_); |
| 852 UpdateLoginState(); | 836 UpdateLoginState(); |
| 853 } | 837 } |
| 854 | 838 |
| 855 user_manager::User::OAuthTokenStatus UserManagerBase::LoadUserOAuthStatus( | 839 User::OAuthTokenStatus UserManagerBase::LoadUserOAuthStatus( |
| 856 const std::string& user_id) const { | 840 const std::string& user_id) const { |
| 857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 858 | 842 |
| 859 const base::DictionaryValue* prefs_oauth_status = | 843 const base::DictionaryValue* prefs_oauth_status = |
| 860 GetLocalState()->GetDictionary(kUserOAuthTokenStatus); | 844 GetLocalState()->GetDictionary(kUserOAuthTokenStatus); |
| 861 int oauth_token_status = user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; | 845 int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN; |
| 862 if (prefs_oauth_status && | 846 if (prefs_oauth_status && |
| 863 prefs_oauth_status->GetIntegerWithoutPathExpansion(user_id, | 847 prefs_oauth_status->GetIntegerWithoutPathExpansion(user_id, |
| 864 &oauth_token_status)) { | 848 &oauth_token_status)) { |
| 865 user_manager::User::OAuthTokenStatus result = | 849 User::OAuthTokenStatus status = |
| 866 static_cast<user_manager::User::OAuthTokenStatus>(oauth_token_status); | 850 static_cast<User::OAuthTokenStatus>(oauth_token_status); |
| 867 if (result == user_manager::User::OAUTH2_TOKEN_STATUS_INVALID) | 851 HandleUserOAuthTokenStatusChange(user_id, status); |
| 868 GetUserFlow(user_id)->HandleOAuthTokenStatusChange(result); | 852 |
| 869 return result; | 853 return status; |
| 870 } | 854 } |
| 871 return user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; | 855 return User::OAUTH_TOKEN_STATUS_UNKNOWN; |
| 872 } | 856 } |
| 873 | 857 |
| 874 bool UserManagerBase::LoadForceOnlineSignin(const std::string& user_id) const { | 858 bool UserManagerBase::LoadForceOnlineSignin(const std::string& user_id) const { |
| 875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 859 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 876 | 860 |
| 877 const base::DictionaryValue* prefs_force_online = | 861 const base::DictionaryValue* prefs_force_online = |
| 878 GetLocalState()->GetDictionary(kUserForceOnlineSignin); | 862 GetLocalState()->GetDictionary(kUserForceOnlineSignin); |
| 879 bool force_online_signin = false; | 863 bool force_online_signin = false; |
| 880 if (prefs_force_online) { | 864 if (prefs_force_online) { |
| 881 prefs_force_online->GetBooleanWithoutPathExpansion(user_id, | 865 prefs_force_online->GetBooleanWithoutPathExpansion(user_id, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 895 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); | 879 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); |
| 896 prefs_display_email_update->RemoveWithoutPathExpansion(user_id, NULL); | 880 prefs_display_email_update->RemoveWithoutPathExpansion(user_id, NULL); |
| 897 | 881 |
| 898 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | 882 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); |
| 899 prefs_oauth_update->RemoveWithoutPathExpansion(user_id, NULL); | 883 prefs_oauth_update->RemoveWithoutPathExpansion(user_id, NULL); |
| 900 | 884 |
| 901 DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin); | 885 DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin); |
| 902 prefs_force_online_update->RemoveWithoutPathExpansion(user_id, NULL); | 886 prefs_force_online_update->RemoveWithoutPathExpansion(user_id, NULL); |
| 903 } | 887 } |
| 904 | 888 |
| 905 user_manager::User* UserManagerBase::RemoveRegularOrSupervisedUserFromList( | 889 User* UserManagerBase::RemoveRegularOrSupervisedUserFromList( |
| 906 const std::string& user_id) { | 890 const std::string& user_id) { |
| 907 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); | 891 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); |
| 908 prefs_users_update->Clear(); | 892 prefs_users_update->Clear(); |
| 909 user_manager::User* user = NULL; | 893 User* user = NULL; |
| 910 for (user_manager::UserList::iterator it = users_.begin(); | 894 for (UserList::iterator it = users_.begin(); it != users_.end();) { |
| 911 it != users_.end();) { | |
| 912 const std::string user_email = (*it)->email(); | 895 const std::string user_email = (*it)->email(); |
| 913 if (user_email == user_id) { | 896 if (user_email == user_id) { |
| 914 user = *it; | 897 user = *it; |
| 915 it = users_.erase(it); | 898 it = users_.erase(it); |
| 916 } else { | 899 } else { |
| 917 if ((*it)->GetType() == user_manager::USER_TYPE_REGULAR || | 900 if ((*it)->GetType() == USER_TYPE_REGULAR || |
| 918 (*it)->GetType() == user_manager::USER_TYPE_SUPERVISED) { | 901 (*it)->GetType() == USER_TYPE_SUPERVISED) { |
| 919 prefs_users_update->Append(new base::StringValue(user_email)); | 902 prefs_users_update->Append(new base::StringValue(user_email)); |
| 920 } | 903 } |
| 921 ++it; | 904 ++it; |
| 922 } | 905 } |
| 923 } | 906 } |
| 924 return user; | 907 return user; |
| 925 } | 908 } |
| 926 | 909 |
| 927 void UserManagerBase::NotifyActiveUserChanged( | 910 void UserManagerBase::NotifyActiveUserChanged(const User* active_user) { |
| 928 const user_manager::User* active_user) { | |
| 929 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 911 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 930 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 912 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
| 931 session_state_observer_list_, | 913 session_state_observer_list_, |
| 932 ActiveUserChanged(active_user)); | 914 ActiveUserChanged(active_user)); |
| 933 } | 915 } |
| 934 | 916 |
| 935 void UserManagerBase::NotifyUserAddedToSession( | 917 void UserManagerBase::NotifyUserAddedToSession(const User* added_user, |
| 936 const user_manager::User* added_user, | 918 bool user_switch_pending) { |
| 937 bool user_switch_pending) { | |
| 938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 939 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 920 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
| 940 session_state_observer_list_, | 921 session_state_observer_list_, |
| 941 UserAddedToSession(added_user)); | 922 UserAddedToSession(added_user)); |
| 942 } | 923 } |
| 943 | 924 |
| 944 void UserManagerBase::NotifyActiveUserHashChanged(const std::string& hash) { | 925 void UserManagerBase::NotifyActiveUserHashChanged(const std::string& hash) { |
| 945 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 926 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 946 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 927 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
| 947 session_state_observer_list_, | 928 session_state_observer_list_, |
| 948 ActiveUserHashChanged(hash)); | 929 ActiveUserHashChanged(hash)); |
| 949 } | 930 } |
| 950 | 931 |
| 951 void UserManagerBase::UpdateLoginState() { | 932 void UserManagerBase::UpdateLoginState() { |
| 952 if (!LoginState::IsInitialized()) | 933 if (!chromeos::LoginState::IsInitialized()) |
| 953 return; // LoginState may not be intialized in tests. | 934 return; // LoginState may not be intialized in tests. |
| 954 | 935 |
| 955 LoginState::LoggedInState logged_in_state; | 936 chromeos::LoginState::LoggedInState logged_in_state; |
| 956 logged_in_state = | 937 logged_in_state = active_user_ ? chromeos::LoginState::LOGGED_IN_ACTIVE |
| 957 active_user_ ? LoginState::LOGGED_IN_ACTIVE : LoginState::LOGGED_IN_NONE; | 938 : chromeos::LoginState::LOGGED_IN_NONE; |
| 958 | 939 |
| 959 LoginState::LoggedInUserType login_user_type; | 940 chromeos::LoginState::LoggedInUserType login_user_type; |
| 960 if (logged_in_state == LoginState::LOGGED_IN_NONE) | 941 if (logged_in_state == chromeos::LoginState::LOGGED_IN_NONE) |
| 961 login_user_type = LoginState::LOGGED_IN_USER_NONE; | 942 login_user_type = chromeos::LoginState::LOGGED_IN_USER_NONE; |
| 962 else if (is_current_user_owner_) | 943 else if (is_current_user_owner_) |
| 963 login_user_type = LoginState::LOGGED_IN_USER_OWNER; | 944 login_user_type = chromeos::LoginState::LOGGED_IN_USER_OWNER; |
| 964 else if (active_user_->GetType() == user_manager::USER_TYPE_GUEST) | 945 else if (active_user_->GetType() == USER_TYPE_GUEST) |
| 965 login_user_type = LoginState::LOGGED_IN_USER_GUEST; | 946 login_user_type = chromeos::LoginState::LOGGED_IN_USER_GUEST; |
| 966 else if (active_user_->GetType() == user_manager::USER_TYPE_RETAIL_MODE) | 947 else if (active_user_->GetType() == USER_TYPE_RETAIL_MODE) |
| 967 login_user_type = LoginState::LOGGED_IN_USER_RETAIL_MODE; | 948 login_user_type = chromeos::LoginState::LOGGED_IN_USER_RETAIL_MODE; |
| 968 else if (active_user_->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) | 949 else if (active_user_->GetType() == USER_TYPE_PUBLIC_ACCOUNT) |
| 969 login_user_type = LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT; | 950 login_user_type = chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT; |
| 970 else if (active_user_->GetType() == user_manager::USER_TYPE_SUPERVISED) | 951 else if (active_user_->GetType() == USER_TYPE_SUPERVISED) |
| 971 login_user_type = LoginState::LOGGED_IN_USER_SUPERVISED; | 952 login_user_type = chromeos::LoginState::LOGGED_IN_USER_SUPERVISED; |
| 972 else if (active_user_->GetType() == user_manager::USER_TYPE_KIOSK_APP) | 953 else if (active_user_->GetType() == USER_TYPE_KIOSK_APP) |
| 973 login_user_type = LoginState::LOGGED_IN_USER_KIOSK_APP; | 954 login_user_type = chromeos::LoginState::LOGGED_IN_USER_KIOSK_APP; |
| 974 else | 955 else |
| 975 login_user_type = LoginState::LOGGED_IN_USER_REGULAR; | 956 login_user_type = chromeos::LoginState::LOGGED_IN_USER_REGULAR; |
| 976 | 957 |
| 977 if (primary_user_) { | 958 if (primary_user_) { |
| 978 LoginState::Get()->SetLoggedInStateAndPrimaryUser( | 959 chromeos::LoginState::Get()->SetLoggedInStateAndPrimaryUser( |
| 979 logged_in_state, login_user_type, primary_user_->username_hash()); | 960 logged_in_state, login_user_type, primary_user_->username_hash()); |
| 980 } else { | 961 } else { |
| 981 LoginState::Get()->SetLoggedInState(logged_in_state, login_user_type); | 962 chromeos::LoginState::Get()->SetLoggedInState(logged_in_state, |
| 963 login_user_type); | |
| 982 } | 964 } |
| 983 } | 965 } |
| 984 | 966 |
| 985 void UserManagerBase::SetLRUUser(user_manager::User* user) { | 967 void UserManagerBase::SetLRUUser(User* user) { |
| 986 user_manager::UserList::iterator it = | 968 UserList::iterator it = |
| 987 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); | 969 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); |
| 988 if (it != lru_logged_in_users_.end()) | 970 if (it != lru_logged_in_users_.end()) |
| 989 lru_logged_in_users_.erase(it); | 971 lru_logged_in_users_.erase(it); |
| 990 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); | 972 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); |
| 991 } | 973 } |
| 992 | 974 |
| 993 void UserManagerBase::SendRegularUserLoginMetrics(const std::string& user_id) { | 975 void UserManagerBase::SendRegularUserLoginMetrics(const std::string& user_id) { |
| 994 // If this isn't the first time Chrome was run after the system booted, | 976 // 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. | 977 // assume that Chrome was restarted because a previous session ended. |
| 996 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 978 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 997 switches::kFirstExecAfterBoot)) { | 979 chromeos::switches::kFirstExecAfterBoot)) { |
| 998 const std::string last_email = | 980 const std::string last_email = |
| 999 GetLocalState()->GetString(kLastLoggedInRegularUser); | 981 GetLocalState()->GetString(kLastLoggedInRegularUser); |
| 1000 const base::TimeDelta time_to_login = | 982 const base::TimeDelta time_to_login = |
| 1001 base::TimeTicks::Now() - manager_creation_time_; | 983 base::TimeTicks::Now() - manager_creation_time_; |
| 1002 if (!last_email.empty() && user_id != last_email && | 984 if (!last_email.empty() && user_id != last_email && |
| 1003 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { | 985 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { |
| 1004 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", | 986 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", |
| 1005 time_to_login.InSeconds(), | 987 time_to_login.InSeconds(), |
| 1006 0, | 988 0, |
| 1007 kLogoutToLoginDelayMaxSec, | 989 kLogoutToLoginDelayMaxSec, |
| 1008 50); | 990 50); |
| 1009 } | 991 } |
| 1010 } | 992 } |
| 1011 } | 993 } |
| 1012 | 994 |
| 1013 void UserManagerBase::UpdateUserAccountLocale(const std::string& user_id, | 995 void UserManagerBase::UpdateUserAccountLocale(const std::string& user_id, |
| 1014 const std::string& locale) { | 996 const std::string& locale) { |
| 1015 if (!locale.empty() && locale != GetApplicationLocale()) { | 997 if (!locale.empty() && locale != GetApplicationLocale()) { |
| 1016 base::Callback<void(const std::string&)> on_resolve_callback = | 998 base::Callback<void(const std::string&)> on_resolve_callback = |
| 1017 base::Bind(&UserManagerBase::DoUpdateAccountLocale, | 999 base::Bind(&UserManagerBase::DoUpdateAccountLocale, |
| 1018 weak_factory_.GetWeakPtr(), | 1000 weak_factory_.GetWeakPtr(), |
| 1019 user_id); | 1001 user_id); |
| 1020 BrowserThread::PostBlockingPoolTask(FROM_HERE, | 1002 BrowserThread::PostBlockingPoolTask( |
| 1021 base::Bind(ResolveLocale, | 1003 FROM_HERE, base::Bind(ResolveLocale, locale, on_resolve_callback)); |
| 1022 locale, | |
| 1023 on_resolve_callback)); | |
| 1024 } else { | 1004 } else { |
| 1025 DoUpdateAccountLocale(user_id, locale); | 1005 DoUpdateAccountLocale(user_id, locale); |
| 1026 } | 1006 } |
| 1027 } | 1007 } |
| 1028 | 1008 |
| 1029 void UserManagerBase::DoUpdateAccountLocale( | 1009 void UserManagerBase::DoUpdateAccountLocale( |
| 1030 const std::string& user_id, | 1010 const std::string& user_id, |
| 1031 const std::string& resolved_locale) { | 1011 const std::string& resolved_locale) { |
| 1032 if (user_manager::User* user = FindUserAndModify(user_id)) | 1012 if (User* user = FindUserAndModify(user_id)) |
| 1033 user->SetAccountLocale(resolved_locale); | 1013 user->SetAccountLocale(resolved_locale); |
| 1034 } | 1014 } |
| 1035 | 1015 |
| 1036 void UserManagerBase::DeleteUser(user_manager::User* user) { | 1016 void UserManagerBase::DeleteUser(User* user) { |
| 1037 const bool is_active_user = (user == active_user_); | 1017 const bool is_active_user = (user == active_user_); |
| 1038 delete user; | 1018 delete user; |
| 1039 if (is_active_user) | 1019 if (is_active_user) |
| 1040 active_user_ = NULL; | 1020 active_user_ = NULL; |
| 1041 } | 1021 } |
| 1042 | 1022 |
| 1043 } // namespace chromeos | 1023 } // namespace user_manager |
| OLD | NEW |