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

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

Issue 33753002: Sooper experimental refactoring of the profile info cache. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years, 2 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
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.h ('k') | chrome/browser/profiles/profile_info_entry.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/profiles/profile_info_cache.cc
diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc
index f57205eb1204285d55b671b3fabc5c2350a23c76..fddd93e10cad2129a9c6d27ab12e5f5d544ae0e4 100644
--- a/chrome/browser/profiles/profile_info_cache.cc
+++ b/chrome/browser/profiles/profile_info_cache.cc
@@ -38,10 +38,10 @@ using content::BrowserThread;
namespace {
const char kNameKey[] = "name";
-const char kShortcutNameKey[] = "shortcut_name";
-const char kGAIANameKey[] = "gaia_name";
-const char kGAIAGivenNameKey[] = "gaia_given_name";
-const char kUseGAIANameKey[] = "use_gaia_name";
+//const char kShortcutNameKey[] = "shortcut_name";
+//const char kGAIANameKey[] = "gaia_name";
+//const char kGAIAGivenNameKey[] = "gaia_given_name";
+//const char kUseGAIANameKey[] = "use_gaia_name";
const char kUserNameKey[] = "user_name";
const char kAvatarIconKey[] = "avatar_icon";
const char kUseGAIAPictureKey[] = "use_gaia_picture";
@@ -180,12 +180,12 @@ ProfileInfoCache::ProfileInfoCache(PrefService* prefs,
// Populate the cache
DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache);
DictionaryValue* cache = update.Get();
+
for (DictionaryValue::Iterator it(*cache); !it.IsAtEnd(); it.Advance()) {
DictionaryValue* info = NULL;
cache->GetDictionaryWithoutPathExpansion(it.key(), &info);
string16 name;
info->GetString(kNameKey, &name);
- sorted_keys_.insert(FindPositionForProfile(it.key(), name), it.key());
// TODO(ibraaaa): delete this when 97% of our users are using M31.
// http://crbug.com/276163
bool is_managed = false;
@@ -193,6 +193,12 @@ ProfileInfoCache::ProfileInfoCache(PrefService* prefs,
info->Remove(kIsManagedKey, NULL);
info->SetString(kManagedUserId, is_managed ? "DUMMY_ID" : std::string());
}
+ if (info) {
+ base::FilePath path = user_data_dir.AppendASCII(it.key());
+ cached_entries_[it.key()] = ProfileInfoEntry(path, *info);
+ }
+
+ //sorted_keys_.insert(FindPositionForProfile(it.key(), name), it.key());
}
}
@@ -201,30 +207,67 @@ ProfileInfoCache::~ProfileInfoCache() {
gaia_pictures_.begin(), gaia_pictures_.end());
}
-void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path,
- const string16& name,
- const string16& username,
- size_t icon_index,
- const std::string& managed_user_id) {
- std::string key = CacheKeyFromProfilePath(profile_path);
+void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) {
+ observer_list_.AddObserver(obs);
+}
+
+void ProfileInfoCache::RemoveObserver(ProfileInfoCacheObserver* obs) {
+ observer_list_.RemoveObserver(obs);
+}
+
+size_t ProfileInfoCache::GetNumberOfProfiles() const {
+ return cached_entries_.size();
+}
+
+std::vector<ProfileInfoEntry> ProfileInfoCache::GetProfilesSortedByName()
+ const {
+ std::vector<ProfileInfoEntry> entries;
+ for (std::map<std::string, ProfileInfoEntry>::const_iterator it =
+ cached_entries_.begin(); it != cached_entries_.end(); ++it) {
+ entries.push_back(it->second);
+ }
+ std::sort(entries.begin(), entries.end());
+ return entries;
+}
+
+bool ProfileInfoCache::GetInfoForProfile(const base::FilePath& path,
+ ProfileInfoEntry* entry) const {
+ // If the info is not in the cache then the profile was deleted.
+ std::string key = CacheKeyFromProfilePath(path);
+ std::map<std::string, ProfileInfoEntry>::const_iterator it =
+ cached_entries_.find(key);
+ if (it == cached_entries_.end())
+ return false;
+
+ *entry = it->second;
+ return true;
+}
+
+void ProfileInfoCache::SetInfoForProfile(const ProfileInfoEntry& info) {
+ std::string key = CacheKeyFromProfilePath(info.path());
+ cached_entries_[key] = info;
+
DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache);
DictionaryValue* cache = update.Get();
- scoped_ptr<DictionaryValue> info(new DictionaryValue);
- info->SetString(kNameKey, name);
- info->SetString(kUserNameKey, username);
- info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index));
+ scoped_ptr<DictionaryValue> info_dict(new DictionaryValue);
+ info_dict->SetString(kNameKey, info.name());
+ info_dict->SetString(kUserNameKey, info.user_name());
+ info_dict->SetString(kAvatarIconKey,
+ GetDefaultAvatarIconUrl(info.icon_index()));
// Default value for whether background apps are running is false.
- info->SetBoolean(kBackgroundAppsKey, false);
- info->SetString(kManagedUserId, managed_user_id);
- info->SetBoolean(kProfileIsEphemeral, false);
- cache->SetWithoutPathExpansion(key, info.release());
+ //info->SetBoolean(kBackgroundAppsKey, false);
+ //info->SetString(kManagedUserId, managed_user_id);
+ //info->SetBoolean(kProfileIsEphemeral, false);
+ //cache->SetWithoutPathExpansion(key, info.release());
+ info_dict->SetBoolean(kBackgroundAppsKey, false);
+ info_dict->SetString(kManagedUserId, info.managed_user_id());
- sorted_keys_.insert(FindPositionForProfile(key, name), key);
+ cache->Set(key, info_dict.get());
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
- OnProfileAdded(profile_path));
+ OnProfileAdded(info.path()));
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
@@ -232,32 +275,46 @@ void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path,
content::NotificationService::NoDetails());
}
-void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) {
- observer_list_.AddObserver(obs);
-}
-
-void ProfileInfoCache::RemoveObserver(ProfileInfoCacheObserver* obs) {
- observer_list_.RemoveObserver(obs);
+void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path,
+ const string16& name,
+ const string16& username,
+ size_t icon_index,
+ const std::string& managed_user_id) {
+ ProfileInfoEntry entry;
+ if (GetInfoForProfile(profile_path, &entry)) {
+ // The profile is already in the cache, nothing to do.
+ return;
+ }
+ entry.set_path(profile_path);
+ entry.set_name(name);
+ entry.set_user_name(username);
+ entry.set_icon_index(icon_index);
+ entry.set_managed_user_id(managed_user_id);
+ SetInfoForProfile(entry);
}
void ProfileInfoCache::DeleteProfileFromCache(
const base::FilePath& profile_path) {
- size_t profile_index = GetIndexOfProfileWithPath(profile_path);
- if (profile_index == std::string::npos) {
- NOTREACHED();
- return;
- }
- string16 name = GetNameOfProfileAtIndex(profile_index);
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
OnProfileWillBeRemoved(profile_path));
+ std::string key = CacheKeyFromProfilePath(profile_path);
+
+ // This should be less suck
+ ProfileInfoEntry p;
+ if (!GetInfoForProfile(profile_path, &p))
+ return;
+
+ string16 name = p.name();
+
+ if (cached_entries_.count(key))
+ cached_entries_.erase(key);
+
DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache);
DictionaryValue* cache = update.Get();
- std::string key = CacheKeyFromProfilePath(profile_path);
cache->Remove(key, NULL);
- sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key));
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
@@ -269,98 +326,107 @@ void ProfileInfoCache::DeleteProfileFromCache(
content::NotificationService::NoDetails());
}
-size_t ProfileInfoCache::GetNumberOfProfiles() const {
- return sorted_keys_.size();
-}
-size_t ProfileInfoCache::GetIndexOfProfileWithPath(
- const base::FilePath& profile_path) const {
- if (profile_path.DirName() != user_data_dir_)
- return std::string::npos;
- std::string search_key = CacheKeyFromProfilePath(profile_path);
- for (size_t i = 0; i < sorted_keys_.size(); ++i) {
- if (sorted_keys_[i] == search_key)
- return i;
- }
- return std::string::npos;
-}
-string16 ProfileInfoCache::GetNameOfProfileAtIndex(size_t index) const {
- string16 name;
- if (IsUsingGAIANameOfProfileAtIndex(index)) {
- string16 given_name = GetGAIAGivenNameOfProfileAtIndex(index);
- name = given_name.empty() ? GetGAIANameOfProfileAtIndex(index) : given_name;
- }
- if (name.empty())
- GetInfoForProfileAtIndex(index)->GetString(kNameKey, &name);
- return name;
-}
-string16 ProfileInfoCache::GetShortcutNameOfProfileAtIndex(size_t index)
- const {
- string16 shortcut_name;
- GetInfoForProfileAtIndex(index)->GetString(
- kShortcutNameKey, &shortcut_name);
- return shortcut_name;
-}
-base::FilePath ProfileInfoCache::GetPathOfProfileAtIndex(size_t index) const {
- return user_data_dir_.AppendASCII(sorted_keys_[index]);
-}
-string16 ProfileInfoCache::GetUserNameOfProfileAtIndex(size_t index) const {
- string16 user_name;
- GetInfoForProfileAtIndex(index)->GetString(kUserNameKey, &user_name);
- return user_name;
-}
-const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfileAtIndex(
- size_t index) const {
- if (IsUsingGAIAPictureOfProfileAtIndex(index)) {
- const gfx::Image* image = GetGAIAPictureOfProfileAtIndex(index);
+// size_t ProfileInfoCache::GetIndexOfProfileWithPath(
+// const base::FilePath& profile_path) const {
+// if (profile_path.DirName() != user_data_dir_)
+// return std::string::npos;
+// std::string search_key = CacheKeyFromProfilePath(profile_path);
+// for (size_t i = 0; i < sorted_keys_.size(); ++i) {
+// if (sorted_keys_[i] == search_key)
+// return i;
+// }
+// return std::string::npos;
+// }
+
+// string16 ProfileInfoCache::GetNameOfProfileAtIndex(size_t index) const {
+// string16 name;
+// if (IsUsingGAIANameOfProfileAtIndex(index)) {
+// string16 given_name = GetGAIAGivenNameOfProfileAtIndex(index);
+// name = given_name.empty() ? GetGAIANameOfProfileAtIndex(index) : given_name;
+// }
+
+// if (name.empty())
+// GetInfoForProfileAtIndex(index)->GetString(kNameKey, &name);
+// return name;
+// }
+
+// string16 ProfileInfoCache::GetShortcutNameOfProfileAtIndex(size_t index)
+// const {
+// string16 shortcut_name;
+// GetInfoForProfileAtIndex(index)->GetString(
+// kShortcutNameKey, &shortcut_name);
+// return shortcut_name;
+// }
+
+// base::FilePath ProfileInfoCache::GetPathOfProfileAtIndex(size_t index) const {
+// return user_data_dir_.AppendASCII(sorted_keys_[index]);
+// }
+
+// string16 ProfileInfoCache::GetUserNameOfProfileAtIndex(size_t index) const {
+// string16 user_name;
+// GetInfoForProfileAtIndex(index)->GetString(kUserNameKey, &user_name);
+// return user_name;
+// }
+
+const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfile(const base::FilePath& profile_path) const {
+ ProfileInfoEntry info;
+
+ // TODO(noms): What happens in the error case here?
+ GetInfoForProfile(profile_path, &info);
+
+ if (info.is_using_GAIA_picture()) {
+ const gfx::Image* image = GetGAIAPictureOfProfile(profile_path);
if (image)
return *image;
}
- int resource_id = GetDefaultAvatarIconResourceIDAtIndex(
- GetAvatarIconIndexOfProfileAtIndex(index));
+ int resource_id = GetDefaultAvatarIconResourceIDAtIndex(info.icon_index());
return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
}
-bool ProfileInfoCache::GetBackgroundStatusOfProfileAtIndex(
- size_t index) const {
- bool background_app_status;
- if (!GetInfoForProfileAtIndex(index)->GetBoolean(kBackgroundAppsKey,
- &background_app_status)) {
- return false;
- }
- return background_app_status;
-}
-
-string16 ProfileInfoCache::GetGAIANameOfProfileAtIndex(size_t index) const {
- string16 name;
- GetInfoForProfileAtIndex(index)->GetString(kGAIANameKey, &name);
- return name;
-}
-
-string16 ProfileInfoCache::GetGAIAGivenNameOfProfileAtIndex(
- size_t index) const {
- string16 name;
- GetInfoForProfileAtIndex(index)->GetString(kGAIAGivenNameKey, &name);
- return name;
-}
-
-bool ProfileInfoCache::IsUsingGAIANameOfProfileAtIndex(size_t index) const {
- bool value = false;
- GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIANameKey, &value);
- return value;
-}
+// bool ProfileInfoCache::GetBackgroundStatusOfProfileAtIndex(
+// size_t index) const {
+// bool background_app_status;
+// if (!GetInfoForProfileAtIndex(index)->GetBoolean(kBackgroundAppsKey,
+// &background_app_status)) {
+// return false;
+// }
+// return background_app_status;
+// }
+
+// string16 ProfileInfoCache::GetGAIANameOfProfileAtIndex(size_t index) const {
+// string16 name;
+// GetInfoForProfileAtIndex(index)->GetString(kGAIANameKey, &name);
+// return name;
+// }
+
+// string16 ProfileInfoCache::GetGAIAGivenNameOfProfileAtIndex(
+// size_t index) const {
+// string16 name;
+// GetInfoForProfileAtIndex(index)->GetString(kGAIAGivenNameKey, &name);
+// return name;
+// }
+
+// bool ProfileInfoCache::IsUsingGAIANameOfProfileAtIndex(size_t index) const {
+// bool value = false;
+// GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIANameKey, &value);
+// return value;
+// }
+
+const gfx::Image* ProfileInfoCache::GetGAIAPictureOfProfile(
+ const base::FilePath& profile_path) const {
+ ProfileInfoEntry info;
+ if (!GetInfoForProfile(profile_path, &info))
+ return NULL;
-const gfx::Image* ProfileInfoCache::GetGAIAPictureOfProfileAtIndex(
- size_t index) const {
- base::FilePath path = GetPathOfProfileAtIndex(index);
- std::string key = CacheKeyFromProfilePath(path);
+ std::string key = CacheKeyFromProfilePath(profile_path);
// If the picture is already loaded then use it.
if (gaia_pictures_.count(key)) {
@@ -369,9 +435,7 @@ const gfx::Image* ProfileInfoCache::GetGAIAPictureOfProfileAtIndex(
return gaia_pictures_[key];
}
- std::string file_name;
- GetInfoForProfileAtIndex(index)->GetString(
- kGAIAPictureFileNameKey, &file_name);
+ std::string file_name = info.GAIA_picture_file_name();
// If the picture is not on disk or it is already being loaded then return
// NULL.
@@ -379,32 +443,33 @@ const gfx::Image* ProfileInfoCache::GetGAIAPictureOfProfileAtIndex(
return NULL;
gaia_pictures_loading_[key] = true;
- base::FilePath image_path = path.AppendASCII(file_name);
+ base::FilePath image_path = profile_path.AppendASCII(file_name);
gfx::Image** image = new gfx::Image*;
BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE,
base::Bind(&ReadBitmap, image_path, image),
base::Bind(&ProfileInfoCache::OnGAIAPictureLoaded,
- const_cast<ProfileInfoCache*>(this)->AsWeakPtr(), path, image));
+ const_cast<ProfileInfoCache*>(this)->AsWeakPtr(),
+ profile_path, image));
return NULL;
}
-bool ProfileInfoCache::ProfileIsManagedAtIndex(size_t index) const {
- return !GetManagedUserIdOfProfileAtIndex(index).empty();
-}
+// bool ProfileInfoCache::ProfileIsManagedAtIndex(size_t index) const {
+// return !GetManagedUserIdOfProfileAtIndex(index).empty();
+// }
-bool ProfileInfoCache::ProfileIsSigninRequiredAtIndex(size_t index) const {
- bool value = false;
- GetInfoForProfileAtIndex(index)->GetBoolean(kSigninRequiredKey, &value);
- return value;
-}
+// bool ProfileInfoCache::ProfileIsSigninRequiredAtIndex(size_t index) const {
+// bool value = false;
+// GetInfoForProfileAtIndex(index)->GetBoolean(kSigninRequiredKey, &value);
+// return value;
+// }
-std::string ProfileInfoCache::GetManagedUserIdOfProfileAtIndex(
- size_t index) const {
- std::string managed_user_id;
- GetInfoForProfileAtIndex(index)->GetString(kManagedUserId, &managed_user_id);
- return managed_user_id;
-}
+// std::string ProfileInfoCache::GetManagedUserIdOfProfileAtIndex(
+// size_t index) const {
+// std::string managed_user_id;
+// GetInfoForProfileAtIndex(index)->GetString(kManagedUserId, &managed_user_id);
+// return managed_user_id;
+// }
bool ProfileInfoCache::ProfileIsEphemeralAtIndex(size_t index) const {
bool value = false;
@@ -447,158 +512,160 @@ void ProfileInfoCache::OnGAIAPictureSaved(const base::FilePath& path,
delete success;
}
-bool ProfileInfoCache::IsUsingGAIAPictureOfProfileAtIndex(
- size_t index) const {
- bool value = false;
- GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIAPictureKey, &value);
- return value;
-}
-
-size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index)
- const {
- std::string icon_url;
- GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url);
- size_t icon_index = 0;
- if (!IsDefaultAvatarIconUrl(icon_url, &icon_index))
- DLOG(WARNING) << "Unknown avatar icon: " << icon_url;
-
- return icon_index;
-}
-
-void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index,
- const string16& name) {
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- string16 current_name;
- info->GetString(kNameKey, &current_name);
- if (name == current_name)
- return;
-
- string16 old_display_name = GetNameOfProfileAtIndex(index);
- info->SetString(kNameKey, name);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
- string16 new_display_name = GetNameOfProfileAtIndex(index);
- base::FilePath profile_path = GetPathOfProfileAtIndex(index);
- UpdateSortForProfileIndex(index);
-
- if (old_display_name != new_display_name) {
- FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
- observer_list_,
- OnProfileNameChanged(profile_path, old_display_name));
- }
-}
-
-void ProfileInfoCache::SetShortcutNameOfProfileAtIndex(
- size_t index,
- const string16& shortcut_name) {
- if (shortcut_name == GetShortcutNameOfProfileAtIndex(index))
- return;
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetString(kShortcutNameKey, shortcut_name);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
-}
-
-void ProfileInfoCache::SetUserNameOfProfileAtIndex(size_t index,
- const string16& user_name) {
- if (user_name == GetUserNameOfProfileAtIndex(index))
- return;
-
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetString(kUserNameKey, user_name);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
-}
-
-void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index,
- size_t icon_index) {
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index));
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
-
- base::FilePath profile_path = GetPathOfProfileAtIndex(index);
- FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
- observer_list_,
- OnProfileAvatarChanged(profile_path));
-}
-
-void ProfileInfoCache::SetManagedUserIdOfProfileAtIndex(size_t index,
- const std::string& id) {
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetString(kManagedUserId, id);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
-}
-
-void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex(
- size_t index,
- bool running_background_apps) {
- if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps)
- return;
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetBoolean(kBackgroundAppsKey, running_background_apps);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
-}
-
-void ProfileInfoCache::SetGAIANameOfProfileAtIndex(size_t index,
- const string16& name) {
- if (name == GetGAIANameOfProfileAtIndex(index))
- return;
-
- string16 old_display_name = GetNameOfProfileAtIndex(index);
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetString(kGAIANameKey, name);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
- string16 new_display_name = GetNameOfProfileAtIndex(index);
- base::FilePath profile_path = GetPathOfProfileAtIndex(index);
- UpdateSortForProfileIndex(index);
-
- if (old_display_name != new_display_name) {
- FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
- observer_list_,
- OnProfileNameChanged(profile_path, old_display_name));
- }
-}
-
-void ProfileInfoCache::SetGAIAGivenNameOfProfileAtIndex(
- size_t index,
- const string16& name) {
- if (name == GetGAIAGivenNameOfProfileAtIndex(index))
- return;
-
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetString(kGAIAGivenNameKey, name);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
-}
-
-void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index,
- bool value) {
- if (value == IsUsingGAIANameOfProfileAtIndex(index))
- return;
+// bool ProfileInfoCache::IsUsingGAIAPictureOfProfileAtIndex(
+// size_t index) const {
+// bool value = false;
+// GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIAPictureKey, &value);
+// return value;
+// }
+
+// size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index)
+// const {
+// std::string icon_url;
+// GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url);
+// size_t icon_index = 0;
+// if (!IsDefaultAvatarIconUrl(icon_url, &icon_index))
+// DLOG(WARNING) << "Unknown avatar icon: " << icon_url;
+
+// return icon_index;
+// }
+
+// void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index,
+// const string16& name) {
+// scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+// string16 current_name;
+// info->GetString(kNameKey, &current_name);
+// if (name == current_name)
+// return;
+
+// string16 old_display_name = GetNameOfProfileAtIndex(index);
+// info->SetString(kNameKey, name);
+// // This takes ownership of |info|.
+// SetInfoForProfileAtIndex(index, info.release());
+// string16 new_display_name = GetNameOfProfileAtIndex(index);
+// base::FilePath profile_path = GetPathOfProfileAtIndex(index);
+// UpdateSortForProfileIndex(index);
+
+// if (old_display_name != new_display_name) {
+// FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
+// observer_list_,
+// OnProfileNameChanged(profile_path, old_display_name));
+// }
+// }
+
+// void ProfileInfoCache::SetShortcutNameOfProfileAtIndex(
+// size_t index,
+// const string16& shortcut_name) {
+// if (shortcut_name == GetShortcutNameOfProfileAtIndex(index))
+// return;
+// scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+// info->SetString(kShortcutNameKey, shortcut_name);
+// // This takes ownership of |info|.
+// SetInfoForProfileAtIndex(index, info.release());
+// }
+
+// void ProfileInfoCache::SetUserNameOfProfileAtIndex(size_t index,
+// const string16& user_name) {
+// if (user_name == GetUserNameOfProfileAtIndex(index))
+// return;
+
+// scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+// info->SetString(kUserNameKey, user_name);
+// // This takes ownership of |info|.
+// SetInfoForProfileAtIndex(index, info.release());
+// }
+
+// void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index,
+// size_t icon_index) {
+// scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+// info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index));
+// // This takes ownership of |info|.
+// SetInfoForProfileAtIndex(index, info.release());
+
+// base::FilePath profile_path = GetPathOfProfileAtIndex(index);
+// FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
+// observer_list_,
+// OnProfileAvatarChanged(profile_path));
+// }
+
+// void ProfileInfoCache::SetManagedUserIdOfProfileAtIndex(size_t index,
+// const std::string& id) {
+// scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+// info->SetString(kManagedUserId, id);
+// // This takes ownership of |info|.
+// SetInfoForProfileAtIndex(index, info.release());
+// }
+
+// void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex(
+// size_t index,
+// bool running_background_apps) {
+// if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps)
+// return;
+// scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+// info->SetBoolean(kBackgroundAppsKey, running_background_apps);
+// // This takes ownership of |info|.
+// SetInfoForProfileAtIndex(index, info.release());
+// }
+
+// void ProfileInfoCache::SetGAIANameOfProfileAtIndex(size_t index,
+// const string16& name) {
+// if (name == GetGAIANameOfProfileAtIndex(index))
+// return;
+
+// string16 old_display_name = GetNameOfProfileAtIndex(index);
+// scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+// info->SetString(kGAIANameKey, name);
+// // This takes ownership of |info|.
+// SetInfoForProfileAtIndex(index, info.release());
+// string16 new_display_name = GetNameOfProfileAtIndex(index);
+// base::FilePath profile_path = GetPathOfProfileAtIndex(index);
+// UpdateSortForProfileIndex(index);
+
+// if (old_display_name != new_display_name) {
+// FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
+// observer_list_,
+// OnProfileNameChanged(profile_path, old_display_name));
+// }
+// }
+
+// void ProfileInfoCache::SetGAIAGivenNameOfProfileAtIndex(
+// size_t index,
+// const string16& name) {
+// if (name == GetGAIAGivenNameOfProfileAtIndex(index))
+// return;
+
+// scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+// info->SetString(kGAIAGivenNameKey, name);
+// // This takes ownership of |info|.
+// SetInfoForProfileAtIndex(index, info.release());
+// }
+
+// void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index,
+// bool value) {
+// if (value == IsUsingGAIANameOfProfileAtIndex(index))
+// return;
+
+// string16 old_display_name = GetNameOfProfileAtIndex(index);
+// scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+// info->SetBoolean(kUseGAIANameKey, value);
+// // This takes ownership of |info|.
+// SetInfoForProfileAtIndex(index, info.release());
+// string16 new_display_name = GetNameOfProfileAtIndex(index);
+// base::FilePath profile_path = GetPathOfProfileAtIndex(index);
+// UpdateSortForProfileIndex(index);
+
+// if (old_display_name != new_display_name) {
+// FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
+// observer_list_,
+// OnProfileNameChanged(profile_path, old_display_name));
+// }
+// }
+
+void ProfileInfoCache::SetGAIAPictureOfProfile(const base::FilePath& path,
+ const gfx::Image* image) {
+ ProfileInfoEntry entry;
+ GetInfoForProfile(path, &entry);
- string16 old_display_name = GetNameOfProfileAtIndex(index);
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetBoolean(kUseGAIANameKey, value);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
- string16 new_display_name = GetNameOfProfileAtIndex(index);
- base::FilePath profile_path = GetPathOfProfileAtIndex(index);
- UpdateSortForProfileIndex(index);
-
- if (old_display_name != new_display_name) {
- FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
- observer_list_,
- OnProfileNameChanged(profile_path, old_display_name));
- }
-}
-
-void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index,
- const gfx::Image* image) {
- base::FilePath path = GetPathOfProfileAtIndex(index);
std::string key = CacheKeyFromProfilePath(path);
// Delete the old bitmap from cache.
@@ -608,9 +675,7 @@ void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index,
gaia_pictures_.erase(it);
}
- std::string old_file_name;
- GetInfoForProfileAtIndex(index)->GetString(
- kGAIAPictureFileNameKey, &old_file_name);
+ std::string old_file_name = entry.GAIA_picture_file_name();
std::string new_file_name;
if (!image) {
@@ -640,40 +705,38 @@ void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index,
}
}
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetString(kGAIAPictureFileNameKey, new_file_name);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
+ entry.set_GAIA_picture_file_name(new_file_name);
+ SetInfoForProfile(entry);
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
OnProfileAvatarChanged(path));
}
-void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index,
- bool value) {
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetBoolean(kUseGAIAPictureKey, value);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
+// void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index,
+// bool value) {
+// scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+// info->SetBoolean(kUseGAIAPictureKey, value);
+// // This takes ownership of |info|.
+// SetInfoForProfileAtIndex(index, info.release());
- // Retrieve some info to update observers who care about avatar changes.
- base::FilePath profile_path = GetPathOfProfileAtIndex(index);
- FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
- observer_list_,
- OnProfileAvatarChanged(profile_path));
-}
+// // Retrieve some info to update observers who care about avatar changes.
+// base::FilePath profile_path = GetPathOfProfileAtIndex(index);
+// FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
+// observer_list_,
+// OnProfileAvatarChanged(profile_path));
+// }
-void ProfileInfoCache::SetProfileSigninRequiredAtIndex(size_t index,
- bool value) {
- if (value == ProfileIsSigninRequiredAtIndex(index))
- return;
+// void ProfileInfoCache::SetProfileSigninRequiredAtIndex(size_t index,
+// bool value) {
+// if (value == ProfileIsSigninRequiredAtIndex(index))
+// return;
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetBoolean(kSigninRequiredKey, value);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
-}
+// scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+// info->SetBoolean(kSigninRequiredKey, value);
+// // This takes ownership of |info|.
+// SetInfoForProfileAtIndex(index, info.release());
+// }
void ProfileInfoCache::SetProfileIsEphemeralAtIndex(size_t index, bool value) {
if (value == ProfileIsEphemeralAtIndex(index))
@@ -700,8 +763,11 @@ string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) const {
// Loop through previously named profiles to ensure we're not duplicating.
bool name_found = false;
- for (size_t i = 0; i < GetNumberOfProfiles(); ++i) {
- if (GetNameOfProfileAtIndex(i) == name) {
+
+ const std::vector<ProfileInfoEntry> entries(GetProfilesSortedByName());
+ for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin();
+ it != entries.end(); ++it) {
+ if (it->GetDisplayName() == name) {
name_found = true;
break;
}
@@ -711,25 +777,27 @@ string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) const {
}
}
-bool ProfileInfoCache::GetHasMigratedToGAIAInfoOfProfileAtIndex(
- size_t index) const {
- bool value = false;
- GetInfoForProfileAtIndex(index)->GetBoolean(
- kHasMigratedToGAIAInfoKey, &value);
- return value;
-}
+// bool ProfileInfoCache::GetHasMigratedToGAIAInfoOfProfileAtIndex(
+// size_t index) const {
+// bool value = false;
+// GetInfoForProfileAtIndex(index)->GetBoolean(
+// kHasMigratedToGAIAInfoKey, &value);
+// return value;
+// }
-void ProfileInfoCache::SetHasMigratedToGAIAInfoOfProfileAtIndex(
- size_t index, bool value) {
- scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
- info->SetBoolean(kHasMigratedToGAIAInfoKey, value);
- // This takes ownership of |info|.
- SetInfoForProfileAtIndex(index, info.release());
-}
+// void ProfileInfoCache::SetHasMigratedToGAIAInfoOfProfileAtIndex(
+// size_t index, bool value) {
+// scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy());
+// info->SetBoolean(kHasMigratedToGAIAInfoKey, value);
+// // This takes ownership of |info|.
+// SetInfoForProfileAtIndex(index, info.release());
+// }
bool ProfileInfoCache::IconIndexIsUnique(size_t icon_index) const {
- for (size_t i = 0; i < GetNumberOfProfiles(); ++i) {
- if (GetAvatarIconIndexOfProfileAtIndex(i) == icon_index)
+ const std::vector<ProfileInfoEntry> entries(GetProfilesSortedByName());
+ for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin();
+ it != entries.end(); ++it) {
+ if (it->icon_index() == icon_index)
return false;
}
return true;
@@ -819,69 +887,71 @@ bool ProfileInfoCache::IsDefaultAvatarIconUrl(const std::string& url,
return false;
}
-const DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex(
- size_t index) const {
- DCHECK_LT(index, GetNumberOfProfiles());
- const DictionaryValue* cache =
- prefs_->GetDictionary(prefs::kProfileInfoCache);
- const DictionaryValue* info = NULL;
- cache->GetDictionaryWithoutPathExpansion(sorted_keys_[index], &info);
- return info;
-}
-
-void ProfileInfoCache::SetInfoForProfileAtIndex(size_t index,
- DictionaryValue* info) {
- DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache);
- DictionaryValue* cache = update.Get();
- cache->SetWithoutPathExpansion(sorted_keys_[index], info);
-
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
- content::NotificationService::AllSources(),
- content::NotificationService::NoDetails());
-}
+// const DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex(
+// size_t index) const {
+// DCHECK_LT(index, GetNumberOfProfiles());
+// const DictionaryValue* cache =
+// prefs_->GetDictionary(prefs::kProfileInfoCache);
+// const DictionaryValue* info = NULL;
+// cache->GetDictionaryWithoutPathExpansion(sorted_keys_[index], &info);
+// return info;
+// }
+
+// void ProfileInfoCache::SetInfoForProfileAtIndex(size_t index,
+// DictionaryValue* info) {
+// DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache);
+// DictionaryValue* cache = update.Get();
+// cache->SetWithoutPathExpansion(sorted_keys_[index], info);
+
+// content::NotificationService::current()->Notify(
+// chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
+// content::NotificationService::AllSources(),
+// content::NotificationService::NoDetails());
+// }
std::string ProfileInfoCache::CacheKeyFromProfilePath(
const base::FilePath& profile_path) const {
- DCHECK(user_data_dir_ == profile_path.DirName());
+ //DCHECK(user_data_dir_ == profile_path.DirName());
+ LOG(ERROR) << "user data is " << user_data_dir_.MaybeAsASCII();
+ LOG(ERROR) << "profile path is " << profile_path.DirName().MaybeAsASCII();
base::FilePath base_name = profile_path.BaseName();
return base_name.MaybeAsASCII();
}
-std::vector<std::string>::iterator ProfileInfoCache::FindPositionForProfile(
- const std::string& search_key,
- const string16& search_name) {
- string16 search_name_l = base::i18n::ToLower(search_name);
- for (size_t i = 0; i < GetNumberOfProfiles(); ++i) {
- string16 name_l = base::i18n::ToLower(GetNameOfProfileAtIndex(i));
- int name_compare = search_name_l.compare(name_l);
- if (name_compare < 0)
- return sorted_keys_.begin() + i;
- if (name_compare == 0) {
- int key_compare = search_key.compare(sorted_keys_[i]);
- if (key_compare < 0)
- return sorted_keys_.begin() + i;
- }
- }
- return sorted_keys_.end();
-}
-
-void ProfileInfoCache::UpdateSortForProfileIndex(size_t index) {
- string16 name = GetNameOfProfileAtIndex(index);
-
- // Remove and reinsert key in |sorted_keys_| to alphasort.
- std::string key = CacheKeyFromProfilePath(GetPathOfProfileAtIndex(index));
- std::vector<std::string>::iterator key_it =
- std::find(sorted_keys_.begin(), sorted_keys_.end(), key);
- DCHECK(key_it != sorted_keys_.end());
- sorted_keys_.erase(key_it);
- sorted_keys_.insert(FindPositionForProfile(key, name), key);
-
- content::NotificationService::current()->Notify(
- chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
- content::NotificationService::AllSources(),
- content::NotificationService::NoDetails());
-}
+// std::vector<std::string>::iterator ProfileInfoCache::FindPositionForProfile(
+// const std::string& search_key,
+// const string16& search_name) {
+// string16 search_name_l = base::i18n::ToLower(search_name);
+// for (size_t i = 0; i < GetNumberOfProfiles(); ++i) {
+// string16 name_l = base::i18n::ToLower(GetNameOfProfileAtIndex(i));
+// int name_compare = search_name_l.compare(name_l);
+// if (name_compare < 0)
+// return sorted_keys_.begin() + i;
+// if (name_compare == 0) {
+// int key_compare = search_key.compare(sorted_keys_[i]);
+// if (key_compare < 0)
+// return sorted_keys_.begin() + i;
+// }
+// }
+// return sorted_keys_.end();
+// }
+
+// void ProfileInfoCache::UpdateSortForProfileIndex(size_t index) {
+// string16 name = GetNameOfProfileAtIndex(index);
+
+// // Remove and reinsert key in |sorted_keys_| to alphasort.
+// std::string key = CacheKeyFromProfilePath(GetPathOfProfileAtIndex(index));
+// std::vector<std::string>::iterator key_it =
+// std::find(sorted_keys_.begin(), sorted_keys_.end(), key);
+// DCHECK(key_it != sorted_keys_.end());
+// sorted_keys_.erase(key_it);
+// sorted_keys_.insert(FindPositionForProfile(key, name), key);
+
+// content::NotificationService::current()->Notify(
+// chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
+// content::NotificationService::AllSources(),
+// content::NotificationService::NoDetails());
+// }
// static
std::vector<string16> ProfileInfoCache::GetProfileNames() {
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.h ('k') | chrome/browser/profiles/profile_info_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698