Skip to content

Commit

Permalink
[PwdSettings] Add new prefs for password manager settings
Browse files Browse the repository at this point in the history
Bug: 1289700
Change-Id: If64d22f7b5fa13da950e1401927d1b51da5b1f0f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3562944
Reviewed-by: Vasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: John Wu <jzw@chromium.org>
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Cr-Commit-Position: refs/heads/main@{#990328}
  • Loading branch information
Ioana Pandele authored and Chromium LUCI CQ committed Apr 8, 2022
1 parent c150cf7 commit 7e7925c
Show file tree
Hide file tree
Showing 19 changed files with 321 additions and 36 deletions.
19 changes: 13 additions & 6 deletions chrome/browser/password_manager/chrome_password_manager_client.cc
Expand Up @@ -64,6 +64,7 @@
#include "components/password_manager/core/browser/hsts_query.h"
#include "components/password_manager/core/browser/http_auth_manager.h"
#include "components/password_manager/core/browser/http_auth_manager_impl.h"
#include "components/password_manager/core/browser/password_bubble_experiment.h"
#include "components/password_manager/core/browser/password_change_success_tracker.h"
#include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/browser/password_form_manager_for_ui.h"
Expand Down Expand Up @@ -187,7 +188,7 @@ namespace {
static const char kPasswordBreachEntryTrigger[] = "PASSWORD_ENTRY";
#endif

const syncer::SyncService* GetSyncService(Profile* profile) {
const syncer::SyncService* GetSyncServiceForProfile(Profile* profile) {
if (SyncServiceFactory::HasSyncService(profile))
return SyncServiceFactory::GetForProfile(profile);
return nullptr;
Expand Down Expand Up @@ -262,7 +263,9 @@ bool ChromePasswordManagerClient::IsSavingAndFillingEnabled(
// page, and there is no API to access (or dismiss) UI bubbles/infobars.
return false;
}
return *saving_passwords_enabled_ && !IsIncognito() && IsFillingEnabled(url);
return password_manager_util::IsSavingPasswordsEnabled(GetPrefs(),
GetSyncService()) &&
!IsIncognito() && IsFillingEnabled(url);
}

bool ChromePasswordManagerClient::IsFillingEnabled(const GURL& url) const {
Expand Down Expand Up @@ -617,6 +620,10 @@ PrefService* ChromePasswordManagerClient::GetPrefs() const {
return profile_->GetPrefs();
}

const syncer::SyncService* ChromePasswordManagerClient::GetSyncService() const {
return GetSyncServiceForProfile(profile_);
}

password_manager::PasswordStoreInterface*
ChromePasswordManagerClient::GetProfilePasswordStore() const {
// Always use EXPLICIT_ACCESS as the password manager checks IsIncognito
Expand Down Expand Up @@ -1232,7 +1239,7 @@ ChromePasswordManagerClient::ChromePasswordManagerClient(
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
credentials_filter_(
this,
base::BindRepeating(&GetSyncService, profile_),
base::BindRepeating(&GetSyncServiceForProfile, profile_),
DiceWebSigninInterceptorFactory::GetForProfile(profile_)),
account_storage_auth_helper_(
IdentityManagerFactory::GetForProfile(profile_),
Expand All @@ -1245,7 +1252,9 @@ ChromePasswordManagerClient::ChromePasswordManagerClient(
},
web_contents)),
#else
credentials_filter_(this, base::BindRepeating(&GetSyncService, profile_)),
credentials_filter_(
this,
base::BindRepeating(&GetSyncServiceForProfile, profile_)),
#endif
helper_(this) {
ContentPasswordManagerDriverFactory::CreateForWebContents(web_contents, this,
Expand All @@ -1259,8 +1268,6 @@ ChromePasswordManagerClient::ChromePasswordManagerClient(
&ContentPasswordManagerDriverFactory::RequestSendLoggingAvailability,
base::Unretained(driver_factory_)));

saving_passwords_enabled_.Init(
password_manager::prefs::kCredentialsEnableService, GetPrefs());
driver_factory_->RequestSendLoggingAvailability();

auto* autofill_assistant_manager =
Expand Down
Expand Up @@ -36,6 +36,7 @@
#include "components/prefs/pref_member.h"
#include "components/safe_browsing/buildflags.h"
#include "components/signin/public/base/signin_buildflags.h"
#include "components/sync/driver/sync_service.h"
#include "content/public/browser/render_frame_host_receiver_set.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/web_contents_observer.h"
Expand Down Expand Up @@ -175,6 +176,7 @@ class ChromePasswordManagerClient
base::OnceCallback<void(ReauthSucceeded)> reauth_callback) override;
void TriggerSignIn(signin_metrics::AccessPoint access_point) override;
PrefService* GetPrefs() const override;
const syncer::SyncService* GetSyncService() const override;
password_manager::PasswordStoreInterface* GetProfilePasswordStore()
const override;
password_manager::PasswordStoreInterface* GetAccountPasswordStore()
Expand Down Expand Up @@ -406,11 +408,6 @@ class ChromePasswordManagerClient
// Controls the popup
base::WeakPtr<PasswordGenerationPopupControllerImpl> popup_controller_;

// Set to false to disable password saving (will no longer ask if you
// want to save passwords). There is no pref for disabling filling at this
// point.
BooleanPrefMember saving_passwords_enabled_;

#if BUILDFLAG(ENABLE_DICE_SUPPORT)
// MultiProfileCredentialsFilter requires DICE support.
const MultiProfileCredentialsFilter credentials_filter_;
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/ui/autofill/chrome_autofill_client.cc
Expand Up @@ -61,6 +61,7 @@
#include "components/autofill_assistant/browser/public/runtime_manager.h"
#include "components/password_manager/content/browser/content_password_manager_driver.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/password_manager_util.h"
#include "components/password_manager/core/browser/password_requirements_service.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
Expand Down Expand Up @@ -867,8 +868,8 @@ bool ChromeAutofillClient::IsAutocompleteEnabled() {
}

bool ChromeAutofillClient::IsPasswordManagerEnabled() {
return GetPrefs()->GetBoolean(
password_manager::prefs::kCredentialsEnableService);
return password_manager_util::IsSavingPasswordsEnabled(GetPrefs(),
GetSyncService());
}

void ChromeAutofillClient::PropagateAutofillPredictions(
Expand Down
Expand Up @@ -28,10 +28,7 @@ void RunGetCallback(GetCallback callback, const CredentialInfo& info) {
} // namespace

CredentialManagerImpl::CredentialManagerImpl(PasswordManagerClient* client)
: client_(client), leak_delegate_(client) {
auto_signin_enabled_.Init(prefs::kCredentialsEnableAutosignin,
client_->GetPrefs());
}
: client_(client), leak_delegate_(client) {}

CredentialManagerImpl::~CredentialManagerImpl() = default;

Expand Down Expand Up @@ -166,7 +163,9 @@ void CredentialManagerImpl::Get(CredentialMediationRequirement mediation,
}

bool CredentialManagerImpl::IsZeroClickAllowed() const {
return *auto_signin_enabled_ && !client_->IsIncognito();
return password_manager_util::IsAutoSignInEnabled(
client_->GetPrefs(), client_->GetSyncService()) &&
!client_->IsIncognito();
}

PasswordFormDigest CredentialManagerImpl::GetSynthesizedFormForOrigin() const {
Expand Down
Expand Up @@ -82,9 +82,6 @@ class CredentialManagerImpl

raw_ptr<PasswordManagerClient> client_;

// Set to false to disable automatic signing in.
BooleanPrefMember auto_signin_enabled_;

// Used to store or update a credential. Calls OnProvisionalSaveComplete
// on this delegate.
std::unique_ptr<CredentialManagerPasswordFormManager> form_manager_;
Expand Down
2 changes: 2 additions & 0 deletions components/password_manager/core/browser/password_manager.cc
Expand Up @@ -253,6 +253,8 @@ void PasswordManager::RegisterProfilePrefs(
prefs::kPasswordDismissCompromisedAlertEnabled, true,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
#if BUILDFLAG(IS_ANDROID)
registry->RegisterBooleanPref(prefs::kOfferToSavePasswordsEnabledGMS, true);
registry->RegisterBooleanPref(prefs::kAutoSignInEnabledGMS, true);
registry->RegisterIntegerPref(
prefs::kCurrentMigrationVersionToGoogleMobileServices, 0);
registry->RegisterDoublePref(prefs::kTimeOfLastMigrationAttempt, 0.0);
Expand Down
Expand Up @@ -28,6 +28,7 @@
#include "components/password_manager/core/browser/webauthn_credentials_delegate.h"
#include "components/profile_metrics/browser_profile_type.h"
#include "components/safe_browsing/buildflags.h"
#include "components/sync/driver/sync_service.h"
#include "net/cert/cert_status_flags.h"
#include "services/metrics/public/cpp/ukm_recorder.h"

Expand Down Expand Up @@ -276,6 +277,9 @@ class PasswordManagerClient {
// Gets prefs associated with this embedder.
virtual PrefService* GetPrefs() const = 0;

// Gets the sync service associated with this client.
virtual const syncer::SyncService* GetSyncService() const = 0;

// Returns the profile PasswordStore associated with this instance.
virtual PasswordStoreInterface* GetProfilePasswordStore() const = 0;

Expand Down
Expand Up @@ -9,6 +9,7 @@
#include "components/password_manager/core/browser/password_feature_manager.h"
#include "components/password_manager/core/browser/password_form_manager_for_ui.h"
#include "components/password_manager/core/browser/password_manager.h"
#include "components/password_manager/core/browser/password_manager_util.h"
#include "components/password_manager/core/browser/password_sync_util.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
Expand Down Expand Up @@ -98,8 +99,8 @@ bool PasswordManagerClientHelper::ShouldPromptToEnableAutoSignIn() const {
return password_bubble_experiment::
ShouldShowAutoSignInPromptFirstRunExperience(
delegate_->GetPrefs()) &&
delegate_->GetPrefs()->GetBoolean(
password_manager::prefs::kCredentialsEnableAutosignin) &&
password_manager_util::IsAutoSignInEnabled(
delegate_->GetPrefs(), delegate_->GetSyncService()) &&
!delegate_->IsIncognito();
}

Expand Down
55 changes: 55 additions & 0 deletions components/password_manager/core/browser/password_manager_util.cc
Expand Up @@ -28,6 +28,7 @@
#include "components/password_manager/core/browser/credentials_cleaner_runner.h"
#include "components/password_manager/core/browser/http_credentials_cleaner.h"
#include "components/password_manager/core/browser/old_google_credentials_cleaner.h"
#include "components/password_manager/core/browser/password_bubble_experiment.h"
#include "components/password_manager/core/browser/password_feature_manager.h"
#include "components/password_manager/core/browser/password_form.h"
#include "components/password_manager/core/browser/password_generation_frame_helper.h"
Expand Down Expand Up @@ -69,6 +70,60 @@ bool IsBetterMatch(const PasswordForm* lhs, const PasswordForm* rhs) {

} // namespace

bool IsSavingPasswordsEnabled(const PrefService* pref_service,
const syncer::SyncService* sync_service) {
DCHECK(pref_service);
const PrefService::Preference* save_passwords_pref =
pref_service->FindPreference(
password_manager::prefs::kCredentialsEnableService);
DCHECK(save_passwords_pref);
#if BUILDFLAG(IS_ANDROID)
if (!password_bubble_experiment::HasChosenToSyncPasswords(sync_service)) {
return save_passwords_pref->GetValue()->GetBool();
}

if (!password_manager::features::UsesUnifiedPasswordManagerUi()) {
return save_passwords_pref->GetValue()->GetBool();
}

if (save_passwords_pref->IsManaged()) {
return save_passwords_pref->GetValue()->GetBool();
}

return pref_service->GetBoolean(
password_manager::prefs::kOfferToSavePasswordsEnabledGMS);
#else
return save_passwords_pref->GetValue()->GetBool();
#endif
}

bool IsAutoSignInEnabled(const PrefService* pref_service,
const syncer::SyncService* sync_service) {
DCHECK(pref_service);
const PrefService::Preference* auto_sign_in_pref =
pref_service->FindPreference(
password_manager::prefs::kCredentialsEnableAutosignin);
DCHECK(auto_sign_in_pref);
#if BUILDFLAG(IS_ANDROID)
if (!password_bubble_experiment::HasChosenToSyncPasswords(sync_service)) {
return auto_sign_in_pref->GetValue()->GetBool();
}

if (!password_manager::features::UsesUnifiedPasswordManagerUi()) {
return auto_sign_in_pref->GetValue()->GetBool();
}

if (auto_sign_in_pref->IsManaged()) {
return auto_sign_in_pref->GetValue()->GetBool();
}

return pref_service->GetBoolean(
password_manager::prefs::kAutoSignInEnabledGMS);
#else
return auto_sign_in_pref->GetValue()->GetBool();
#endif
}

// Update |credential| to reflect usage.
void UpdateMetadataForUsage(PasswordForm* credential) {
++credential->times_used;
Expand Down
12 changes: 12 additions & 0 deletions components/password_manager/core/browser/password_manager_util.h
Expand Up @@ -53,6 +53,18 @@ enum class GetLoginMatchType {
kPSL,
};

// Checks if saving passwords is enabled. On Android, it ensures that the
// correct pref is checked on Android, which depends on the unified password
// manager status.
bool IsSavingPasswordsEnabled(const PrefService* pref_service,
const syncer::SyncService* sync_service);

// Checks if auto sign in is enabled. On Android, it ensures that the
// correct pref is checked on Android, which depends on the unified password
// manager status.
bool IsAutoSignInEnabled(const PrefService* pref_service,
const syncer::SyncService* sync_service);

// Update |credential| to reflect usage.
void UpdateMetadataForUsage(password_manager::PasswordForm* credential);

Expand Down

0 comments on commit 7e7925c

Please sign in to comment.