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

Update ProfileInfoCache::GetNumberOfProfiles for ephemeral Guest

Ephemeral Guest profiles are registered in profile attributes storage
because if Chrome crashes we need the registry to find and delete them.
But they should not be counted as a regular profile, so they are removed
from the count when the number of profiles is asked.

This was previously done in ProfileManager, but now moved to
ProfileInfoCache to avoid inconsistency when asked from different
classes.

Bug: 1161494, 1125474
Change-Id: I5fd9f9a262a940dd2e9358daa09f6e714d574669
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2606282Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarMonica Basta <msalama@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841030}
parent 1d98b098
...@@ -717,9 +717,7 @@ void ProfileAttributesEntry::ClearAccountCategories() { ...@@ -717,9 +717,7 @@ void ProfileAttributesEntry::ClearAccountCategories() {
} }
size_t ProfileAttributesEntry::profile_index() const { size_t ProfileAttributesEntry::profile_index() const {
size_t index = profile_info_cache_->GetIndexOfProfileWithPath(profile_path_); return profile_info_cache_->GetIndexOfProfileWithPath(profile_path_);
DCHECK(index < profile_info_cache_->GetNumberOfProfiles());
return index;
} }
const gfx::Image* ProfileAttributesEntry::GetHighResAvatar() const { const gfx::Image* ProfileAttributesEntry::GetHighResAvatar() const {
......
...@@ -84,7 +84,8 @@ class ProfileAttributesStorage ...@@ -84,7 +84,8 @@ class ProfileAttributesStorage
const base::FilePath& path, ProfileAttributesEntry** entry) = 0; const base::FilePath& path, ProfileAttributesEntry** entry) = 0;
// Returns the count of known profiles. // Returns the count of known profiles.
virtual size_t GetNumberOfProfiles() const = 0; virtual size_t GetNumberOfProfiles(
bool include_guest_profile = false) const = 0;
// Returns a unique name that can be assigned to a newly created profile. // Returns a unique name that can be assigned to a newly created profile.
base::string16 ChooseNameForNewProfile(size_t icon_index) const; base::string16 ChooseNameForNewProfile(size_t icon_index) const;
......
...@@ -263,7 +263,19 @@ void ProfileInfoCache::DeleteProfileFromCache( ...@@ -263,7 +263,19 @@ void ProfileInfoCache::DeleteProfileFromCache(
} }
} }
size_t ProfileInfoCache::GetNumberOfProfiles() const { size_t ProfileInfoCache::GetNumberOfProfiles(bool include_guest_profile) const {
// Ephemeral Guest profile is registered in profile attributes storage,
// because if Chrome crashes we need the registry to find and delete it.
// But it should not be counted as a regular profile.
#if !defined(OS_ANDROID)
if (!include_guest_profile) {
for (auto& profile : profile_attributes_entries_) {
if (profile.second && profile.second->IsGuest())
return keys_.size() - 1;
}
}
#endif
return keys_.size(); return keys_.size();
} }
...@@ -508,7 +520,7 @@ void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { ...@@ -508,7 +520,7 @@ void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) {
const base::DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex( const base::DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex(
size_t index) const { size_t index) const {
DCHECK_LT(index, GetNumberOfProfiles()); DCHECK_LT(index, GetNumberOfProfiles(true));
const base::DictionaryValue* cache = const base::DictionaryValue* cache =
prefs_->GetDictionary(prefs::kProfileInfoCache); prefs_->GetDictionary(prefs::kProfileInfoCache);
const base::DictionaryValue* info = nullptr; const base::DictionaryValue* info = nullptr;
...@@ -628,7 +640,7 @@ void ProfileInfoCache::AddProfile(const base::FilePath& profile_path, ...@@ -628,7 +640,7 @@ void ProfileInfoCache::AddProfile(const base::FilePath& profile_path,
} }
void ProfileInfoCache::RemoveProfileByAccountId(const AccountId& account_id) { void ProfileInfoCache::RemoveProfileByAccountId(const AccountId& account_id) {
for (size_t i = 0; i < GetNumberOfProfiles(); i++) { for (size_t i = 0; i < GetNumberOfProfiles(true); i++) {
std::string account_id_key; std::string account_id_key;
std::string gaia_id; std::string gaia_id;
std::string user_name; std::string user_name;
......
...@@ -70,7 +70,7 @@ class ProfileInfoCache : public ProfileInfoInterface, ...@@ -70,7 +70,7 @@ class ProfileInfoCache : public ProfileInfoInterface,
void DeleteProfileFromCache(const base::FilePath& profile_path); void DeleteProfileFromCache(const base::FilePath& profile_path);
// ProfileInfoInterface: // ProfileInfoInterface:
size_t GetNumberOfProfiles() const override; size_t GetNumberOfProfiles(bool include_guest_profile = false) const override;
// Don't cache this value and reuse, because resorting the menu could cause // Don't cache this value and reuse, because resorting the menu could cause
// the item being referred to to change out from under you. // the item being referred to to change out from under you.
// Deprecated. Prefer using the ProfileAttributesStorage interface instead of // Deprecated. Prefer using the ProfileAttributesStorage interface instead of
......
...@@ -21,7 +21,8 @@ class Image; ...@@ -21,7 +21,8 @@ class Image;
// ProfileAttributesStorage and avoid using the Get*AtIndex family of functions. // ProfileAttributesStorage and avoid using the Get*AtIndex family of functions.
class ProfileInfoInterface { class ProfileInfoInterface {
public: public:
virtual size_t GetNumberOfProfiles() const = 0; virtual size_t GetNumberOfProfiles(
bool include_guest_profile = false) const = 0;
virtual size_t GetIndexOfProfileWithPath( virtual size_t GetIndexOfProfileWithPath(
const base::FilePath& profile_path) const = 0; const base::FilePath& profile_path) const = 0;
......
...@@ -524,18 +524,8 @@ Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) { ...@@ -524,18 +524,8 @@ Profile* ProfileManager::GetProfile(const base::FilePath& profile_dir) {
} }
size_t ProfileManager::GetNumberOfProfiles() { size_t ProfileManager::GetNumberOfProfiles() {
ProfileAttributesStorage& storage = GetProfileAttributesStorage(); return GetProfileAttributesStorage().GetNumberOfProfiles(
int offset = 0; /*include_guest_profile=*/false);
// Ephemeral Guest profile is registered in profile attributes storage,
// because if Chrome crashes we need the registry to find and delete it.
// But it should not be counted as a regular profile.
if (!guest_profile_path_.empty()) {
ProfileAttributesEntry* entry;
if (storage.GetProfileAttributesWithPath(guest_profile_path_, &entry))
offset = 1;
}
return storage.GetNumberOfProfiles() - offset;
} }
bool ProfileManager::LoadProfile(const std::string& profile_name, bool ProfileManager::LoadProfile(const std::string& profile_name,
......
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