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

Side by Side Diff: chrome/browser/profiles/profile_info_cache.cc

Issue 7400032: Multi-profile WebUI settings (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Notify when deleting profile from cache Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 19 matching lines...) Expand all
30 30
31 const int kDefaultAvatarIconResources[] = { 31 const int kDefaultAvatarIconResources[] = {
32 IDR_PROFILE_AVATAR_0, 32 IDR_PROFILE_AVATAR_0,
33 IDR_PROFILE_AVATAR_1, 33 IDR_PROFILE_AVATAR_1,
34 IDR_PROFILE_AVATAR_2, 34 IDR_PROFILE_AVATAR_2,
35 IDR_PROFILE_AVATAR_3, 35 IDR_PROFILE_AVATAR_3,
36 }; 36 };
37 37
38 const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources); 38 const size_t kDefaultAvatarIconsCount = arraysize(kDefaultAvatarIconResources);
39 39
40 // Checks if the given URL points to one of the default avatar icons. if it is,
41 // returns true and its index through |icon_index|. If not, returns false.
42 bool IsDefaultAvatarIconUrl(const std::string& url, size_t* icon_index) {
43 DCHECK(icon_index);
44 if (url.find(kDefaultUrlPrefix) != 0)
45 return false;
46
47 int int_value = -1;
48 if (base::StringToInt(url.begin() + strlen(kDefaultUrlPrefix),
49 url.end(),
50 &int_value)) {
51 if (int_value < 0 ||
52 int_value >= static_cast<int>(kDefaultAvatarIconsCount))
53 return false;
54 *icon_index = int_value;
55 return true;
56 }
57
58 return false;
59 }
60
61 } // namespace 40 } // namespace
62 41
63 ProfileInfoCache::ProfileInfoCache(PrefService* prefs, 42 ProfileInfoCache::ProfileInfoCache(PrefService* prefs,
64 const FilePath& user_data_dir) 43 const FilePath& user_data_dir)
65 : prefs_(prefs), 44 : prefs_(prefs),
66 user_data_dir_(user_data_dir) { 45 user_data_dir_(user_data_dir) {
67 // Populate the cache 46 // Populate the cache
68 const DictionaryValue* cache = 47 const DictionaryValue* cache =
69 prefs_->GetDictionary(prefs::kProfileInfoCache); 48 prefs_->GetDictionary(prefs::kProfileInfoCache);
70 for (DictionaryValue::key_iterator it = cache->begin_keys(); 49 for (DictionaryValue::key_iterator it = cache->begin_keys();
(...skipping 25 matching lines...) Expand all
96 sorted_keys_.insert(FindPositionForProfile(key, name), key); 75 sorted_keys_.insert(FindPositionForProfile(key, name), key);
97 } 76 }
98 77
99 void ProfileInfoCache::DeleteProfileFromCache(const FilePath& profile_path) { 78 void ProfileInfoCache::DeleteProfileFromCache(const FilePath& profile_path) {
100 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); 79 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache);
101 DictionaryValue* cache = update.Get(); 80 DictionaryValue* cache = update.Get();
102 81
103 std::string key = CacheKeyFromProfilePath(profile_path); 82 std::string key = CacheKeyFromProfilePath(profile_path);
104 cache->Remove(key, NULL); 83 cache->Remove(key, NULL);
105 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); 84 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key));
85
86 NotificationService::current()->Notify(
sail 2011/07/19 19:39:50 Good catch. Can you add this to AddProfileToCache
87 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
88 NotificationService::AllSources(),
89 NotificationService::NoDetails());
106 } 90 }
107 91
108 size_t ProfileInfoCache::GetNumberOfProfiles() const { 92 size_t ProfileInfoCache::GetNumberOfProfiles() const {
109 return sorted_keys_.size(); 93 return sorted_keys_.size();
110 } 94 }
111 95
112 size_t ProfileInfoCache::GetIndexOfProfileWithPath( 96 size_t ProfileInfoCache::GetIndexOfProfileWithPath(
113 const FilePath& profile_path) const { 97 const FilePath& profile_path) const {
114 if (profile_path.DirName() != user_data_dir_) 98 if (profile_path.DirName() != user_data_dir_)
115 return std::string::npos; 99 return std::string::npos;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 int ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(size_t index) { 205 int ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(size_t index) {
222 DCHECK_LT(index, GetDefaultAvatarIconCount()); 206 DCHECK_LT(index, GetDefaultAvatarIconCount());
223 return kDefaultAvatarIconResources[index]; 207 return kDefaultAvatarIconResources[index];
224 } 208 }
225 209
226 std::string ProfileInfoCache::GetDefaultAvatarIconUrl(size_t index) { 210 std::string ProfileInfoCache::GetDefaultAvatarIconUrl(size_t index) {
227 DCHECK_LT(index, kDefaultAvatarIconsCount); 211 DCHECK_LT(index, kDefaultAvatarIconsCount);
228 return StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index); 212 return StringPrintf("%s%" PRIuS, kDefaultUrlPrefix, index);
229 } 213 }
230 214
215 bool ProfileInfoCache::IsDefaultAvatarIconUrl(const std::string& url,
Miranda Callahan 2011/07/19 20:40:55 nit: could you put "// static" above this method s
216 size_t* icon_index) {
217 DCHECK(icon_index);
218 if (url.find(kDefaultUrlPrefix) != 0)
219 return false;
220
221 int int_value = -1;
222 if (base::StringToInt(url.begin() + strlen(kDefaultUrlPrefix),
223 url.end(),
224 &int_value)) {
225 if (int_value < 0 ||
226 int_value >= static_cast<int>(kDefaultAvatarIconsCount))
227 return false;
228 *icon_index = int_value;
229 return true;
230 }
231
232 return false;
233 }
234
231 const DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex( 235 const DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex(
232 size_t index) const { 236 size_t index) const {
233 DCHECK_LT(index, GetNumberOfProfiles()); 237 DCHECK_LT(index, GetNumberOfProfiles());
234 const DictionaryValue* cache = 238 const DictionaryValue* cache =
235 prefs_->GetDictionary(prefs::kProfileInfoCache); 239 prefs_->GetDictionary(prefs::kProfileInfoCache);
236 DictionaryValue* info = NULL; 240 DictionaryValue* info = NULL;
237 cache->GetDictionary(sorted_keys_[index], &info); 241 cache->GetDictionary(sorted_keys_[index], &info);
238 return info; 242 return info;
239 } 243 }
240 244
(...skipping 28 matching lines...) Expand all
269 if (key_compare < 0) 273 if (key_compare < 0)
270 return sorted_keys_.begin() + i; 274 return sorted_keys_.begin() + i;
271 } 275 }
272 } 276 }
273 return sorted_keys_.end(); 277 return sorted_keys_.end();
274 } 278 }
275 279
276 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) { 280 void ProfileInfoCache::RegisterPrefs(PrefService* prefs) {
277 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache); 281 prefs->RegisterDictionaryPref(prefs::kProfileInfoCache);
278 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698