Commit 2c2fdc7c authored by Ramin Halavati's avatar Ramin Halavati Committed by Chromium LUCI CQ

Update GetAllProfilesAttributes to exclude Guest profiles.

ProfileAttributesStorage::GetAllProfilesAttributes is updated to exclude
Guest profile unless it is explicitly requested by the caller.

Bug: 1161494, 1125474
Change-Id: I1f006d6fb8c58bb23099d111d83da0f84c2ec2ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2621299Reviewed-by: default avatarMonica Basta <msalama@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842451}
parent 8d26cade
......@@ -76,12 +76,10 @@ void BrowserReportGeneratorDesktop::GenerateProfileInfo(
base::flat_set<base::FilePath> extension_request_profile_paths =
throttler->GetProfiles();
for (const auto* entry : g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetAllProfilesAttributes()) {
// Exclude Guest profiles.
if (entry->IsGuest())
continue;
for (const auto* entry :
g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetAllProfilesAttributes(/*include_guest_profile=*/false)) {
#if BUILDFLAG(IS_CHROMEOS_ASH)
// Skip sign-in and lock screen app profile on Chrome OS.
if (!chromeos::ProfileHelper::IsRegularProfilePath(
......
......@@ -245,7 +245,7 @@ ProfileAttributesStorage::~ProfileAttributesStorage() {
}
std::vector<ProfileAttributesEntry*>
ProfileAttributesStorage::GetAllProfilesAttributes() {
ProfileAttributesStorage::GetAllProfilesAttributes(bool include_guest_profile) {
std::vector<ProfileAttributesEntry*> ret;
for (const auto& path_and_entry : profile_attributes_entries_) {
ProfileAttributesEntry* entry;
......@@ -253,7 +253,8 @@ ProfileAttributesStorage::GetAllProfilesAttributes() {
bool success = GetProfileAttributesWithPath(
base::FilePath(path_and_entry.first), &entry);
DCHECK(success);
ret.push_back(entry);
if (!entry->IsGuest() || include_guest_profile)
ret.push_back(entry);
}
return ret;
}
......@@ -261,7 +262,8 @@ ProfileAttributesStorage::GetAllProfilesAttributes() {
std::vector<ProfileAttributesEntry*>
ProfileAttributesStorage::GetAllProfilesAttributesSorted(
bool use_local_profile_name) {
std::vector<ProfileAttributesEntry*> ret = GetAllProfilesAttributes();
std::vector<ProfileAttributesEntry*> ret =
GetAllProfilesAttributes(/*include_guest_profile=*/false);
// Do not allocate the collator and sort if it is not necessary.
if (ret.size() < 2)
return ret;
......@@ -317,7 +319,8 @@ base::string16 ProfileAttributesStorage::ChooseNameForNewProfile(
// Loop through previously named profiles to ensure we're not duplicating.
std::vector<ProfileAttributesEntry*> entries =
const_cast<ProfileAttributesStorage*>(this)->GetAllProfilesAttributes();
const_cast<ProfileAttributesStorage*>(this)->GetAllProfilesAttributes(
/*include_guest_profile=*/false);
if (std::none_of(entries.begin(), entries.end(),
[name](ProfileAttributesEntry* entry) {
......@@ -364,7 +367,8 @@ size_t ProfileAttributesStorage::ChooseAvatarIconIndexForNewProfile() const {
std::unordered_set<size_t> used_icon_indices;
std::vector<ProfileAttributesEntry*> entries =
const_cast<ProfileAttributesStorage*>(this)->GetAllProfilesAttributes();
const_cast<ProfileAttributesStorage*>(this)->GetAllProfilesAttributes(
/*include_guest_profile=*/false);
for (const ProfileAttributesEntry* entry : entries)
used_icon_indices.insert(entry->GetAvatarIconIndex());
......@@ -423,15 +427,14 @@ void ProfileAttributesStorage::RecordDeletedProfileState(
#endif
void ProfileAttributesStorage::RecordProfilesState() {
std::vector<ProfileAttributesEntry*> entries = GetAllProfilesAttributes();
std::vector<ProfileAttributesEntry*> entries =
GetAllProfilesAttributes(/*include_guest_profile=*/false);
if (entries.size() == 0)
return;
MultiProfileUserType type = GetMultiProfileUserType(entries);
for (ProfileAttributesEntry* entry : entries) {
if (entry->IsGuest())
continue;
RecordProfileState(entry, profile_metrics::StateSuffix::kAll);
switch (type) {
......
......@@ -69,9 +69,13 @@ class ProfileAttributesStorage
// Returns a vector containing one attributes entry per known profile. They
// are not sorted in any particular order.
std::vector<ProfileAttributesEntry*> GetAllProfilesAttributes();
std::vector<ProfileAttributesEntry*> GetAllProfilesAttributes(
bool include_guest_profile = false);
// Returns all non-Guest profile attributes sorted by name.
std::vector<ProfileAttributesEntry*> GetAllProfilesAttributesSortedByName();
// Returns all non-Guest profile attributes sorted by local profile name.
std::vector<ProfileAttributesEntry*>
GetAllProfilesAttributesSortedByLocalProfilName();
......
......@@ -71,13 +71,13 @@ bool ProfilePicker::ShouldShowAtLaunch() {
return false;
std::vector<ProfileAttributesEntry*> profile_attributes =
profile_manager->GetProfileAttributesStorage().GetAllProfilesAttributes();
profile_manager->GetProfileAttributesStorage().GetAllProfilesAttributes(
/*include_guest_profile=*/false);
int number_of_active_profiles =
std::count_if(profile_attributes.begin(), profile_attributes.end(),
[](ProfileAttributesEntry* entry) {
return (base::Time::Now() - entry->GetActiveTime() <
kActiveTimeThreshold) &&
!entry->IsGuest();
kActiveTimeThreshold);
});
// Don't show the profile picker at launch if the user has less than two
// active profiles. However, if the user has already seen the profile picker
......
......@@ -695,11 +695,9 @@ void ProfileMenuView::BuildSelectableProfiles() {
->GetProfileAttributesStorage()
.GetAllProfilesAttributesSortedByName();
for (ProfileAttributesEntry* profile_entry : profile_entries) {
// Guest profile and the current profile are excluded.
if (profile_entry->IsGuest() ||
profile_entry->GetPath() == browser()->profile()->GetPath()) {
// The current profile is excluded.
if (profile_entry->GetPath() == browser()->profile()->GetPath())
continue;
}
AddSelectableProfile(
ui::ImageModel::FromImage(
......
......@@ -637,9 +637,6 @@ ProfilePickerHandler::GetProfileAttributes() {
// Vector of nullptr entries.
std::vector<ProfileAttributesEntry*> entries(number_of_profiles);
for (ProfileAttributesEntry* entry : ordered_entries) {
if (entry->IsGuest())
continue;
DCHECK(profiles_order_.find(entry->GetPath()) != profiles_order_.end());
size_t index = profiles_order_[entry->GetPath()];
DCHECK_LT(index, number_of_profiles);
......@@ -655,8 +652,6 @@ base::Value ProfilePickerHandler::GetProfilesList() {
const int avatar_icon_size =
kProfileCardAvatarSize * web_ui()->GetDeviceScaleFactor();
for (const ProfileAttributesEntry* entry : entries) {
if (entry->IsGuest())
continue;
auto profile_entry = std::make_unique<base::DictionaryValue>();
profile_entry->SetKey("profilePath",
util::FilePathToValue(entry->GetPath()));
......
......@@ -91,7 +91,7 @@ class ProfilePickerHandler : public content::WebUIMessageHandler,
void SetProfilesOrder(const std::vector<ProfileAttributesEntry*>& entries);
// Returns the list of profiles in the same order as when the picker
// was first shown.
// was first shown. Guest profile is not included here.
std::vector<ProfileAttributesEntry*> GetProfileAttributes();
// Creation time of the handler, to measure performance on startup. Only set
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment