Chromium Code Reviews| Index: chrome/browser/chromeos/login/user_manager.cc |
| diff --git a/chrome/browser/chromeos/login/user_manager.cc b/chrome/browser/chromeos/login/user_manager.cc |
| index 6f3737b16a8564fab9c1e47a79a522c1b6d6f3f4..9000ea16cd6de7fb94a10411b8d75eb3a54fe40c 100644 |
| --- a/chrome/browser/chromeos/login/user_manager.cc |
| +++ b/chrome/browser/chromeos/login/user_manager.cc |
| @@ -65,6 +65,8 @@ namespace { |
| const char kLoggedInUsers[] = "LoggedInUsers"; |
| // A dictionary that maps usernames to file paths to their images. |
| const char kUserImages[] = "UserImages"; |
| +// A dictionary that maps usernames to the displayed (non-canonical) emails. |
| +const char kUserDisplayEmail[] = "UserDisplayEmail"; |
| // A dictionary that maps usernames to OAuth token presence flag. |
| const char kUserOAuthTokenStatus[] = "OAuthTokenStatus"; |
| @@ -226,6 +228,8 @@ void UserManager::RegisterPrefs(PrefService* local_state) { |
| PrefService::UNSYNCABLE_PREF); |
| local_state->RegisterDictionaryPref(kUserOAuthTokenStatus, |
| PrefService::UNSYNCABLE_PREF); |
| + local_state->RegisterDictionaryPref(kUserDisplayEmail, |
| + PrefService::UNSYNCABLE_PREF); |
| } |
| const UserList& UserManager::GetUsers() const { |
| @@ -360,6 +364,9 @@ void UserManager::RemoveUserFromList(const std::string& email) { |
| prefs_oauth_update->GetIntegerWithoutPathExpansion(email, &oauth_status); |
| prefs_oauth_update->RemoveWithoutPathExpansion(email, NULL); |
| + DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail); |
| + prefs_display_email_update->RemoveWithoutPathExpansion(email, NULL); |
| + |
| prefs->ScheduleSavePersistentPrefs(); |
|
Nikita (slow)
2011/12/05 13:13:04
nit: Cleanup, this call could be removed.
Ivan Korotkov
2011/12/05 14:12:48
Done.
|
| if (user_to_remove != users_.end()) { |
| @@ -409,14 +416,14 @@ void UserManager::SaveUserOAuthStatus( |
| DictionaryPrefUpdate oauth_status_update(local_state, kUserOAuthTokenStatus); |
| oauth_status_update->SetWithoutPathExpansion(username, |
| new base::FundamentalValue(static_cast<int>(oauth_token_status))); |
| - DVLOG(1) << "Saving user OAuth token status in Local State."; |
| + DVLOG(1) << "Saving user OAuth token status in Local State"; |
| local_state->ScheduleSavePersistentPrefs(); |
|
Nikita (slow)
2011/12/05 13:13:04
nit: Cleanup, this call could be removed.
Ivan Korotkov
2011/12/05 14:12:48
Done.
|
| User* user = const_cast<User*>(FindUser(username)); |
| if (user) |
| user->set_oauth_token_status(oauth_token_status); |
| } |
| -User::OAuthTokenStatus UserManager::GetUserOAuthStatus( |
| +User::OAuthTokenStatus UserManager::LoadUserOAuthStatus( |
| const std::string& username) const { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -440,6 +447,43 @@ User::OAuthTokenStatus UserManager::GetUserOAuthStatus( |
| return User::OAUTH_TOKEN_STATUS_UNKNOWN; |
| } |
| +void UserManager::SaveUserDisplayEmail(const std::string& username, |
| + const std::string& display_email, |
| + bool update_if_exists) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + PrefService* local_state = g_browser_process->local_state(); |
| + |
| + if (!update_if_exists) { |
| + // Check if a display name is already known for that username. |
| + std::string display_email; |
| + const DictionaryValue* prefs_display_email = |
| + local_state->GetDictionary(kUserDisplayEmail); |
| + if (prefs_display_email && |
| + prefs_display_email->GetStringWithoutPathExpansion( |
| + username, &display_email)) |
| + return; |
| + } |
| + |
| + DictionaryPrefUpdate display_email_update(local_state, kUserDisplayEmail); |
| + display_email_update->SetWithoutPathExpansion( |
| + username, |
| + base::Value::CreateStringValue(display_email)); |
| + DVLOG(1) << "Saving displayed email in Local State"; |
|
Nikita (slow)
2011/12/05 13:13:04
nit: cleanup log.
Ivan Korotkov
2011/12/05 14:12:48
Done.
|
| + local_state->ScheduleSavePersistentPrefs(); |
|
Nikita (slow)
2011/12/05 13:13:04
Please remove since prefs are automatically schedu
Ivan Korotkov
2011/12/05 14:12:48
Done.
|
| + |
| + User* user = const_cast<User*>(FindUser(username)); |
| + if (user) |
| + user->set_display_email(display_email); |
| +} |
| + |
| +std::string UserManager::GetUserDisplayEmail( |
| + const std::string& username) const { |
| + // TODO(ivankr): won't work with users that are not registered but present |
|
Nikita (slow)
2011/12/05 13:13:04
Is this only for whitelist? We may as well ignore
Ivan Korotkov
2011/12/05 14:12:48
Yes, it's for whitelist only. I'll leave a TODO fo
|
| + // in |kUserDisplayEmail| dictionary. |
| + const User* user = FindUser(username); |
| + return user ? user->display_email() : username; |
| +} |
| + |
| void UserManager::SaveUserDefaultImageIndex(const std::string& username, |
| int image_index) { |
| DCHECK(image_index >= 0 && image_index < kDefaultImagesCount); |
| @@ -567,6 +611,8 @@ void UserManager::EnsureUsersLoaded() { |
| PrefService* local_state = g_browser_process->local_state(); |
| const ListValue* prefs_users = local_state->GetList(kLoggedInUsers); |
| const DictionaryValue* prefs_images = local_state->GetDictionary(kUserImages); |
| + const DictionaryValue* prefs_display_emails = |
| + local_state->GetDictionary(kUserDisplayEmail); |
| if (prefs_users) { |
| for (ListValue::const_iterator it = prefs_users->begin(); |
| @@ -630,6 +676,13 @@ void UserManager::EnsureUsersLoaded() { |
| } |
| } |
| } |
| + |
| + std::string display_email; |
| + if (prefs_display_emails && |
| + prefs_display_emails->GetStringWithoutPathExpansion( |
| + email, &display_email)) { |
| + user->set_display_email(display_email); |
| + } |
| } |
| } |
| } |
| @@ -910,7 +963,7 @@ void UserManager::OnDownloadComplete(ProfileDownloader* downloader, |
| User* UserManager::CreateUser(const std::string& email) const { |
| User* user = new User(email); |
| - user->set_oauth_token_status(GetUserOAuthStatus(email)); |
| + user->set_oauth_token_status(LoadUserOAuthStatus(email)); |
| // Used to determine whether user's display name is unique. |
| ++display_name_count_[user->GetDisplayName()]; |
| return user; |