| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 14 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/memory/weak_ptr.h" |
| 15 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 16 #include "base/string16.h" | 18 #include "base/string16.h" |
| 17 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 19 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 18 #include "chrome/browser/profiles/profile_info_interface.h" | 20 #include "chrome/browser/profiles/profile_info_interface.h" |
| 19 | 21 |
| 20 namespace gfx { | 22 namespace gfx { |
| 21 class Image; | 23 class Image; |
| 22 } | 24 } |
| 23 | 25 |
| 24 namespace base { | 26 namespace base { |
| 25 class DictionaryValue; | 27 class DictionaryValue; |
| 26 } | 28 } |
| 27 | 29 |
| 28 class PrefService; | 30 class PrefService; |
| 29 | 31 |
| 30 // This class saves various information about profiles to local preferences. | 32 // This class saves various information about profiles to local preferences. |
| 31 // 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 |
| 32 // actually load the profiles from disk. | 34 // actually load the profiles from disk. |
| 33 class ProfileInfoCache : public ProfileInfoInterface { | 35 class ProfileInfoCache : public ProfileInfoInterface, |
| 36 public base::SupportsWeakPtr<ProfileInfoCache> { |
| 34 public: | 37 public: |
| 35 ProfileInfoCache(PrefService* prefs, const FilePath& user_data_dir); | 38 ProfileInfoCache(PrefService* prefs, const FilePath& user_data_dir); |
| 36 virtual ~ProfileInfoCache(); | 39 virtual ~ProfileInfoCache(); |
| 37 | 40 |
| 38 void AddProfileToCache(const FilePath& profile_path, | 41 void AddProfileToCache(const FilePath& profile_path, |
| 39 const string16& name, | 42 const string16& name, |
| 40 const string16& username, | 43 const string16& username, |
| 41 size_t icon_index); | 44 size_t icon_index); |
| 42 void DeleteProfileFromCache(const FilePath& profile_path); | 45 void DeleteProfileFromCache(const FilePath& profile_path); |
| 43 | 46 |
| 44 // ProfileInfoInterface: | 47 // ProfileInfoInterface: |
| 45 virtual size_t GetNumberOfProfiles() const OVERRIDE; | 48 virtual size_t GetNumberOfProfiles() const OVERRIDE; |
| 46 // Don't cache this value and reuse, because resorting the menu could cause | 49 // Don't cache this value and reuse, because resorting the menu could cause |
| 47 // the item being referred to to change out from under you. | 50 // the item being referred to to change out from under you. |
| 48 virtual size_t GetIndexOfProfileWithPath( | 51 virtual size_t GetIndexOfProfileWithPath( |
| 49 const FilePath& profile_path) const OVERRIDE; | 52 const FilePath& profile_path) const OVERRIDE; |
| 50 virtual string16 GetNameOfProfileAtIndex(size_t index) const OVERRIDE; | 53 virtual string16 GetNameOfProfileAtIndex(size_t index) const OVERRIDE; |
| 51 virtual FilePath GetPathOfProfileAtIndex(size_t index) const OVERRIDE; | 54 virtual FilePath GetPathOfProfileAtIndex(size_t index) const OVERRIDE; |
| 52 virtual string16 GetUserNameOfProfileAtIndex(size_t index) const OVERRIDE; | 55 virtual string16 GetUserNameOfProfileAtIndex(size_t index) const OVERRIDE; |
| 53 virtual const gfx::Image& GetAvatarIconOfProfileAtIndex( | 56 virtual const gfx::Image& GetAvatarIconOfProfileAtIndex( |
| 54 size_t index) const OVERRIDE; | 57 size_t index) const OVERRIDE; |
| 55 virtual bool GetBackgroundStatusOfProfileAtIndex( | 58 virtual bool GetBackgroundStatusOfProfileAtIndex( |
| 56 size_t index) const OVERRIDE; | 59 size_t index) const OVERRIDE; |
| 60 virtual string16 GetGAIANameOfProfileAtIndex(size_t index) const OVERRIDE; |
| 61 virtual bool IsUsingGAIANameOfProfileAtIndex(size_t index) const OVERRIDE; |
| 62 virtual const gfx::Image& GetGAIAPictureOfProfileAtIndex( |
| 63 size_t index) const OVERRIDE; |
| 64 virtual bool IsUsingGAIAPictureOfProfileAtIndex( |
| 65 size_t index) const OVERRIDE; |
| 57 | 66 |
| 58 size_t GetAvatarIconIndexOfProfileAtIndex(size_t index) const; | 67 size_t GetAvatarIconIndexOfProfileAtIndex(size_t index) const; |
| 59 | 68 |
| 60 void SetNameOfProfileAtIndex(size_t index, const string16& name); | 69 void SetNameOfProfileAtIndex(size_t index, const string16& name); |
| 61 void SetUserNameOfProfileAtIndex(size_t index, const string16& user_name); | 70 void SetUserNameOfProfileAtIndex(size_t index, const string16& user_name); |
| 62 void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index); | 71 void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index); |
| 63 void SetBackgroundStatusOfProfileAtIndex(size_t index, | 72 void SetBackgroundStatusOfProfileAtIndex(size_t index, |
| 64 bool running_background_apps); | 73 bool running_background_apps); |
| 74 void SetGAIANameOfProfileAtIndex(size_t index, const string16& name); |
| 75 void SetIsUsingGAIANameOfProfileAtIndex(size_t index, bool value); |
| 76 void SetGAIAPictureOfProfileAtIndex(size_t index, const gfx::Image& image); |
| 77 void SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, bool value); |
| 65 | 78 |
| 66 // Returns unique name that can be assigned to a newly created profile. | 79 // Returns unique name that can be assigned to a newly created profile. |
| 67 string16 ChooseNameForNewProfile(size_t icon_index); | 80 string16 ChooseNameForNewProfile(size_t icon_index); |
| 68 | 81 |
| 82 // Checks if the given profile has switched to using GAIA information |
| 83 // for the profile name and picture. This pref is used to switch over |
| 84 // to GAIA info the first time it is available. Afterwards this pref is |
| 85 // checked to prevent clobbering the user's custom settings. |
| 86 bool GetHasMigratedToGAIAInfoOfProfileAtIndex(size_t index) const; |
| 87 |
| 88 // Marks the given profile as having switched to using GAIA information |
| 89 // for the profile name and picture. |
| 90 void SetHasMigratedToGAIAInfoOfProfileAtIndex(size_t index, bool value); |
| 91 |
| 69 // Returns an avatar icon index that can be assigned to a newly created | 92 // Returns an avatar icon index that can be assigned to a newly created |
| 70 // profile. Note that the icon may not be unique since there are a limited | 93 // profile. Note that the icon may not be unique since there are a limited |
| 71 // set of default icons. | 94 // set of default icons. |
| 72 size_t ChooseAvatarIconIndexForNewProfile() const; | 95 size_t ChooseAvatarIconIndexForNewProfile() const; |
| 73 | 96 |
| 74 const FilePath& GetUserDataDir() const; | 97 const FilePath& GetUserDataDir() const; |
| 75 | 98 |
| 76 // Gets the number of default avatar icons that exist. | 99 // Gets the number of default avatar icons that exist. |
| 77 static size_t GetDefaultAvatarIconCount(); | 100 static size_t GetDefaultAvatarIconCount(); |
| 78 // Gets the resource ID of the default avatar icon at |index|. | 101 // Gets the resource ID of the default avatar icon at |index|. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 109 | 132 |
| 110 // Returns true if the given icon index is not in use by another profie. | 133 // Returns true if the given icon index is not in use by another profie. |
| 111 bool IconIndexIsUnique(size_t icon_index) const; | 134 bool IconIndexIsUnique(size_t icon_index) const; |
| 112 | 135 |
| 113 // Tries to find an icon index that satisfies all the given conditions. | 136 // Tries to find an icon index that satisfies all the given conditions. |
| 114 // Returns true if an icon was found, false otherwise. | 137 // Returns true if an icon was found, false otherwise. |
| 115 bool ChooseAvatarIconIndexForNewProfile(bool allow_generic_icon, | 138 bool ChooseAvatarIconIndexForNewProfile(bool allow_generic_icon, |
| 116 bool must_be_unique, | 139 bool must_be_unique, |
| 117 size_t* out_icon_index) const; | 140 size_t* out_icon_index) const; |
| 118 | 141 |
| 142 // Updates the position of the profile at the given index so that the list |
| 143 // of profiles is still sorted. |
| 144 void UpdateSortForProfileIndex(size_t index); |
| 145 |
| 146 void OnGAIAPictureLoaded(FilePath path, gfx::Image** image) const; |
| 147 void OnGAIAPictureSaved(FilePath path, bool* success) const; |
| 148 |
| 119 PrefService* prefs_; | 149 PrefService* prefs_; |
| 120 std::vector<std::string> sorted_keys_; | 150 std::vector<std::string> sorted_keys_; |
| 121 FilePath user_data_dir_; | 151 FilePath user_data_dir_; |
| 122 | 152 |
| 123 ObserverList<ProfileInfoCacheObserver> observer_list_; | 153 ObserverList<ProfileInfoCacheObserver> observer_list_; |
| 124 | 154 |
| 155 // A cache of gaia profile pictures. This cache is updated lazily so it needs |
| 156 // to be mutable. |
| 157 mutable std::map<std::string, gfx::Image*> gaia_pictures_; |
| 158 |
| 125 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); | 159 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); |
| 126 }; | 160 }; |
| 127 | 161 |
| 128 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ | 162 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ |
| OLD | NEW |