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