Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_PROFILES_PROFILE_ATTRIBUTES_ENTRY_H_ |
| 6 | #define CHROME_BROWSER_PROFILES_PROFILE_ATTRIBUTES_ENTRY_H_ |
| 7 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 10 | #include <memory> |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 11 | #include <optional> |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 12 | #include <string> |
| 13 | |
David Roger | f90eb30 | 2021-07-30 08:02:53 | [diff] [blame] | 14 | #include "base/containers/flat_set.h" |
Monica Basta | 2288a0e3 | 2019-09-26 13:29:32 | [diff] [blame] | 15 | #include "base/feature_list.h" |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 17 | #include "base/gtest_prod_util.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 18 | #include "base/memory/raw_ptr.h" |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 19 | #include "base/time/time.h" |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 20 | #include "base/values.h" |
Amelie Schneider | 80c2f0b0 | 2024-07-09 08:00:33 | [diff] [blame] | 21 | #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
Mikel Astiz | bee274d | 2024-12-16 19:54:31 | [diff] [blame] | 22 | #include "google_apis/gaia/gaia_id.h" |
Alex Ilin | 1020018 | 2020-07-29 14:19:37 | [diff] [blame] | 23 | #include "third_party/skia/include/core/SkColor.h" |
Alex Ilin | a67b047 | 2020-08-06 12:11:10 | [diff] [blame] | 24 | #include "ui/gfx/image/image.h" |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 25 | |
Thomas Tangl | c67ace4 | 2019-06-07 19:31:50 | [diff] [blame] | 26 | class PrefRegistrySimple; |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 27 | class PrefService; |
Alex Ilin | bb08a0d | 2021-07-08 09:37:24 | [diff] [blame] | 28 | class ProfileAttributesStorage; |
Jan Krcal | 5fa5da8 | 2020-11-11 16:10:57 | [diff] [blame] | 29 | struct ProfileThemeColors; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 30 | |
Amelie Schneider | 7b036dd | 2024-07-15 11:08:48 | [diff] [blame] | 31 | inline constexpr int kDefaultSizeForPlaceholderAvatar = 74; |
| 32 | |
Monica Basta | 9ca4704 | 2019-09-16 17:36:51 | [diff] [blame] | 33 | enum class SigninState { |
| 34 | kNotSignedIn, |
| 35 | kSignedInWithUnconsentedPrimaryAccount, |
| 36 | kSignedInWithConsentedPrimaryAccount, |
| 37 | }; |
| 38 | |
David Roger | e582c445 | 2020-03-18 20:45:38 | [diff] [blame] | 39 | enum class NameForm { |
| 40 | kGaiaName, |
| 41 | kLocalName, |
| 42 | kGaiaAndLocalName, |
| 43 | }; |
| 44 | |
Zonghan Xu | 9f1191d | 2024-12-02 18:33:16 | [diff] [blame] | 45 | // TODO(381117479): Currently we support two different OIDC enrollment flows: |
| 46 | // 1. by sending both Auth and ID token through URL param and |
| 47 | // 2. by sending encrypted user information in the auth header |
| 48 | // Method 1 is completed but it will be deprecated once we completely implement, |
| 49 | // test and rollout method 2. |
hmare | b63e5a1c5 | 2024-07-22 07:51:45 | [diff] [blame] | 50 | struct ProfileManagementOidcTokens { |
| 51 | ProfileManagementOidcTokens(); |
| 52 | ProfileManagementOidcTokens(const std::string& auth_token, |
hmare | 6191d19d | 2024-07-17 21:20:45 | [diff] [blame] | 53 | const std::string& id_token, |
| 54 | const std::u16string& identity_name); |
hmare | b63e5a1c5 | 2024-07-22 07:51:45 | [diff] [blame] | 55 | ProfileManagementOidcTokens(const std::string& auth_token, |
hmare | 6191d19d | 2024-07-17 21:20:45 | [diff] [blame] | 56 | const std::string& id_token, |
| 57 | const std::string& state); |
Zonghan Xu | 9f1191d | 2024-12-02 18:33:16 | [diff] [blame] | 58 | // This will be the new format of the `ProfileManagementOidcTokens` struct, |
| 59 | // after we fully migrate. |
| 60 | explicit ProfileManagementOidcTokens(const std::string& encrypted_user_info); |
hmare | 6191d19d | 2024-07-17 21:20:45 | [diff] [blame] | 61 | |
hmare | b63e5a1c5 | 2024-07-22 07:51:45 | [diff] [blame] | 62 | ProfileManagementOidcTokens(const ProfileManagementOidcTokens& other); |
| 63 | ProfileManagementOidcTokens& operator=( |
| 64 | const ProfileManagementOidcTokens& other); |
hmare | 6191d19d | 2024-07-17 21:20:45 | [diff] [blame] | 65 | |
hmare | b63e5a1c5 | 2024-07-22 07:51:45 | [diff] [blame] | 66 | ProfileManagementOidcTokens(ProfileManagementOidcTokens&& other); |
| 67 | ProfileManagementOidcTokens& operator=(ProfileManagementOidcTokens&& other); |
| 68 | ~ProfileManagementOidcTokens(); |
hmare | 6191d19d | 2024-07-17 21:20:45 | [diff] [blame] | 69 | |
| 70 | // Authorization token from the authorization response. |
Zonghan Xu | b03bc37 | 2024-01-30 22:11:48 | [diff] [blame] | 71 | std::string auth_token; |
hmare | 6191d19d | 2024-07-17 21:20:45 | [diff] [blame] | 72 | |
Zonghan Xu | 9f1191d | 2024-12-02 18:33:16 | [diff] [blame] | 73 | // ID token from the authorization response or the encrypted user information. |
| 74 | // Field will be renamed to encrypted_user_information once we fully migrate. |
Zonghan Xu | b03bc37 | 2024-01-30 22:11:48 | [diff] [blame] | 75 | std::string id_token; |
hmare | 6191d19d | 2024-07-17 21:20:45 | [diff] [blame] | 76 | |
| 77 | // Identity name of the profile. This is only relevant after the completion of |
| 78 | // profile registration. |
Zonghan Xu | 4b014d99 | 2024-07-09 17:23:33 | [diff] [blame] | 79 | std::u16string identity_name; |
Zonghan Xu | e1b11db | 2024-03-06 18:17:57 | [diff] [blame] | 80 | |
hmare | 6191d19d | 2024-07-17 21:20:45 | [diff] [blame] | 81 | // OIDC configuration state. This is only relevant during profile |
| 82 | // registration. |
| 83 | std::string state; |
Zonghan Xu | 9f1191d | 2024-12-02 18:33:16 | [diff] [blame] | 84 | |
| 85 | // Whether the passing ID token/user info is encrypted. This field will be |
| 86 | // removed after we fully migrate. |
| 87 | bool is_token_encrypted = false; |
Zonghan Xu | b03bc37 | 2024-01-30 22:11:48 | [diff] [blame] | 88 | }; |
| 89 | |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 90 | class ProfileAttributesEntry { |
| 91 | public: |
Thomas Tangl | c67ace4 | 2019-06-07 19:31:50 | [diff] [blame] | 92 | static void RegisterLocalStatePrefs(PrefRegistrySimple* registry); |
| 93 | |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 94 | ProfileAttributesEntry(); |
David Bienvenu | 1e9f6a7 | 2020-08-20 01:05:48 | [diff] [blame] | 95 | ProfileAttributesEntry(const ProfileAttributesEntry&) = delete; |
| 96 | ProfileAttributesEntry& operator=(const ProfileAttributesEntry&) = delete; |
| 97 | virtual ~ProfileAttributesEntry() = default; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 98 | |
Monica Basta | bafd44c2 | 2019-10-10 10:14:54 | [diff] [blame] | 99 | // Gets the name of the profile to be displayed in the User Menu. The name can |
| 100 | // be the GAIA name, local profile name or a combination of them. |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 101 | std::u16string GetName() const; |
Monica Basta | 6655884a | 2019-10-29 10:38:39 | [diff] [blame] | 102 | // Returns |GetGAIAGivenName()| if not empty. Otherwise, returns |
| 103 | // |GetGAIAName()|. |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 104 | std::u16string GetGAIANameToDisplay() const; |
Monica Basta | 36cb265 | 2019-10-23 11:17:44 | [diff] [blame] | 105 | // Returns true if the profile name has changed. |
| 106 | bool HasProfileNameChanged(); |
David Roger | e582c445 | 2020-03-18 20:45:38 | [diff] [blame] | 107 | // Returns how the value of GetName() gets constructed. |
| 108 | NameForm GetNameForm() const; |
Monica Basta | 36cb265 | 2019-10-23 11:17:44 | [diff] [blame] | 109 | |
Monica Basta | bafd44c2 | 2019-10-10 10:14:54 | [diff] [blame] | 110 | // Gets the local profile name. |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 111 | std::u16string GetLocalProfileName() const; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 112 | |
Salma Elmahallawy | 67c2cca0 | 2025-01-24 20:02:18 | [diff] [blame] | 113 | // Get the profile label set for a managed profile. This is used instead of |
| 114 | // the local profile name if present. |
| 115 | std::u16string GetEnterpriseProfileLabel() const; |
| 116 | |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 117 | std::u16string GetShortcutName() const; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 118 | // Gets the path to the profile. Should correspond to the path passed to |
| 119 | // ProfileAttributesStorage::GetProfileAttributesWithPath to get this entry. |
| 120 | base::FilePath GetPath() const; |
| 121 | base::Time GetActiveTime() const; |
| 122 | // Gets the user name of the signed in profile. This is typically the email |
| 123 | // address used to sign in and the empty string for profiles that aren't |
| 124 | // signed in to chrome. |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 125 | std::u16string GetUserName() const; |
Jan Krcal | a4cd6bc | 2020-11-06 17:14:13 | [diff] [blame] | 126 | // Gets the icon used as this profile's avatar. High res icon are downloaded |
| 127 | // only if `download_high_res` is true, otherwise a low-res fallback is |
| 128 | // returned. |
Alison Gale | 3f4203f7 | 2024-04-26 19:27:42 | [diff] [blame] | 129 | // TODO(crbug.com/40138086): Rename |size_for_placeholder_avatar| to |size| |
| 130 | // and make this function resize all avatars appropriately. Remove the default |
Alex Ilin | a67b047 | 2020-08-06 12:11:10 | [diff] [blame] | 131 | // value of |size_for_placeholder_avatar| when all callsites pass some value. |
| 132 | // Consider adding a |shape| parameter and get rid of |
| 133 | // profiles::GetSizedAvatarIcon(). |
Amelie Schneider | 80c2f0b0 | 2024-07-09 08:00:33 | [diff] [blame] | 134 | gfx::Image GetAvatarIcon( |
Amelie Schneider | 7b036dd | 2024-07-15 11:08:48 | [diff] [blame] | 135 | int size_for_placeholder_avatar = kDefaultSizeForPlaceholderAvatar, |
Amelie Schneider | 80c2f0b0 | 2024-07-09 08:00:33 | [diff] [blame] | 136 | bool use_high_res_file = true, |
| 137 | const profiles::PlaceholderAvatarIconParams& icon_params = {}) const; |
WC Leung | 1775638 | 2017-08-25 04:57:36 | [diff] [blame] | 138 | // Returns true if the profile is currently running any background apps. Note |
| 139 | // that a return value of false could mean an error in collection or that |
| 140 | // there are currently no background apps running. However, the action which |
| 141 | // results is the same in both cases (thus far). |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 142 | bool GetBackgroundStatus() const; |
| 143 | // Gets the GAIA full name associated with this profile if it's signed in. |
Zonghan Xu | 4b014d99 | 2024-07-09 17:23:33 | [diff] [blame] | 144 | // If GAIA full name is empty, gets the full name from the 3P identity |
| 145 | // associated with this profile, currently only available for OIDC profiles. |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 146 | std::u16string GetGAIAName() const; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 147 | // Gets the GAIA given name associated with this profile if it's signed in. |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 148 | std::u16string GetGAIAGivenName() const; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 149 | // Gets the opaque string representation of the profile's GAIA ID if it's |
| 150 | // signed in. |
Mikel Astiz | bee274d | 2024-12-16 19:54:31 | [diff] [blame] | 151 | GaiaId GetGAIAId() const; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 152 | // Returns the GAIA picture for the given profile. This may return NULL |
| 153 | // if the profile does not have a GAIA picture or if the picture must be |
| 154 | // loaded from disk. |
| 155 | const gfx::Image* GetGAIAPicture() const; |
| 156 | // Returns true if the profile displays a GAIA picture instead of one of the |
| 157 | // locally bundled icons. |
| 158 | bool IsUsingGAIAPicture() const; |
Xi Cheng | 1b76138 | 2017-08-15 20:37:34 | [diff] [blame] | 159 | // Returns true if a GAIA picture has been loaded or has failed to load. |
| 160 | bool IsGAIAPictureLoaded() const; |
Alex Ilin | 9c5d041f | 2021-06-17 07:36:30 | [diff] [blame] | 161 | // Returns the last downloaded GAIA picture URL with size. |
| 162 | std::string GetLastDownloadedGAIAPictureUrlWithSize() const; |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 163 | // Returns true if the profile is signed in as a supervised user. |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 164 | bool IsSupervised() const; |
Alex Ilin | 310e38d | 2021-01-21 16:36:51 | [diff] [blame] | 165 | // Returns true if the profile should not be displayed to the user in the |
| 166 | // list of profiles. |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 167 | bool IsOmitted() const; |
Alex Ilin | 4554c99 | 2021-06-10 08:17:47 | [diff] [blame] | 168 | // Returns true if the user must sign before a profile can be opened. |
| 169 | // Currently, this returns true iff a profile is locked due to the force |
| 170 | // sign-in policy. |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 171 | bool IsSigninRequired() const; |
| 172 | // Gets the supervised user ID of the profile's signed in account, if it's a |
| 173 | // supervised user. |
| 174 | std::string GetSupervisedUserId() const; |
| 175 | // Returns true if the profile is an ephemeral profile. |
| 176 | bool IsEphemeral() const; |
| 177 | // Returns true if the profile is using a default name, typically of the |
| 178 | // format "Person %d". |
| 179 | bool IsUsingDefaultName() const; |
Monica Basta | 9ca4704 | 2019-09-16 17:36:51 | [diff] [blame] | 180 | // Returns Signin state. |
| 181 | SigninState GetSigninState() const; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 182 | // Returns true if the profile is signed in. |
| 183 | bool IsAuthenticated() const; |
Yann Dago | e73f933 | 2021-08-12 18:54:55 | [diff] [blame] | 184 | // Returns true if the account can be be managed. |
| 185 | bool CanBeManaged() const; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 186 | // Returns true if the Profile is using the default avatar, which is one of |
| 187 | // the profile icons selectable at profile creation. |
| 188 | bool IsUsingDefaultAvatar() const; |
Yusuf Sengul | 202917b | 2020-04-03 21:36:17 | [diff] [blame] | 189 | // Indicates that profile was signed in through native OS credential provider. |
| 190 | bool IsSignedInWithCredentialProvider() const; |
Zonghan Xu | b386dff | 2024-02-08 16:06:43 | [diff] [blame] | 191 | // Returns true if the profile is managed by a third party identity that is |
| 192 | // not sync-ed to Google (i.e dasher-based). |
| 193 | bool IsDasherlessManagement() const; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 194 | // Returns the index of the default icon used by the profile. |
| 195 | size_t GetAvatarIconIndex() const; |
Alex Ilin | 9c573604 | 2020-08-03 13:52:13 | [diff] [blame] | 196 | // Returns the colors specified by the profile theme, or default colors if no |
| 197 | // theme is specified for the profile. |
| 198 | ProfileThemeColors GetProfileThemeColors() const; |
Jan Krcal | 920f460c | 2020-11-13 22:33:22 | [diff] [blame] | 199 | // Returns the colors specified by the profile theme, or empty if no theme is |
| 200 | // set for the profile. |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 201 | std::optional<ProfileThemeColors> GetProfileThemeColorsIfSet() const; |
Thomas Tangl | c67ace4 | 2019-06-07 19:31:50 | [diff] [blame] | 202 | // Returns the metrics bucket this profile should be recorded in. |
| 203 | // Note: The bucket index is assigned once and remains the same all time. 0 is |
| 204 | // reserved for the guest profile. |
| 205 | size_t GetMetricsBucketIndex(); |
Jan Krcal | 8fb12cf | 2020-04-01 21:31:42 | [diff] [blame] | 206 | // Returns the hosted domain for the current signed-in account. Returns empty |
Tanmoy Mollik | 469985a | 2024-12-05 09:38:24 | [diff] [blame] | 207 | // string if there is no signed-in account and returns |
| 208 | // |signin::constants::kNoHostedDomainFound| if the signed-in account has no |
| 209 | // hosted domain (such as when it is a standard gmail.com account). Unlike |
| 210 | // for other string getters, the returned value is UTF8 encoded. |
Jan Krcal | 8fb12cf | 2020-04-01 21:31:42 | [diff] [blame] | 211 | std::string GetHostedDomain() const; |
Yann Dago | 2fa00f8e | 2023-03-20 16:40:36 | [diff] [blame] | 212 | |
| 213 | // Returns the enrollment token to get policies for a profile. |
| 214 | std::string GetProfileManagementEnrollmentToken() const; |
| 215 | |
Zonghan Xu | b03bc37 | 2024-01-30 22:11:48 | [diff] [blame] | 216 | // Returns the Oauth token and Id token from the OIDC authentication response |
| 217 | // that created the profile. The existence of these tokens are also used to |
| 218 | // check whether the profile is created by an OIDC authentication response. |
hmare | b63e5a1c5 | 2024-07-22 07:51:45 | [diff] [blame] | 219 | ProfileManagementOidcTokens GetProfileManagementOidcTokens() const; |
Zonghan Xu | b03bc37 | 2024-01-30 22:11:48 | [diff] [blame] | 220 | |
Yann Dago | 2fa00f8e | 2023-03-20 16:40:36 | [diff] [blame] | 221 | // Returns the signin id for a profile managed by a token. This may be empty |
| 222 | // even if there is an enrollment token. |
| 223 | std::string GetProfileManagementId() const; |
| 224 | |
Alex Ilin | d5cc777 | 2021-06-30 12:14:53 | [diff] [blame] | 225 | // Returns an account id key of the user of the profile. Empty if the profile |
| 226 | // doesn't have any associated `user_manager::User`. |
| 227 | std::string GetAccountIdKey() const; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 228 | |
Ryan Sultanem | a96d3743 | 2025-01-14 15:35:14 | [diff] [blame] | 229 | // Returns whether the current profile state is glic eligibile or not based on |
| 230 | // the signed in account. Signed out profiles are ineligible. |
| 231 | bool IsGlicEligible() const; |
| 232 | |
David Roger | f90eb30 | 2021-07-30 08:02:53 | [diff] [blame] | 233 | // Gets/Sets the gaia IDs of the accounts signed into the profile (accounts |
| 234 | // known by the `IdentityManager`). |
Mikel Astiz | a7d9d66 | 2025-02-04 11:22:12 | [diff] [blame] | 235 | base::flat_set<GaiaId> GetGaiaIds() const; |
| 236 | void SetGaiaIds(const base::flat_set<GaiaId>& gaia_ids); |
David Roger | f90eb30 | 2021-07-30 08:02:53 | [diff] [blame] | 237 | |
Monica Basta | a948f95 | 2021-01-14 17:31:11 | [diff] [blame] | 238 | // |is_using_default| should be set to false for non default profile names. |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 239 | void SetLocalProfileName(const std::u16string& name, bool is_default_name); |
Salma Elmahallawy | 67c2cca0 | 2025-01-24 20:02:18 | [diff] [blame] | 240 | void SetEnterpriseProfileLabel(const std::u16string& name); |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 241 | void SetShortcutName(const std::u16string& name); |
lwchkg | 498e9249 | 2016-04-23 11:04:12 | [diff] [blame] | 242 | void SetActiveTimeToNow(); |
Jan Krcal | ac72ebcf | 2021-03-15 08:41:26 | [diff] [blame] | 243 | // Only ephemeral profiles can be set as omitted. |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 244 | void SetIsOmitted(bool is_omitted); |
| 245 | void SetSupervisedUserId(const std::string& id); |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 246 | void SetBackgroundStatus(bool running_background_apps); |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 247 | void SetGAIAName(const std::u16string& name); |
| 248 | void SetGAIAGivenName(const std::u16string& name); |
Monica Basta | ff6a3597 | 2020-02-14 19:16:04 | [diff] [blame] | 249 | void SetGAIAPicture(const std::string& image_url_with_size, gfx::Image image); |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 250 | void SetIsUsingGAIAPicture(bool value); |
Alex Ilin | 9c5d041f | 2021-06-17 07:36:30 | [diff] [blame] | 251 | void SetLastDownloadedGAIAPictureUrlWithSize( |
| 252 | const std::string& image_url_with_size); |
Yusuf Sengul | 202917b | 2020-04-03 21:36:17 | [diff] [blame] | 253 | void SetSignedInWithCredentialProvider(bool value); |
Zonghan Xu | b386dff | 2024-02-08 16:06:43 | [diff] [blame] | 254 | void SetDasherlessManagement(bool value); |
Jan Krcal | ac72ebcf | 2021-03-15 08:41:26 | [diff] [blame] | 255 | // Only non-omitted profiles can be set as non-ephemeral. It's the |
| 256 | // responsibility of the caller to make sure that the entry is set as |
| 257 | // non-ephemeral only if prefs::kForceEphemeralProfiles is false. |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 258 | void SetIsEphemeral(bool value); |
Yann Dago | e73f933 | 2021-08-12 18:54:55 | [diff] [blame] | 259 | void SetUserAcceptedAccountManagement(bool value); |
| 260 | bool UserAcceptedAccountManagement() const; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 261 | void SetIsUsingDefaultAvatar(bool value); |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 262 | void SetAvatarIconIndex(size_t icon_index); |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 263 | // std::nullopt resets colors to default. |
| 264 | void SetProfileThemeColors(const std::optional<ProfileThemeColors>& colors); |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 265 | |
Jan Krcal | 8fb12cf | 2020-04-01 21:31:42 | [diff] [blame] | 266 | // Unlike for other string setters, the argument is expected to be UTF8 |
| 267 | // encoded. |
| 268 | void SetHostedDomain(std::string hosted_domain); |
| 269 | |
Yann Dago | 2fa00f8e | 2023-03-20 16:40:36 | [diff] [blame] | 270 | void SetProfileManagementEnrollmentToken(const std::string& enrollment_token); |
Zonghan Xu | b03bc37 | 2024-01-30 22:11:48 | [diff] [blame] | 271 | void SetProfileManagementOidcTokens( |
hmare | b63e5a1c5 | 2024-07-22 07:51:45 | [diff] [blame] | 272 | const ProfileManagementOidcTokens& oidc_tokens); |
Yann Dago | 2fa00f8e | 2023-03-20 16:40:36 | [diff] [blame] | 273 | void SetProfileManagementId(const std::string& id); |
| 274 | |
Mikel Astiz | bee274d | 2024-12-16 19:54:31 | [diff] [blame] | 275 | void SetAuthInfo(const GaiaId& gaia_id, |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 276 | const std::u16string& user_name, |
Monica Basta | 9ca4704 | 2019-09-16 17:36:51 | [diff] [blame] | 277 | bool is_consented_primary_account); |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 278 | |
Ryan Sultanem | a96d3743 | 2025-01-14 15:35:14 | [diff] [blame] | 279 | void SetIsGlicEligible(bool value); |
| 280 | |
Jan Krcal | 8fb12cf | 2020-04-01 21:31:42 | [diff] [blame] | 281 | // Update info about accounts. These functions are idempotent, only the first |
| 282 | // call for a given input matters. |
| 283 | void AddAccountName(const std::string& name); |
Jan Krcal | 8fb12cf | 2020-04-01 21:31:42 | [diff] [blame] | 284 | |
| 285 | // Clears info about all accounts that have been added in the past via |
David Roger | 0043076 | 2023-03-31 10:20:04 | [diff] [blame] | 286 | // AddAccountName(). |
Jan Krcal | 8fb12cf | 2020-04-01 21:31:42 | [diff] [blame] | 287 | void ClearAccountNames(); |
Jan Krcal | 8fb12cf | 2020-04-01 21:31:42 | [diff] [blame] | 288 | |
zmin | 5db8709 | 2016-11-08 20:21:35 | [diff] [blame] | 289 | // Lock/Unlock the profile, should be called only if force-sign-in is enabled. |
| 290 | void LockForceSigninProfile(bool is_lock); |
| 291 | |
David Roger | 0043076 | 2023-03-31 10:20:04 | [diff] [blame] | 292 | // Records aggregate metrics about all accounts used in this profile. |
| 293 | void RecordAccountNamesMetric() const; |
Jan Krcal | 8fb12cf | 2020-04-01 21:31:42 | [diff] [blame] | 294 | |
Monica Basta | 3029056 | 2019-11-21 16:24:03 | [diff] [blame] | 295 | static const char kSupervisedUserId[]; |
Daniel Bratell | 15cbb31 | 2018-02-05 18:01:59 | [diff] [blame] | 296 | static const char kAvatarIconKey[]; |
| 297 | static const char kBackgroundAppsKey[]; |
| 298 | static const char kProfileIsEphemeral[]; |
| 299 | static const char kUserNameKey[]; |
Monica Basta | d82d88e | 2019-10-31 11:24:12 | [diff] [blame] | 300 | static const char kGAIAIdKey[]; |
Monica Basta | 9ca4704 | 2019-09-16 17:36:51 | [diff] [blame] | 301 | static const char kIsConsentedPrimaryAccountKey[]; |
Monica Basta | 7ff9e23 | 2019-11-19 15:33:28 | [diff] [blame] | 302 | static const char kNameKey[]; |
Salma Elmahallawy | 67c2cca0 | 2025-01-24 20:02:18 | [diff] [blame] | 303 | static const char kEnterpriseLabelKey[]; |
Monica Basta | 7ff9e23 | 2019-11-19 15:33:28 | [diff] [blame] | 304 | static const char kIsUsingDefaultNameKey[]; |
Alex Ilin | d4a6595 | 2021-06-17 08:26:11 | [diff] [blame] | 305 | static const char kIsUsingDefaultAvatarKey[]; |
Alex Ilin | 17c0720 | 2021-06-21 11:40:31 | [diff] [blame] | 306 | static const char kUseGAIAPictureKey[]; |
Alex Ilin | d5cc777 | 2021-06-30 12:14:53 | [diff] [blame] | 307 | static const char kAccountIdKey[]; |
Ryan Sultanem | a96d3743 | 2025-01-14 15:35:14 | [diff] [blame] | 308 | static const char kIsGlicEligible[]; |
Daniel Bratell | 15cbb31 | 2018-02-05 18:01:59 | [diff] [blame] | 309 | |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 310 | private: |
Alex Ilin | 6fd88369 | 2021-06-23 14:38:30 | [diff] [blame] | 311 | friend class ProfileAttributesStorage; |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 312 | FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest, |
| 313 | EntryInternalAccessors); |
WC Leung | 1775638 | 2017-08-25 04:57:36 | [diff] [blame] | 314 | FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest, ProfileActiveTime); |
WC Leung | 484920e | 2017-10-03 00:24:18 | [diff] [blame] | 315 | FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest, |
| 316 | DownloadHighResAvatarTest); |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 317 | |
Alex Ilin | 95d596d | 2021-04-12 10:32:58 | [diff] [blame] | 318 | // Initializes the current entry instance. The callers must subsequently call |
| 319 | // InitializeLastNameToDisplay() for this entry. |
Alex Ilin | bb08a0d | 2021-07-08 09:37:24 | [diff] [blame] | 320 | void Initialize(ProfileAttributesStorage* storage, |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 321 | const base::FilePath& path, |
| 322 | PrefService* prefs); |
| 323 | |
Alex Ilin | 95d596d | 2021-04-12 10:32:58 | [diff] [blame] | 324 | // Sets the initial name of the profile to be displayed. The name might depend |
| 325 | // on other's profiles names so this must be called only after all profiles |
| 326 | // has been initialized. |
| 327 | void InitializeLastNameToDisplay(); |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 328 | std::u16string GetLastNameToDisplay() const; |
Monica Basta | 36cb265 | 2019-10-23 11:17:44 | [diff] [blame] | 329 | |
| 330 | // Returns true if: |
| 331 | // - The user has chosen a local profile name on purpose. One exception where |
| 332 | // we don't show the local profile name, is when it is equal to the |
| 333 | // GAIA name. |
| 334 | // - If two profiles have the same GAIA name and we need to show the local |
| 335 | // profile name to clear ambiguity. |
| 336 | bool ShouldShowProfileLocalName( |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 337 | const std::u16string& gaia_name_to_display) const; |
Monica Basta | bafd44c2 | 2019-10-10 10:14:54 | [diff] [blame] | 338 | |
Alex Ilin | 17c0720 | 2021-06-21 11:40:31 | [diff] [blame] | 339 | // Returns true if the current GAIA picture should be updated with an image |
| 340 | // having provided parameters. `image_is_empty` is true when attempting to |
| 341 | // clear the current GAIA picture. |
| 342 | bool ShouldUpdateGAIAPicture(const std::string& image_url_with_size, |
| 343 | bool image_is_empty) const; |
| 344 | |
WC Leung | 484920e | 2017-10-03 00:24:18 | [diff] [blame] | 345 | // Loads or uses an already loaded high resolution image of the generic |
| 346 | // profile avatar. |
| 347 | const gfx::Image* GetHighResAvatar() const; |
| 348 | |
Alex Ilin | a67b047 | 2020-08-06 12:11:10 | [diff] [blame] | 349 | // Generates the colored placeholder avatar icon for the given |size|. |
Amelie Schneider | 80c2f0b0 | 2024-07-09 08:00:33 | [diff] [blame] | 350 | gfx::Image GetPlaceholderAvatarIcon( |
| 351 | int size, |
| 352 | const profiles::PlaceholderAvatarIconParams& icon_params) const; |
Alex Ilin | a67b047 | 2020-08-06 12:11:10 | [diff] [blame] | 353 | |
Jan Krcal | 8fb12cf | 2020-04-01 21:31:42 | [diff] [blame] | 354 | // Returns if this profile has accounts (signed-in or signed-out) with |
| 355 | // different account names. This is approximate as only a short hash of an |
| 356 | // account name is stored so there can be false negatives. |
| 357 | bool HasMultipleAccountNames() const; |
Jan Krcal | 8fb12cf | 2020-04-01 21:31:42 | [diff] [blame] | 358 | |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 359 | // Loads and saves the data to the local state. |
Roland Bock | 2cf65ce | 2022-08-18 13:23:45 | [diff] [blame] | 360 | const base::Value::Dict* GetEntryData() const; |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 361 | |
| 362 | // Internal getter that returns a base::Value*, or nullptr if the key is not |
| 363 | // present. |
| 364 | const base::Value* GetValue(const char* key) const; |
| 365 | |
| 366 | // Internal getters that return basic data types. If the key is not present, |
Thomas Tangl | c67ace4 | 2019-06-07 19:31:50 | [diff] [blame] | 367 | // or if the data is in a wrong data type, return empty string, 0.0, false or |
| 368 | // -1 depending on the target data type. We do not assume that the data type |
| 369 | // is correct because the local state file can be modified by a third party. |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 370 | std::string GetString(const char* key) const; |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 371 | std::u16string GetString16(const char* key) const; |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 372 | double GetDouble(const char* key) const; |
| 373 | bool GetBool(const char* key) const; |
Thomas Tangl | c67ace4 | 2019-06-07 19:31:50 | [diff] [blame] | 374 | int GetInteger(const char* key) const; |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 375 | |
Alex Ilin | 1020018 | 2020-07-29 14:19:37 | [diff] [blame] | 376 | // Internal getter that returns one of the profile theme colors or |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 377 | // std::nullopt if the key is not present. |
| 378 | std::optional<SkColor> GetProfileThemeColor(const char* key) const; |
Alex Ilin | 1020018 | 2020-07-29 14:19:37 | [diff] [blame] | 379 | |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 380 | // Type checking. Only IsDouble is implemented because others do not have |
| 381 | // callsites. |
| 382 | bool IsDouble(const char* key) const; |
| 383 | |
| 384 | // Internal setters that accept basic data types. Return if the original data |
| 385 | // is different from the new data, i.e. whether actual update is done. |
Gabriel Oliveira | 936cbb4 | 2022-06-02 16:07:23 | [diff] [blame] | 386 | // If the data was missing or was from a different type and `value` is the |
| 387 | // default value (e.g. false, 0, empty string...), the value is explicitly |
| 388 | // written but these return false. |
David Roger | bd5eb37 | 2021-07-29 14:08:04 | [diff] [blame] | 389 | bool SetString(const char* key, const std::string& value); |
| 390 | bool SetString16(const char* key, const std::u16string& value); |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 391 | bool SetDouble(const char* key, double value); |
| 392 | bool SetBool(const char* key, bool value); |
Thomas Tangl | c67ace4 | 2019-06-07 19:31:50 | [diff] [blame] | 393 | bool SetInteger(const char* key, int value); |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 394 | |
David Roger | bd5eb37 | 2021-07-29 14:08:04 | [diff] [blame] | 395 | // Generic setter, used to implement the more specific ones. If the value was |
| 396 | // missing and `value` is the default value (e.g. false, 0, empty string...), |
| 397 | // the value is written and this returns true. |
| 398 | bool SetValue(const char* key, base::Value value); |
| 399 | |
Jan Krcal | 8fb12cf | 2020-04-01 21:31:42 | [diff] [blame] | 400 | // Clears value stored for |key|. Returns if the original data is different |
| 401 | // from the new data, i.e. whether actual update is done. |
| 402 | bool ClearValue(const char* key); |
| 403 | |
Alex Ilin | 2f32b58 | 2021-02-08 21:45:55 | [diff] [blame] | 404 | // Migrate/cleanup deprecated keys in profile attributes. Over time, long |
| 405 | // deprecated keys should be removed as new ones are added, but this call |
| 406 | // should never go away (even if it becomes an empty call for some time) as it |
| 407 | // should remain *the* place to drop deprecated profile attributes keys at. |
| 408 | void MigrateObsoleteProfileAttributes(); |
| 409 | |
Alex Ilin | 2f4c4d3 | 2021-04-29 15:15:28 | [diff] [blame] | 410 | // Internal version of `SetIsOmitted()` that doesn't trigger any |
| 411 | // notifications. |
| 412 | void SetIsOmittedInternal(bool is_omitted); |
| 413 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 414 | raw_ptr<ProfileAttributesStorage> profile_attributes_storage_ = nullptr; |
| 415 | raw_ptr<PrefService> prefs_ = nullptr; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 416 | base::FilePath profile_path_; |
WC Leung | 9fd803f | 2017-08-23 08:27:13 | [diff] [blame] | 417 | std::string storage_key_; |
Jan Wilken Dörrie | dec9912 | 2021-03-11 18:02:30 | [diff] [blame] | 418 | std::u16string last_name_to_display_; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 419 | |
Alex Ilin | 310e38d | 2021-01-21 16:36:51 | [diff] [blame] | 420 | // Indicates whether the profile should not be displayed to the user in the |
| 421 | // list of profiles. This flag is intended to work only with ephemeral |
| 422 | // profiles which get removed after the browser restart. Thus, this flag is |
| 423 | // stored in memory only. Storing in memory also allows to avoid the risk of |
| 424 | // having permanent profiles that the user cannot see or delete, in case the |
| 425 | // ephemeral profile deletion fails. |
| 426 | bool is_omitted_ = false; |
anthonyvd | b50a7cb | 2015-07-13 15:42:03 | [diff] [blame] | 427 | }; |
| 428 | |
| 429 | #endif // CHROME_BROWSER_PROFILES_PROFILE_ATTRIBUTES_ENTRY_H_ |