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

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 according to code 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,
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,
220 kAutofillPositiveUploadRateDefaultValue, 225 kAutofillPositiveUploadRateDefaultValue,
221 PrefService::UNSYNCABLE_PREF); 226 PrefService::UNSYNCABLE_PREF);
222 prefs->RegisterDoublePref(prefs::kAutofillNegativeUploadRate, 227 prefs->RegisterDoublePref(prefs::kAutofillNegativeUploadRate,
223 kAutofillNegativeUploadRateDefaultValue, 228 kAutofillNegativeUploadRateDefaultValue,
224 PrefService::UNSYNCABLE_PREF); 229 PrefService::UNSYNCABLE_PREF);
225 } 230 }
226 231
227 void AutofillManager::RegisterWithSyncService() { 232 void AutofillManager::RegisterWithSyncService() {
228 ProfileSyncService* temp_sync_service = 233 ProfileSyncService* temp_sync_service =
229 ProfileSyncServiceFactory::GetForProfile( 234 ProfileSyncServiceFactory::GetForProfile(
230 tab_contents_wrapper_->profile()); 235 tab_contents_wrapper_->profile());
231 if (temp_sync_service) { 236 if (temp_sync_service) {
232 sync_service_ = temp_sync_service->AsWeakPtr(); 237 sync_service_ = temp_sync_service->AsWeakPtr();
233 sync_service_->AddObserver(this); 238 sync_service_->AddObserver(this);
234 } 239 }
235 } 240 }
236 241
237 void AutofillManager::SendPasswordGenerationStateToRenderer( 242 // In order for password generation to be enabled, we need to make sure:
238 content::RenderViewHost* host, bool enabled) { 243 // (1) Password sync is enabled,
239 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), 244 // (2) Password manager is enabled, and
240 enabled)); 245 // (3) Password generation preference check box is checked.
241 }
242
243 void AutofillManager::UpdatePasswordGenerationState( 246 void AutofillManager::UpdatePasswordGenerationState(
244 content::RenderViewHost* host, 247 content::RenderViewHost* host,
245 bool new_renderer) { 248 bool new_renderer) {
246 if (!sync_service_) 249 if (!sync_service_)
247 return; 250 return;
248 251
249 // Password generation requires sync for passwords and the password manager
250 // to both be enabled.
251 syncable::ModelTypeSet sync_set = sync_service_->GetPreferredDataTypes(); 252 syncable::ModelTypeSet sync_set = sync_service_->GetPreferredDataTypes();
252 bool password_sync_enabled = (sync_service_->HasSyncSetupCompleted() && 253 bool password_sync_enabled =
253 sync_set.Has(syncable::PASSWORDS)); 254 sync_service_->HasSyncSetupCompleted() &&
255 sync_set.Has(syncable::PASSWORDS);
256
257 bool password_manager_enabled =
258 tab_contents_wrapper_->password_manager()->IsEnabled();
259
260 Profile* profile = Profile::FromBrowserContext(
261 web_contents()->GetBrowserContext());
262 bool preference_checked =
263 profile->GetPrefs()->GetBoolean(prefs::kPasswordGenerationEnabled);
264
254 bool new_password_generation_enabled = 265 bool new_password_generation_enabled =
255 password_sync_enabled && 266 password_sync_enabled &&
256 tab_contents_wrapper_->password_manager()->IsEnabled(); 267 password_manager_enabled &&
268 preference_checked;
269
257 if (new_password_generation_enabled != password_generation_enabled_ || 270 if (new_password_generation_enabled != password_generation_enabled_ ||
258 new_renderer) { 271 new_renderer) {
259 password_generation_enabled_ = new_password_generation_enabled; 272 password_generation_enabled_ = new_password_generation_enabled;
260 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_); 273 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_);
261 } 274 }
262 } 275 }
263 276
277 void AutofillManager::SendPasswordGenerationStateToRenderer(
278 content::RenderViewHost* host, bool enabled) {
279 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(),
280 enabled));
281 }
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.
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