Chromium Code Reviews| 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 // Takes ownership of |avatar_dowloader|, which will be deleted either | |
| 141 // when the download comples and OnAvatarPictureSaved is called, or when | |
|
rpetterson
2014/04/24 23:40:32
comples -> completes?
noms (inactive)
2014/04/28 19:08:57
Done.
| |
| 142 // the ProfileInfoCache is destroyed. | |
| 143 void DownloadHighResAvatar(ProfileAvatarDownloader* avatar_downloader, | |
| 144 size_t icon_index); | |
| 145 | |
| 146 // Saves the avatar |image| at |image_path|. This is used both for the | |
| 147 // GAIA profile pictures and the ProfileAvatarDownloader that is used to | |
| 148 // download the high res avatars. | |
| 149 void SaveAvatarImageAtPath(const gfx::Image* image, | |
| 150 const std::string& key, | |
| 151 const base::FilePath& image_path); | |
| 152 | |
| 138 void AddObserver(ProfileInfoCacheObserver* obs); | 153 void AddObserver(ProfileInfoCacheObserver* obs); |
| 139 void RemoveObserver(ProfileInfoCacheObserver* obs); | 154 void RemoveObserver(ProfileInfoCacheObserver* obs); |
| 140 | 155 |
| 141 private: | 156 private: |
| 142 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; | 157 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; |
| 143 // Saves the profile info to a cache and takes ownership of |info|. | 158 // 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, | 159 // Currently the only information that is cached is the profile's name, |
| 145 // user name, and avatar icon. | 160 // user name, and avatar icon. |
| 146 void SetInfoQuietlyForProfileAtIndex(size_t index, | 161 void SetInfoQuietlyForProfileAtIndex(size_t index, |
| 147 base::DictionaryValue* info); | 162 base::DictionaryValue* info); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 161 size_t* out_icon_index) const; | 176 size_t* out_icon_index) const; |
| 162 | 177 |
| 163 // Updates the position of the profile at the given index so that the list | 178 // Updates the position of the profile at the given index so that the list |
| 164 // of profiles is still sorted. | 179 // of profiles is still sorted. |
| 165 void UpdateSortForProfileIndex(size_t index); | 180 void UpdateSortForProfileIndex(size_t index); |
| 166 | 181 |
| 167 // Loads or uses an already loaded high resolution image of the | 182 // Loads or uses an already loaded high resolution image of the |
| 168 // generic profile avatar. | 183 // generic profile avatar. |
| 169 const gfx::Image* GetHighResAvatarOfProfileAtIndex(size_t index) const; | 184 const gfx::Image* GetHighResAvatarOfProfileAtIndex(size_t index) const; |
| 170 | 185 |
| 186 // Returns the decoded image at |image_path|. Used both by the GAIA profile | |
| 187 // image and the high res avatars. | |
| 171 const gfx::Image* LoadAvatarPictureFromPath( | 188 const gfx::Image* LoadAvatarPictureFromPath( |
| 172 const std::string& key, | 189 const std::string& key, |
| 173 const base::FilePath& image_path) const; | 190 const base::FilePath& image_path) const; |
| 191 | |
| 192 // Called when the picture given by |key| has been loaded from disk and | |
| 193 // decoded into |image|. | |
| 174 void OnAvatarPictureLoaded(const std::string& key, | 194 void OnAvatarPictureLoaded(const std::string& key, |
| 175 gfx::Image** image) const; | 195 gfx::Image** image) const; |
| 176 void OnGAIAPictureSaved(const base::FilePath& path, bool* success) const; | 196 // Called when the picture given by |file_name| has been saved to disk. |
| 197 // Used both for the GAIA profile picture and the high res avatar files. | |
| 198 void OnAvatarPictureSaved(const std::string& file_name, bool* success); | |
| 177 | 199 |
| 178 PrefService* prefs_; | 200 PrefService* prefs_; |
| 179 std::vector<std::string> sorted_keys_; | 201 std::vector<std::string> sorted_keys_; |
| 180 base::FilePath user_data_dir_; | 202 base::FilePath user_data_dir_; |
| 181 | 203 |
| 182 ObserverList<ProfileInfoCacheObserver> observer_list_; | 204 ObserverList<ProfileInfoCacheObserver> observer_list_; |
| 183 | 205 |
| 184 // A cache of gaia/high res avatar profile pictures. This cache is updated | 206 // A cache of gaia/high res avatar profile pictures. This cache is updated |
| 185 // lazily so it needs to be mutable. | 207 // lazily so it needs to be mutable. |
| 186 mutable std::map<std::string, gfx::Image*> cached_avatar_images_; | 208 mutable std::map<std::string, gfx::Image*> cached_avatar_images_; |
| 187 // Marks a profile picture as loading. This prevents a picture from | 209 // Marks a profile picture as loading from disk. This prevents a picture from |
| 188 // loading multiple times. | 210 // loading multiple times. |
| 189 mutable std::map<std::string, bool> cached_avatar_images_loading_; | 211 mutable std::map<std::string, bool> cached_avatar_images_loading_; |
| 190 | 212 |
| 213 // Map of profile pictures currently being downloaded from the remote | |
| 214 // location and the ProfileAvatarDownloader instances downloading them. | |
| 215 // This prevents a picture from being downloaded multiple times. The | |
| 216 // ProfileAvatarDownloader pointers are deleted when the download completes or | |
| 217 // when the ProfileInfoCache is destroyed. | |
| 218 mutable std::map<std::string, ProfileAvatarDownloader*> | |
| 219 avatar_images_downloads_in_progress_; | |
| 220 | |
| 191 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); | 221 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); |
| 192 }; | 222 }; |
| 193 | 223 |
| 194 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ | 224 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ |
| OLD | NEW |