Commit d566dd99 authored by Daniel Classon's avatar Daniel Classon Committed by Commit Bot

[OsPeoplePage] Fix "Remove fingerprint" search tag when no prints

Fix the behavior of the "Remove fingerprint" search tag so that it
dynamically changes based on the number of registered fingerprints.

Bug: 1116553
Change-Id: Ifd109dbf6757bede7b079eb7a31d7db3b45b27b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424507
Commit-Queue: Daniel Classon <dclasson@google.com>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809557}
parent ffe3ef4f
...@@ -264,12 +264,6 @@ const std::vector<SearchConcept>& GetKerberosSearchConcepts() { ...@@ -264,12 +264,6 @@ const std::vector<SearchConcept>& GetKerberosSearchConcepts() {
const std::vector<SearchConcept>& GetFingerprintSearchConcepts() { const std::vector<SearchConcept>& GetFingerprintSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({ static const base::NoDestructor<std::vector<SearchConcept>> tags({
{IDS_OS_SETTINGS_TAG_FINGERPRINT_REMOVE,
mojom::kFingerprintSubpagePath,
mojom::SearchResultIcon::kFingerprint,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSetting,
{.setting = mojom::Setting::kRemoveFingerprint}},
{IDS_OS_SETTINGS_TAG_FINGERPRINT_ADD, {IDS_OS_SETTINGS_TAG_FINGERPRINT_ADD,
mojom::kFingerprintSubpagePath, mojom::kFingerprintSubpagePath,
mojom::SearchResultIcon::kFingerprint, mojom::SearchResultIcon::kFingerprint,
...@@ -286,6 +280,18 @@ const std::vector<SearchConcept>& GetFingerprintSearchConcepts() { ...@@ -286,6 +280,18 @@ const std::vector<SearchConcept>& GetFingerprintSearchConcepts() {
return *tags; return *tags;
} }
const std::vector<SearchConcept>& GetRemoveFingerprintSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({
{IDS_OS_SETTINGS_TAG_FINGERPRINT_REMOVE,
mojom::kFingerprintSubpagePath,
mojom::SearchResultIcon::kFingerprint,
mojom::SearchResultDefaultRank::kMedium,
mojom::SearchResultType::kSetting,
{.setting = mojom::Setting::kRemoveFingerprint}},
});
return *tags;
}
const std::vector<SearchConcept>& GetParentalSearchConcepts() { const std::vector<SearchConcept>& GetParentalSearchConcepts() {
static const base::NoDestructor<std::vector<SearchConcept>> tags({ static const base::NoDestructor<std::vector<SearchConcept>> tags({
{IDS_OS_SETTINGS_TAG_PARENTAL_CONTROLS, {IDS_OS_SETTINGS_TAG_PARENTAL_CONTROLS,
...@@ -753,10 +759,18 @@ PeopleSection::PeopleSection( ...@@ -753,10 +759,18 @@ PeopleSection::PeopleSection(
if (features::ShouldShowParentalControlSettings(profile)) if (features::ShouldShowParentalControlSettings(profile))
updater.AddSearchTags(GetParentalSearchConcepts()); updater.AddSearchTags(GetParentalSearchConcepts());
// Fingerprint search tags are added if necessary and do not update // Fingerprint search tags are added if necessary. Remove fingerprint search
// dynamically during a user session. // tags update dynamically during a user session.
if (AreFingerprintSettingsAllowed()) if (AreFingerprintSettingsAllowed()) {
updater.AddSearchTags(GetFingerprintSearchConcepts()); updater.AddSearchTags(GetFingerprintSearchConcepts());
fingerprint_pref_change_registrar_.Init(pref_service_);
fingerprint_pref_change_registrar_.Add(
::prefs::kQuickUnlockFingerprintRecord,
base::BindRepeating(&PeopleSection::UpdateRemoveFingerprintSearchTags,
base::Unretained(this)));
UpdateRemoveFingerprintSearchTags();
}
} }
PeopleSection::~PeopleSection() { PeopleSection::~PeopleSection() {
...@@ -1118,5 +1132,18 @@ bool PeopleSection::AreFingerprintSettingsAllowed() { ...@@ -1118,5 +1132,18 @@ bool PeopleSection::AreFingerprintSettingsAllowed() {
return chromeos::quick_unlock::IsFingerprintEnabled(profile()); return chromeos::quick_unlock::IsFingerprintEnabled(profile());
} }
void PeopleSection::UpdateRemoveFingerprintSearchTags() {
SearchTagRegistry::ScopedTagUpdater updater = registry()->StartUpdate();
updater.RemoveSearchTags(GetRemoveFingerprintSearchConcepts());
// "Remove fingerprint" search tag should exist only when 1 or more
// fingerprints are registered.
int registered_fingerprint_count =
pref_service_->GetInteger(::prefs::kQuickUnlockFingerprintRecord);
if (registered_fingerprint_count > 0) {
updater.AddSearchTags(GetRemoveFingerprintSearchConcepts());
}
}
} // namespace settings } // namespace settings
} // namespace chromeos } // namespace chromeos
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "chrome/browser/chromeos/kerberos/kerberos_credentials_manager.h" #include "chrome/browser/chromeos/kerberos/kerberos_credentials_manager.h"
#include "chrome/browser/ui/webui/settings/chromeos/os_settings_section.h" #include "chrome/browser/ui/webui/settings/chromeos/os_settings_section.h"
#include "chromeos/components/account_manager/account_manager.h" #include "chromeos/components/account_manager/account_manager.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/sync/driver/sync_service_observer.h" #include "components/sync/driver/sync_service_observer.h"
class PrefService; class PrefService;
...@@ -79,6 +80,7 @@ class PeopleSection : public OsSettingsSection, ...@@ -79,6 +80,7 @@ class PeopleSection : public OsSettingsSection,
void FetchAccounts(); void FetchAccounts();
void UpdateAccountManagerSearchTags( void UpdateAccountManagerSearchTags(
const std::vector<AccountManager::Account>& accounts); const std::vector<AccountManager::Account>& accounts);
void UpdateRemoveFingerprintSearchTags();
AccountManager* account_manager_ = nullptr; AccountManager* account_manager_ = nullptr;
syncer::SyncService* sync_service_; syncer::SyncService* sync_service_;
...@@ -86,6 +88,7 @@ class PeopleSection : public OsSettingsSection, ...@@ -86,6 +88,7 @@ class PeopleSection : public OsSettingsSection,
KerberosCredentialsManager* kerberos_credentials_manager_; KerberosCredentialsManager* kerberos_credentials_manager_;
signin::IdentityManager* identity_manager_; signin::IdentityManager* identity_manager_;
PrefService* pref_service_; PrefService* pref_service_;
PrefChangeRegistrar fingerprint_pref_change_registrar_;
base::WeakPtrFactory<PeopleSection> weak_factory_{this}; base::WeakPtrFactory<PeopleSection> weak_factory_{this};
}; };
......
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