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 <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/observer_list.h" |
15 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
16 #include "chrome/browser/profiles/profile_info_interface.h" | 18 #include "chrome/browser/profiles/profile_info_interface.h" |
17 | 19 |
18 namespace gfx { | 20 namespace gfx { |
19 class Image; | 21 class Image; |
20 } | 22 } |
21 | 23 |
22 namespace base { | 24 namespace base { |
23 class DictionaryValue; | 25 class DictionaryValue; |
24 } | 26 } |
25 | 27 |
26 class PrefService; | 28 class PrefService; |
27 | 29 |
28 | |
29 // This class saves various information about profiles to local preferences. | 30 // This class saves various information about profiles to local preferences. |
30 // This cache can be used to display a list of profiles without having to | 31 // This cache can be used to display a list of profiles without having to |
31 // actually load the profiles from disk. | 32 // actually load the profiles from disk. |
32 class ProfileInfoCache : public ProfileInfoInterface { | 33 class ProfileInfoCache : public ProfileInfoInterface { |
33 public: | 34 public: |
34 ProfileInfoCache(PrefService* prefs, const FilePath& user_data_dir); | 35 ProfileInfoCache(PrefService* prefs, const FilePath& user_data_dir); |
35 virtual ~ProfileInfoCache(); | 36 virtual ~ProfileInfoCache(); |
36 | 37 |
37 void AddProfileToCache(const FilePath& profile_path, | 38 void AddProfileToCache(const FilePath& profile_path, |
38 const string16& name, | 39 const string16& name, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 static size_t GetDefaultAvatarIconCount(); | 77 static size_t GetDefaultAvatarIconCount(); |
77 // Gets the resource ID of the default avatar icon at |index|. | 78 // Gets the resource ID of the default avatar icon at |index|. |
78 static int GetDefaultAvatarIconResourceIDAtIndex(size_t index); | 79 static int GetDefaultAvatarIconResourceIDAtIndex(size_t index); |
79 // Returns a URL for the default avatar icon with specified index. | 80 // Returns a URL for the default avatar icon with specified index. |
80 static std::string GetDefaultAvatarIconUrl(size_t index); | 81 static std::string GetDefaultAvatarIconUrl(size_t index); |
81 // Checks if the given URL points to one of the default avatar icons. If it | 82 // Checks if the given URL points to one of the default avatar icons. If it |
82 // is, returns true and its index through |icon_index|. If not, returns false. | 83 // is, returns true and its index through |icon_index|. If not, returns false. |
83 static bool IsDefaultAvatarIconUrl(const std::string& icon_url, | 84 static bool IsDefaultAvatarIconUrl(const std::string& icon_url, |
84 size_t *icon_index); | 85 size_t *icon_index); |
85 | 86 |
| 87 // Gets all names of profiles associated with this instance of Chrome. |
| 88 // Because this method will be called during uninstall, before the creation |
| 89 // of the ProfileManager, it reads directly from the local state preferences, |
| 90 // rather than going through the ProfileInfoCache object. |
| 91 static std::vector<string16> GetProfileNames(); |
| 92 |
86 // Register cache related preferences in Local State. | 93 // Register cache related preferences in Local State. |
87 static void RegisterPrefs(PrefService* prefs); | 94 static void RegisterPrefs(PrefService* prefs); |
88 | 95 |
| 96 void AddObserver(ProfileInfoCacheObserver* obs); |
| 97 void RemoveObserver(ProfileInfoCacheObserver* obs); |
| 98 |
89 private: | 99 private: |
90 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; | 100 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; |
91 // Saves the profile info to a cache and takes ownership of |info|. | 101 // Saves the profile info to a cache and takes ownership of |info|. |
92 // Currently the only information that is cached is the profiles name, | 102 // Currently the only information that is cached is the profile's name, |
93 // user name, and avatar icon. | 103 // user name, and avatar icon. |
94 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); | 104 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); |
95 std::string CacheKeyFromProfilePath(const FilePath& profile_path) const; | 105 std::string CacheKeyFromProfilePath(const FilePath& profile_path) const; |
96 std::vector<std::string>::iterator FindPositionForProfile( | 106 std::vector<std::string>::iterator FindPositionForProfile( |
97 std::string search_key, | 107 std::string search_key, |
98 const string16& search_name); | 108 const string16& search_name); |
99 | 109 |
100 // Returns true if the given icon index is not in use by another profie. | 110 // Returns true if the given icon index is not in use by another profie. |
101 bool IconIndexIsUnique(size_t icon_index) const; | 111 bool IconIndexIsUnique(size_t icon_index) const; |
102 | 112 |
103 // Tries to find an icon index that satisfies all the given conditions. | 113 // Tries to find an icon index that satisfies all the given conditions. |
104 // Returns true if an icon was found, false otherwise. | 114 // Returns true if an icon was found, false otherwise. |
105 bool ChooseAvatarIconIndexForNewProfile(bool allow_generic_icon, | 115 bool ChooseAvatarIconIndexForNewProfile(bool allow_generic_icon, |
106 bool must_be_unique, | 116 bool must_be_unique, |
107 size_t* out_icon_index) const; | 117 size_t* out_icon_index) const; |
108 | 118 |
109 PrefService* prefs_; | 119 PrefService* prefs_; |
110 std::vector<std::string> sorted_keys_; | 120 std::vector<std::string> sorted_keys_; |
111 FilePath user_data_dir_; | 121 FilePath user_data_dir_; |
112 | 122 |
| 123 ObserverList<ProfileInfoCacheObserver> observer_list_; |
| 124 |
113 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); | 125 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); |
114 }; | 126 }; |
115 | 127 |
116 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ | 128 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ |
OLD | NEW |