Chromium Code Reviews| Index: chrome/browser/autofill/autofill_manager.cc |
| diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc |
| index 63c051a924e11af6ca65e85d7f69a2731cc33971..60940e17fb518a4f98f79eda4341b517a7d13011 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, |
| + false, |
| + PrefService::SYNCABLE_PREF); |
| #if defined(OS_MACOSX) |
| prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled, |
| true, |
| @@ -234,26 +239,34 @@ void AutofillManager::RegisterWithSyncService() { |
| } |
| } |
| -void AutofillManager::SendPasswordGenerationStateToRenderer( |
| - content::RenderViewHost* host, bool enabled) { |
| - host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), |
| - 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()->IsEnabled(); |
| + |
| + 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()->IsEnabled(); |
| + password_manager_enabled && |
| + preference_checked; |
| + |
| if (new_password_generation_enabled != password_generation_enabled_ || |
| new_renderer) { |
| password_generation_enabled_ = new_password_generation_enabled; |
| @@ -261,8 +274,25 @@ void AutofillManager::UpdatePasswordGenerationState( |
| } |
| } |
| +void AutofillManager::SendPasswordGenerationStateToRenderer( |
| + content::RenderViewHost* host, bool enabled) { |
| + host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), |
| + enabled)); |
| +} |
|
Ilya Sherman
2012/05/04 06:04:50
nit: Why is it helpful to move this method impleme
zysxqn
2012/05/04 18:52:54
Done.
|
| + |
| 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) { |