OLD | NEW |
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/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 169 |
170 } // namespace | 170 } // namespace |
171 | 171 |
172 ProfileInfoCache::ProfileInfoCache(PrefService* prefs, | 172 ProfileInfoCache::ProfileInfoCache(PrefService* prefs, |
173 const base::FilePath& user_data_dir) | 173 const base::FilePath& user_data_dir) |
174 : prefs_(prefs), | 174 : prefs_(prefs), |
175 user_data_dir_(user_data_dir) { | 175 user_data_dir_(user_data_dir) { |
176 // Populate the cache | 176 // Populate the cache |
177 const DictionaryValue* cache = | 177 const DictionaryValue* cache = |
178 prefs_->GetDictionary(prefs::kProfileInfoCache); | 178 prefs_->GetDictionary(prefs::kProfileInfoCache); |
179 for (DictionaryValue::key_iterator it = cache->begin_keys(); | 179 for (DictionaryValue::Iterator it(*cache); !it.IsAtEnd(); it.Advance()) { |
180 it != cache->end_keys(); ++it) { | |
181 std::string key = *it; | |
182 const DictionaryValue* info = NULL; | 180 const DictionaryValue* info = NULL; |
183 cache->GetDictionary(key, &info); | 181 it.value().GetAsDictionary(&info); |
184 string16 name; | 182 string16 name; |
185 info->GetString(kNameKey, &name); | 183 info->GetString(kNameKey, &name); |
186 sorted_keys_.insert(FindPositionForProfile(key, name), key); | 184 sorted_keys_.insert(FindPositionForProfile(it.key(), name), it.key()); |
187 } | 185 } |
188 } | 186 } |
189 | 187 |
190 ProfileInfoCache::~ProfileInfoCache() { | 188 ProfileInfoCache::~ProfileInfoCache() { |
191 STLDeleteContainerPairSecondPointers( | 189 STLDeleteContainerPairSecondPointers( |
192 gaia_pictures_.begin(), gaia_pictures_.end()); | 190 gaia_pictures_.begin(), gaia_pictures_.end()); |
193 } | 191 } |
194 | 192 |
195 void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path, | 193 void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path, |
196 const string16& name, | 194 const string16& name, |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 content::NotificationService::NoDetails()); | 804 content::NotificationService::NoDetails()); |
807 } | 805 } |
808 | 806 |
809 // static | 807 // static |
810 std::vector<string16> ProfileInfoCache::GetProfileNames() { | 808 std::vector<string16> ProfileInfoCache::GetProfileNames() { |
811 std::vector<string16> names; | 809 std::vector<string16> names; |
812 PrefService* local_state = g_browser_process->local_state(); | 810 PrefService* local_state = g_browser_process->local_state(); |
813 const DictionaryValue* cache = local_state->GetDictionary( | 811 const DictionaryValue* cache = local_state->GetDictionary( |
814 prefs::kProfileInfoCache); | 812 prefs::kProfileInfoCache); |
815 string16 name; | 813 string16 name; |
816 for (base::DictionaryValue::key_iterator it = cache->begin_keys(); | 814 for (base::DictionaryValue::Iterator it(*cache); !it.IsAtEnd(); |
817 it != cache->end_keys(); | 815 it.Advance()) { |
818 ++it) { | |
819 const base::DictionaryValue* info = NULL; | 816 const base::DictionaryValue* info = NULL; |
820 cache->GetDictionary(*it, &info); | 817 it.value().GetAsDictionary(&info); |
821 info->GetString(kNameKey, &name); | 818 info->GetString(kNameKey, &name); |
822 names.push_back(name); | 819 names.push_back(name); |
823 } | 820 } |
824 return names; | 821 return names; |
825 } | 822 } |
826 | 823 |
827 // static | 824 // static |
828 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { | 825 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { |
829 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); | 826 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); |
830 } | 827 } |
OLD | NEW |