blob: 27a76eb3b95901b3c2696d00ec9d93bcc8ddd1b6 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2015 The Chromium Authors
anthonyvdb50a7cb2015-07-13 15:42:032// 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
avib896c712015-12-26 02:10:438#include <stddef.h>
9
WC Leung9fd803f2017-08-23 08:27:1310#include <memory>
Arthur Sonzognife132ee2024-01-15 11:01:0411#include <optional>
anthonyvdb50a7cb2015-07-13 15:42:0312#include <string>
13
David Rogerf90eb302021-07-30 08:02:5314#include "base/containers/flat_set.h"
Monica Basta2288a0e32019-09-26 13:29:3215#include "base/feature_list.h"
anthonyvdb50a7cb2015-07-13 15:42:0316#include "base/files/file_path.h"
WC Leung9fd803f2017-08-23 08:27:1317#include "base/gtest_prod_util.h"
Keishi Hattori0e45c022021-11-27 09:25:5218#include "base/memory/raw_ptr.h"
anthonyvdb50a7cb2015-07-13 15:42:0319#include "base/time/time.h"
WC Leung9fd803f2017-08-23 08:27:1320#include "base/values.h"
Amelie Schneider80c2f0b02024-07-09 08:00:3321#include "chrome/browser/profiles/profile_avatar_icon_util.h"
Mikel Astizbee274d2024-12-16 19:54:3122#include "google_apis/gaia/gaia_id.h"
Alex Ilin10200182020-07-29 14:19:3723#include "third_party/skia/include/core/SkColor.h"
Alex Ilina67b0472020-08-06 12:11:1024#include "ui/gfx/image/image.h"
anthonyvdb50a7cb2015-07-13 15:42:0325
Thomas Tanglc67ace42019-06-07 19:31:5026class PrefRegistrySimple;
WC Leung9fd803f2017-08-23 08:27:1327class PrefService;
Alex Ilinbb08a0d2021-07-08 09:37:2428class ProfileAttributesStorage;
Jan Krcal5fa5da82020-11-11 16:10:5729struct ProfileThemeColors;
anthonyvdb50a7cb2015-07-13 15:42:0330
Amelie Schneider7b036dd2024-07-15 11:08:4831inline constexpr int kDefaultSizeForPlaceholderAvatar = 74;
32
Monica Basta9ca47042019-09-16 17:36:5133enum class SigninState {
34 kNotSignedIn,
35 kSignedInWithUnconsentedPrimaryAccount,
36 kSignedInWithConsentedPrimaryAccount,
37};
38
David Rogere582c4452020-03-18 20:45:3839enum class NameForm {
40 kGaiaName,
41 kLocalName,
42 kGaiaAndLocalName,
43};
44
Zonghan Xu9f1191d2024-12-02 18:33:1645// 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.
hmareb63e5a1c52024-07-22 07:51:4550struct ProfileManagementOidcTokens {
51 ProfileManagementOidcTokens();
52 ProfileManagementOidcTokens(const std::string& auth_token,
hmare6191d19d2024-07-17 21:20:4553 const std::string& id_token,
54 const std::u16string& identity_name);
hmareb63e5a1c52024-07-22 07:51:4555 ProfileManagementOidcTokens(const std::string& auth_token,
hmare6191d19d2024-07-17 21:20:4556 const std::string& id_token,
57 const std::string& state);
Zonghan Xu9f1191d2024-12-02 18:33:1658 // This will be the new format of the `ProfileManagementOidcTokens` struct,
59 // after we fully migrate.
60 explicit ProfileManagementOidcTokens(const std::string& encrypted_user_info);
hmare6191d19d2024-07-17 21:20:4561
hmareb63e5a1c52024-07-22 07:51:4562 ProfileManagementOidcTokens(const ProfileManagementOidcTokens& other);
63 ProfileManagementOidcTokens& operator=(
64 const ProfileManagementOidcTokens& other);
hmare6191d19d2024-07-17 21:20:4565
hmareb63e5a1c52024-07-22 07:51:4566 ProfileManagementOidcTokens(ProfileManagementOidcTokens&& other);
67 ProfileManagementOidcTokens& operator=(ProfileManagementOidcTokens&& other);
68 ~ProfileManagementOidcTokens();
hmare6191d19d2024-07-17 21:20:4569
70 // Authorization token from the authorization response.
Zonghan Xub03bc372024-01-30 22:11:4871 std::string auth_token;
hmare6191d19d2024-07-17 21:20:4572
Zonghan Xu9f1191d2024-12-02 18:33:1673 // 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 Xub03bc372024-01-30 22:11:4875 std::string id_token;
hmare6191d19d2024-07-17 21:20:4576
77 // Identity name of the profile. This is only relevant after the completion of
78 // profile registration.
Zonghan Xu4b014d992024-07-09 17:23:3379 std::u16string identity_name;
Zonghan Xue1b11db2024-03-06 18:17:5780
hmare6191d19d2024-07-17 21:20:4581 // OIDC configuration state. This is only relevant during profile
82 // registration.
83 std::string state;
Zonghan Xu9f1191d2024-12-02 18:33:1684
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 Xub03bc372024-01-30 22:11:4888};
89
anthonyvdb50a7cb2015-07-13 15:42:0390class ProfileAttributesEntry {
91 public:
Thomas Tanglc67ace42019-06-07 19:31:5092 static void RegisterLocalStatePrefs(PrefRegistrySimple* registry);
93
anthonyvdb50a7cb2015-07-13 15:42:0394 ProfileAttributesEntry();
David Bienvenu1e9f6a72020-08-20 01:05:4895 ProfileAttributesEntry(const ProfileAttributesEntry&) = delete;
96 ProfileAttributesEntry& operator=(const ProfileAttributesEntry&) = delete;
97 virtual ~ProfileAttributesEntry() = default;
anthonyvdb50a7cb2015-07-13 15:42:0398
Monica Bastabafd44c22019-10-10 10:14:5499 // 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örriedec99122021-03-11 18:02:30101 std::u16string GetName() const;
Monica Basta6655884a2019-10-29 10:38:39102 // Returns |GetGAIAGivenName()| if not empty. Otherwise, returns
103 // |GetGAIAName()|.
Jan Wilken Dörriedec99122021-03-11 18:02:30104 std::u16string GetGAIANameToDisplay() const;
Monica Basta36cb2652019-10-23 11:17:44105 // Returns true if the profile name has changed.
106 bool HasProfileNameChanged();
David Rogere582c4452020-03-18 20:45:38107 // Returns how the value of GetName() gets constructed.
108 NameForm GetNameForm() const;
Monica Basta36cb2652019-10-23 11:17:44109
Monica Bastabafd44c22019-10-10 10:14:54110 // Gets the local profile name.
Jan Wilken Dörriedec99122021-03-11 18:02:30111 std::u16string GetLocalProfileName() const;
anthonyvdb50a7cb2015-07-13 15:42:03112
Salma Elmahallawy67c2cca02025-01-24 20:02:18113 // 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örriedec99122021-03-11 18:02:30117 std::u16string GetShortcutName() const;
anthonyvdb50a7cb2015-07-13 15:42:03118 // 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örriedec99122021-03-11 18:02:30125 std::u16string GetUserName() const;
Jan Krcala4cd6bc2020-11-06 17:14:13126 // 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 Gale3f4203f72024-04-26 19:27:42129 // TODO(crbug.com/40138086): Rename |size_for_placeholder_avatar| to |size|
130 // and make this function resize all avatars appropriately. Remove the default
Alex Ilina67b0472020-08-06 12:11:10131 // 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 Schneider80c2f0b02024-07-09 08:00:33134 gfx::Image GetAvatarIcon(
Amelie Schneider7b036dd2024-07-15 11:08:48135 int size_for_placeholder_avatar = kDefaultSizeForPlaceholderAvatar,
Amelie Schneider80c2f0b02024-07-09 08:00:33136 bool use_high_res_file = true,
137 const profiles::PlaceholderAvatarIconParams& icon_params = {}) const;
WC Leung17756382017-08-25 04:57:36138 // 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).
anthonyvdb50a7cb2015-07-13 15:42:03142 bool GetBackgroundStatus() const;
143 // Gets the GAIA full name associated with this profile if it's signed in.
Zonghan Xu4b014d992024-07-09 17:23:33144 // 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örriedec99122021-03-11 18:02:30146 std::u16string GetGAIAName() const;
anthonyvdb50a7cb2015-07-13 15:42:03147 // Gets the GAIA given name associated with this profile if it's signed in.
Jan Wilken Dörriedec99122021-03-11 18:02:30148 std::u16string GetGAIAGivenName() const;
anthonyvdb50a7cb2015-07-13 15:42:03149 // Gets the opaque string representation of the profile's GAIA ID if it's
150 // signed in.
Mikel Astizbee274d2024-12-16 19:54:31151 GaiaId GetGAIAId() const;
anthonyvdb50a7cb2015-07-13 15:42:03152 // 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 Cheng1b761382017-08-15 20:37:34159 // Returns true if a GAIA picture has been loaded or has failed to load.
160 bool IsGAIAPictureLoaded() const;
Alex Ilin9c5d041f2021-06-17 07:36:30161 // Returns the last downloaded GAIA picture URL with size.
162 std::string GetLastDownloadedGAIAPictureUrlWithSize() const;
WC Leung9fd803f2017-08-23 08:27:13163 // Returns true if the profile is signed in as a supervised user.
anthonyvdb50a7cb2015-07-13 15:42:03164 bool IsSupervised() const;
Alex Ilin310e38d2021-01-21 16:36:51165 // Returns true if the profile should not be displayed to the user in the
166 // list of profiles.
anthonyvdb50a7cb2015-07-13 15:42:03167 bool IsOmitted() const;
Alex Ilin4554c992021-06-10 08:17:47168 // 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.
anthonyvdb50a7cb2015-07-13 15:42:03171 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 Basta9ca47042019-09-16 17:36:51180 // Returns Signin state.
181 SigninState GetSigninState() const;
anthonyvdb50a7cb2015-07-13 15:42:03182 // Returns true if the profile is signed in.
183 bool IsAuthenticated() const;
Yann Dagoe73f9332021-08-12 18:54:55184 // Returns true if the account can be be managed.
185 bool CanBeManaged() const;
anthonyvdb50a7cb2015-07-13 15:42:03186 // 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 Sengul202917b2020-04-03 21:36:17189 // Indicates that profile was signed in through native OS credential provider.
190 bool IsSignedInWithCredentialProvider() const;
Zonghan Xub386dff2024-02-08 16:06:43191 // 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;
anthonyvdb50a7cb2015-07-13 15:42:03194 // Returns the index of the default icon used by the profile.
195 size_t GetAvatarIconIndex() const;
Alex Ilin9c5736042020-08-03 13:52:13196 // 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 Krcal920f460c2020-11-13 22:33:22199 // Returns the colors specified by the profile theme, or empty if no theme is
200 // set for the profile.
Arthur Sonzognife132ee2024-01-15 11:01:04201 std::optional<ProfileThemeColors> GetProfileThemeColorsIfSet() const;
Thomas Tanglc67ace42019-06-07 19:31:50202 // 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 Krcal8fb12cf2020-04-01 21:31:42206 // Returns the hosted domain for the current signed-in account. Returns empty
Tanmoy Mollik469985a2024-12-05 09:38:24207 // 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 Krcal8fb12cf2020-04-01 21:31:42211 std::string GetHostedDomain() const;
Yann Dago2fa00f8e2023-03-20 16:40:36212
213 // Returns the enrollment token to get policies for a profile.
214 std::string GetProfileManagementEnrollmentToken() const;
215
Zonghan Xub03bc372024-01-30 22:11:48216 // 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.
hmareb63e5a1c52024-07-22 07:51:45219 ProfileManagementOidcTokens GetProfileManagementOidcTokens() const;
Zonghan Xub03bc372024-01-30 22:11:48220
Yann Dago2fa00f8e2023-03-20 16:40:36221 // 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 Ilind5cc7772021-06-30 12:14:53225 // 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;
anthonyvdb50a7cb2015-07-13 15:42:03228
Ryan Sultanema96d37432025-01-14 15:35:14229 // 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 Rogerf90eb302021-07-30 08:02:53233 // Gets/Sets the gaia IDs of the accounts signed into the profile (accounts
234 // known by the `IdentityManager`).
Mikel Astiza7d9d662025-02-04 11:22:12235 base::flat_set<GaiaId> GetGaiaIds() const;
236 void SetGaiaIds(const base::flat_set<GaiaId>& gaia_ids);
David Rogerf90eb302021-07-30 08:02:53237
Monica Bastaa948f952021-01-14 17:31:11238 // |is_using_default| should be set to false for non default profile names.
Jan Wilken Dörriedec99122021-03-11 18:02:30239 void SetLocalProfileName(const std::u16string& name, bool is_default_name);
Salma Elmahallawy67c2cca02025-01-24 20:02:18240 void SetEnterpriseProfileLabel(const std::u16string& name);
Jan Wilken Dörriedec99122021-03-11 18:02:30241 void SetShortcutName(const std::u16string& name);
lwchkg498e92492016-04-23 11:04:12242 void SetActiveTimeToNow();
Jan Krcalac72ebcf2021-03-15 08:41:26243 // Only ephemeral profiles can be set as omitted.
anthonyvdb50a7cb2015-07-13 15:42:03244 void SetIsOmitted(bool is_omitted);
245 void SetSupervisedUserId(const std::string& id);
anthonyvdb50a7cb2015-07-13 15:42:03246 void SetBackgroundStatus(bool running_background_apps);
Jan Wilken Dörriedec99122021-03-11 18:02:30247 void SetGAIAName(const std::u16string& name);
248 void SetGAIAGivenName(const std::u16string& name);
Monica Bastaff6a35972020-02-14 19:16:04249 void SetGAIAPicture(const std::string& image_url_with_size, gfx::Image image);
anthonyvdb50a7cb2015-07-13 15:42:03250 void SetIsUsingGAIAPicture(bool value);
Alex Ilin9c5d041f2021-06-17 07:36:30251 void SetLastDownloadedGAIAPictureUrlWithSize(
252 const std::string& image_url_with_size);
Yusuf Sengul202917b2020-04-03 21:36:17253 void SetSignedInWithCredentialProvider(bool value);
Zonghan Xub386dff2024-02-08 16:06:43254 void SetDasherlessManagement(bool value);
Jan Krcalac72ebcf2021-03-15 08:41:26255 // 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.
anthonyvdb50a7cb2015-07-13 15:42:03258 void SetIsEphemeral(bool value);
Yann Dagoe73f9332021-08-12 18:54:55259 void SetUserAcceptedAccountManagement(bool value);
260 bool UserAcceptedAccountManagement() const;
anthonyvdb50a7cb2015-07-13 15:42:03261 void SetIsUsingDefaultAvatar(bool value);
anthonyvdb50a7cb2015-07-13 15:42:03262 void SetAvatarIconIndex(size_t icon_index);
Arthur Sonzognife132ee2024-01-15 11:01:04263 // std::nullopt resets colors to default.
264 void SetProfileThemeColors(const std::optional<ProfileThemeColors>& colors);
anthonyvdb50a7cb2015-07-13 15:42:03265
Jan Krcal8fb12cf2020-04-01 21:31:42266 // Unlike for other string setters, the argument is expected to be UTF8
267 // encoded.
268 void SetHostedDomain(std::string hosted_domain);
269
Yann Dago2fa00f8e2023-03-20 16:40:36270 void SetProfileManagementEnrollmentToken(const std::string& enrollment_token);
Zonghan Xub03bc372024-01-30 22:11:48271 void SetProfileManagementOidcTokens(
hmareb63e5a1c52024-07-22 07:51:45272 const ProfileManagementOidcTokens& oidc_tokens);
Yann Dago2fa00f8e2023-03-20 16:40:36273 void SetProfileManagementId(const std::string& id);
274
Mikel Astizbee274d2024-12-16 19:54:31275 void SetAuthInfo(const GaiaId& gaia_id,
Jan Wilken Dörriedec99122021-03-11 18:02:30276 const std::u16string& user_name,
Monica Basta9ca47042019-09-16 17:36:51277 bool is_consented_primary_account);
anthonyvdb50a7cb2015-07-13 15:42:03278
Ryan Sultanema96d37432025-01-14 15:35:14279 void SetIsGlicEligible(bool value);
280
Jan Krcal8fb12cf2020-04-01 21:31:42281 // 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 Krcal8fb12cf2020-04-01 21:31:42284
285 // Clears info about all accounts that have been added in the past via
David Roger00430762023-03-31 10:20:04286 // AddAccountName().
Jan Krcal8fb12cf2020-04-01 21:31:42287 void ClearAccountNames();
Jan Krcal8fb12cf2020-04-01 21:31:42288
zmin5db87092016-11-08 20:21:35289 // Lock/Unlock the profile, should be called only if force-sign-in is enabled.
290 void LockForceSigninProfile(bool is_lock);
291
David Roger00430762023-03-31 10:20:04292 // Records aggregate metrics about all accounts used in this profile.
293 void RecordAccountNamesMetric() const;
Jan Krcal8fb12cf2020-04-01 21:31:42294
Monica Basta30290562019-11-21 16:24:03295 static const char kSupervisedUserId[];
Daniel Bratell15cbb312018-02-05 18:01:59296 static const char kAvatarIconKey[];
297 static const char kBackgroundAppsKey[];
298 static const char kProfileIsEphemeral[];
299 static const char kUserNameKey[];
Monica Bastad82d88e2019-10-31 11:24:12300 static const char kGAIAIdKey[];
Monica Basta9ca47042019-09-16 17:36:51301 static const char kIsConsentedPrimaryAccountKey[];
Monica Basta7ff9e232019-11-19 15:33:28302 static const char kNameKey[];
Salma Elmahallawy67c2cca02025-01-24 20:02:18303 static const char kEnterpriseLabelKey[];
Monica Basta7ff9e232019-11-19 15:33:28304 static const char kIsUsingDefaultNameKey[];
Alex Ilind4a65952021-06-17 08:26:11305 static const char kIsUsingDefaultAvatarKey[];
Alex Ilin17c07202021-06-21 11:40:31306 static const char kUseGAIAPictureKey[];
Alex Ilind5cc7772021-06-30 12:14:53307 static const char kAccountIdKey[];
Ryan Sultanema96d37432025-01-14 15:35:14308 static const char kIsGlicEligible[];
Daniel Bratell15cbb312018-02-05 18:01:59309
anthonyvdb50a7cb2015-07-13 15:42:03310 private:
Alex Ilin6fd883692021-06-23 14:38:30311 friend class ProfileAttributesStorage;
WC Leung9fd803f2017-08-23 08:27:13312 FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest,
313 EntryInternalAccessors);
WC Leung17756382017-08-25 04:57:36314 FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest, ProfileActiveTime);
WC Leung484920e2017-10-03 00:24:18315 FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest,
316 DownloadHighResAvatarTest);
WC Leung9fd803f2017-08-23 08:27:13317
Alex Ilin95d596d2021-04-12 10:32:58318 // Initializes the current entry instance. The callers must subsequently call
319 // InitializeLastNameToDisplay() for this entry.
Alex Ilinbb08a0d2021-07-08 09:37:24320 void Initialize(ProfileAttributesStorage* storage,
WC Leung9fd803f2017-08-23 08:27:13321 const base::FilePath& path,
322 PrefService* prefs);
323
Alex Ilin95d596d2021-04-12 10:32:58324 // 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örriedec99122021-03-11 18:02:30328 std::u16string GetLastNameToDisplay() const;
Monica Basta36cb2652019-10-23 11:17:44329
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örriedec99122021-03-11 18:02:30337 const std::u16string& gaia_name_to_display) const;
Monica Bastabafd44c22019-10-10 10:14:54338
Alex Ilin17c07202021-06-21 11:40:31339 // 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 Leung484920e2017-10-03 00:24:18345 // Loads or uses an already loaded high resolution image of the generic
346 // profile avatar.
347 const gfx::Image* GetHighResAvatar() const;
348
Alex Ilina67b0472020-08-06 12:11:10349 // Generates the colored placeholder avatar icon for the given |size|.
Amelie Schneider80c2f0b02024-07-09 08:00:33350 gfx::Image GetPlaceholderAvatarIcon(
351 int size,
352 const profiles::PlaceholderAvatarIconParams& icon_params) const;
Alex Ilina67b0472020-08-06 12:11:10353
Jan Krcal8fb12cf2020-04-01 21:31:42354 // 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 Krcal8fb12cf2020-04-01 21:31:42358
WC Leung9fd803f2017-08-23 08:27:13359 // Loads and saves the data to the local state.
Roland Bock2cf65ce2022-08-18 13:23:45360 const base::Value::Dict* GetEntryData() const;
WC Leung9fd803f2017-08-23 08:27:13361
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 Tanglc67ace42019-06-07 19:31:50367 // 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 Leung9fd803f2017-08-23 08:27:13370 std::string GetString(const char* key) const;
Jan Wilken Dörriedec99122021-03-11 18:02:30371 std::u16string GetString16(const char* key) const;
WC Leung9fd803f2017-08-23 08:27:13372 double GetDouble(const char* key) const;
373 bool GetBool(const char* key) const;
Thomas Tanglc67ace42019-06-07 19:31:50374 int GetInteger(const char* key) const;
WC Leung9fd803f2017-08-23 08:27:13375
Alex Ilin10200182020-07-29 14:19:37376 // Internal getter that returns one of the profile theme colors or
Arthur Sonzognife132ee2024-01-15 11:01:04377 // std::nullopt if the key is not present.
378 std::optional<SkColor> GetProfileThemeColor(const char* key) const;
Alex Ilin10200182020-07-29 14:19:37379
WC Leung9fd803f2017-08-23 08:27:13380 // 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 Oliveira936cbb42022-06-02 16:07:23386 // 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 Rogerbd5eb372021-07-29 14:08:04389 bool SetString(const char* key, const std::string& value);
390 bool SetString16(const char* key, const std::u16string& value);
WC Leung9fd803f2017-08-23 08:27:13391 bool SetDouble(const char* key, double value);
392 bool SetBool(const char* key, bool value);
Thomas Tanglc67ace42019-06-07 19:31:50393 bool SetInteger(const char* key, int value);
WC Leung9fd803f2017-08-23 08:27:13394
David Rogerbd5eb372021-07-29 14:08:04395 // 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 Krcal8fb12cf2020-04-01 21:31:42400 // 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 Ilin2f32b582021-02-08 21:45:55404 // 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 Ilin2f4c4d32021-04-29 15:15:28410 // Internal version of `SetIsOmitted()` that doesn't trigger any
411 // notifications.
412 void SetIsOmittedInternal(bool is_omitted);
413
Keishi Hattori0e45c022021-11-27 09:25:52414 raw_ptr<ProfileAttributesStorage> profile_attributes_storage_ = nullptr;
415 raw_ptr<PrefService> prefs_ = nullptr;
anthonyvdb50a7cb2015-07-13 15:42:03416 base::FilePath profile_path_;
WC Leung9fd803f2017-08-23 08:27:13417 std::string storage_key_;
Jan Wilken Dörriedec99122021-03-11 18:02:30418 std::u16string last_name_to_display_;
anthonyvdb50a7cb2015-07-13 15:42:03419
Alex Ilin310e38d2021-01-21 16:36:51420 // 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;
anthonyvdb50a7cb2015-07-13 15:42:03427};
428
429#endif // CHROME_BROWSER_PROFILES_PROFILE_ATTRIBUTES_ENTRY_H_