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

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

Issue 8539043: Refactor ProfileInfoCache (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 ae4fb090d41a8c7d3c84cd8cd02d73cb44953392..3b0a4bc187bc0b1bd8fb757148624e11e77ece58 100644
--- a/chrome/browser/profiles/profile_manager.cc
+++ b/chrome/browser/profiles/profile_manager.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile_info_cache.h"
+#include "chrome/browser/profiles/profile_info_util.h"
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/ui/browser.h"
@@ -599,23 +600,28 @@ void ProfileManager::AddProfileToCache(Profile* profile) {
if (profile->GetPath().DirName() != cache.GetUserDataDir())
return;
- if (cache.GetIndexOfProfileWithPath(profile->GetPath()) != std::string::npos)
+ ProfileInfoEntry entry;
+ if (cache.GetInfoForProfile(profile->GetPath(), &entry)) {
+ // The profile is already in the cache, nothing to do.
return;
+ }
- string16 username = UTF8ToUTF16(profile->GetPrefs()->GetString(
- prefs::kGoogleServicesUsername));
+ entry.set_path(profile->GetPath());
+ entry.set_user_name(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);
+ entry.set_name(l10n_util::GetStringUTF16(IDS_DEFAULT_PROFILE_NAME));
+ entry.set_icon_index(0);
} else {
- size_t icon_index = cache.ChooseAvatarIconIndexForNewProfile();
- cache.AddProfileToCache(profile->GetPath(),
- cache.ChooseNameForNewProfile(icon_index),
- username,
- icon_index);
+ const std::vector<ProfileInfoEntry>& entries =
+ cache.GetProfilesSortedByName();
+ entry.set_icon_index(profiles::ChooseAvatarIconIndexForNewProfile(entries));
+ entry.set_name(
+ profiles::ChooseNameForNewProfile(entries, entry.icon_index()));
}
+
+ cache.SetInfoForProfile(entry);
}
bool ProfileManager::ShouldGoOffTheRecord() {
@@ -663,13 +669,14 @@ bool ProfileManager::IsMultipleProfilesEnabled() {
void ProfileManager::AutoloadProfiles() {
ProfileInfoCache& cache = GetProfileInfoCache();
- size_t number_of_profiles = cache.GetNumberOfProfiles();
- for (size_t p = 0; p < number_of_profiles; ++p) {
- if (cache.GetBackgroundStatusOfProfileAtIndex(p)) {
+ const std::vector<ProfileInfoEntry> entries(cache.GetProfilesSortedByName());
+ for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin();
+ it != entries.end(); ++it) {
+ if (it->is_running_background_apps()) {
// 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(it->path());
}
}
}
« no previous file with comments | « chrome/browser/profiles/profile_info_util.cc ('k') | chrome/browser/task_manager/task_manager_resource_providers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698