Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Unified Diff: chrome/browser/autofill/autofill_manager.cc

Issue 10222017: Make password generation switched by a preference in chrome settings rather than a command line fla… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make MockAutofillManager to use the constructor designated for unit tests to avoid dangling pref_ob… Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/autofill_manager.cc
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index 627b0cbf74ec01d5d34bd4f6c4fe820f5bca8856..74193effe1c7bef294da14bf3aec9b818b5bffd1 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -195,6 +195,8 @@ AutofillManager::AutofillManager(TabContentsWrapper* tab_contents)
personal_data_ = PersonalDataManagerFactory::GetForProfile(
tab_contents->profile()->GetOriginalProfile());
RegisterWithSyncService();
+ registrar_.Init(tab_contents->profile()->GetPrefs());
+ registrar_.Add(prefs::kPasswordGenerationEnabled, this);
}
AutofillManager::~AutofillManager() {
@@ -207,6 +209,9 @@ void AutofillManager::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kAutofillEnabled,
true,
PrefService::SYNCABLE_PREF);
+ prefs->RegisterBooleanPref(prefs::kPasswordGenerationEnabled,
+ true,
+ PrefService::SYNCABLE_PREF);
#if defined(OS_MACOSX)
prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled,
true,
@@ -240,20 +245,34 @@ void AutofillManager::SendPasswordGenerationStateToRenderer(
enabled));
}
+// In order for password generation to be enabled, we need to make sure:
+// (1) Password sync is enabled,
+// (2) Password manager is enabled, and
+// (3) Password generation preference check box is checked.
void AutofillManager::UpdatePasswordGenerationState(
content::RenderViewHost* host,
bool new_renderer) {
if (!sync_service_)
return;
- // Password generation requires sync for passwords and the password manager
- // to both be enabled.
syncable::ModelTypeSet sync_set = sync_service_->GetPreferredDataTypes();
- bool password_sync_enabled = (sync_service_->HasSyncSetupCompleted() &&
- sync_set.Has(syncable::PASSWORDS));
+ bool password_sync_enabled =
+ sync_service_->HasSyncSetupCompleted() &&
+ sync_set.Has(syncable::PASSWORDS);
+
+ bool password_manager_enabled =
+ tab_contents_wrapper_->password_manager()->IsSavingEnabled();
+
+ Profile* profile = Profile::FromBrowserContext(
+ web_contents()->GetBrowserContext());
+ bool preference_checked =
+ profile->GetPrefs()->GetBoolean(prefs::kPasswordGenerationEnabled);
+
bool new_password_generation_enabled =
password_sync_enabled &&
- tab_contents_wrapper_->password_manager()->IsSavingEnabled();
+ password_manager_enabled &&
+ preference_checked;
+
if (new_password_generation_enabled != password_generation_enabled_ ||
new_renderer) {
password_generation_enabled_ = new_password_generation_enabled;
@@ -262,7 +281,18 @@ void AutofillManager::UpdatePasswordGenerationState(
}
void AutofillManager::RenderViewCreated(content::RenderViewHost* host) {
- UpdatePasswordGenerationState(host, true);
+ UpdatePasswordGenerationState(host, true);
+}
+
+void AutofillManager::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type);
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ std::string* pref = content::Details<std::string>(details).ptr();
+ DCHECK_EQ(prefs::kPasswordGenerationEnabled, *pref);
+ UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), false);
}
void AutofillManager::OnStateChanged() {
@@ -867,6 +897,7 @@ AutofillManager::AutofillManager(TabContentsWrapper* tab_contents,
external_delegate_(NULL) {
DCHECK(tab_contents);
RegisterWithSyncService();
+ // Test code doesn't need registrar_.
}
void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) {

Powered by Google App Engine
This is Rietveld 408576698