| 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> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 namespace gfx { | 21 namespace gfx { |
| 22 class Image; | 22 class Image; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace base { | 25 namespace base { |
| 26 class DictionaryValue; | 26 class DictionaryValue; |
| 27 } | 27 } |
| 28 | 28 |
| 29 class PrefService; | 29 class PrefService; |
| 30 class PrefRegistrySimple; | 30 class PrefRegistrySimple; |
| 31 class ProfileAvatarDownloader; |
| 31 | 32 |
| 32 // This class saves various information about profiles to local preferences. | 33 // This class saves various information about profiles to local preferences. |
| 33 // This cache can be used to display a list of profiles without having to | 34 // This cache can be used to display a list of profiles without having to |
| 34 // actually load the profiles from disk. | 35 // actually load the profiles from disk. |
| 35 class ProfileInfoCache : public ProfileInfoInterface, | 36 class ProfileInfoCache : public ProfileInfoInterface, |
| 36 public base::SupportsWeakPtr<ProfileInfoCache> { | 37 public base::SupportsWeakPtr<ProfileInfoCache> { |
| 37 public: | 38 public: |
| 38 ProfileInfoCache(PrefService* prefs, const base::FilePath& user_data_dir); | 39 ProfileInfoCache(PrefService* prefs, const base::FilePath& user_data_dir); |
| 39 virtual ~ProfileInfoCache(); | 40 virtual ~ProfileInfoCache(); |
| 40 | 41 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 129 |
| 129 // Gets all names of profiles associated with this instance of Chrome. | 130 // Gets all names of profiles associated with this instance of Chrome. |
| 130 // Because this method will be called during uninstall, before the creation | 131 // Because this method will be called during uninstall, before the creation |
| 131 // of the ProfileManager, it reads directly from the local state preferences, | 132 // of the ProfileManager, it reads directly from the local state preferences, |
| 132 // rather than going through the ProfileInfoCache object. | 133 // rather than going through the ProfileInfoCache object. |
| 133 static std::vector<base::string16> GetProfileNames(); | 134 static std::vector<base::string16> GetProfileNames(); |
| 134 | 135 |
| 135 // Register cache related preferences in Local State. | 136 // Register cache related preferences in Local State. |
| 136 static void RegisterPrefs(PrefRegistrySimple* registry); | 137 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 137 | 138 |
| 139 // Starts downloading the high res avatar at index |icon_index|. |
| 140 void DownloadHighResAvatar(size_t icon_index); |
| 141 |
| 142 // Saves the avatar |image| at |image_path|. This is used both for the |
| 143 // GAIA profile pictures and the ProfileAvatarDownloader that is used to |
| 144 // download the high res avatars. |
| 145 void SaveAvatarImageAtPath(const gfx::Image* image, |
| 146 const std::string& key, |
| 147 const base::FilePath& image_path); |
| 148 |
| 138 void AddObserver(ProfileInfoCacheObserver* obs); | 149 void AddObserver(ProfileInfoCacheObserver* obs); |
| 139 void RemoveObserver(ProfileInfoCacheObserver* obs); | 150 void RemoveObserver(ProfileInfoCacheObserver* obs); |
| 140 | 151 |
| 141 private: | 152 private: |
| 153 FRIEND_TEST_ALL_PREFIXES(ProfileInfoCacheTest, DownloadHighResAvatarTest); |
| 154 |
| 142 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; | 155 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; |
| 143 // Saves the profile info to a cache and takes ownership of |info|. | 156 // Saves the profile info to a cache and takes ownership of |info|. |
| 144 // Currently the only information that is cached is the profile's name, | 157 // Currently the only information that is cached is the profile's name, |
| 145 // user name, and avatar icon. | 158 // user name, and avatar icon. |
| 146 void SetInfoQuietlyForProfileAtIndex(size_t index, | 159 void SetInfoQuietlyForProfileAtIndex(size_t index, |
| 147 base::DictionaryValue* info); | 160 base::DictionaryValue* info); |
| 148 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); | 161 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); |
| 149 std::string CacheKeyFromProfilePath(const base::FilePath& profile_path) const; | 162 std::string CacheKeyFromProfilePath(const base::FilePath& profile_path) const; |
| 150 std::vector<std::string>::iterator FindPositionForProfile( | 163 std::vector<std::string>::iterator FindPositionForProfile( |
| 151 const std::string& search_key, | 164 const std::string& search_key, |
| 152 const base::string16& search_name); | 165 const base::string16& search_name); |
| 153 | 166 |
| 154 // Returns true if the given icon index is not in use by another profie. | 167 // Returns true if the given icon index is not in use by another profie. |
| 155 bool IconIndexIsUnique(size_t icon_index) const; | 168 bool IconIndexIsUnique(size_t icon_index) const; |
| 156 | 169 |
| 157 // Tries to find an icon index that satisfies all the given conditions. | 170 // Tries to find an icon index that satisfies all the given conditions. |
| 158 // Returns true if an icon was found, false otherwise. | 171 // Returns true if an icon was found, false otherwise. |
| 159 bool ChooseAvatarIconIndexForNewProfile(bool allow_generic_icon, | 172 bool ChooseAvatarIconIndexForNewProfile(bool allow_generic_icon, |
| 160 bool must_be_unique, | 173 bool must_be_unique, |
| 161 size_t* out_icon_index) const; | 174 size_t* out_icon_index) const; |
| 162 | 175 |
| 163 // Updates the position of the profile at the given index so that the list | 176 // Updates the position of the profile at the given index so that the list |
| 164 // of profiles is still sorted. | 177 // of profiles is still sorted. |
| 165 void UpdateSortForProfileIndex(size_t index); | 178 void UpdateSortForProfileIndex(size_t index); |
| 166 | 179 |
| 167 // Loads or uses an already loaded high resolution image of the | 180 // Loads or uses an already loaded high resolution image of the |
| 168 // generic profile avatar. | 181 // generic profile avatar. |
| 169 const gfx::Image* GetHighResAvatarOfProfileAtIndex(size_t index) const; | 182 const gfx::Image* GetHighResAvatarOfProfileAtIndex(size_t index) const; |
| 170 | 183 |
| 184 // Returns the decoded image at |image_path|. Used both by the GAIA profile |
| 185 // image and the high res avatars. |
| 171 const gfx::Image* LoadAvatarPictureFromPath( | 186 const gfx::Image* LoadAvatarPictureFromPath( |
| 172 const std::string& key, | 187 const std::string& key, |
| 173 const base::FilePath& image_path) const; | 188 const base::FilePath& image_path) const; |
| 189 |
| 190 // Called when the picture given by |key| has been loaded from disk and |
| 191 // decoded into |image|. |
| 174 void OnAvatarPictureLoaded(const std::string& key, | 192 void OnAvatarPictureLoaded(const std::string& key, |
| 175 gfx::Image** image) const; | 193 gfx::Image** image) const; |
| 176 void OnGAIAPictureSaved(const base::FilePath& path, bool* success) const; | 194 // Called when the picture given by |file_name| has been saved to disk. |
| 195 // Used both for the GAIA profile picture and the high res avatar files. |
| 196 void OnAvatarPictureSaved(const std::string& file_name); |
| 177 | 197 |
| 178 PrefService* prefs_; | 198 PrefService* prefs_; |
| 179 std::vector<std::string> sorted_keys_; | 199 std::vector<std::string> sorted_keys_; |
| 180 base::FilePath user_data_dir_; | 200 base::FilePath user_data_dir_; |
| 181 | 201 |
| 182 ObserverList<ProfileInfoCacheObserver> observer_list_; | 202 ObserverList<ProfileInfoCacheObserver> observer_list_; |
| 183 | 203 |
| 184 // A cache of gaia/high res avatar profile pictures. This cache is updated | 204 // A cache of gaia/high res avatar profile pictures. This cache is updated |
| 185 // lazily so it needs to be mutable. | 205 // lazily so it needs to be mutable. |
| 186 mutable std::map<std::string, gfx::Image*> cached_avatar_images_; | 206 mutable std::map<std::string, gfx::Image*> cached_avatar_images_; |
| 187 // Marks a profile picture as loading. This prevents a picture from | 207 // Marks a profile picture as loading from disk. This prevents a picture from |
| 188 // loading multiple times. | 208 // loading multiple times. |
| 189 mutable std::map<std::string, bool> cached_avatar_images_loading_; | 209 mutable std::map<std::string, bool> cached_avatar_images_loading_; |
| 190 | 210 |
| 211 // Map of profile pictures currently being downloaded from the remote |
| 212 // location and the ProfileAvatarDownloader instances downloading them. |
| 213 // This prevents a picture from being downloaded multiple times. The |
| 214 // ProfileAvatarDownloader instances are deleted when the download completes |
| 215 // or when the ProfileInfoCache is destroyed. |
| 216 mutable std::map<std::string, ProfileAvatarDownloader*> |
| 217 avatar_images_downloads_in_progress_; |
| 218 |
| 191 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); | 219 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); |
| 192 }; | 220 }; |
| 193 | 221 |
| 194 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ | 222 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ |
| OLD | NEW |