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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/profiles/profile_info_cache.h" 5 #include "chrome/browser/profiles/profile_info_cache.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 252
253 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, 253 FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
254 observer_list_, 254 observer_list_,
255 OnProfileWillBeRemoved(profile_path)); 255 OnProfileWillBeRemoved(profile_path));
256 256
257 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); 257 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache);
258 base::DictionaryValue* cache = update.Get(); 258 base::DictionaryValue* cache = update.Get();
259 std::string key = CacheKeyFromProfilePath(profile_path); 259 std::string key = CacheKeyFromProfilePath(profile_path);
260 cache->Remove(key, NULL); 260 cache->Remove(key, NULL);
261 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); 261 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key));
262 profile_attributes_entries_.erase(profile_path);
262 263
263 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, 264 FOR_EACH_OBSERVER(ProfileInfoCacheObserver,
264 observer_list_, 265 observer_list_,
265 OnProfileWasRemoved(profile_path, name)); 266 OnProfileWasRemoved(profile_path, name));
266 } 267 }
267 268
268 size_t ProfileInfoCache::GetNumberOfProfiles() const { 269 size_t ProfileInfoCache::GetNumberOfProfiles() const {
269 return sorted_keys_.size(); 270 return sorted_keys_.size();
270 } 271 }
271 272
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 std::vector<base::FilePath>::const_iterator it; 1232 std::vector<base::FilePath>::const_iterator it;
1232 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { 1233 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) {
1233 size_t profile_index = GetIndexOfProfileWithPath(*it); 1234 size_t profile_index = GetIndexOfProfileWithPath(*it);
1234 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); 1235 SetProfileIsUsingDefaultNameAtIndex(profile_index, true);
1235 // This will assign a new "Person %d" type name and re-sort the cache. 1236 // This will assign a new "Person %d" type name and re-sort the cache.
1236 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( 1237 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile(
1237 GetAvatarIconIndexOfProfileAtIndex(profile_index))); 1238 GetAvatarIconIndexOfProfileAtIndex(profile_index)));
1238 } 1239 }
1239 #endif 1240 #endif
1240 } 1241 }
1242
1243 void ProfileInfoCache::AddProfile(
1244 const base::FilePath& profile_path,
1245 const base::string16& name,
1246 const std::string& gaia_id,
1247 const base::string16& user_name,
1248 size_t icon_index,
1249 const std::string& supervised_user_id) {
1250 AddProfileToCache(
1251 profile_path, name, gaia_id, user_name, icon_index, supervised_user_id);
1252 }
1253
1254 void ProfileInfoCache::DeleteProfile(const base::FilePath& profile_path) {
1255 DeleteProfileFromCache(profile_path);
1256 }
1257
1258 std::vector<ProfileAttributesEntry*>
1259 ProfileInfoCache::GetAllProfilesAttributes() {
1260 std::vector<ProfileAttributesEntry*> ret;
1261 for (size_t i = 0; i < GetNumberOfProfiles(); ++i) {
1262 ProfileAttributesEntry* entry;
1263 if (GetProfileAttributesWithPath(GetPathOfProfileAtIndex(i), &entry)) {
1264 ret.push_back(entry);
1265 }
1266 }
1267 return ret;
1268 }
1269
1270 bool ProfileInfoCache::GetProfileAttributesWithPath(
1271 const base::FilePath& path, ProfileAttributesEntry** entry) {
1272 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.
1273 return false;
1274 }
1275
1276 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.
1277 if (index == std::string::npos) {
1278 return false;
1279 }
1280
1281 if (profile_attributes_entries_.find(path) ==
1282 profile_attributes_entries_.end()) {
1283 // The profile info is in the cache but its entry isn't created yet, insert
1284 // it in the map.
1285 profile_attributes_entries_[path].Initialize(this, path);
1286 }
1287
1288 *entry = &profile_attributes_entries_[path];
1289 return true;
1290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698