Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/profiles/profile_info_cache.h

Issue 33753002: Sooper experimental refactoring of the profile info cache. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/profiles/profile_impl.cc ('k') | chrome/browser/profiles/profile_info_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/files/file_path.h" 14 #include "base/files/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/strings/string16.h" 17 #include "base/strings/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 #include "chrome/browser/profiles/profile_info_entry.h"
20 21
21 namespace gfx { 22 namespace gfx {
22 class Image; 23 class Image;
23 } 24 }
24 25
25 namespace base { 26 namespace base {
26 class DictionaryValue; 27 class DictionaryValue;
27 } 28 }
28 29
29 class PrefService; 30 class PrefService;
30 class PrefRegistrySimple; 31 class PrefRegistrySimple;
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
42
43
44 // ******************* Start new code
45
46 virtual std::vector<ProfileInfoEntry> GetProfilesSortedByName() const OVERRIDE ;
47
48 bool GetInfoForProfile(const base::FilePath& path,
49 ProfileInfoEntry* entry) const;
50
51 void SetInfoForProfile(const ProfileInfoEntry& info);
52
41 // This |is_managed| refers to local management (formerly "managed mode"), 53 // This |is_managed| refers to local management (formerly "managed mode"),
42 // not enterprise management. 54 // not enterprise management.
43 void AddProfileToCache(const base::FilePath& profile_path, 55 void AddProfileToCache(const base::FilePath& profile_path,
44 const string16& name, 56 const string16& name,
45 const string16& username, 57 const string16& username,
46 size_t icon_index, 58 size_t icon_index,
47 const std::string& managed_user_id); 59 const std::string& managed_user_id);
60
48 void DeleteProfileFromCache(const base::FilePath& profile_path); 61 void DeleteProfileFromCache(const base::FilePath& profile_path);
49 62
63
64 // ********************* End new code
65
66
67
68
69
70
50 // ProfileInfoInterface: 71 // ProfileInfoInterface:
51 virtual size_t GetNumberOfProfiles() const OVERRIDE; 72 virtual size_t GetNumberOfProfiles() const OVERRIDE;
73
52 // Don't cache this value and reuse, because resorting the menu could cause 74 // Don't cache this value and reuse, because resorting the menu could cause
53 // the item being referred to to change out from under you. 75 // the item being referred to to change out from under you.
54 virtual size_t GetIndexOfProfileWithPath( 76 // virtual size_t GetIndexOfProfileWithPath(
55 const base::FilePath& profile_path) const OVERRIDE; 77 // const base::FilePath& profile_path) const OVERRIDE;
56 virtual string16 GetNameOfProfileAtIndex(size_t index) const OVERRIDE; 78
57 virtual string16 GetShortcutNameOfProfileAtIndex(size_t index) 79
58 const OVERRIDE; 80
59 virtual base::FilePath GetPathOfProfileAtIndex(size_t index) const OVERRIDE; 81 //virtual string16 GetNameOfProfileAtIndex(size_t index) const OVERRIDE;
60 virtual string16 GetUserNameOfProfileAtIndex(size_t index) const OVERRIDE; 82 //virtual string16 GetShortcutNameOfProfileAtIndex(size_t index)
61 virtual const gfx::Image& GetAvatarIconOfProfileAtIndex( 83 // const OVERRIDE;
62 size_t index) const OVERRIDE; 84 //virtual base::FilePath GetPathOfProfileAtIndex(size_t index) const OVERRIDE;
85 //virtual string16 GetUserNameOfProfileAtIndex(size_t index) const OVERRIDE;
86 virtual const gfx::Image& GetAvatarIconOfProfile(const base::FilePath& profile _path) const OVERRIDE;
63 // Note that a return value of false could mean an error in collection or 87 // Note that a return value of false could mean an error in collection or
64 // that there are currently no background apps running. However, the action 88 // that there are currently no background apps running. However, the action
65 // which results is the same in both cases (thus far). 89 // which results is the same in both cases (thus far).
66 virtual bool GetBackgroundStatusOfProfileAtIndex( 90 //virtual bool GetBackgroundStatusOfProfileAtIndex(
67 size_t index) const OVERRIDE; 91 // size_t index) const OVERRIDE;
68 virtual string16 GetGAIANameOfProfileAtIndex(size_t index) const OVERRIDE; 92 //virtual string16 GetGAIANameOfProfileAtIndex(size_t index) const OVERRIDE;
69 virtual string16 GetGAIAGivenNameOfProfileAtIndex( 93 //virtual string16 GetGAIAGivenNameOfProfileAtIndex(
70 size_t index) const OVERRIDE; 94 // size_t index) const OVERRIDE;
71 virtual bool IsUsingGAIANameOfProfileAtIndex(size_t index) const OVERRIDE; 95 //virtual bool IsUsingGAIANameOfProfileAtIndex(size_t index) const OVERRIDE;
72 // Returns the GAIA picture for the given profile. This may return NULL 96 // Returns the GAIA picture for the given profile. This may return NULL
73 // if the profile does not have a GAIA picture or if the picture must be 97 // if the profile does not have a GAIA picture or if the picture must be
74 // loaded from disk. 98 // loaded from disk.
75 virtual const gfx::Image* GetGAIAPictureOfProfileAtIndex(
76 size_t index) const OVERRIDE;
77 virtual bool IsUsingGAIAPictureOfProfileAtIndex(
78 size_t index) const OVERRIDE;
79 virtual bool ProfileIsManagedAtIndex(size_t index) const OVERRIDE;
80 virtual bool ProfileIsSigninRequiredAtIndex(size_t index) const OVERRIDE;
81 virtual std::string GetManagedUserIdOfProfileAtIndex(size_t index) const
82 OVERRIDE;
83 virtual bool ProfileIsEphemeralAtIndex(size_t index) const OVERRIDE;
84 99
85 size_t GetAvatarIconIndexOfProfileAtIndex(size_t index) const;
86 100
87 void SetNameOfProfileAtIndex(size_t index, const string16& name); 101 // *** FROM HEAD
88 void SetShortcutNameOfProfileAtIndex(size_t index, const string16& name); 102 // virtual const gfx::Image* GetGAIAPictureOfProfileAtIndex(
89 void SetUserNameOfProfileAtIndex(size_t index, const string16& user_name); 103 // size_t index) const OVERRIDE;
90 void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index); 104 // virtual bool IsUsingGAIAPictureOfProfileAtIndex(
91 void SetManagedUserIdOfProfileAtIndex(size_t index, const std::string& id); 105 // size_t index) const OVERRIDE;
92 void SetBackgroundStatusOfProfileAtIndex(size_t index, 106 // virtual bool ProfileIsManagedAtIndex(size_t index) const OVERRIDE;
93 bool running_background_apps); 107 // virtual bool ProfileIsSigninRequiredAtIndex(size_t index) const OVERRIDE;
94 void SetGAIANameOfProfileAtIndex(size_t index, const string16& name); 108 // virtual std::string GetManagedUserIdOfProfileAtIndex(size_t index) const
95 void SetGAIAGivenNameOfProfileAtIndex(size_t index, const string16& name); 109 // OVERRIDE;
96 void SetIsUsingGAIANameOfProfileAtIndex(size_t index, bool value); 110 // virtual bool ProfileIsEphemeralAtIndex(size_t index) const OVERRIDE;
97 void SetGAIAPictureOfProfileAtIndex(size_t index, const gfx::Image* image); 111
98 void SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, bool value); 112 // size_t GetAvatarIconIndexOfProfileAtIndex(size_t index) const;
99 void SetProfileSigninRequiredAtIndex(size_t index, bool value); 113
100 void SetProfileIsEphemeralAtIndex(size_t index, bool value); 114 // void SetNameOfProfileAtIndex(size_t index, const string16& name);
115 // void SetShortcutNameOfProfileAtIndex(size_t index, const string16& name);
116 // void SetUserNameOfProfileAtIndex(size_t index, const string16& user_name);
117 // void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index);
118 // void SetManagedUserIdOfProfileAtIndex(size_t index, const std::string& id);
119 // void SetBackgroundStatusOfProfileAtIndex(size_t index,
120 // bool running_background_apps);
121 // void SetGAIANameOfProfileAtIndex(size_t index, const string16& name);
122 // void SetGAIAGivenNameOfProfileAtIndex(size_t index, const string16& name);
123 // void SetIsUsingGAIANameOfProfileAtIndex(size_t index, bool value);
124 // void SetGAIAPictureOfProfileAtIndex(size_t index, const gfx::Image* image);
125 // void SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, bool value);
126 // void SetProfileSigninRequiredAtIndex(size_t index, bool value);
127 // void SetProfileIsEphemeralAtIndex(size_t index, bool value);
128
129 virtual const gfx::Image* GetGAIAPictureOfProfile(const base::FilePath& profil e_path) const OVERRIDE;
130 //virtual bool IsUsingGAIAPictureOfProfileAtIndex(
131 // size_t index) const OVERRIDE;
132 //virtual bool ProfileIsManagedAtIndex(size_t index) const OVERRIDE;
133 //virtual bool ProfileIsSigninRequiredAtIndex(size_t index) const OVERRIDE;
134 //virtual std::string GetManagedUserIdOfProfileAtIndex(size_t index) const
135 // OVERRIDE;
136
137 //size_t GetAvatarIconIndexOfProfileAtIndex(size_t index) const;
138
139 //void SetNameOfProfileAtIndex(size_t index, const string16& name);
140 //void SetShortcutNameOfProfileAtIndex(size_t index, const string16& name);
141 //void SetUserNameOfProfileAtIndex(size_t index, const string16& user_name);
142 //void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index);
143 //void SetManagedUserIdOfProfileAtIndex(size_t index, const std::string& id);
144 //void SetBackgroundStatusOfProfileAtIndex(size_t index,
145 // bool running_background_apps);
146 //void SetGAIANameOfProfileAtIndex(size_t index, const string16& name);
147 //void SetGAIAGivenNameOfProfileAtIndex(size_t index, const string16& name);
148 //void SetIsUsingGAIANameOfProfileAtIndex(size_t index, bool value);
149 void SetGAIAPictureOfProfile(const base::FilePath& profile_path, const gfx::Im age* image);
150 //void SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, bool value);
151 //void SetProfileSigninRequiredAtIndex(size_t index, bool value);
152
153
154
101 155
102 // Returns unique name that can be assigned to a newly created profile. 156 // Returns unique name that can be assigned to a newly created profile.
103 string16 ChooseNameForNewProfile(size_t icon_index) const; 157 string16 ChooseNameForNewProfile(size_t icon_index) const;
104 158
105 // Checks if the given profile has switched to using GAIA information 159 // Checks if the given profile has switched to using GAIA information
106 // for the profile name and picture. This pref is used to switch over 160 // for the profile name and picture. This pref is used to switch over
107 // to GAIA info the first time it is available. Afterwards this pref is 161 // to GAIA info the first time it is available. Afterwards this pref is
108 // checked to prevent clobbering the user's custom settings. 162 // checked to prevent clobbering the user's custom settings.
109 bool GetHasMigratedToGAIAInfoOfProfileAtIndex(size_t index) const; 163 //bool GetHasMigratedToGAIAInfoOfProfileAtIndex(size_t index) const;
110 164
111 // Marks the given profile as having switched to using GAIA information 165 // Marks the given profile as having switched to using GAIA information
112 // for the profile name and picture. 166 // for the profile name and picture.
113 void SetHasMigratedToGAIAInfoOfProfileAtIndex(size_t index, bool value); 167 //void SetHasMigratedToGAIAInfoOfProfileAtIndex(size_t index, bool value);
114 168
115 // Returns an avatar icon index that can be assigned to a newly created 169 // Returns an avatar icon index that can be assigned to a newly created
116 // profile. Note that the icon may not be unique since there are a limited 170 // profile. Note that the icon may not be unique since there are a limited
117 // set of default icons. 171 // set of default icons.
118 size_t ChooseAvatarIconIndexForNewProfile() const; 172 size_t ChooseAvatarIconIndexForNewProfile() const;
119 173
120 const base::FilePath& GetUserDataDir() const; 174 const base::FilePath& GetUserDataDir() const;
121 175
122 // Gets the number of default avatar icons that exist. 176 // Gets the number of default avatar icons that exist.
123 static size_t GetDefaultAvatarIconCount(); 177 static size_t GetDefaultAvatarIconCount();
(...skipping 14 matching lines...) Expand all
138 // rather than going through the ProfileInfoCache object. 192 // rather than going through the ProfileInfoCache object.
139 static std::vector<string16> GetProfileNames(); 193 static std::vector<string16> GetProfileNames();
140 194
141 // Register cache related preferences in Local State. 195 // Register cache related preferences in Local State.
142 static void RegisterPrefs(PrefRegistrySimple* registry); 196 static void RegisterPrefs(PrefRegistrySimple* registry);
143 197
144 void AddObserver(ProfileInfoCacheObserver* obs); 198 void AddObserver(ProfileInfoCacheObserver* obs);
145 void RemoveObserver(ProfileInfoCacheObserver* obs); 199 void RemoveObserver(ProfileInfoCacheObserver* obs);
146 200
147 private: 201 private:
148 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; 202 //const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const;
149 // Saves the profile info to a cache and takes ownership of |info|. 203 // Saves the profile info to a cache and takes ownership of |info|.
150 // Currently the only information that is cached is the profile's name, 204 // Currently the only information that is cached is the profile's name,
151 // user name, and avatar icon. 205 // user name, and avatar icon.
152 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); 206 //void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info);
153 std::string CacheKeyFromProfilePath(const base::FilePath& profile_path) const; 207 std::string CacheKeyFromProfilePath(const base::FilePath& profile_path) const;
154 std::vector<std::string>::iterator FindPositionForProfile( 208 //std::vector<std::string>::iterator FindPositionForProfile(
155 const std::string& search_key, 209 // const std::string& search_key,
156 const string16& search_name); 210 // const string16& search_name);
157 211
158 // Returns true if the given icon index is not in use by another profie. 212 // Returns true if the given icon index is not in use by another profie.
159 bool IconIndexIsUnique(size_t icon_index) const; 213 bool IconIndexIsUnique(size_t icon_index) const;
160 214
161 // Tries to find an icon index that satisfies all the given conditions. 215 // Tries to find an icon index that satisfies all the given conditions.
162 // Returns true if an icon was found, false otherwise. 216 // Returns true if an icon was found, false otherwise.
163 bool ChooseAvatarIconIndexForNewProfile(bool allow_generic_icon, 217 bool ChooseAvatarIconIndexForNewProfile(bool allow_generic_icon,
164 bool must_be_unique, 218 bool must_be_unique,
165 size_t* out_icon_index) const; 219 size_t* out_icon_index) const;
166 220
167 // Updates the position of the profile at the given index so that the list 221 // Updates the position of the profile at the given index so that the list
168 // of profiles is still sorted. 222 // of profiles is still sorted.
169 void UpdateSortForProfileIndex(size_t index); 223 //void UpdateSortForProfileIndex(size_t index);
170 224
171 void OnGAIAPictureLoaded(const base::FilePath& path, 225 void OnGAIAPictureLoaded(const base::FilePath& path,
172 gfx::Image** image) const; 226 gfx::Image** image) const;
173 void OnGAIAPictureSaved(const base::FilePath& path, bool* success) const; 227 void OnGAIAPictureSaved(const base::FilePath& path, bool* success) const;
174 228
175 PrefService* prefs_; 229 PrefService* prefs_;
176 std::vector<std::string> sorted_keys_; 230 //std::vector<std::string> sorted_keys_;
231 std::map<std::string, ProfileInfoEntry> cached_entries_;
177 base::FilePath user_data_dir_; 232 base::FilePath user_data_dir_;
178 233
179 ObserverList<ProfileInfoCacheObserver> observer_list_; 234 ObserverList<ProfileInfoCacheObserver> observer_list_;
180 235
181 // A cache of gaia profile pictures. This cache is updated lazily so it needs 236 // A cache of gaia profile pictures. This cache is updated lazily so it needs
182 // to be mutable. 237 // to be mutable.
183 mutable std::map<std::string, gfx::Image*> gaia_pictures_; 238 mutable std::map<std::string, gfx::Image*> gaia_pictures_;
184 // Marks a gaia profile picture as loading. This prevents a picture from 239 // Marks a gaia profile picture as loading. This prevents a picture from
185 // loading multiple times. 240 // loading multiple times.
186 mutable std::map<std::string, bool> gaia_pictures_loading_; 241 mutable std::map<std::string, bool> gaia_pictures_loading_;
187 242
188 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); 243 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache);
189 }; 244 };
190 245
191 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ 246 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_impl.cc ('k') | chrome/browser/profiles/profile_info_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698