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 #ifndef CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ | 5 #ifndef CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ |
6 #define CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ | 6 #define CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "chrome/browser/profiles/profile_attributes_entry.h" | |
19 #include "chrome/browser/profiles/profile_attributes_storage.h" | |
18 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 20 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
19 #include "chrome/browser/profiles/profile_info_interface.h" | 21 #include "chrome/browser/profiles/profile_info_interface.h" |
20 | 22 |
21 namespace gfx { | 23 namespace gfx { |
22 class Image; | 24 class Image; |
23 } | 25 } |
24 | 26 |
25 namespace base { | 27 namespace base { |
26 class DictionaryValue; | 28 class DictionaryValue; |
27 } | 29 } |
28 | 30 |
29 class PrefService; | 31 class PrefService; |
30 class PrefRegistrySimple; | 32 class PrefRegistrySimple; |
31 class ProfileAvatarDownloader; | 33 class ProfileAvatarDownloader; |
32 | 34 |
33 // This class saves various information about profiles to local preferences. | 35 // This class saves various information about profiles to local preferences. |
34 // This cache can be used to display a list of profiles without having to | 36 // This cache can be used to display a list of profiles without having to |
35 // actually load the profiles from disk. | 37 // actually load the profiles from disk. |
36 class ProfileInfoCache : public ProfileInfoInterface, | 38 class ProfileInfoCache : public ProfileInfoInterface, |
39 public ProfileAttributesStorage, | |
37 public base::SupportsWeakPtr<ProfileInfoCache> { | 40 public base::SupportsWeakPtr<ProfileInfoCache> { |
38 public: | 41 public: |
39 ProfileInfoCache(PrefService* prefs, const base::FilePath& user_data_dir); | 42 ProfileInfoCache(PrefService* prefs, const base::FilePath& user_data_dir); |
40 ~ProfileInfoCache() override; | 43 ~ProfileInfoCache() override; |
41 | 44 |
42 // If the |supervised_user_id| is non-empty, the profile will be marked to be | 45 // If the |supervised_user_id| is non-empty, the profile will be marked to be |
43 // omitted from the avatar-menu list on desktop versions. This is used while a | 46 // omitted from the avatar-menu list on desktop versions. This is used while a |
44 // supervised user is in the process of being registered with the server. Use | 47 // supervised user is in the process of being registered with the server. Use |
45 // SetIsOmittedProfileAtIndex() to clear the flag when the profile is ready to | 48 // SetIsOmittedProfileAtIndex() to clear the flag when the profile is ready to |
46 // be shown in the menu. | 49 // be shown in the menu. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 const base::FilePath& profile_path); | 157 const base::FilePath& profile_path); |
155 | 158 |
156 void AddObserver(ProfileInfoCacheObserver* obs); | 159 void AddObserver(ProfileInfoCacheObserver* obs); |
157 void RemoveObserver(ProfileInfoCacheObserver* obs); | 160 void RemoveObserver(ProfileInfoCacheObserver* obs); |
158 | 161 |
159 void set_disable_avatar_download_for_testing( | 162 void set_disable_avatar_download_for_testing( |
160 bool disable_avatar_download_for_testing) { | 163 bool disable_avatar_download_for_testing) { |
161 disable_avatar_download_for_testing_ = disable_avatar_download_for_testing; | 164 disable_avatar_download_for_testing_ = disable_avatar_download_for_testing; |
162 } | 165 } |
163 | 166 |
167 // ProfileMetadataStorage: | |
Mike Lerman
2015/07/08 18:26:35
Perhaps note that these methods are experimental,
anthonyvd
2015/07/09 17:02:14
Well I'd argue the opposite. If someone were to be
Mike Lerman
2015/07/09 20:47:27
SGTM.
| |
168 void AddProfile(const base::FilePath& profile_path, | |
169 const base::string16& name, | |
170 const std::string& gaia_id, | |
171 const base::string16& user_name, | |
172 size_t icon_index, | |
173 const std::string& supervised_user_id) override; | |
174 void DeleteProfile(const base::FilePath& profile_path) override; | |
175 std::vector<ProfileAttributesEntry*> GetAllProfilesAttributes() override; | |
176 bool GetProfileAttributesWithPath( | |
177 const base::FilePath& path, | |
178 ProfileAttributesEntry** entry) override; | |
179 | |
164 private: | 180 private: |
165 FRIEND_TEST_ALL_PREFIXES(ProfileInfoCacheTest, DownloadHighResAvatarTest); | 181 FRIEND_TEST_ALL_PREFIXES(ProfileInfoCacheTest, DownloadHighResAvatarTest); |
166 FRIEND_TEST_ALL_PREFIXES(ProfileInfoCacheTest, | 182 FRIEND_TEST_ALL_PREFIXES(ProfileInfoCacheTest, |
167 NothingToDownloadHighResAvatarTest); | 183 NothingToDownloadHighResAvatarTest); |
168 | 184 |
169 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; | 185 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; |
170 // Saves the profile info to a cache and takes ownership of |info|. | 186 // Saves the profile info to a cache and takes ownership of |info|. |
171 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); | 187 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); |
172 std::string CacheKeyFromProfilePath(const base::FilePath& profile_path) const; | 188 std::string CacheKeyFromProfilePath(const base::FilePath& profile_path) const; |
173 std::vector<std::string>::iterator FindPositionForProfile( | 189 std::vector<std::string>::iterator FindPositionForProfile( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 void OnAvatarPictureSaved(const std::string& file_name, | 229 void OnAvatarPictureSaved(const std::string& file_name, |
214 const base::FilePath& profile_path); | 230 const base::FilePath& profile_path); |
215 | 231 |
216 // Migrate any legacy profile names ("First user", "Default Profile") to | 232 // Migrate any legacy profile names ("First user", "Default Profile") to |
217 // new style default names ("Person 1"), and download and high-res avatars | 233 // new style default names ("Person 1"), and download and high-res avatars |
218 // used by the profiles. | 234 // used by the profiles. |
219 void MigrateLegacyProfileNamesAndDownloadAvatars(); | 235 void MigrateLegacyProfileNamesAndDownloadAvatars(); |
220 | 236 |
221 PrefService* prefs_; | 237 PrefService* prefs_; |
222 std::vector<std::string> sorted_keys_; | 238 std::vector<std::string> sorted_keys_; |
239 std::map<base::FilePath, ProfileAttributesEntry> profile_attributes_entries_; | |
223 base::FilePath user_data_dir_; | 240 base::FilePath user_data_dir_; |
224 | 241 |
225 mutable base::ObserverList<ProfileInfoCacheObserver> observer_list_; | 242 mutable base::ObserverList<ProfileInfoCacheObserver> observer_list_; |
226 | 243 |
227 // A cache of gaia/high res avatar profile pictures. This cache is updated | 244 // A cache of gaia/high res avatar profile pictures. This cache is updated |
228 // lazily so it needs to be mutable. | 245 // lazily so it needs to be mutable. |
229 mutable std::map<std::string, gfx::Image*> cached_avatar_images_; | 246 mutable std::map<std::string, gfx::Image*> cached_avatar_images_; |
230 // Marks a profile picture as loading from disk. This prevents a picture from | 247 // Marks a profile picture as loading from disk. This prevents a picture from |
231 // loading multiple times. | 248 // loading multiple times. |
232 mutable std::map<std::string, bool> cached_avatar_images_loading_; | 249 mutable std::map<std::string, bool> cached_avatar_images_loading_; |
233 | 250 |
234 // Map of profile pictures currently being downloaded from the remote | 251 // Map of profile pictures currently being downloaded from the remote |
235 // location and the ProfileAvatarDownloader instances downloading them. | 252 // location and the ProfileAvatarDownloader instances downloading them. |
236 // This prevents a picture from being downloaded multiple times. The | 253 // This prevents a picture from being downloaded multiple times. The |
237 // ProfileAvatarDownloader instances are deleted when the download completes | 254 // ProfileAvatarDownloader instances are deleted when the download completes |
238 // or when the ProfileInfoCache is destroyed. | 255 // or when the ProfileInfoCache is destroyed. |
239 std::map<std::string, ProfileAvatarDownloader*> | 256 std::map<std::string, ProfileAvatarDownloader*> |
240 avatar_images_downloads_in_progress_; | 257 avatar_images_downloads_in_progress_; |
241 | 258 |
242 // Determines of the ProfileAvatarDownloader should be created and executed | 259 // Determines of the ProfileAvatarDownloader should be created and executed |
243 // or not. Only set to true for tests. | 260 // or not. Only set to true for tests. |
244 bool disable_avatar_download_for_testing_; | 261 bool disable_avatar_download_for_testing_; |
245 | 262 |
246 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); | 263 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); |
247 }; | 264 }; |
248 | 265 |
249 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ | 266 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ |
OLD | NEW |