| 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> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 void SetNameOfProfileAtIndex(size_t index, const string16& name); | 55 void SetNameOfProfileAtIndex(size_t index, const string16& name); |
| 56 void SetUserNameOfProfileAtIndex(size_t index, const string16& user_name); | 56 void SetUserNameOfProfileAtIndex(size_t index, const string16& user_name); |
| 57 void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index); | 57 void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index); |
| 58 | 58 |
| 59 // Returns unique name that can be assigned to a newly created profile. | 59 // Returns unique name that can be assigned to a newly created profile. |
| 60 string16 ChooseNameForNewProfile(); | 60 string16 ChooseNameForNewProfile(); |
| 61 | 61 |
| 62 // Returns an avatar icon index that can be assigned to a newly created | 62 // Returns an avatar icon index that can be assigned to a newly created |
| 63 // profile. Note that the icon may not be unique since there are a limited | 63 // profile. Note that the icon may not be unique since there are a limited |
| 64 // set of default icons. | 64 // set of default icons. |
| 65 int ChooseAvatarIconIndexForNewProfile(); | 65 size_t ChooseAvatarIconIndexForNewProfile() const; |
| 66 | 66 |
| 67 const FilePath& GetUserDataDir() const; | 67 const FilePath& GetUserDataDir() const; |
| 68 | 68 |
| 69 // Gets the number of default avatar icons that exist. | 69 // Gets the number of default avatar icons that exist. |
| 70 static size_t GetDefaultAvatarIconCount(); | 70 static size_t GetDefaultAvatarIconCount(); |
| 71 // Gets the resource ID of the default avatar icon at |index|. | 71 // Gets the resource ID of the default avatar icon at |index|. |
| 72 static int GetDefaultAvatarIconResourceIDAtIndex(size_t index); | 72 static int GetDefaultAvatarIconResourceIDAtIndex(size_t index); |
| 73 // Returns a URL for the default avatar icon with specified index. | 73 // Returns a URL for the default avatar icon with specified index. |
| 74 static std::string GetDefaultAvatarIconUrl(size_t index); | 74 static std::string GetDefaultAvatarIconUrl(size_t index); |
| 75 // Checks if the given URL points to one of the default avatar icons. If it | 75 // Checks if the given URL points to one of the default avatar icons. If it |
| 76 // is, returns true and its index through |icon_index|. If not, returns false. | 76 // is, returns true and its index through |icon_index|. If not, returns false. |
| 77 static bool IsDefaultAvatarIconUrl(const std::string& icon_url, | 77 static bool IsDefaultAvatarIconUrl(const std::string& icon_url, |
| 78 size_t *icon_index); | 78 size_t *icon_index); |
| 79 | 79 |
| 80 // Register cache related preferences in Local State. | 80 // Register cache related preferences in Local State. |
| 81 static void RegisterPrefs(PrefService* prefs); | 81 static void RegisterPrefs(PrefService* prefs); |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; | 84 const base::DictionaryValue* GetInfoForProfileAtIndex(size_t index) const; |
| 85 // Saves the profile info to a cache and takes ownership of |info|. | 85 // Saves the profile info to a cache and takes ownership of |info|. |
| 86 // Currently the only information that is cached is the profiles name and | 86 // Currently the only information that is cached is the profiles name and |
| 87 // avatar icon. | 87 // avatar icon. |
| 88 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); | 88 void SetInfoForProfileAtIndex(size_t index, base::DictionaryValue* info); |
| 89 std::string CacheKeyFromProfilePath(const FilePath& profile_path) const; | 89 std::string CacheKeyFromProfilePath(const FilePath& profile_path) const; |
| 90 std::vector<std::string>::iterator FindPositionForProfile( | 90 std::vector<std::string>::iterator FindPositionForProfile( |
| 91 std::string search_key, | 91 std::string search_key, |
| 92 const string16& search_name); | 92 const string16& search_name); |
| 93 | 93 |
| 94 // Returns true if the given icon index is not in use by another profie. |
| 95 bool IconIndexIsUnique(size_t icon_index) const; |
| 96 |
| 97 // Tries to find an icon index that satisfies all the given conditions. |
| 98 // Returns true if an icon was found, false otherwise. |
| 99 bool ChooseAvatarIconIndexForNewProfile(bool allow_generic_icon, |
| 100 bool must_be_unique, |
| 101 size_t* out_icon_index) const; |
| 102 |
| 94 PrefService* prefs_; | 103 PrefService* prefs_; |
| 95 std::vector<std::string> sorted_keys_; | 104 std::vector<std::string> sorted_keys_; |
| 96 FilePath user_data_dir_; | 105 FilePath user_data_dir_; |
| 97 | 106 |
| 98 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); | 107 DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache); |
| 99 }; | 108 }; |
| 100 | 109 |
| 101 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ | 110 #endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_ |
| OLD | NEW |