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