| Index: chrome/browser/profiles/profile_manager.cc
|
| diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
|
| index 1a4f6f9c0fd4a16424cfe8ced5b3e2f19c339b81..2fc40d70ec6460d9579dd46162818d03dc3ceba7 100644
|
| --- a/chrome/browser/profiles/profile_manager.cc
|
| +++ b/chrome/browser/profiles/profile_manager.cc
|
| @@ -56,6 +56,18 @@ std::vector<FilePath>& ProfilesToDelete() {
|
| return profiles_to_delete;
|
| }
|
|
|
| +// Checks if any user prefs for |profile| have default values.
|
| +bool HasAnyDefaultUserPrefs(Profile* profile) {
|
| + const PrefService::Preference* avatar_index =
|
| + profile->GetPrefs()->FindPreference(prefs::kProfileAvatarIndex);
|
| + DCHECK(avatar_index);
|
| + const PrefService::Preference* profile_name =
|
| + profile->GetPrefs()->FindPreference(prefs::kProfileName);
|
| + DCHECK(profile_name);
|
| + return avatar_index->IsDefaultValue() ||
|
| + profile_name->IsDefaultValue();
|
| +}
|
| +
|
| // Simple task to log the size of the current profile.
|
| class ProfileSizeTask : public Task {
|
| public:
|
| @@ -453,6 +465,7 @@ void ProfileManager::OnBrowserSetLastActive(const Browser* browser) {
|
|
|
| void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) {
|
| DoFinalInitForServices(profile, go_off_the_record);
|
| + InitProfileUserPrefs(profile);
|
| AddProfileToCache(profile);
|
| DoFinalInitLogging(profile);
|
| }
|
| @@ -595,16 +608,49 @@ void ProfileManager::AddProfileToCache(Profile* profile) {
|
| string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString(
|
| prefs::kGoogleServicesUsername));
|
|
|
| - if (profile->GetPath() == GetDefaultProfileDir(cache.GetUserDataDir())) {
|
| - cache.AddProfileToCache(
|
| - profile->GetPath(),
|
| - l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME), username, 0);
|
| - } else {
|
| - size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile();
|
| - cache.AddProfileToCache(profile->GetPath(),
|
| - cache.ChooseNameForNewProfile(icon_index),
|
| - username,
|
| - icon_index);
|
| + // Profile name and avatar are set by InitProfileUserPrefs and stored in the
|
| + // profile. Use those values to setup the cache entry.
|
| + string16 profile_name = UTF8ToUTF16(profile->GetPrefs()->GetString(
|
| + prefs::kProfileName));
|
| +
|
| + size_t icon_index = profile->GetPrefs()->GetInteger(
|
| + prefs::kProfileAvatarIndex);
|
| +
|
| + cache.AddProfileToCache(profile->GetPath(),
|
| + profile_name,
|
| + username,
|
| + icon_index);
|
| +}
|
| +
|
| +void ProfileManager::InitProfileUserPrefs(Profile* profile) {
|
| + ProfileInfoCache& cache = GetProfileInfoCache();
|
| +
|
| + if (profile->GetPath().DirName() != cache.GetUserDataDir())
|
| + return;
|
| +
|
| + // Initialize the user preferences (name and avatar) only if the profile
|
| + // doesn't have default preferenc values for them.
|
| + if (HasAnyDefaultUserPrefs(profile)) {
|
| + size_t profile_cache_index =
|
| + cache.GetIndexOfProfileWithPath(profile->GetPath());
|
| + // If the cache has an entry for this profile, use the cache data
|
| + if (profile_cache_index != std::string::npos) {
|
| + profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex,
|
| + cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index));
|
| + profile->GetPrefs()->SetString(prefs::kProfileName,
|
| + UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index)));
|
| + } else if (profile->GetPath() ==
|
| + GetDefaultProfileDir(cache.GetUserDataDir())) {
|
| + profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, 0);
|
| + profile->GetPrefs()->SetString(prefs::kProfileName,
|
| + l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME));
|
| + } else {
|
| + size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile();
|
| + profile->GetPrefs()->SetInteger(prefs::kProfileAvatarIndex, icon_index);
|
| + profile->GetPrefs()->SetString(
|
| + prefs::kProfileName,
|
| + UTF16ToUTF8(cache.ChooseNameForNewProfile(icon_index)));
|
| + }
|
| }
|
| }
|
|
|
| @@ -690,8 +736,10 @@ ProfileManagerWithoutInit::ProfileManagerWithoutInit(
|
| void ProfileManager::RegisterTestingProfile(Profile* profile,
|
| bool add_to_cache) {
|
| RegisterProfile(profile, true);
|
| - if (add_to_cache)
|
| + if (add_to_cache){
|
| + InitProfileUserPrefs(profile);
|
| AddProfileToCache(profile);
|
| + }
|
| }
|
|
|
| #if defined(OS_WIN)
|
|
|