| Index: chrome/browser/profiles/profile_manager.cc
|
| diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
|
| index 186c738a5065fffa4a98ce5628c1920ea6c4a93f..6bdc4f93a295f58f39c0d27eb3a5c6faf22b14c1 100644
|
| --- a/chrome/browser/profiles/profile_manager.cc
|
| +++ b/chrome/browser/profiles/profile_manager.cc
|
| @@ -37,6 +37,7 @@
|
| #include "chrome/browser/password_manager/password_store_factory.h"
|
| #include "chrome/browser/prefs/incognito_mode_prefs.h"
|
| #include "chrome/browser/profiles/bookmark_model_loaded_observer.h"
|
| +#include "chrome/browser/profiles/profile_attributes_entry.h"
|
| #include "chrome/browser/profiles/profile_attributes_storage.h"
|
| #include "chrome/browser/profiles/profile_avatar_icon_util.h"
|
| #include "chrome/browser/profiles/profile_destroyer.h"
|
| @@ -430,7 +431,7 @@ Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) {
|
| }
|
|
|
| size_t ProfileManager::GetNumberOfProfiles() {
|
| - return GetProfileInfoCache().GetNumberOfProfiles();
|
| + return GetProfileAttributesStorage().GetNumberOfProfiles();
|
| }
|
|
|
| bool ProfileManager::LoadProfile(const std::string& profile_name,
|
| @@ -480,14 +481,12 @@ void ProfileManager::CreateProfileAsync(
|
| } else {
|
| // Initiate asynchronous creation process.
|
| info = RegisterProfile(CreateProfileAsyncHelper(profile_path, this), false);
|
| - ProfileInfoCache& cache = GetProfileInfoCache();
|
| - // Get the icon index from the user's icon url
|
| size_t icon_index;
|
| DCHECK(base::IsStringASCII(icon_url));
|
| if (profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index)) {
|
| // add profile to cache with user selected name and avatar
|
| - cache.AddProfileToCache(profile_path, name, std::string(),
|
| - base::string16(), icon_index, supervised_user_id);
|
| + GetProfileAttributesStorage().AddProfile(profile_path, name,
|
| + std::string(), base::string16(), icon_index, supervised_user_id);
|
| }
|
|
|
| if (!supervised_user_id.empty()) {
|
| @@ -742,17 +741,18 @@ void ProfileManager::ScheduleProfileForDeletion(
|
| service->CancelDownloads();
|
| }
|
|
|
| - ProfileInfoCache& cache = GetProfileInfoCache();
|
| -
|
| + ProfileAttributesStorage& storage = GetProfileAttributesStorage();
|
| // If we're deleting the last (non-legacy-supervised) profile, then create a
|
| // new profile in its place.
|
| base::FilePath last_non_supervised_profile_path;
|
| - for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
|
| - base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i);
|
| + std::vector<ProfileAttributesEntry*> entries =
|
| + storage.GetAllProfilesAttributes();
|
| + for (ProfileAttributesEntry* entry : entries) {
|
| + base::FilePath cur_path = entry->GetPath();
|
| // Make sure that this profile is not pending deletion, and is not
|
| // legacy-supervised.
|
| if (cur_path != profile_dir &&
|
| - !cache.ProfileIsLegacySupervisedAtIndex(i) &&
|
| + !entry->IsLegacySupervised() &&
|
| !IsProfileMarkedForDeletion(cur_path)) {
|
| last_non_supervised_profile_path = cur_path;
|
| break;
|
| @@ -766,7 +766,7 @@ void ProfileManager::ScheduleProfileForDeletion(
|
| #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
|
| int avatar_index = profiles::GetPlaceholderAvatarIndex();
|
| new_avatar_url = profiles::GetDefaultAvatarIconUrl(avatar_index);
|
| - new_profile_name = cache.ChooseNameForNewProfile(avatar_index);
|
| + new_profile_name = storage.ChooseNameForNewProfile(avatar_index);
|
| #endif
|
|
|
| base::FilePath new_path(GenerateNextProfileDirectoryPath());
|
| @@ -820,14 +820,14 @@ void ProfileManager::AutoloadProfiles() {
|
| return;
|
| }
|
|
|
| - ProfileInfoCache& cache = GetProfileInfoCache();
|
| - size_t number_of_profiles = cache.GetNumberOfProfiles();
|
| - for (size_t p = 0; p < number_of_profiles; ++p) {
|
| - if (cache.GetBackgroundStatusOfProfileAtIndex(p)) {
|
| + std::vector<ProfileAttributesEntry*> entries =
|
| + GetProfileAttributesStorage().GetAllProfilesAttributes();
|
| + for (ProfileAttributesEntry* entry : entries) {
|
| + if (entry->GetBackgroundStatus()) {
|
| // If status is true, that profile is running background apps. By calling
|
| // GetProfile, we automatically cause the profile to be loaded which will
|
| // register it with the BackgroundModeManager.
|
| - GetProfile(cache.GetPathOfProfileAtIndex(p));
|
| + GetProfile(entry->GetPath());
|
| }
|
| }
|
| }
|
| @@ -838,11 +838,12 @@ void ProfileManager::CleanUpEphemeralProfiles() {
|
| bool last_active_profile_deleted = false;
|
| base::FilePath new_profile_path;
|
| std::vector<base::FilePath> profiles_to_delete;
|
| - ProfileInfoCache& profile_cache = GetProfileInfoCache();
|
| - size_t profiles_count = profile_cache.GetNumberOfProfiles();
|
| - for (size_t i = 0; i < profiles_count; ++i) {
|
| - base::FilePath profile_path = profile_cache.GetPathOfProfileAtIndex(i);
|
| - if (profile_cache.ProfileIsEphemeralAtIndex(i)) {
|
| + ProfileAttributesStorage& storage = GetProfileAttributesStorage();
|
| + std::vector<ProfileAttributesEntry*> entries =
|
| + storage.GetAllProfilesAttributes();
|
| + for (ProfileAttributesEntry* entry : entries) {
|
| + base::FilePath profile_path = entry->GetPath();
|
| + if (entry->IsEphemeral()) {
|
| profiles_to_delete.push_back(profile_path);
|
| if (profile_path.BaseName().MaybeAsASCII() == last_used_profile)
|
| last_active_profile_deleted = true;
|
| @@ -865,16 +866,18 @@ void ProfileManager::CleanUpEphemeralProfiles() {
|
| BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
|
| base::Bind(&NukeProfileFromDisk, profile_path));
|
|
|
| - profile_cache.DeleteProfileFromCache(profile_path);
|
| + storage.RemoveProfile(profile_path);
|
| }
|
| }
|
|
|
| void ProfileManager::InitProfileUserPrefs(Profile* profile) {
|
| TRACE_EVENT0("browser", "ProfileManager::InitProfileUserPrefs");
|
| - ProfileInfoCache& cache = GetProfileInfoCache();
|
| + ProfileAttributesStorage& storage = GetProfileAttributesStorage();
|
|
|
| - if (profile->GetPath().DirName() != cache.GetUserDataDir())
|
| + if (profile->GetPath().DirName() != user_data_dir()) {
|
| + UMA_HISTOGRAM_BOOLEAN("Profile.InitProfileUserPrefs.OutsideUserDir", true);
|
| return;
|
| + }
|
|
|
| size_t avatar_index;
|
| std::string profile_name;
|
| @@ -883,29 +886,28 @@ void ProfileManager::InitProfileUserPrefs(Profile* profile) {
|
| profile_name = l10n_util::GetStringUTF8(IDS_PROFILES_GUEST_PROFILE_NAME);
|
| avatar_index = 0;
|
| } else {
|
| - 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) {
|
| - avatar_index =
|
| - cache.GetAvatarIconIndexOfProfileAtIndex(profile_cache_index);
|
| - profile_name =
|
| - base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_cache_index));
|
| - supervised_user_id =
|
| - cache.GetSupervisedUserIdOfProfileAtIndex(profile_cache_index);
|
| + ProfileAttributesEntry* entry;
|
| + bool has_entry = storage.GetProfileAttributesWithPath(profile->GetPath(),
|
| + &entry);
|
| + // If the profile attributes storage has an entry for this profile, use the
|
| + // data in the profile attributes storage.
|
| + if (has_entry) {
|
| + avatar_index = entry->GetAvatarIconIndex();
|
| + profile_name = base::UTF16ToUTF8(entry->GetName());
|
| + supervised_user_id = entry->GetSupervisedUserId();
|
| } else if (profile->GetPath() ==
|
| - profiles::GetDefaultProfileDir(cache.GetUserDataDir())) {
|
| + profiles::GetDefaultProfileDir(user_data_dir())) {
|
| avatar_index = profiles::GetPlaceholderAvatarIndex();
|
| #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
|
| profile_name =
|
| - base::UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index));
|
| + base::UTF16ToUTF8(storage.ChooseNameForNewProfile(avatar_index));
|
| #else
|
| profile_name = l10n_util::GetStringUTF8(IDS_DEFAULT_PROFILE_NAME);
|
| #endif
|
| } else {
|
| - avatar_index = cache.ChooseAvatarIconIndexForNewProfile();
|
| + avatar_index = storage.ChooseAvatarIconIndexForNewProfile();
|
| profile_name =
|
| - base::UTF16ToUTF8(cache.ChooseNameForNewProfile(avatar_index));
|
| + base::UTF16ToUTF8(storage.ChooseNameForNewProfile(avatar_index));
|
| }
|
| }
|
|
|
| @@ -935,12 +937,12 @@ void ProfileManager::InitProfileUserPrefs(Profile* profile) {
|
| }
|
|
|
| void ProfileManager::RegisterTestingProfile(Profile* profile,
|
| - bool add_to_cache,
|
| + bool add_to_storage,
|
| bool start_deferred_task_runners) {
|
| RegisterProfile(profile, true);
|
| - if (add_to_cache) {
|
| + if (add_to_storage) {
|
| InitProfileUserPrefs(profile);
|
| - AddProfileToCache(profile);
|
| + AddProfileToStorage(profile);
|
| }
|
| if (start_deferred_task_runners) {
|
| StartupTaskRunnerServiceFactory::GetForProfile(profile)->
|
| @@ -1112,7 +1114,7 @@ void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) {
|
| TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInit");
|
|
|
| DoFinalInitForServices(profile, go_off_the_record);
|
| - AddProfileToCache(profile);
|
| + AddProfileToStorage(profile);
|
| DoFinalInitLogging(profile);
|
|
|
| ProfileMetrics::LogNumberOfProfiles(this);
|
| @@ -1139,8 +1141,6 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
|
| TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInitForServices");
|
|
|
| #if defined(ENABLE_EXTENSIONS)
|
| - ProfileInfoCache& cache = GetProfileInfoCache();
|
| -
|
| // Ensure that the HostContentSettingsMap has been created before the
|
| // ExtensionSystem is initialized otherwise the ExtensionSystem will be
|
| // registered twice
|
| @@ -1160,9 +1160,10 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
|
| }
|
| // Set the block extensions bit on the ExtensionService. There likely are no
|
| // blockable extensions to block.
|
| - size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
|
| - if (profile_index != std::string::npos &&
|
| - cache.ProfileIsSigninRequiredAtIndex(profile_index)) {
|
| + ProfileAttributesEntry* entry;
|
| + bool has_entry = GetProfileAttributesStorage().
|
| + GetProfileAttributesWithPath(profile->GetPath(), &entry);
|
| + if (has_entry && entry->IsSigninRequired()) {
|
| extensions::ExtensionSystem::Get(profile)
|
| ->extension_service()
|
| ->BlockAllExtensions();
|
| @@ -1339,7 +1340,7 @@ void ProfileManager::FinishDeletingProfile(
|
| profiles::SetLastUsedProfile(
|
| new_active_profile_dir.BaseName().MaybeAsASCII());
|
|
|
| - ProfileInfoCache& cache = GetProfileInfoCache();
|
| + ProfileAttributesStorage& storage = GetProfileAttributesStorage();
|
| // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we
|
| // start deleting the profile instance we need to close background apps too.
|
| Profile* profile = GetProfileByPath(profile_dir);
|
| @@ -1355,12 +1356,12 @@ void ProfileManager::FinishDeletingProfile(
|
| // By this point, all in-progress downloads for the profile being deleted
|
| // must have been canceled (crbug.com/336725).
|
| DCHECK(DownloadServiceFactory::GetForBrowserContext(profile)->
|
| - NonMaliciousDownloadCount() == 0);
|
| + NonMaliciousDownloadCount() == 0);
|
| BrowserList::CloseAllBrowsersWithProfile(profile);
|
|
|
| // Disable sync for doomed profile.
|
| if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(
|
| - profile)) {
|
| + profile)) {
|
| ProfileSyncService* sync_service =
|
| ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
|
| if (sync_service->IsSyncRequested()) {
|
| @@ -1374,8 +1375,10 @@ void ProfileManager::FinishDeletingProfile(
|
| profile)->RequestStop(ProfileSyncService::CLEAR_DATA);
|
| }
|
|
|
| - ProfileMetrics::LogProfileDelete(cache.ProfileIsAuthenticatedAtIndex(
|
| - cache.GetIndexOfProfileWithPath(profile_dir)));
|
| + ProfileAttributesEntry* entry;
|
| + bool has_entry = storage.GetProfileAttributesWithPath(profile_dir, &entry);
|
| + DCHECK(has_entry);
|
| + ProfileMetrics::LogProfileDelete(entry->IsAuthenticated());
|
| // Some platforms store passwords in keychains. They should be removed.
|
| scoped_refptr<password_manager::PasswordStore> password_store =
|
| PasswordStoreFactory::GetForProfile(
|
| @@ -1398,7 +1401,7 @@ void ProfileManager::FinishDeletingProfile(
|
| // Queue even a profile that was nuked so it will be MarkedForDeletion and so
|
| // CreateProfileAsync can't create it.
|
| QueueProfileDirectoryForDeletion(profile_dir);
|
| - cache.DeleteProfileFromCache(profile_dir);
|
| + storage.RemoveProfile(profile_dir);
|
| ProfileMetrics::UpdateReportedProfilesStatistics(this);
|
| }
|
| #endif // !defined(OS_ANDROID)
|
| @@ -1419,13 +1422,15 @@ ProfileManager::ProfileInfo* ProfileManager::GetProfileInfoByPath(
|
| return (iter == profiles_info_.end()) ? NULL : iter->second.get();
|
| }
|
|
|
| -void ProfileManager::AddProfileToCache(Profile* profile) {
|
| +void ProfileManager::AddProfileToStorage(Profile* profile) {
|
| TRACE_EVENT0("browser", "ProfileManager::AddProfileToCache");
|
| if (profile->IsGuestSession() || profile->IsSystemProfile())
|
| return;
|
| - ProfileInfoCache& cache = GetProfileInfoCache();
|
| - if (profile->GetPath().DirName() != cache.GetUserDataDir())
|
| + if (profile->GetPath().DirName() != user_data_dir()) {
|
| + UMA_HISTOGRAM_BOOLEAN("Profile.GetProfileInfoPath.OutsideUserDir", true);
|
| return;
|
| + }
|
| +
|
|
|
| SigninManagerBase* signin_manager =
|
| SigninManagerFactory::GetForProfile(profile);
|
| @@ -1435,35 +1440,40 @@ void ProfileManager::AddProfileToCache(Profile* profile) {
|
| signin_manager->GetAuthenticatedAccountId());
|
| base::string16 username = base::UTF8ToUTF16(account_info.email);
|
|
|
| - size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath());
|
| - if (profile_index != std::string::npos) {
|
| - // The ProfileInfoCache's info must match the Signin Manager.
|
| - cache.SetAuthInfoOfProfileAtIndex(profile_index, account_info.gaia,
|
| - username);
|
| - return;
|
| + ProfileAttributesStorage& storage = GetProfileAttributesStorage();
|
| + // |entry| and |has_entry| below are put inside a pair of brackets for
|
| + // scoping, to avoid potential clashes of variable names.
|
| + {
|
| + ProfileAttributesEntry* entry;
|
| + bool has_entry = storage.GetProfileAttributesWithPath(profile->GetPath(),
|
| + &entry);
|
| + if (has_entry) {
|
| + // The ProfileAttributesStorage's info must match the Signin Manager.
|
| + entry->SetAuthInfo(account_info.gaia, username);
|
| + return;
|
| + }
|
| }
|
|
|
| // Profile name and avatar are set by InitProfileUserPrefs and stored in the
|
| - // profile. Use those values to setup the cache entry.
|
| + // profile. Use those values to setup the entry in profile attributes storage.
|
| base::string16 profile_name =
|
| base::UTF8ToUTF16(profile->GetPrefs()->GetString(prefs::kProfileName));
|
|
|
| - size_t icon_index = profile->GetPrefs()->GetInteger(
|
| - prefs::kProfileAvatarIndex);
|
| + size_t icon_index =
|
| + profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex);
|
|
|
| std::string supervised_user_id =
|
| profile->GetPrefs()->GetString(prefs::kSupervisedUserId);
|
|
|
| - cache.AddProfileToCache(profile->GetPath(),
|
| - profile_name,
|
| - account_info.gaia,
|
| - username,
|
| - icon_index,
|
| - supervised_user_id);
|
| + storage.AddProfile(profile->GetPath(), profile_name, account_info.gaia,
|
| + username, icon_index, supervised_user_id);
|
|
|
| if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) {
|
| - cache.SetProfileIsEphemeralAtIndex(
|
| - cache.GetIndexOfProfileWithPath(profile->GetPath()), true);
|
| + ProfileAttributesEntry* entry;
|
| + bool has_entry = storage.GetProfileAttributesWithPath(profile->GetPath(),
|
| + &entry);
|
| + DCHECK(has_entry);
|
| + entry->SetIsEphemeral(true);
|
| }
|
| }
|
|
|
| @@ -1515,19 +1525,17 @@ void ProfileManager::UpdateLastUser(Profile* last_active) {
|
| if (profile_path_base != GetLastUsedProfileName())
|
| profiles::SetLastUsedProfile(profile_path_base);
|
|
|
| - ProfileInfoCache& cache = GetProfileInfoCache();
|
| - size_t profile_index =
|
| - cache.GetIndexOfProfileWithPath(last_active->GetPath());
|
| - if (profile_index != std::string::npos) {
|
| + ProfileAttributesEntry* entry;
|
| + if (GetProfileAttributesStorage().
|
| + GetProfileAttributesWithPath(last_active->GetPath(), &entry)) {
|
| #if !defined(OS_CHROMEOS)
|
| // Incognito Profiles don't have ProfileKeyedServices.
|
| if (!last_active->IsOffTheRecord()) {
|
| - CrossDevicePromoFactory::GetForProfile(last_active)
|
| - ->MaybeBrowsingSessionStarted(
|
| - cache.GetProfileActiveTimeAtIndex(profile_index));
|
| + CrossDevicePromoFactory::GetForProfile(last_active)->
|
| + MaybeBrowsingSessionStarted(entry->GetActiveTime());
|
| }
|
| #endif
|
| - cache.SetProfileActiveTimeAtIndex(profile_index);
|
| + entry->SetActiveTimeToNow();
|
| }
|
| }
|
| }
|
|
|