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

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

Issue 1214483002: Improve the ProfileInfoCache API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback and slightly change the interface. 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_info_cache.cc
diff --git a/chrome/browser/profiles/profile_info_cache.cc b/chrome/browser/profiles/profile_info_cache.cc
index 2c1d80f166e7e4edac254274f0375594ff4ffb6f..94e7182451507917f3a7a9860d642932048d024e 100644
--- a/chrome/browser/profiles/profile_info_cache.cc
+++ b/chrome/browser/profiles/profile_info_cache.cc
@@ -259,6 +259,7 @@ void ProfileInfoCache::DeleteProfileFromCache(
std::string key = CacheKeyFromProfilePath(profile_path);
cache->Remove(key, NULL);
sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key));
+ profile_attributes_entries_.erase(profile_path);
FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
observer_list_,
@@ -1238,3 +1239,52 @@ void ProfileInfoCache::MigrateLegacyProfileNamesAndDownloadAvatars() {
}
#endif
}
+
+void ProfileInfoCache::AddProfile(
+ const base::FilePath& profile_path,
+ const base::string16& name,
+ const std::string& gaia_id,
+ const base::string16& user_name,
+ size_t icon_index,
+ const std::string& supervised_user_id) {
+ AddProfileToCache(
+ profile_path, name, gaia_id, user_name, icon_index, supervised_user_id);
+}
+
+void ProfileInfoCache::DeleteProfile(const base::FilePath& profile_path) {
+ DeleteProfileFromCache(profile_path);
+}
+
+std::vector<ProfileAttributesEntry*>
+ProfileInfoCache::GetAllProfilesAttributes() {
+ std::vector<ProfileAttributesEntry*> ret;
+ for (size_t i = 0; i < GetNumberOfProfiles(); ++i) {
+ ProfileAttributesEntry* entry;
+ if (GetProfileAttributesWithPath(GetPathOfProfileAtIndex(i), &entry)) {
+ ret.push_back(entry);
+ }
+ }
+ return ret;
+}
+
+bool ProfileInfoCache::GetProfileAttributesWithPath(
+ const base::FilePath& path, ProfileAttributesEntry** entry) {
+ if (GetNumberOfProfiles() == 0) {
Mike Lerman 2015/07/08 18:26:35 nit: braces unneeded here - the condition's really
anthonyvd 2015/07/09 17:02:14 Done.
+ return false;
+ }
+
+ size_t index = GetIndexOfProfileWithPath(path);
Mike Lerman 2015/07/08 18:26:35 inline GetIndexOfProfileWithPath into the conditio
anthonyvd 2015/07/09 17:02:14 Done.
+ if (index == std::string::npos) {
+ return false;
+ }
+
+ if (profile_attributes_entries_.find(path) ==
+ profile_attributes_entries_.end()) {
+ // The profile info is in the cache but its entry isn't created yet, insert
+ // it in the map.
+ profile_attributes_entries_[path].Initialize(this, path);
+ }
+
+ *entry = &profile_attributes_entries_[path];
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698