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

Side by Side 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: Changes from reviews. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autofill/autofill_manager.h" 5 #include "chrome/browser/autofill/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 did_show_suggestions_(false), 188 did_show_suggestions_(false),
189 user_did_type_(false), 189 user_did_type_(false),
190 user_did_autofill_(false), 190 user_did_autofill_(false),
191 user_did_edit_autofilled_field_(false), 191 user_did_edit_autofilled_field_(false),
192 password_generation_enabled_(false), 192 password_generation_enabled_(false),
193 external_delegate_(NULL) { 193 external_delegate_(NULL) {
194 // |personal_data_| is NULL when using test-enabled WebContents. 194 // |personal_data_| is NULL when using test-enabled WebContents.
195 personal_data_ = PersonalDataManagerFactory::GetForProfile( 195 personal_data_ = PersonalDataManagerFactory::GetForProfile(
196 tab_contents->profile()->GetOriginalProfile()); 196 tab_contents->profile()->GetOriginalProfile());
197 RegisterWithSyncService(); 197 RegisterWithSyncService();
198 registrar_.Init(tab_contents->profile()->GetPrefs());
199 registrar_.Add(prefs::kPasswordGenerationEnabled, this);
198 } 200 }
199 201
200 AutofillManager::~AutofillManager() { 202 AutofillManager::~AutofillManager() {
201 if (sync_service_ && sync_service_->HasObserver(this)) 203 if (sync_service_ && sync_service_->HasObserver(this))
202 sync_service_->RemoveObserver(this); 204 sync_service_->RemoveObserver(this);
203 } 205 }
204 206
205 // static 207 // static
206 void AutofillManager::RegisterUserPrefs(PrefService* prefs) { 208 void AutofillManager::RegisterUserPrefs(PrefService* prefs) {
207 prefs->RegisterBooleanPref(prefs::kAutofillEnabled, 209 prefs->RegisterBooleanPref(prefs::kAutofillEnabled,
208 true, 210 true,
209 PrefService::SYNCABLE_PREF); 211 PrefService::SYNCABLE_PREF);
212 prefs->RegisterBooleanPref(prefs::kPasswordGenerationEnabled,
213 false,
Garrett Casto 2012/05/11 23:01:28 I'd think that I'd prefer this default to true for
zysxqn 2012/05/11 23:52:51 Done.
214 PrefService::SYNCABLE_PREF);
210 #if defined(OS_MACOSX) 215 #if defined(OS_MACOSX)
211 prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled, 216 prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled,
212 true, 217 true,
213 PrefService::SYNCABLE_PREF); 218 PrefService::SYNCABLE_PREF);
214 #else 219 #else
215 prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled, 220 prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled,
216 false, 221 false,
217 PrefService::UNSYNCABLE_PREF); 222 PrefService::UNSYNCABLE_PREF);
218 #endif 223 #endif
219 prefs->RegisterDoublePref(prefs::kAutofillPositiveUploadRate, 224 prefs->RegisterDoublePref(prefs::kAutofillPositiveUploadRate,
(...skipping 13 matching lines...) Expand all
233 sync_service_->AddObserver(this); 238 sync_service_->AddObserver(this);
234 } 239 }
235 } 240 }
236 241
237 void AutofillManager::SendPasswordGenerationStateToRenderer( 242 void AutofillManager::SendPasswordGenerationStateToRenderer(
238 content::RenderViewHost* host, bool enabled) { 243 content::RenderViewHost* host, bool enabled) {
239 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), 244 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(),
240 enabled)); 245 enabled));
241 } 246 }
242 247
248 // In order for password generation to be enabled, we need to make sure:
249 // (1) Password sync is enabled,
250 // (2) Password manager is enabled, and
251 // (3) Password generation preference check box is checked.
243 void AutofillManager::UpdatePasswordGenerationState( 252 void AutofillManager::UpdatePasswordGenerationState(
244 content::RenderViewHost* host, 253 content::RenderViewHost* host,
245 bool new_renderer) { 254 bool new_renderer) {
246 if (!sync_service_) 255 if (!sync_service_)
247 return; 256 return;
248 257
249 // Password generation requires sync for passwords and the password manager
250 // to both be enabled.
251 syncable::ModelTypeSet sync_set = sync_service_->GetPreferredDataTypes(); 258 syncable::ModelTypeSet sync_set = sync_service_->GetPreferredDataTypes();
252 bool password_sync_enabled = (sync_service_->HasSyncSetupCompleted() && 259 bool password_sync_enabled =
253 sync_set.Has(syncable::PASSWORDS)); 260 sync_service_->HasSyncSetupCompleted() &&
261 sync_set.Has(syncable::PASSWORDS);
262
263 bool password_manager_enabled =
264 tab_contents_wrapper_->password_manager()->IsEnabled();
265
266 Profile* profile = Profile::FromBrowserContext(
267 web_contents()->GetBrowserContext());
268 bool preference_checked =
269 profile->GetPrefs()->GetBoolean(prefs::kPasswordGenerationEnabled);
270
254 bool new_password_generation_enabled = 271 bool new_password_generation_enabled =
255 password_sync_enabled && 272 password_sync_enabled &&
256 tab_contents_wrapper_->password_manager()->IsEnabled(); 273 password_manager_enabled &&
274 preference_checked;
275
257 if (new_password_generation_enabled != password_generation_enabled_ || 276 if (new_password_generation_enabled != password_generation_enabled_ ||
258 new_renderer) { 277 new_renderer) {
259 password_generation_enabled_ = new_password_generation_enabled; 278 password_generation_enabled_ = new_password_generation_enabled;
260 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_); 279 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_);
261 } 280 }
262 } 281 }
263 282
264 void AutofillManager::RenderViewCreated(content::RenderViewHost* host) { 283 void AutofillManager::RenderViewCreated(content::RenderViewHost* host) {
265 UpdatePasswordGenerationState(host, true); 284 UpdatePasswordGenerationState(host, true);
285 }
286
287 void AutofillManager::Observe(
288 int type,
289 const content::NotificationSource& source,
290 const content::NotificationDetails& details) {
291 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type);
292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
293 std::string* pref = content::Details<std::string>(details).ptr();
294 DCHECK_EQ(prefs::kPasswordGenerationEnabled, *pref);
295 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), false);
266 } 296 }
267 297
268 void AutofillManager::OnStateChanged() { 298 void AutofillManager::OnStateChanged() {
269 // It is possible for sync state to change during tab contents destruction. 299 // It is possible for sync state to change during tab contents destruction.
270 // In this case, we don't need to update the renderer since it's going away. 300 // In this case, we don't need to update the renderer since it's going away.
271 if (web_contents() && web_contents()->GetRenderViewHost()) { 301 if (web_contents() && web_contents()->GetRenderViewHost()) {
272 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), 302 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(),
273 false); 303 false);
274 } 304 }
275 } 305 }
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 has_logged_autofill_enabled_(false), 890 has_logged_autofill_enabled_(false),
861 has_logged_address_suggestions_count_(false), 891 has_logged_address_suggestions_count_(false),
862 did_show_suggestions_(false), 892 did_show_suggestions_(false),
863 user_did_type_(false), 893 user_did_type_(false),
864 user_did_autofill_(false), 894 user_did_autofill_(false),
865 user_did_edit_autofilled_field_(false), 895 user_did_edit_autofilled_field_(false),
866 password_generation_enabled_(false), 896 password_generation_enabled_(false),
867 external_delegate_(NULL) { 897 external_delegate_(NULL) {
868 DCHECK(tab_contents); 898 DCHECK(tab_contents);
869 RegisterWithSyncService(); 899 RegisterWithSyncService();
900 // Test code doesn't need registrar_.
870 } 901 }
871 902
872 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { 903 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) {
873 metric_logger_.reset(metric_logger); 904 metric_logger_.reset(metric_logger);
874 } 905 }
875 906
876 bool AutofillManager::GetHost(const std::vector<AutofillProfile*>& profiles, 907 bool AutofillManager::GetHost(const std::vector<AutofillProfile*>& profiles,
877 const std::vector<CreditCard*>& credit_cards, 908 const std::vector<CreditCard*>& credit_cards,
878 RenderViewHost** host) const { 909 RenderViewHost** host) const {
879 if (!IsAutofillEnabled()) 910 if (!IsAutofillEnabled())
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 *profile_guid = IDToGUID(profile_id); 1382 *profile_guid = IDToGUID(profile_id);
1352 } 1383 }
1353 1384
1354 void AutofillManager::UpdateInitialInteractionTimestamp( 1385 void AutofillManager::UpdateInitialInteractionTimestamp(
1355 const TimeTicks& interaction_timestamp) { 1386 const TimeTicks& interaction_timestamp) {
1356 if (initial_interaction_timestamp_.is_null() || 1387 if (initial_interaction_timestamp_.is_null() ||
1357 interaction_timestamp < initial_interaction_timestamp_) { 1388 interaction_timestamp < initial_interaction_timestamp_) {
1358 initial_interaction_timestamp_ = interaction_timestamp; 1389 initial_interaction_timestamp_ = interaction_timestamp;
1359 } 1390 }
1360 } 1391 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698