| 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/file_path.h" | 14 #include "base/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/string16.h" | 17 #include "base/string16.h" |
| 18 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 18 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 19 #include "chrome/browser/profiles/profile_info_interface.h" | 19 #include "chrome/browser/profiles/profile_info_interface.h" |
| 20 | 20 |
| 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 PrefServiceSimple; |
| 30 | 31 |
| 31 // This class saves various information about profiles to local preferences. | 32 // This class saves various information about profiles to local preferences. |
| 32 // This cache can be used to display a list of profiles without having to | 33 // This cache can be used to display a list of profiles without having to |
| 33 // actually load the profiles from disk. | 34 // actually load the profiles from disk. |
| 34 class ProfileInfoCache : public ProfileInfoInterface, | 35 class ProfileInfoCache : public ProfileInfoInterface, |
| 35 public base::SupportsWeakPtr<ProfileInfoCache> { | 36 public base::SupportsWeakPtr<ProfileInfoCache> { |
| 36 public: | 37 public: |
| 37 ProfileInfoCache(PrefService* prefs, const FilePath& user_data_dir); | 38 ProfileInfoCache(PrefService* prefs, const FilePath& user_data_dir); |
| 38 virtual ~ProfileInfoCache(); | 39 virtual ~ProfileInfoCache(); |
| 39 | 40 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 static bool IsDefaultAvatarIconUrl(const std::string& icon_url, | 118 static bool IsDefaultAvatarIconUrl(const std::string& icon_url, |
| 118 size_t *icon_index); | 119 size_t *icon_index); |
| 119 | 120 |
| 120 // Gets all names of profiles associated with this instance of Chrome. | 121 // Gets all names of profiles associated with this instance of Chrome. |
| 121 // Because this method will be called during uninstall, before the creation | 122 // Because this method will be called during uninstall, before the creation |
| 122 // of the ProfileManager, it reads directly from the local state preferences, | 123 // of the ProfileManager, it reads directly from the local state preferences, |
| 123 // rather than going through the ProfileInfoCache object. | 124 // rather than going through the ProfileInfoCache object. |
| 124 static std::vector<string16> GetProfileNames(); | 125 static std::vector<string16> GetProfileNames(); |
| 125 | 126 |
| 126 // Register cache related preferences in Local State. | 127 // Register cache related preferences in Local State. |
| 127 static void RegisterPrefs(PrefService* prefs); | 128 static void RegisterPrefs(PrefServiceSimple* prefs); |
| 128 | 129 |
| 129 void AddObserver(ProfileInfoCacheObserver* obs); | 130 void AddObserver(ProfileInfoCacheObserver* obs); |
| 130 void RemoveObserver(ProfileInfoCacheObserver* obs); | 131 void RemoveObserver(ProfileInfoCacheObserver* obs); |
| 131 | 132 |
| 132 private: | 133 private: |
| 133 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; | 134 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; |
| 134 // Saves the profile info to a cache and takes ownership of |info|. | 135 // Saves the profile info to a cache and takes ownership of |info|. |
| 135 // Currently the only information that is cached is the profile's name, | 136 // Currently the only information that is cached is the profile's name, |
| 136 // user name, and avatar icon. | 137 // user name, and avatar icon. |
| 137 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); | 138 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 166 // to be mutable. | 167 // to be mutable. |
| 167 mutable std::map<std::string, gfx::Image*> gaia_pictures_; | 168 mutable std::map<std::string, gfx::Image*> gaia_pictures_; |
| 168 // Marks a gaia profile picture as loading. This prevents a picture from | 169 // Marks a gaia profile picture as loading. This prevents a picture from |
| 169 // loading multiple times. | 170 // loading multiple times. |
| 170 mutable std::map<std::string, bool> gaia_pictures_loading_; | 171 mutable std::map<std::string, bool> gaia_pictures_loading_; |
| 171 | 172 |
| 172 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); | 173 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); |
| 173 }; | 174 }; |
| 174 | 175 |
| 175 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ | 176 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ |
| OLD | NEW |