| 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/containers/scoped_ptr_hash_map.h" |
| 14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 20 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 18 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 21 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 19 #include "chrome/browser/profiles/profile_info_interface.h" | 22 #include "chrome/browser/profiles/profile_info_interface.h" |
| 20 | 23 |
| 21 namespace gfx { | 24 namespace gfx { |
| 22 class Image; | 25 class Image; |
| 23 } | 26 } |
| 24 | 27 |
| 25 namespace base { | 28 namespace base { |
| 26 class DictionaryValue; | 29 class DictionaryValue; |
| 27 } | 30 } |
| 28 | 31 |
| 29 class PrefService; | 32 class PrefService; |
| 30 class PrefRegistrySimple; | 33 class PrefRegistrySimple; |
| 31 class ProfileAvatarDownloader; | 34 class ProfileAvatarDownloader; |
| 32 | 35 |
| 33 // This class saves various information about profiles to local preferences. | 36 // 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 | 37 // This cache can be used to display a list of profiles without having to |
| 35 // actually load the profiles from disk. | 38 // actually load the profiles from disk. |
| 39 // The ProfileInfoInterface is being deprecated. Prefer using the |
| 40 // ProfileAttributesStorage and avoid using the Get*AtIndex family of functions. |
| 36 class ProfileInfoCache : public ProfileInfoInterface, | 41 class ProfileInfoCache : public ProfileInfoInterface, |
| 42 public ProfileAttributesStorage, |
| 37 public base::SupportsWeakPtr<ProfileInfoCache> { | 43 public base::SupportsWeakPtr<ProfileInfoCache> { |
| 38 public: | 44 public: |
| 39 ProfileInfoCache(PrefService* prefs, const base::FilePath& user_data_dir); | 45 ProfileInfoCache(PrefService* prefs, const base::FilePath& user_data_dir); |
| 40 ~ProfileInfoCache() override; | 46 ~ProfileInfoCache() override; |
| 41 | 47 |
| 42 // If the |supervised_user_id| is non-empty, the profile will be marked to be | 48 // 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 | 49 // 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 | 50 // 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 | 51 // SetIsOmittedProfileAtIndex() to clear the flag when the profile is ready to |
| 46 // be shown in the menu. | 52 // be shown in the menu. |
| 53 // Deprecated. Use AddProfile instead. |
| 47 void AddProfileToCache(const base::FilePath& profile_path, | 54 void AddProfileToCache(const base::FilePath& profile_path, |
| 48 const base::string16& name, | 55 const base::string16& name, |
| 49 const std::string& gaia_id, | 56 const std::string& gaia_id, |
| 50 const base::string16& user_name, | 57 const base::string16& user_name, |
| 51 size_t icon_index, | 58 size_t icon_index, |
| 52 const std::string& supervised_user_id); | 59 const std::string& supervised_user_id); |
| 60 // Deprecated. Use RemoveProfile instead. |
| 53 void DeleteProfileFromCache(const base::FilePath& profile_path); | 61 void DeleteProfileFromCache(const base::FilePath& profile_path); |
| 54 | 62 |
| 55 // ProfileInfoInterface: | 63 // ProfileInfoInterface: |
| 56 size_t GetNumberOfProfiles() const override; | 64 size_t GetNumberOfProfiles() const override; |
| 57 // Don't cache this value and reuse, because resorting the menu could cause | 65 // Don't cache this value and reuse, because resorting the menu could cause |
| 58 // the item being referred to to change out from under you. | 66 // the item being referred to to change out from under you. |
| 67 // Deprecated. Prefer using the ProfileAttributesStorage interface instead of |
| 68 // directly referring to this implementation. |
| 59 size_t GetIndexOfProfileWithPath( | 69 size_t GetIndexOfProfileWithPath( |
| 60 const base::FilePath& profile_path) const override; | 70 const base::FilePath& profile_path) const override; |
| 61 base::string16 GetNameOfProfileAtIndex(size_t index) const override; | 71 base::string16 GetNameOfProfileAtIndex(size_t index) const override; |
| 62 base::string16 GetShortcutNameOfProfileAtIndex(size_t index) const override; | 72 base::string16 GetShortcutNameOfProfileAtIndex(size_t index) const override; |
| 63 base::FilePath GetPathOfProfileAtIndex(size_t index) const override; | 73 base::FilePath GetPathOfProfileAtIndex(size_t index) const override; |
| 64 base::Time GetProfileActiveTimeAtIndex(size_t index) const override; | 74 base::Time GetProfileActiveTimeAtIndex(size_t index) const override; |
| 65 base::string16 GetUserNameOfProfileAtIndex(size_t index) const override; | 75 base::string16 GetUserNameOfProfileAtIndex(size_t index) const override; |
| 66 const gfx::Image& GetAvatarIconOfProfileAtIndex(size_t index) override; | 76 const gfx::Image& GetAvatarIconOfProfileAtIndex(size_t index) override; |
| 67 std::string GetLocalAuthCredentialsOfProfileAtIndex( | 77 std::string GetLocalAuthCredentialsOfProfileAtIndex( |
| 68 size_t index) const override; | 78 size_t index) const override; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 const base::FilePath& profile_path); | 164 const base::FilePath& profile_path); |
| 155 | 165 |
| 156 void AddObserver(ProfileInfoCacheObserver* obs); | 166 void AddObserver(ProfileInfoCacheObserver* obs); |
| 157 void RemoveObserver(ProfileInfoCacheObserver* obs); | 167 void RemoveObserver(ProfileInfoCacheObserver* obs); |
| 158 | 168 |
| 159 void set_disable_avatar_download_for_testing( | 169 void set_disable_avatar_download_for_testing( |
| 160 bool disable_avatar_download_for_testing) { | 170 bool disable_avatar_download_for_testing) { |
| 161 disable_avatar_download_for_testing_ = disable_avatar_download_for_testing; | 171 disable_avatar_download_for_testing_ = disable_avatar_download_for_testing; |
| 162 } | 172 } |
| 163 | 173 |
| 174 // ProfileAttributesStorage: |
| 175 void AddProfile(const base::FilePath& profile_path, |
| 176 const base::string16& name, |
| 177 const std::string& gaia_id, |
| 178 const base::string16& user_name, |
| 179 size_t icon_index, |
| 180 const std::string& supervised_user_id) override; |
| 181 void RemoveProfile(const base::FilePath& profile_path) override; |
| 182 // Returns a vector containing one attributes entry per known profile. They |
| 183 // are not sorted in any particular order. |
| 184 std::vector<ProfileAttributesEntry*> GetAllProfilesAttributes() override; |
| 185 bool GetProfileAttributesWithPath( |
| 186 const base::FilePath& path, |
| 187 ProfileAttributesEntry** entry) override; |
| 188 |
| 164 private: | 189 private: |
| 165 FRIEND_TEST_ALL_PREFIXES(ProfileInfoCacheTest, DownloadHighResAvatarTest); | 190 FRIEND_TEST_ALL_PREFIXES(ProfileInfoCacheTest, DownloadHighResAvatarTest); |
| 166 FRIEND_TEST_ALL_PREFIXES(ProfileInfoCacheTest, | 191 FRIEND_TEST_ALL_PREFIXES(ProfileInfoCacheTest, |
| 167 NothingToDownloadHighResAvatarTest); | 192 NothingToDownloadHighResAvatarTest); |
| 168 | 193 |
| 169 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; | 194 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; |
| 170 // Saves the profile info to a cache and takes ownership of |info|. | 195 // Saves the profile info to a cache and takes ownership of |info|. |
| 171 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); | 196 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); |
| 172 std::string CacheKeyFromProfilePath(const base::FilePath& profile_path) const; | 197 std::string CacheKeyFromProfilePath(const base::FilePath& profile_path) const; |
| 173 std::vector<std::string>::iterator FindPositionForProfile( | 198 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, | 238 void OnAvatarPictureSaved(const std::string& file_name, |
| 214 const base::FilePath& profile_path); | 239 const base::FilePath& profile_path); |
| 215 | 240 |
| 216 // Migrate any legacy profile names ("First user", "Default Profile") to | 241 // Migrate any legacy profile names ("First user", "Default Profile") to |
| 217 // new style default names ("Person 1"), and download and high-res avatars | 242 // new style default names ("Person 1"), and download and high-res avatars |
| 218 // used by the profiles. | 243 // used by the profiles. |
| 219 void MigrateLegacyProfileNamesAndDownloadAvatars(); | 244 void MigrateLegacyProfileNamesAndDownloadAvatars(); |
| 220 | 245 |
| 221 PrefService* prefs_; | 246 PrefService* prefs_; |
| 222 std::vector<std::string> sorted_keys_; | 247 std::vector<std::string> sorted_keys_; |
| 248 base::ScopedPtrHashMap<base::FilePath, scoped_ptr<ProfileAttributesEntry> > |
| 249 profile_attributes_entries_; |
| 223 base::FilePath user_data_dir_; | 250 base::FilePath user_data_dir_; |
| 224 | 251 |
| 225 mutable base::ObserverList<ProfileInfoCacheObserver> observer_list_; | 252 mutable base::ObserverList<ProfileInfoCacheObserver> observer_list_; |
| 226 | 253 |
| 227 // A cache of gaia/high res avatar profile pictures. This cache is updated | 254 // A cache of gaia/high res avatar profile pictures. This cache is updated |
| 228 // lazily so it needs to be mutable. | 255 // lazily so it needs to be mutable. |
| 229 mutable std::map<std::string, gfx::Image*> cached_avatar_images_; | 256 mutable std::map<std::string, gfx::Image*> cached_avatar_images_; |
| 230 // Marks a profile picture as loading from disk. This prevents a picture from | 257 // Marks a profile picture as loading from disk. This prevents a picture from |
| 231 // loading multiple times. | 258 // loading multiple times. |
| 232 mutable std::map<std::string, bool> cached_avatar_images_loading_; | 259 mutable std::map<std::string, bool> cached_avatar_images_loading_; |
| 233 | 260 |
| 234 // Map of profile pictures currently being downloaded from the remote | 261 // Map of profile pictures currently being downloaded from the remote |
| 235 // location and the ProfileAvatarDownloader instances downloading them. | 262 // location and the ProfileAvatarDownloader instances downloading them. |
| 236 // This prevents a picture from being downloaded multiple times. The | 263 // This prevents a picture from being downloaded multiple times. The |
| 237 // ProfileAvatarDownloader instances are deleted when the download completes | 264 // ProfileAvatarDownloader instances are deleted when the download completes |
| 238 // or when the ProfileInfoCache is destroyed. | 265 // or when the ProfileInfoCache is destroyed. |
| 239 std::map<std::string, ProfileAvatarDownloader*> | 266 std::map<std::string, ProfileAvatarDownloader*> |
| 240 avatar_images_downloads_in_progress_; | 267 avatar_images_downloads_in_progress_; |
| 241 | 268 |
| 242 // Determines of the ProfileAvatarDownloader should be created and executed | 269 // Determines of the ProfileAvatarDownloader should be created and executed |
| 243 // or not. Only set to true for tests. | 270 // or not. Only set to true for tests. |
| 244 bool disable_avatar_download_for_testing_; | 271 bool disable_avatar_download_for_testing_; |
| 245 | 272 |
| 246 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); | 273 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); |
| 247 }; | 274 }; |
| 248 | 275 |
| 249 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ | 276 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ |
| OLD | NEW |