Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
| 6 | 6 |
| 7 #include <cstddef> | |
| 8 #include <set> | |
| 9 #include <vector> | |
| 10 | |
| 7 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 8 #include "base/bind.h" | 12 #include "base/bind.h" |
| 9 #include "base/chromeos/chromeos_version.h" | 13 #include "base/chromeos/chromeos_version.h" |
| 10 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 11 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 12 #include "base/file_path.h" | 16 #include "base/file_path.h" |
| 13 #include "base/file_util.h" | 17 #include "base/file_util.h" |
| 14 #include "base/logging.h" | 18 #include "base/logging.h" |
| 15 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
| 16 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 17 #include "base/values.h" | 21 #include "base/values.h" |
| 18 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chromeos/cros/cert_library.h" | 23 #include "chrome/browser/chromeos/cros/cert_library.h" |
| 20 #include "chrome/browser/chromeos/cros/cros_library.h" | 24 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 21 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 25 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 22 #include "chrome/browser/chromeos/login/login_display.h" | 26 #include "chrome/browser/chromeos/login/login_display.h" |
| 23 #include "chrome/browser/chromeos/login/remove_user_delegate.h" | 27 #include "chrome/browser/chromeos/login/remove_user_delegate.h" |
| 24 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" | 28 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" |
| 25 #include "chrome/browser/chromeos/login/wizard_controller.h" | 29 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 26 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
| 27 #include "chrome/browser/policy/browser_policy_connector.h" | 30 #include "chrome/browser/policy/browser_policy_connector.h" |
| 28 #include "chrome/browser/prefs/pref_service.h" | 31 #include "chrome/browser/prefs/pref_service.h" |
| 29 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 32 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 30 #include "chrome/browser/profiles/profile_manager.h" | 33 #include "chrome/browser/profiles/profile_manager.h" |
| 31 #include "chrome/browser/sync/profile_sync_service.h" | 34 #include "chrome/browser/sync/profile_sync_service.h" |
| 32 #include "chrome/browser/sync/profile_sync_service_factory.h" | 35 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 33 #include "chrome/common/chrome_notification_types.h" | 36 #include "chrome/common/chrome_notification_types.h" |
| 34 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 36 #include "chromeos/cryptohome/async_method_caller.h" | 39 #include "chromeos/cryptohome/async_method_caller.h" |
| 37 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/notification_service.h" | 41 #include "content/public/browser/notification_service.h" |
| 39 #include "google_apis/gaia/google_service_auth_error.h" | 42 #include "google_apis/gaia/google_service_auth_error.h" |
| 40 | 43 |
| 41 using content::BrowserThread; | 44 using content::BrowserThread; |
| 42 | 45 |
| 43 namespace chromeos { | 46 namespace chromeos { |
| 44 | 47 |
| 45 namespace { | 48 namespace { |
| 46 | 49 |
| 47 // A vector pref of the users who have logged into the device. | 50 // A vector pref of the the regular users known on this device, arranged in LRU |
| 48 const char kLoggedInUsers[] = "LoggedInUsers"; | 51 // order. |
| 52 const char kRegularUsers[] = "LoggedInUsers"; | |
| 53 | |
| 54 // A vector pref of the public accounts defined on this device. | |
| 55 const char kPublicAccounts[] = "PublicAccounts"; | |
| 56 | |
| 57 // A string pref that gets set when a public account is removed but a user is | |
| 58 // currently logged into that account, requiring the account's data to be | |
| 59 // removed after logout. | |
| 60 const char kPublicAccountPendingDataRemoval[] = | |
| 61 "PublicAccountPendingDataRemoval"; | |
| 49 | 62 |
| 50 // A dictionary that maps usernames to the displayed name. | 63 // A dictionary that maps usernames to the displayed name. |
| 51 const char kUserDisplayName[] = "UserDisplayName"; | 64 const char kUserDisplayName[] = "UserDisplayName"; |
| 52 | 65 |
| 53 // A dictionary that maps usernames to the displayed (non-canonical) emails. | 66 // A dictionary that maps usernames to the displayed (non-canonical) emails. |
| 54 const char kUserDisplayEmail[] = "UserDisplayEmail"; | 67 const char kUserDisplayEmail[] = "UserDisplayEmail"; |
| 55 | 68 |
| 56 // A dictionary that maps usernames to OAuth token presence flag. | 69 // A dictionary that maps usernames to OAuth token presence flag. |
| 57 const char kUserOAuthTokenStatus[] = "OAuthTokenStatus"; | 70 const char kUserOAuthTokenStatus[] = "OAuthTokenStatus"; |
| 58 | 71 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 delegate->OnBeforeUserRemoved(user_email); | 103 delegate->OnBeforeUserRemoved(user_email); |
| 91 | 104 |
| 92 chromeos::UserManager::Get()->RemoveUserFromList(user_email); | 105 chromeos::UserManager::Get()->RemoveUserFromList(user_email); |
| 93 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( | 106 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
| 94 user_email, base::Bind(&OnRemoveUserComplete, user_email)); | 107 user_email, base::Bind(&OnRemoveUserComplete, user_email)); |
| 95 | 108 |
| 96 if (delegate) | 109 if (delegate) |
| 97 delegate->OnUserRemoved(user_email); | 110 delegate->OnUserRemoved(user_email); |
| 98 } | 111 } |
| 99 | 112 |
| 113 // Helper function that copies users from |users_list| to |users_vector| and | |
| 114 // |users_set|. Duplicates and users already present in |existing_users| are | |
| 115 // skipped. The |logged_in_user| is also skipped and the return value | |
| 116 // indicates whether that user was found in |users_list|. | |
| 117 bool ParseUserList(const ListValue& users_list, | |
| 118 const std::set<std::string>& existing_users, | |
| 119 const std::string& logged_in_user, | |
| 120 std::vector<std::string>* users_vector, | |
| 121 std::set<std::string>* users_set) { | |
| 122 users_vector->clear(); | |
| 123 users_set->clear(); | |
| 124 bool logged_in_user_on_list = false; | |
| 125 for (size_t i = 0; i < users_list.GetSize(); ++i) { | |
| 126 std::string email; | |
| 127 if (!users_list.GetString(i, &email) || email.empty()) { | |
| 128 LOG(ERROR) << "Corrupt entry in user list at index " << i << "."; | |
|
Nikita (slow)
2012/11/30 14:32:57
Wouldn't that be the case for public accounts or t
bartfab (slow)
2012/11/30 14:46:27
Public accounts are defined via (fake) e-mail addr
| |
| 129 continue; | |
| 130 } | |
| 131 if (existing_users.find(email) != existing_users.end() || | |
| 132 !users_set->insert(email).second) { | |
| 133 LOG(ERROR) << "Duplicate user: " << email; | |
| 134 continue; | |
| 135 } | |
| 136 if (email == logged_in_user) { | |
| 137 logged_in_user_on_list = true; | |
| 138 continue; | |
| 139 } | |
| 140 users_vector->push_back(email); | |
| 141 } | |
| 142 users_set->erase(logged_in_user); | |
| 143 return logged_in_user_on_list; | |
| 144 } | |
| 145 | |
| 100 } // namespace | 146 } // namespace |
| 101 | 147 |
| 102 // static | 148 // static |
| 103 void UserManager::RegisterPrefs(PrefService* local_state) { | 149 void UserManager::RegisterPrefs(PrefService* local_state) { |
| 104 local_state->RegisterListPref(kLoggedInUsers, PrefService::UNSYNCABLE_PREF); | 150 local_state->RegisterListPref(kRegularUsers, PrefService::UNSYNCABLE_PREF); |
| 151 local_state->RegisterListPref(kPublicAccounts, PrefService::UNSYNCABLE_PREF); | |
| 152 local_state->RegisterStringPref(kPublicAccountPendingDataRemoval, "", | |
| 153 PrefService::UNSYNCABLE_PREF); | |
| 105 local_state->RegisterDictionaryPref(kUserOAuthTokenStatus, | 154 local_state->RegisterDictionaryPref(kUserOAuthTokenStatus, |
| 106 PrefService::UNSYNCABLE_PREF); | 155 PrefService::UNSYNCABLE_PREF); |
| 107 local_state->RegisterDictionaryPref(kUserDisplayName, | 156 local_state->RegisterDictionaryPref(kUserDisplayName, |
| 108 PrefService::UNSYNCABLE_PREF); | 157 PrefService::UNSYNCABLE_PREF); |
| 109 local_state->RegisterDictionaryPref(kUserDisplayEmail, | 158 local_state->RegisterDictionaryPref(kUserDisplayEmail, |
| 110 PrefService::UNSYNCABLE_PREF); | 159 PrefService::UNSYNCABLE_PREF); |
| 111 } | 160 } |
| 112 | 161 |
| 113 UserManagerImpl::UserManagerImpl() | 162 UserManagerImpl::UserManagerImpl() |
| 114 : logged_in_user_(NULL), | 163 : cros_settings_(CrosSettings::Get()), |
| 164 users_loaded_(false), | |
| 165 logged_in_user_(NULL), | |
| 115 session_started_(false), | 166 session_started_(false), |
| 116 is_current_user_owner_(false), | 167 is_current_user_owner_(false), |
| 117 is_current_user_new_(false), | 168 is_current_user_new_(false), |
| 118 is_current_user_ephemeral_(false), | 169 is_current_user_ephemeral_(false), |
| 119 ephemeral_users_enabled_(false), | 170 ephemeral_users_enabled_(false), |
| 120 observed_sync_service_(NULL), | 171 observed_sync_service_(NULL), |
| 121 user_image_manager_(new UserImageManagerImpl) { | 172 user_image_manager_(new UserImageManagerImpl) { |
| 122 // UserManager instance should be used only on UI thread. | 173 // UserManager instance should be used only on UI thread. |
| 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 124 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, | 175 registrar_.Add(this, chrome::NOTIFICATION_OWNERSHIP_STATUS_CHANGED, |
| 125 content::NotificationService::AllSources()); | 176 content::NotificationService::AllSources()); |
| 126 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, | 177 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED, |
| 127 content::NotificationService::AllSources()); | 178 content::NotificationService::AllSources()); |
| 128 RetrieveTrustedDevicePolicies(); | 179 RetrieveTrustedDevicePolicies(); |
| 129 } | 180 } |
| 130 | 181 |
| 131 UserManagerImpl::~UserManagerImpl() { | 182 UserManagerImpl::~UserManagerImpl() { |
| 132 // Can't use STLDeleteElements because of the private destructor of User. | 183 // Can't use STLDeleteElements because of the private destructor of User. |
| 133 for (size_t i = 0; i < users_.size(); ++i) | 184 for (size_t i = 0; i < users_.size(); ++i) |
| 134 delete users_[i]; | 185 delete users_[i]; |
| 135 users_.clear(); | 186 users_.clear(); |
| 136 if (is_current_user_ephemeral_) | 187 if (is_current_user_ephemeral_) |
| 137 delete logged_in_user_; | 188 delete logged_in_user_; |
| 138 } | 189 } |
| 139 | 190 |
| 191 void UserManagerImpl::Shutdown() { | |
| 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 193 cros_settings_->RemoveSettingsObserver(kAccountsPrefDeviceLocalAccounts, | |
| 194 this); | |
| 195 } | |
| 196 | |
| 140 UserImageManager* UserManagerImpl::GetUserImageManager() { | 197 UserImageManager* UserManagerImpl::GetUserImageManager() { |
| 141 return user_image_manager_.get(); | 198 return user_image_manager_.get(); |
| 142 } | 199 } |
| 143 | 200 |
| 144 const UserList& UserManagerImpl::GetUsers() const { | 201 const UserList& UserManagerImpl::GetUsers() const { |
| 145 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); | 202 const_cast<UserManagerImpl*>(this)->EnsureUsersLoaded(); |
| 146 return users_; | 203 return users_; |
| 147 } | 204 } |
| 148 | 205 |
| 149 void UserManagerImpl::UserLoggedIn(const std::string& email, | 206 void UserManagerImpl::UserLoggedIn(const std::string& email, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 161 return; | 218 return; |
| 162 } | 219 } |
| 163 | 220 |
| 164 if (IsEphemeralUser(email)) { | 221 if (IsEphemeralUser(email)) { |
| 165 EphemeralUserLoggedIn(email); | 222 EphemeralUserLoggedIn(email); |
| 166 return; | 223 return; |
| 167 } | 224 } |
| 168 | 225 |
| 169 EnsureUsersLoaded(); | 226 EnsureUsersLoaded(); |
| 170 | 227 |
| 171 // Clear the prefs view of the users. | 228 // Remove the user from the user list. |
| 172 PrefService* prefs = g_browser_process->local_state(); | 229 logged_in_user_ = RemoveRegularUserFromList(email); |
| 173 ListPrefUpdate prefs_users_update(prefs, kLoggedInUsers); | |
| 174 prefs_users_update->Clear(); | |
| 175 | 230 |
| 176 // Make sure this user is first. | 231 // Add the user to the front of the persistent user list. |
| 177 prefs_users_update->Append(new base::StringValue(email)); | 232 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), |
| 178 UserList::iterator logged_in_user = users_.end(); | 233 kRegularUsers); |
| 179 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { | 234 prefs_users_update->Insert(0, new base::StringValue(email)); |
| 180 std::string user_email = (*it)->email(); | |
| 181 // Skip the most recent user. | |
| 182 if (email != user_email) | |
| 183 prefs_users_update->Append(new base::StringValue(user_email)); | |
| 184 else | |
| 185 logged_in_user = it; | |
| 186 } | |
| 187 | 235 |
| 188 if (logged_in_user == users_.end()) { | 236 // If the user was not found on the user list, create a new user. |
| 237 if (!logged_in_user_) { | |
| 189 is_current_user_new_ = true; | 238 is_current_user_new_ = true; |
| 190 logged_in_user_ = User::CreateRegularUser(email); | 239 logged_in_user_ = User::CreateRegularUser(email); |
| 191 logged_in_user_->set_oauth_token_status(LoadUserOAuthStatus(email)); | 240 logged_in_user_->set_oauth_token_status(LoadUserOAuthStatus(email)); |
| 192 } else { | |
| 193 logged_in_user_ = *logged_in_user; | |
| 194 users_.erase(logged_in_user); | |
| 195 } | |
| 196 // This user must be in the front of the user list. | |
| 197 users_.insert(users_.begin(), logged_in_user_); | |
| 198 | |
| 199 if (is_current_user_new_) { | |
| 200 SaveUserDisplayName(logged_in_user_->email(), | 241 SaveUserDisplayName(logged_in_user_->email(), |
| 201 UTF8ToUTF16(logged_in_user_->GetAccountName(true))); | 242 UTF8ToUTF16(logged_in_user_->GetAccountName(true))); |
| 202 WallpaperManager::Get()->SetInitialUserWallpaper(email, true); | 243 WallpaperManager::Get()->SetInitialUserWallpaper(email, true); |
| 203 } | 244 } |
| 204 | 245 |
| 205 user_image_manager_->UserLoggedIn(email, is_current_user_new_); | 246 user_image_manager_->UserLoggedIn(email, is_current_user_new_); |
| 206 | 247 |
| 207 if (!browser_restart) { | 248 if (!browser_restart) { |
| 208 // For GAIA login flow, logged in user wallpaper may not be loaded. | 249 // For GAIA login flow, logged in user wallpaper may not be loaded. |
| 209 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); | 250 WallpaperManager::Get()->EnsureLoggedInUserWallpaperLoaded(); |
| 210 } | 251 } |
| 211 | 252 |
| 212 // Make sure we persist new user data to Local State. | 253 // Make sure that new data is persisted to Local State. |
| 213 prefs->CommitPendingWrite(); | 254 g_browser_process->local_state()->CommitPendingWrite(); |
| 214 | 255 |
| 215 NotifyOnLogin(); | 256 NotifyOnLogin(); |
| 216 } | 257 } |
| 217 | 258 |
| 218 void UserManagerImpl::RetailModeUserLoggedIn() { | 259 void UserManagerImpl::RetailModeUserLoggedIn() { |
| 219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 220 is_current_user_new_ = true; | 261 is_current_user_new_ = true; |
| 221 is_current_user_ephemeral_ = true; | 262 is_current_user_ephemeral_ = true; |
| 222 logged_in_user_ = User::CreateRetailModeUser(); | 263 logged_in_user_ = User::CreateRetailModeUser(); |
| 223 user_image_manager_->UserLoggedIn(kRetailModeUserEMail, | 264 user_image_manager_->UserLoggedIn(kRetailModeUserEMail, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 246 } | 287 } |
| 247 | 288 |
| 248 void UserManagerImpl::SessionStarted() { | 289 void UserManagerImpl::SessionStarted() { |
| 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 250 session_started_ = true; | 291 session_started_ = true; |
| 251 content::NotificationService::current()->Notify( | 292 content::NotificationService::current()->Notify( |
| 252 chrome::NOTIFICATION_SESSION_STARTED, | 293 chrome::NOTIFICATION_SESSION_STARTED, |
| 253 content::NotificationService::AllSources(), | 294 content::NotificationService::AllSources(), |
| 254 content::NotificationService::NoDetails()); | 295 content::NotificationService::NoDetails()); |
| 255 if (is_current_user_new_) { | 296 if (is_current_user_new_) { |
| 256 // Make sure we persist new user data to Local State. | 297 // Make sure that the new user's data is persisted to Local State. |
| 257 g_browser_process->local_state()->CommitPendingWrite(); | 298 g_browser_process->local_state()->CommitPendingWrite(); |
| 258 } | 299 } |
| 259 } | 300 } |
| 260 | 301 |
| 261 void UserManagerImpl::RemoveUser(const std::string& email, | 302 void UserManagerImpl::RemoveUser(const std::string& email, |
| 262 RemoveUserDelegate* delegate) { | 303 RemoveUserDelegate* delegate) { |
| 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 264 | 305 |
| 265 if (!IsKnownUser(email)) | 306 const User* user = FindUser(email); |
| 307 if (!user || user->GetType() != User::USER_TYPE_REGULAR) | |
| 266 return; | 308 return; |
| 267 | 309 |
| 268 // Sanity check: we must not remove single user. This check may seem | 310 // Sanity check: we must not remove single user. This check may seem |
| 269 // redundant at a first sight because this single user must be an owner and | 311 // redundant at a first sight because this single user must be an owner and |
| 270 // we perform special check later in order not to remove an owner. However | 312 // we perform special check later in order not to remove an owner. However |
| 271 // due to non-instant nature of ownership assignment this later check may | 313 // due to non-instant nature of ownership assignment this later check may |
| 272 // sometimes fail. See http://crosbug.com/12723 | 314 // sometimes fail. See http://crosbug.com/12723 |
| 273 if (users_.size() < 2) | 315 if (users_.size() < 2) |
| 274 return; | 316 return; |
| 275 | 317 |
| 276 // Sanity check: do not allow the logged-in user to remove himself. | 318 // Sanity check: do not allow the logged-in user to remove himself. |
| 277 if (logged_in_user_ && logged_in_user_->email() == email) | 319 if (logged_in_user_ && logged_in_user_->email() == email) |
| 278 return; | 320 return; |
| 279 | 321 |
| 280 RemoveUserInternal(email, delegate); | 322 RemoveUserInternal(email, delegate); |
| 281 } | 323 } |
| 282 | 324 |
| 283 void UserManagerImpl::RemoveUserFromList(const std::string& email) { | 325 void UserManagerImpl::RemoveUserFromList(const std::string& email) { |
| 284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 285 EnsureUsersLoaded(); | 327 EnsureUsersLoaded(); |
| 286 RemoveUserFromListInternal(email); | 328 RemoveNonCryptohomeData(email); |
| 329 delete RemoveRegularUserFromList(email); | |
| 330 // Make sure that new data is persisted to Local State. | |
| 331 g_browser_process->local_state()->CommitPendingWrite(); | |
| 287 } | 332 } |
| 288 | 333 |
| 289 bool UserManagerImpl::IsKnownUser(const std::string& email) const { | 334 bool UserManagerImpl::IsKnownUser(const std::string& email) const { |
| 290 return FindUser(email) != NULL; | 335 return FindUser(email) != NULL; |
| 291 } | 336 } |
| 292 | 337 |
| 293 const User* UserManagerImpl::FindUser(const std::string& email) const { | 338 const User* UserManagerImpl::FindUser(const std::string& email) const { |
| 294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 295 if (logged_in_user_ && logged_in_user_->email() == email) | 340 if (logged_in_user_ && logged_in_user_->email() == email) |
| 296 return logged_in_user_; | 341 return logged_in_user_; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 if (!profile->IsOffTheRecord() && | 467 if (!profile->IsOffTheRecord() && |
| 423 profile == ProfileManager::GetDefaultProfile()) { | 468 profile == ProfileManager::GetDefaultProfile()) { |
| 424 DCHECK(NULL == observed_sync_service_); | 469 DCHECK(NULL == observed_sync_service_); |
| 425 observed_sync_service_ = | 470 observed_sync_service_ = |
| 426 ProfileSyncServiceFactory::GetForProfile(profile); | 471 ProfileSyncServiceFactory::GetForProfile(profile); |
| 427 if (observed_sync_service_) | 472 if (observed_sync_service_) |
| 428 observed_sync_service_->AddObserver(this); | 473 observed_sync_service_->AddObserver(this); |
| 429 } | 474 } |
| 430 } | 475 } |
| 431 break; | 476 break; |
| 477 case chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED: | |
| 478 DCHECK_EQ(*content::Details<const std::string>(details).ptr(), | |
| 479 kAccountsPrefDeviceLocalAccounts); | |
| 480 RetrieveTrustedDevicePolicies(); | |
| 481 break; | |
| 432 default: | 482 default: |
| 433 NOTREACHED(); | 483 NOTREACHED(); |
| 434 } | 484 } |
| 435 } | 485 } |
| 436 | 486 |
| 437 void UserManagerImpl::OnStateChanged() { | 487 void UserManagerImpl::OnStateChanged() { |
| 438 DCHECK(IsUserLoggedIn() && !IsLoggedInAsGuest()); | 488 DCHECK(IsLoggedInAsRegularUser()); |
| 439 GoogleServiceAuthError::State state = | 489 GoogleServiceAuthError::State state = |
| 440 observed_sync_service_->GetAuthError().state(); | 490 observed_sync_service_->GetAuthError().state(); |
| 441 if (state != GoogleServiceAuthError::NONE && | 491 if (state != GoogleServiceAuthError::NONE && |
| 442 state != GoogleServiceAuthError::CONNECTION_FAILED && | 492 state != GoogleServiceAuthError::CONNECTION_FAILED && |
| 443 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE && | 493 state != GoogleServiceAuthError::SERVICE_UNAVAILABLE && |
| 444 state != GoogleServiceAuthError::REQUEST_CANCELED) { | 494 state != GoogleServiceAuthError::REQUEST_CANCELED) { |
| 445 // Invalidate OAuth token to force Gaia sign-in flow. This is needed | 495 // Invalidate OAuth token to force Gaia sign-in flow. This is needed |
| 446 // because sign-out/sign-in solution is suggested to the user. | 496 // because sign-out/sign-in solution is suggested to the user. |
| 447 // TODO(altimofeev): this code isn't needed after crosbug.com/25978 is | 497 // TODO(altimofeev): this code isn't needed after crosbug.com/25978 is |
| 448 // implemented. | 498 // implemented. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 477 bool UserManagerImpl::CanCurrentUserLock() const { | 527 bool UserManagerImpl::CanCurrentUserLock() const { |
| 478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 479 return IsUserLoggedIn() && logged_in_user_->can_lock(); | 529 return IsUserLoggedIn() && logged_in_user_->can_lock(); |
| 480 } | 530 } |
| 481 | 531 |
| 482 bool UserManagerImpl::IsUserLoggedIn() const { | 532 bool UserManagerImpl::IsUserLoggedIn() const { |
| 483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 484 return logged_in_user_; | 534 return logged_in_user_; |
| 485 } | 535 } |
| 486 | 536 |
| 537 bool UserManagerImpl::IsLoggedInAsRegularUser() const { | |
| 538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 539 return IsUserLoggedIn() && | |
| 540 logged_in_user_->GetType() == User::USER_TYPE_REGULAR; | |
| 541 } | |
| 542 | |
| 487 bool UserManagerImpl::IsLoggedInAsDemoUser() const { | 543 bool UserManagerImpl::IsLoggedInAsDemoUser() const { |
| 488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 489 return IsUserLoggedIn() && | 545 return IsUserLoggedIn() && |
| 490 logged_in_user_->GetType() == User::USER_TYPE_RETAIL_MODE; | 546 logged_in_user_->GetType() == User::USER_TYPE_RETAIL_MODE; |
| 491 } | 547 } |
| 492 | 548 |
| 493 bool UserManagerImpl::IsLoggedInAsPublicAccount() const { | 549 bool UserManagerImpl::IsLoggedInAsPublicAccount() const { |
| 494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 495 return IsUserLoggedIn() && | 551 return IsUserLoggedIn() && |
| 496 logged_in_user_->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT; | 552 logged_in_user_->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 } | 602 } |
| 547 | 603 |
| 548 void UserManagerImpl::NotifyLocalStateChanged() { | 604 void UserManagerImpl::NotifyLocalStateChanged() { |
| 549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 550 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, | 606 FOR_EACH_OBSERVER(UserManager::Observer, observer_list_, |
| 551 LocalStateChanged(this)); | 607 LocalStateChanged(this)); |
| 552 } | 608 } |
| 553 | 609 |
| 554 void UserManagerImpl::EnsureUsersLoaded() { | 610 void UserManagerImpl::EnsureUsersLoaded() { |
| 555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 556 if (!users_.empty()) | |
| 557 return; | |
| 558 if (!g_browser_process) | 612 if (!g_browser_process) |
| 559 return; | 613 return; |
| 560 | 614 |
| 615 if (users_loaded_) | |
| 616 return; | |
| 617 users_loaded_ = true; | |
| 618 | |
| 561 PrefService* local_state = g_browser_process->local_state(); | 619 PrefService* local_state = g_browser_process->local_state(); |
| 562 const ListValue* prefs_users = | 620 const ListValue* prefs_regular_users = local_state->GetList(kRegularUsers); |
| 563 local_state->GetList(kLoggedInUsers); | 621 const ListValue* prefs_public_accounts = |
| 622 local_state->GetList(kPublicAccounts); | |
| 564 const DictionaryValue* prefs_display_names = | 623 const DictionaryValue* prefs_display_names = |
| 565 local_state->GetDictionary(kUserDisplayName); | 624 local_state->GetDictionary(kUserDisplayName); |
| 566 const DictionaryValue* prefs_display_emails = | 625 const DictionaryValue* prefs_display_emails = |
| 567 local_state->GetDictionary(kUserDisplayEmail); | 626 local_state->GetDictionary(kUserDisplayEmail); |
| 568 | 627 |
| 569 if (!prefs_users) | 628 // Load regular users. |
| 570 return; | 629 std::vector<std::string> regular_users; |
| 630 std::set<std::string> regular_users_set; | |
| 631 ParseUserList(*prefs_regular_users, std::set<std::string>(), "", | |
| 632 ®ular_users, ®ular_users_set); | |
| 633 for (std::vector<std::string>::const_iterator it = regular_users.begin(); | |
| 634 it != regular_users.end(); ++it) { | |
| 635 User* user = User::CreateRegularUser(*it); | |
| 636 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); | |
| 637 users_.push_back(user); | |
| 571 | 638 |
| 572 for (ListValue::const_iterator it = prefs_users->begin(); | 639 string16 display_name; |
| 573 it != prefs_users->end(); ++it) { | 640 if (prefs_display_names->GetStringWithoutPathExpansion(*it, |
| 574 std::string email; | 641 &display_name)) { |
| 575 if ((*it)->GetAsString(&email)) { | 642 user->set_display_name(display_name); |
| 576 User* user = User::CreateRegularUser(email); | 643 } |
| 577 user->set_oauth_token_status(LoadUserOAuthStatus(email)); | |
| 578 users_.push_back(user); | |
| 579 | 644 |
| 580 string16 display_name; | 645 std::string display_email; |
| 581 if (prefs_display_names && | 646 if (prefs_display_emails->GetStringWithoutPathExpansion(*it, |
| 582 prefs_display_names->GetStringWithoutPathExpansion( | 647 &display_email)) { |
| 583 email, &display_name)) { | 648 user->set_display_email(display_email); |
| 584 user->set_display_name(display_name); | 649 } |
| 585 } | 650 } |
| 586 | 651 |
| 587 std::string display_email; | 652 // Load public accounts. |
| 588 if (prefs_display_emails && | 653 std::vector<std::string> public_accounts; |
| 589 prefs_display_emails->GetStringWithoutPathExpansion( | 654 std::set<std::string> public_accounts_set; |
| 590 email, &display_email)) { | 655 ParseUserList(*prefs_public_accounts, regular_users_set, "", |
| 591 user->set_display_email(display_email); | 656 &public_accounts, &public_accounts_set); |
| 592 } | 657 for (std::vector<std::string>::const_iterator it = public_accounts.begin(); |
| 593 } | 658 it != public_accounts.end(); ++it) { |
| 659 users_.push_back(User::CreatePublicAccountUser(*it)); | |
| 594 } | 660 } |
| 595 | 661 |
| 596 user_image_manager_->LoadUserImages(users_); | 662 user_image_manager_->LoadUserImages(users_); |
| 597 } | 663 } |
| 598 | 664 |
| 599 void UserManagerImpl::RetrieveTrustedDevicePolicies() { | 665 void UserManagerImpl::RetrieveTrustedDevicePolicies() { |
| 600 ephemeral_users_enabled_ = false; | 666 ephemeral_users_enabled_ = false; |
| 601 owner_email_ = ""; | 667 owner_email_ = ""; |
| 602 | 668 |
| 603 CrosSettings* cros_settings = CrosSettings::Get(); | |
| 604 // Schedule a callback if device policy has not yet been verified. | 669 // Schedule a callback if device policy has not yet been verified. |
| 605 if (CrosSettingsProvider::TRUSTED != cros_settings->PrepareTrustedValues( | 670 if (CrosSettingsProvider::TRUSTED != cros_settings_->PrepareTrustedValues( |
| 606 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, | 671 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, |
| 607 base::Unretained(this)))) { | 672 base::Unretained(this)))) { |
| 608 return; | 673 return; |
| 609 } | 674 } |
| 610 | 675 |
| 611 cros_settings->GetBoolean(kAccountsPrefEphemeralUsersEnabled, | 676 cros_settings_->GetBoolean(kAccountsPrefEphemeralUsersEnabled, |
| 612 &ephemeral_users_enabled_); | 677 &ephemeral_users_enabled_); |
| 613 cros_settings->GetString(kDeviceOwner, &owner_email_); | 678 cros_settings_->GetString(kDeviceOwner, &owner_email_); |
| 679 const base::ListValue* public_accounts; | |
| 680 cros_settings_->GetList(kAccountsPrefDeviceLocalAccounts, &public_accounts); | |
| 681 | |
| 682 EnsureUsersLoaded(); | |
| 683 | |
| 684 bool changed = UpdateAndCleanUpPublicAccounts(*public_accounts); | |
| 614 | 685 |
| 615 // If ephemeral users are enabled and we are on the login screen, take this | 686 // If ephemeral users are enabled and we are on the login screen, take this |
| 616 // opportunity to clean up by removing all users except the owner. | 687 // opportunity to clean up by removing all regular users except the owner. |
| 617 if (ephemeral_users_enabled_ && !IsUserLoggedIn()) { | 688 if (ephemeral_users_enabled_ && !IsUserLoggedIn()) { |
| 618 scoped_ptr<base::ListValue> users( | 689 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), |
| 619 g_browser_process->local_state()->GetList(kLoggedInUsers)->DeepCopy()); | 690 kRegularUsers); |
| 620 | 691 prefs_users_update->Clear(); |
| 621 bool changed = false; | 692 for (UserList::iterator it = users_.begin(); it != users_.end(); ) { |
| 622 for (base::ListValue::const_iterator user = users->begin(); | 693 const std::string user_email = (*it)->email(); |
| 623 user != users->end(); ++user) { | 694 if ((*it)->GetType() == User::USER_TYPE_REGULAR && |
| 624 std::string user_email; | 695 user_email != owner_email_) { |
| 625 (*user)->GetAsString(&user_email); | 696 RemoveNonCryptohomeData(user_email); |
| 626 if (user_email != owner_email_) { | 697 delete *it; |
| 627 RemoveUserFromListInternal(user_email); | 698 it = users_.erase(it); |
| 628 changed = true; | 699 changed = true; |
| 700 } else { | |
| 701 prefs_users_update->Append(new base::StringValue(user_email)); | |
| 702 ++it; | |
| 629 } | 703 } |
| 630 } | 704 } |
| 705 } | |
| 631 | 706 |
| 632 if (changed) { | 707 if (changed) { |
| 633 content::NotificationService::current()->Notify( | 708 content::NotificationService::current()->Notify( |
| 634 chrome::NOTIFICATION_POLICY_USER_LIST_CHANGED, | 709 chrome::NOTIFICATION_POLICY_USER_LIST_CHANGED, |
| 635 content::Source<UserManager>(this), | 710 content::Source<UserManager>(this), |
| 636 content::NotificationService::NoDetails()); | 711 content::NotificationService::NoDetails()); |
| 637 } | |
| 638 } | 712 } |
| 713 | |
| 714 cros_settings_->AddSettingsObserver(kAccountsPrefDeviceLocalAccounts, | |
| 715 this); | |
| 639 } | 716 } |
| 640 | 717 |
| 641 bool UserManagerImpl::AreEphemeralUsersEnabled() const { | 718 bool UserManagerImpl::AreEphemeralUsersEnabled() const { |
| 642 return ephemeral_users_enabled_ && | 719 return ephemeral_users_enabled_ && |
| 643 (g_browser_process->browser_policy_connector()->IsEnterpriseManaged() || | 720 (g_browser_process->browser_policy_connector()->IsEnterpriseManaged() || |
| 644 !owner_email_.empty()); | 721 !owner_email_.empty()); |
| 645 } | 722 } |
| 646 | 723 |
| 647 const User* UserManagerImpl::FindUserInList(const std::string& email) const { | 724 const User* UserManagerImpl::FindUserInList(const std::string& email) const { |
| 648 const UserList& users = GetUsers(); | 725 const UserList& users = GetUsers(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 674 | 751 |
| 675 SetCurrentUserIsOwner(is_owner); | 752 SetCurrentUserIsOwner(is_owner); |
| 676 } | 753 } |
| 677 | 754 |
| 678 void UserManagerImpl::CheckOwnership() { | 755 void UserManagerImpl::CheckOwnership() { |
| 679 DeviceSettingsService::Get()->GetOwnershipStatusAsync( | 756 DeviceSettingsService::Get()->GetOwnershipStatusAsync( |
| 680 base::Bind(&UserManagerImpl::UpdateOwnership, | 757 base::Bind(&UserManagerImpl::UpdateOwnership, |
| 681 base::Unretained(this))); | 758 base::Unretained(this))); |
| 682 } | 759 } |
| 683 | 760 |
| 684 void UserManagerImpl::RemoveUserFromListInternal(const std::string& email) { | 761 void UserManagerImpl::RemoveNonCryptohomeData(const std::string& email) { |
| 685 // Clear the prefs view of the users. | 762 WallpaperManager::Get()->RemoveUserWallpaperInfo(email); |
| 763 user_image_manager_->DeleteUserImage(email); | |
| 764 | |
| 686 PrefService* prefs = g_browser_process->local_state(); | 765 PrefService* prefs = g_browser_process->local_state(); |
| 687 ListPrefUpdate prefs_users_update(prefs, kLoggedInUsers); | |
| 688 prefs_users_update->Clear(); | |
| 689 | |
| 690 UserList::iterator user_to_remove = users_.end(); | |
| 691 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { | |
| 692 std::string user_email = (*it)->email(); | |
| 693 // Skip user that we would like to delete. | |
| 694 if (email != user_email) | |
| 695 prefs_users_update->Append(new base::StringValue(user_email)); | |
| 696 else | |
| 697 user_to_remove = it; | |
| 698 } | |
| 699 | |
| 700 WallpaperManager::Get()->RemoveUserWallpaperInfo(email); | |
| 701 | |
| 702 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | 766 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); |
| 703 int oauth_status; | 767 int oauth_status; |
| 704 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); | 768 prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); |
| 705 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); | 769 prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); |
| 706 | 770 |
| 707 DictionaryPrefUpdate prefs_display_name_update(prefs, kUserDisplayName); | 771 DictionaryPrefUpdate prefs_display_name_update(prefs, kUserDisplayName); |
| 708 prefs_display_name_update->RemoveWithoutPathExpansion(email, NULL); | 772 prefs_display_name_update->RemoveWithoutPathExpansion(email, NULL); |
| 709 | 773 |
| 710 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); | 774 DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); |
| 711 prefs_display_email_update->RemoveWithoutPathExpansion(email, NULL); | 775 prefs_display_email_update->RemoveWithoutPathExpansion(email, NULL); |
| 776 } | |
| 712 | 777 |
| 713 if (user_to_remove != users_.end()) { | 778 User *UserManagerImpl::RemoveRegularUserFromList(const std::string& email) { |
| 714 delete *user_to_remove; | 779 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), |
| 715 users_.erase(user_to_remove); | 780 kRegularUsers); |
| 781 prefs_users_update->Clear(); | |
| 782 User* user = NULL; | |
| 783 for (UserList::iterator it = users_.begin(); it != users_.end(); ) { | |
| 784 const std::string user_email = (*it)->email(); | |
| 785 if (user_email == email) { | |
| 786 user = *it; | |
| 787 it = users_.erase(it); | |
| 788 } else { | |
| 789 if ((*it)->GetType() == User::USER_TYPE_REGULAR) | |
| 790 prefs_users_update->Append(new base::StringValue(user_email)); | |
| 791 ++it; | |
| 792 } | |
| 716 } | 793 } |
| 794 return user; | |
| 795 } | |
| 796 | |
| 797 bool UserManagerImpl::UpdateAndCleanUpPublicAccounts( | |
| 798 const base::ListValue& public_accounts) { | |
| 799 PrefService* local_state = g_browser_process->local_state(); | |
| 800 | |
| 801 // Determine the currently logged-in user's email. | |
| 802 std::string logged_in_user_email; | |
| 803 if (IsUserLoggedIn()) | |
| 804 logged_in_user_email = GetLoggedInUser()->email(); | |
| 805 | |
| 806 // If there is a public account whose data is pending removal and the user is | |
| 807 // not currently logged in with that account, take this opportunity to remove | |
| 808 // the data. | |
| 809 std::string public_account_pending_data_removal = | |
| 810 local_state->GetString(kPublicAccountPendingDataRemoval); | |
| 811 if (!public_account_pending_data_removal.empty() && | |
| 812 public_account_pending_data_removal != logged_in_user_email) { | |
| 813 RemoveNonCryptohomeData(public_account_pending_data_removal); | |
| 814 local_state->ClearPref(kPublicAccountPendingDataRemoval); | |
| 815 } | |
| 816 | |
| 817 // Split the current user list public accounts and regular users. | |
| 818 std::vector<std::string> old_public_accounts; | |
| 819 std::set<std::string> regular_users; | |
| 820 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { | |
| 821 if ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT) | |
| 822 old_public_accounts.push_back((*it)->email()); | |
| 823 else | |
| 824 regular_users.insert((*it)->email()); | |
| 825 } | |
| 826 | |
| 827 // Get the new list of public accounts from policy. | |
| 828 std::vector<std::string> new_public_accounts; | |
| 829 std::set<std::string> new_public_accounts_set; | |
| 830 if (!ParseUserList(public_accounts, regular_users, logged_in_user_email, | |
| 831 &new_public_accounts, &new_public_accounts_set) && | |
| 832 IsUserLoggedIn()) { | |
| 833 User* user = GetLoggedInUser(); | |
| 834 // If the user is currently logged into a public account that has been | |
| 835 // removed from the list, mark the account's data as pending removal after | |
| 836 // logout. | |
| 837 if (user->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT) { | |
| 838 local_state->SetString(kPublicAccountPendingDataRemoval, | |
| 839 logged_in_user_email); | |
| 840 } | |
| 841 } | |
| 842 | |
| 843 // Persist the new list of public accounts in a pref. | |
| 844 ListPrefUpdate prefs_public_accounts_update(local_state, kPublicAccounts); | |
| 845 scoped_ptr<base::ListValue> prefs_public_accounts(public_accounts.DeepCopy()); | |
| 846 prefs_public_accounts_update->Swap(prefs_public_accounts.get()); | |
| 847 | |
| 848 // If the list of public accounts has not changed, return. | |
| 849 if (new_public_accounts.size() == old_public_accounts.size()) { | |
| 850 bool changed = false; | |
| 851 for (size_t i = 0; i < new_public_accounts.size(); ++i) { | |
| 852 if (new_public_accounts[i] != old_public_accounts[i]) { | |
| 853 changed = true; | |
| 854 break; | |
| 855 } | |
| 856 } | |
| 857 if (!changed) | |
| 858 return false; | |
| 859 } | |
| 860 | |
| 861 // Remove the old public accounts from the user list. | |
| 862 for (UserList::iterator it = users_.begin(); it != users_.end(); ) { | |
| 863 if ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT) { | |
| 864 delete *it; | |
| 865 it = users_.erase(it); | |
| 866 } else { | |
| 867 ++it; | |
| 868 } | |
| 869 } | |
| 870 | |
| 871 // Add the new public accounts to the front of the user list. | |
| 872 for (std::vector<std::string>::const_reverse_iterator | |
| 873 it = new_public_accounts.rbegin(); | |
| 874 it != new_public_accounts.rend(); ++it) { | |
| 875 users_.insert(users_.begin(), User::CreatePublicAccountUser(*it)); | |
| 876 } | |
| 877 | |
| 878 user_image_manager_->LoadUserImages( | |
| 879 UserList(users_.begin(), users_.begin() + new_public_accounts.size())); | |
| 880 | |
| 881 return true; | |
| 717 } | 882 } |
| 718 | 883 |
| 719 } // namespace chromeos | 884 } // namespace chromeos |
| OLD | NEW |