class PrefService;
class PrefRegistrySimple;
+class ProfileAvatarDownloader;
// This class saves various information about profiles to local preferences.
// This cache can be used to display a list of profiles without having to
const base::FilePath& GetUserDataDir() const;
- // Gets the number of default avatar icons that exist.
- static size_t GetDefaultAvatarIconCount();
- // Gets the resource ID of the default avatar icon at |index|.
- static int GetDefaultAvatarIconResourceIDAtIndex(size_t index);
- // Returns a URL for the default avatar icon with specified index.
- static std::string GetDefaultAvatarIconUrl(size_t index);
- // Checks if |index| is a valid avatar icon index
- static bool IsDefaultAvatarIconIndex(size_t index);
- // Checks if the given URL points to one of the default avatar icons. If it
- // is, returns true and its index through |icon_index|. If not, returns false.
- static bool IsDefaultAvatarIconUrl(const std::string& icon_url,
- size_t *icon_index);
-
// Gets all names of profiles associated with this instance of Chrome.
// Because this method will be called during uninstall, before the creation
// of the ProfileManager, it reads directly from the local state preferences,
// Register cache related preferences in Local State.
static void RegisterPrefs(PrefRegistrySimple* registry);
+ // Starts downloading the high res avatar at index |icon_index|.
+ void DownloadHighResAvatar(size_t icon_index);
+
+ // Saves the avatar |image| at |image_path|. This is used both for the
+ // GAIA profile pictures and the ProfileAvatarDownloader that is used to
+ // download the high res avatars.
+ void SaveAvatarImageAtPath(const gfx::Image* image,
+ const std::string& key,
+ const base::FilePath& image_path);
+
void AddObserver(ProfileInfoCacheObserver* obs);
void RemoveObserver(ProfileInfoCacheObserver* obs);
private:
+ FRIEND_TEST_ALL_PREFIXES(ProfileInfoCacheTest, DownloadHighResAvatarTest);
+
const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const;
// Saves the profile info to a cache and takes ownership of |info|.
// Currently the only information that is cached is the profile's name,
// of profiles is still sorted.
void UpdateSortForProfileIndex(size_t index);
- void OnGAIAPictureLoaded(const base::FilePath& path,
- gfx::Image** image) const;
- void OnGAIAPictureSaved(const base::FilePath& path, bool* success) const;
+ // Loads or uses an already loaded high resolution image of the
+ // generic profile avatar.
+ const gfx::Image* GetHighResAvatarOfProfileAtIndex(size_t index) const;
+
+ // Returns the decoded image at |image_path|. Used both by the GAIA profile
+ // image and the high res avatars.
+ const gfx::Image* LoadAvatarPictureFromPath(
+ const std::string& key,
+ const base::FilePath& image_path) const;
+
+ // Called when the picture given by |key| has been loaded from disk and
+ // decoded into |image|.
+ void OnAvatarPictureLoaded(const std::string& key,
+ gfx::Image** image) const;
+ // Called when the picture given by |file_name| has been saved to disk.
+ // Used both for the GAIA profile picture and the high res avatar files.
+ void OnAvatarPictureSaved(const std::string& file_name);
PrefService* prefs_;
std::vector<std::string> sorted_keys_;
ObserverList<ProfileInfoCacheObserver> observer_list_;
- // A cache of gaia profile pictures. This cache is updated lazily so it needs
- // to be mutable.
- mutable std::map<std::string, gfx::Image*> gaia_pictures_;
- // Marks a gaia profile picture as loading. This prevents a picture from
+ // A cache of gaia/high res avatar profile pictures. This cache is updated
+ // lazily so it needs to be mutable.
+ mutable std::map<std::string, gfx::Image*> cached_avatar_images_;
+ // Marks a profile picture as loading from disk. This prevents a picture from
// loading multiple times.
- mutable std::map<std::string, bool> gaia_pictures_loading_;
+ mutable std::map<std::string, bool> cached_avatar_images_loading_;
+
+ // Map of profile pictures currently being downloaded from the remote
+ // location and the ProfileAvatarDownloader instances downloading them.
+ // This prevents a picture from being downloaded multiple times. The
+ // ProfileAvatarDownloader instances are deleted when the download completes
+ // or when the ProfileInfoCache is destroyed.
+ mutable std::map<std::string, ProfileAvatarDownloader*>
+ avatar_images_downloads_in_progress_;
DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache);
};