| 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/profiles/profile_manager.h" | 5 #include "chrome/browser/profiles/profile_manager.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 return profile_shortcut_manager_.get(); | 955 return profile_shortcut_manager_.get(); |
| 956 } | 956 } |
| 957 | 957 |
| 958 void ProfileManager::AddProfileToCache(Profile* profile) { | 958 void ProfileManager::AddProfileToCache(Profile* profile) { |
| 959 if (profile->IsGuestSession()) | 959 if (profile->IsGuestSession()) |
| 960 return; | 960 return; |
| 961 ProfileInfoCache& cache = GetProfileInfoCache(); | 961 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 962 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | 962 if (profile->GetPath().DirName() != cache.GetUserDataDir()) |
| 963 return; | 963 return; |
| 964 | 964 |
| 965 if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos) | 965 // If the profile is already in the cache, there's nothing to do. |
| 966 ProfileInfoEntry entry; |
| 967 if (cache.GetInfoForProfile(profile->GetPath(), &entry)) |
| 966 return; | 968 return; |
| 967 | 969 |
| 968 string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString( | 970 string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString( |
| 969 prefs::kGoogleServicesUsername)); | 971 prefs::kGoogleServicesUsername)); |
| 970 | 972 |
| 971 // Profile name and avatar are set by InitProfileUserPrefs and stored in the | 973 // Profile name and avatar are set by InitProfileUserPrefs and stored in the |
| 972 // profile. Use those values to setup the cache entry. | 974 // profile. Use those values to setup the cache entry. |
| 973 string16 profile_name = UTF8ToUTF16(profile->GetPrefs()->GetString( | 975 string16 profile_name = UTF8ToUTF16(profile->GetPrefs()->GetString( |
| 974 prefs::kProfileName)); | 976 prefs::kProfileName)); |
| 975 | 977 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 992 if (profile->GetPath().DirName() != cache.GetUserDataDir()) | 994 if (profile->GetPath().DirName() != cache.GetUserDataDir()) |
| 993 return; | 995 return; |
| 994 | 996 |
| 995 size_t avatar_index; | 997 size_t avatar_index; |
| 996 std::string profile_name; | 998 std::string profile_name; |
| 997 std::string managed_user_id; | 999 std::string managed_user_id; |
| 998 if (profile->IsGuestSession()) { | 1000 if (profile->IsGuestSession()) { |
| 999 profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME); | 1001 profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME); |
| 1000 avatar_index = 0; | 1002 avatar_index = 0; |
| 1001 } else { | 1003 } else { |
| 1002 size_t profile_cache_index = | 1004 ProfileInfoEntry entry; |
| 1003 cache.GetIndexOfProfileWithPath(profile->GetPath()); | |
| 1004 // If the cache has an entry for this profile, use the cache data. | 1005 // If the cache has an entry for this profile, use the cache data. |
| 1005 if (profile_cache_index != std::string::npos) { | 1006 if (cache.GetInfoForProfile(profile->GetPath(), &entry)) { |
| 1006 avatar_index = | 1007 avatar_index = entry.icon_index(); |
| 1007 cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index); | 1008 profile_name = UTF16ToUTF8(entry.GetDisplayName()); |
| 1008 profile_name = | 1009 managed_user_id = entry.managed_user_id(); |
| 1009 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index)); | |
| 1010 managed_user_id = | |
| 1011 cache.GetManagedUserIdOfProfileAtIndex(profile_cache_index); | |
| 1012 } else if (profile->GetPath() == | 1010 } else if (profile->GetPath() == |
| 1013 profiles::GetDefaultProfileDir(cache.GetUserDataDir())) { | 1011 profiles::GetDefaultProfileDir(cache.GetUserDataDir())) { |
| 1014 avatar_index = 0; | 1012 avatar_index = 0; |
| 1015 profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME); | 1013 profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME); |
| 1016 } else { | 1014 } else { |
| 1017 avatar_index = cache.ChooseAvatarIconIndexForNewProfile(); | 1015 avatar_index = cache.ChooseAvatarIconIndexForNewProfile(); |
| 1018 profile_name = UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index)); | 1016 profile_name = UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index)); |
| 1019 } | 1017 } |
| 1020 } | 1018 } |
| 1021 | 1019 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 const CreateCallback& callback) { | 1057 const CreateCallback& callback) { |
| 1060 DCHECK(profiles::IsMultipleProfilesEnabled()); | 1058 DCHECK(profiles::IsMultipleProfilesEnabled()); |
| 1061 PrefService* local_state = g_browser_process->local_state(); | 1059 PrefService* local_state = g_browser_process->local_state(); |
| 1062 ProfileInfoCache& cache = GetProfileInfoCache(); | 1060 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 1063 | 1061 |
| 1064 if (profile_dir.BaseName().MaybeAsASCII() == | 1062 if (profile_dir.BaseName().MaybeAsASCII() == |
| 1065 local_state->GetString(prefs::kProfileLastUsed)) { | 1063 local_state->GetString(prefs::kProfileLastUsed)) { |
| 1066 // Update the last used profile pref before closing browser windows. This | 1064 // Update the last used profile pref before closing browser windows. This |
| 1067 // way the correct last used profile is set for any notification observers. | 1065 // way the correct last used profile is set for any notification observers. |
| 1068 base::FilePath last_non_managed_profile_path; | 1066 base::FilePath last_non_managed_profile_path; |
| 1069 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { | 1067 const std::vector<ProfileInfoEntry> entries(cache.GetProfilesSortedByName())
; |
| 1070 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); | 1068 for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin(); |
| 1069 it != entries.end(); ++it) { |
| 1070 base::FilePath cur_path = it->path(); |
| 1071 // Make sure that this profile is not pending deletion. | 1071 // Make sure that this profile is not pending deletion. |
| 1072 if (cur_path != profile_dir && !cache.ProfileIsManagedAtIndex(i) && | 1072 if (cur_path != profile_dir && !it->IsManaged() && |
| 1073 !IsProfileMarkedForDeletion(cur_path)) { | 1073 !IsProfileMarkedForDeletion(cur_path)) { |
| 1074 last_non_managed_profile_path = cur_path; | 1074 last_non_managed_profile_path = cur_path; |
| 1075 break; | 1075 break; |
| 1076 } | 1076 } |
| 1077 } | 1077 } |
| 1078 | 1078 |
| 1079 // If we're deleting the last (non-managed) profile, then create a new | 1079 // If we're deleting the last (non-managed) profile, then create a new |
| 1080 // profile in its place. | 1080 // profile in its place. |
| 1081 const std::string last_non_managed_profile = | 1081 const std::string last_non_managed_profile = |
| 1082 last_non_managed_profile_path.BaseName().MaybeAsASCII(); | 1082 last_non_managed_profile_path.BaseName().MaybeAsASCII(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 void ProfileManager::AutoloadProfiles() { | 1166 void ProfileManager::AutoloadProfiles() { |
| 1167 // If running in the background is disabled for the browser, do not autoload | 1167 // If running in the background is disabled for the browser, do not autoload |
| 1168 // any profiles. | 1168 // any profiles. |
| 1169 PrefService* local_state = g_browser_process->local_state(); | 1169 PrefService* local_state = g_browser_process->local_state(); |
| 1170 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || | 1170 if (!local_state->HasPrefPath(prefs::kBackgroundModeEnabled) || |
| 1171 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { | 1171 !local_state->GetBoolean(prefs::kBackgroundModeEnabled)) { |
| 1172 return; | 1172 return; |
| 1173 } | 1173 } |
| 1174 | 1174 |
| 1175 ProfileInfoCache& cache = GetProfileInfoCache(); | 1175 ProfileInfoCache& cache = GetProfileInfoCache(); |
| 1176 size_t number_of_profiles = cache.GetNumberOfProfiles(); | 1176 const std::vector<ProfileInfoEntry> entries(cache.GetProfilesSortedByName()); |
| 1177 for (size_t p = 0; p < number_of_profiles; ++p) { | 1177 for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin(); |
| 1178 if (cache.GetBackgroundStatusOfProfileAtIndex(p)) { | 1178 it != entries.end(); ++it) { |
| 1179 if (it->is_running_background_apps()) { |
| 1179 // If status is true, that profile is running background apps. By calling | 1180 // If status is true, that profile is running background apps. By calling |
| 1180 // GetProfile, we automatically cause the profile to be loaded which will | 1181 // GetProfile, we automatically cause the profile to be loaded which will |
| 1181 // register it with the BackgroundModeManager. | 1182 // register it with the BackgroundModeManager. |
| 1182 GetProfile(cache.GetPathOfProfileAtIndex(p)); | 1183 GetProfile(it->path()); |
| 1183 } | 1184 } |
| 1184 } | 1185 } |
| 1185 } | 1186 } |
| 1186 | 1187 |
| 1187 ProfileManagerWithoutInit::ProfileManagerWithoutInit( | 1188 ProfileManagerWithoutInit::ProfileManagerWithoutInit( |
| 1188 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { | 1189 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { |
| 1189 } | 1190 } |
| 1190 | 1191 |
| 1191 void ProfileManager::RegisterTestingProfile(Profile* profile, | 1192 void ProfileManager::RegisterTestingProfile(Profile* profile, |
| 1192 bool add_to_cache, | 1193 bool add_to_cache, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1212 ProfileManager::ProfileInfo::ProfileInfo( | 1213 ProfileManager::ProfileInfo::ProfileInfo( |
| 1213 Profile* profile, | 1214 Profile* profile, |
| 1214 bool created) | 1215 bool created) |
| 1215 : profile(profile), | 1216 : profile(profile), |
| 1216 created(created) { | 1217 created(created) { |
| 1217 } | 1218 } |
| 1218 | 1219 |
| 1219 ProfileManager::ProfileInfo::~ProfileInfo() { | 1220 ProfileManager::ProfileInfo::~ProfileInfo() { |
| 1220 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); | 1221 ProfileDestroyer::DestroyProfileWhenAppropriate(profile.release()); |
| 1221 } | 1222 } |
| OLD | NEW |