Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(998)

Unified Diff: chrome/browser/profiles/profile_manager.cc

Issue 1242793005: Refactor most c/b/profiles calls to ProfileInfoCache. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Windows unit test and ChromeOS build Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/profile_manager.cc
diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc
index 67acac17bb9292879caed2b9e2b9722271896fc3..3ea9b0bbccbe047875f02cfc192acde7747665bd 100644
--- a/chrome/browser/profiles/profile_manager.cc
+++ b/chrome/browser/profiles/profile_manager.cc
@@ -31,6 +31,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_storage.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_destroyer.h"
#include "chrome/browser/profiles/profile_info_cache.h"
@@ -649,6 +650,10 @@ ProfileInfoCache& ProfileManager::GetProfileInfoCache() {
return *profile_info_cache_.get();
}
+ProfileAttributesStorage& ProfileManager::GetProfileAttributesStorage() {
+ return GetProfileInfoCache();
+}
+
ProfileShortcutManager* ProfileManager::profile_shortcut_manager() {
return profile_shortcut_manager_.get();
}
@@ -810,16 +815,13 @@ 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());
+ ProfileAttributesEntry* entry;
// 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);
+ if (GetProfileAttributesStorage().GetProfileAttributesWithPath(
+ profile->GetPath(), &entry)) {
+ avatar_index = entry->GetAvatarIconIndex();
+ profile_name = base::UTF16ToUTF8(entry->GetName());
+ supervised_user_id = entry->GetSupervisedUserId();
} else if (profile->GetPath() ==
profiles::GetDefaultProfileDir(cache.GetUserDataDir())) {
// The --new-avatar-menu flag no longer uses the "First User" name.
@@ -1054,7 +1056,6 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
TRACK_SCOPED_REGION("Startup", "ProfileManager::DoFinalInitForServices");
#if defined(ENABLE_EXTENSIONS)
- ProfileInfoCache& cache = GetProfileInfoCache();
extensions::ExtensionSystem::Get(profile)->InitForRegularProfile(
!go_off_the_record);
// During tests, when |profile| is an instance of TestingProfile,
@@ -1065,9 +1066,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)) {
+ ProfileAttributesStorage& storage = GetProfileAttributesStorage();
+ ProfileAttributesEntry* entry;
+ if (storage.GetProfileAttributesWithPath(profile->GetPath(), &entry) &&
+ entry->IsSigninRequired()) {
extensions::ExtensionSystem::Get(profile)
->extension_service()
->BlockAllExtensions();
@@ -1219,10 +1221,13 @@ void ProfileManager::FinishDeletingProfile(
profiles::SetLastUsedProfile(
new_active_profile_dir.BaseName().MaybeAsASCII());
- ProfileInfoCache& cache = GetProfileInfoCache();
// 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);
+ ProfileAttributesStorage& storage = GetProfileAttributesStorage();
+ ProfileAttributesEntry* entry;
+ bool profile_in_storage =
+ storage.GetProfileAttributesWithPath(profile_dir, &entry);
if (profile) {
// TODO: Migrate additional code in this block to observe this notification
@@ -1245,8 +1250,9 @@ void ProfileManager::FinishDeletingProfile(
profile)->RequestStop(ProfileSyncService::CLEAR_DATA);
}
- ProfileMetrics::LogProfileDelete(cache.ProfileIsAuthenticatedAtIndex(
- cache.GetIndexOfProfileWithPath(profile_dir)));
+
+ if (profile_in_storage)
+ ProfileMetrics::LogProfileDelete(entry->IsAuthenticated());
// Some platforms store passwords in keychains. They should be removed.
scoped_refptr<password_manager::PasswordStore> password_store =
PasswordStoreFactory::GetForProfile(
@@ -1269,7 +1275,8 @@ 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);
+ if (profile_in_storage)
Mike Lerman 2015/08/06 16:06:19 Why do we need this caution now? How are we ever t
+ storage.RemoveProfile(profile_dir);
ProfileMetrics::UpdateReportedProfilesStatistics(this);
}
@@ -1306,11 +1313,11 @@ 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) {
+ ProfileAttributesStorage& storage = GetProfileAttributesStorage();
+ ProfileAttributesEntry* entry;
+ if (storage.GetProfileAttributesWithPath(profile->GetPath(), &entry)) {
// The ProfileInfoCache's info must match the Signin Manager.
- cache.SetAuthInfoOfProfileAtIndex(profile_index, account_info.gaia,
- username);
+ entry->SetAuthInfo(account_info.gaia, username);
return;
}
@@ -1325,16 +1332,21 @@ void ProfileManager::AddProfileToCache(Profile* profile) {
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);
+
+ ProfileAttributesEntry* new_entry = nullptr;
+ if (!storage.GetProfileAttributesWithPath(profile->GetPath(), &new_entry)) {
+ NOTREACHED();
Mike Lerman 2015/08/06 16:06:19 Can you add some descriptive comment at this NOTRE
+ return;
+ }
if (profile->GetPrefs()->GetBoolean(prefs::kForceEphemeralProfiles)) {
Mike Lerman 2015/08/06 16:06:20 nit: no {}. Can even just write new_entry->SetIsE
- cache.SetProfileIsEphemeralAtIndex(
- cache.GetIndexOfProfileWithPath(profile->GetPath()), true);
+ new_entry->SetIsEphemeral(true);
}
}
@@ -1386,19 +1398,18 @@ 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) {
+ ProfileAttributesStorage& storage = GetProfileAttributesStorage();
+ ProfileAttributesEntry* entry;
+
+ if (storage.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));
+ ->MaybeBrowsingSessionStarted(entry->GetActiveTime());
}
#endif
- cache.SetProfileActiveTimeAtIndex(profile_index);
+ entry->SetActiveTime();
}
}
}

Powered by Google App Engine
This is Rietveld 408576698