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

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: Created 8 years, 8 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 personal_data_(NULL), 182 personal_data_(NULL),
183 download_manager_(tab_contents->profile(), this), 183 download_manager_(tab_contents->profile(), this),
184 disable_download_manager_requests_(false), 184 disable_download_manager_requests_(false),
185 metric_logger_(new AutofillMetrics), 185 metric_logger_(new AutofillMetrics),
186 has_logged_autofill_enabled_(false), 186 has_logged_autofill_enabled_(false),
187 has_logged_address_suggestions_count_(false), 187 has_logged_address_suggestions_count_(false),
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_sync_enabled_(false),
192 password_generation_enabled_(false), 193 password_generation_enabled_(false),
193 external_delegate_(NULL) { 194 external_delegate_(NULL) {
194 // |personal_data_| is NULL when using test-enabled WebContents. 195 // |personal_data_| is NULL when using test-enabled WebContents.
195 personal_data_ = PersonalDataManagerFactory::GetForProfile( 196 personal_data_ = PersonalDataManagerFactory::GetForProfile(
196 tab_contents->profile()->GetOriginalProfile()); 197 tab_contents->profile()->GetOriginalProfile());
197 RegisterWithSyncService(); 198 RegisterWithSyncService();
199 registrar_.Init(tab_contents->profile()->GetPrefs());
200 registrar_.Add(prefs::kPasswordGenerationEnabled, this);
198 } 201 }
199 202
200 AutofillManager::~AutofillManager() { 203 AutofillManager::~AutofillManager() {
201 if (sync_service_ && sync_service_->HasObserver(this)) 204 if (sync_service_ && sync_service_->HasObserver(this))
202 sync_service_->RemoveObserver(this); 205 sync_service_->RemoveObserver(this);
203 } 206 }
204 207
205 // static 208 // static
206 void AutofillManager::RegisterUserPrefs(PrefService* prefs) { 209 void AutofillManager::RegisterUserPrefs(PrefService* prefs) {
207 prefs->RegisterBooleanPref(prefs::kAutofillEnabled, 210 prefs->RegisterBooleanPref(prefs::kAutofillEnabled,
208 true, 211 true,
209 PrefService::SYNCABLE_PREF); 212 PrefService::SYNCABLE_PREF);
213 prefs->RegisterBooleanPref(prefs::kPasswordGenerationEnabled,
214 true,
Garrett Casto 2012/04/26 23:23:59 We are going to have this be an opt-in feature at
zysxqn 2012/04/27 18:38:34 Done.
215 PrefService::SYNCABLE_PREF);
210 #if defined(OS_MACOSX) 216 #if defined(OS_MACOSX)
211 prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled, 217 prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled,
212 true, 218 true,
213 PrefService::SYNCABLE_PREF); 219 PrefService::SYNCABLE_PREF);
214 #else 220 #else
215 prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled, 221 prefs->RegisterBooleanPref(prefs::kAutofillAuxiliaryProfilesEnabled,
216 false, 222 false,
217 PrefService::UNSYNCABLE_PREF); 223 PrefService::UNSYNCABLE_PREF);
218 #endif 224 #endif
219 prefs->RegisterDoublePref(prefs::kAutofillPositiveUploadRate, 225 prefs->RegisterDoublePref(prefs::kAutofillPositiveUploadRate,
220 kAutofillPositiveUploadRateDefaultValue, 226 kAutofillPositiveUploadRateDefaultValue,
221 PrefService::UNSYNCABLE_PREF); 227 PrefService::UNSYNCABLE_PREF);
222 prefs->RegisterDoublePref(prefs::kAutofillNegativeUploadRate, 228 prefs->RegisterDoublePref(prefs::kAutofillNegativeUploadRate,
223 kAutofillNegativeUploadRateDefaultValue, 229 kAutofillNegativeUploadRateDefaultValue,
224 PrefService::UNSYNCABLE_PREF); 230 PrefService::UNSYNCABLE_PREF);
225 } 231 }
226 232
227 void AutofillManager::RegisterWithSyncService() { 233 void AutofillManager::RegisterWithSyncService() {
228 ProfileSyncService* temp_sync_service = 234 ProfileSyncService* temp_sync_service =
229 ProfileSyncServiceFactory::GetForProfile( 235 ProfileSyncServiceFactory::GetForProfile(
230 tab_contents_wrapper_->profile()); 236 tab_contents_wrapper_->profile());
231 if (temp_sync_service) { 237 if (temp_sync_service) {
232 sync_service_ = temp_sync_service->AsWeakPtr(); 238 sync_service_ = temp_sync_service->AsWeakPtr();
233 sync_service_->AddObserver(this); 239 sync_service_->AddObserver(this);
234 } 240 }
235 } 241 }
236 242
243 void AutofillManager::SendPasswordSyncStateToRenderer(
Garrett Casto 2012/04/26 23:23:59 Remove this.
244 content::RenderViewHost* host, bool enabled) {
245 host->Send(new AutofillMsg_PasswordSyncEnabled(host->GetRoutingID(),
246 enabled));
247 }
248
249 void AutofillManager::UpdatePasswordSyncState(
250 content::RenderViewHost* host,
251 bool new_renderer) {
252 if (!sync_service_)
253 return;
254
255 // Also need to check whether password manager is enabled.
256 syncable::ModelTypeSet sync_set = sync_service_->GetPreferredDataTypes();
257 bool new_password_sync_enabled =
258 sync_service_->HasSyncSetupCompleted() &&
259 sync_set.Has(syncable::PASSWORDS) &&
260 tab_contents_wrapper_->password_manager()->IsEnabled();
261 if (new_password_sync_enabled != password_sync_enabled_ ||
262 new_renderer) {
263 password_sync_enabled_ = new_password_sync_enabled;
264 SendPasswordSyncStateToRenderer(host, password_sync_enabled_);
265 }
266 }
267
237 void AutofillManager::SendPasswordGenerationStateToRenderer( 268 void AutofillManager::SendPasswordGenerationStateToRenderer(
238 content::RenderViewHost* host, bool enabled) { 269 content::RenderViewHost* host, bool enabled) {
239 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), 270 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(),
240 enabled)); 271 enabled));
241 } 272 }
242 273
243 void AutofillManager::UpdatePasswordGenerationState( 274 void AutofillManager::UpdatePasswordGenerationState(
244 content::RenderViewHost* host, 275 content::RenderViewHost* host, bool new_renderer) {
245 bool new_renderer) { 276 Profile* profile = Profile::FromBrowserContext(
246 if (!sync_service_) 277 web_contents()->GetBrowserContext());
247 return; 278 // Also need to check whether password manager is enabled.
248
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 bool password_sync_enabled = (sync_service_->HasSyncSetupCompleted() &&
253 sync_set.Has(syncable::PASSWORDS));
254 bool new_password_generation_enabled = 279 bool new_password_generation_enabled =
255 password_sync_enabled && 280 profile->GetPrefs()->GetBoolean(prefs::kPasswordGenerationEnabled) &&
Garrett Casto 2012/04/26 23:23:59 This should check if password sync is enabled as w
256 tab_contents_wrapper_->password_manager()->IsEnabled(); 281 tab_contents_wrapper_->password_manager()->IsEnabled();
257 if (new_password_generation_enabled != password_generation_enabled_ || 282 if (new_password_generation_enabled != password_generation_enabled_ ||
258 new_renderer) { 283 new_renderer) {
259 password_generation_enabled_ = new_password_generation_enabled; 284 password_generation_enabled_ = new_password_generation_enabled;
260 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_); 285 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_);
261 } 286 }
262 } 287 }
263 288
264 void AutofillManager::RenderViewCreated(content::RenderViewHost* host) { 289 void AutofillManager::RenderViewCreated(content::RenderViewHost* host) {
265 UpdatePasswordGenerationState(host, true); 290 UpdatePasswordSyncState(host, true);
Garrett Casto 2012/04/26 23:23:59 This should just call UpdatePasswordGenerationStat
291 UpdatePasswordGenerationState(host, true);
292 }
293
294 void AutofillManager::Observe(
295 int type,
296 const content::NotificationSource& source,
297 const content::NotificationDetails& details) {
298 switch (type) {
Garrett Casto 2012/04/26 23:23:59 I'm actually not totally sure that we need this ob
zysxqn 2012/04/27 18:38:34 I feel that it is useful since users sometimes exp
299 case chrome::NOTIFICATION_PREF_CHANGED: {
300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
301 std::string* pref = content::Details<std::string>(details).ptr();
302 DCHECK(*pref == prefs::kPasswordGenerationEnabled);
303 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), false);
304 break;
305 }
306 default:
307 NOTREACHED();
308 }
266 } 309 }
267 310
268 void AutofillManager::OnStateChanged() { 311 void AutofillManager::OnStateChanged() {
269 // It is possible for sync state to change during tab contents destruction. 312 // 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. 313 // In this case, we don't need to update the renderer since it's going away.
271 if (web_contents() && web_contents()->GetRenderViewHost()) { 314 if (web_contents() && web_contents()->GetRenderViewHost()) {
272 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), 315 UpdatePasswordSyncState(web_contents()->GetRenderViewHost(),
Garrett Casto 2012/04/26 23:23:59 Don't change this.
273 false); 316 false);
274 } 317 }
275 } 318 }
276 319
277 void AutofillManager::DidNavigateMainFrame( 320 void AutofillManager::DidNavigateMainFrame(
278 const content::LoadCommittedDetails& details, 321 const content::LoadCommittedDetails& details,
279 const content::FrameNavigateParams& params) { 322 const content::FrameNavigateParams& params) {
280 Reset(); 323 Reset();
281 } 324 }
282 325
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 personal_data_(personal_data), 875 personal_data_(personal_data),
833 download_manager_(tab_contents->profile(), this), 876 download_manager_(tab_contents->profile(), this),
834 disable_download_manager_requests_(true), 877 disable_download_manager_requests_(true),
835 metric_logger_(new AutofillMetrics), 878 metric_logger_(new AutofillMetrics),
836 has_logged_autofill_enabled_(false), 879 has_logged_autofill_enabled_(false),
837 has_logged_address_suggestions_count_(false), 880 has_logged_address_suggestions_count_(false),
838 did_show_suggestions_(false), 881 did_show_suggestions_(false),
839 user_did_type_(false), 882 user_did_type_(false),
840 user_did_autofill_(false), 883 user_did_autofill_(false),
841 user_did_edit_autofilled_field_(false), 884 user_did_edit_autofilled_field_(false),
885 password_sync_enabled_(false),
842 password_generation_enabled_(false), 886 password_generation_enabled_(false),
843 external_delegate_(NULL) { 887 external_delegate_(NULL) {
844 DCHECK(tab_contents); 888 DCHECK(tab_contents);
845 RegisterWithSyncService(); 889 RegisterWithSyncService();
890 // Test code doens't need registrar_.
846 } 891 }
847 892
848 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { 893 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) {
849 metric_logger_.reset(metric_logger); 894 metric_logger_.reset(metric_logger);
850 } 895 }
851 896
852 bool AutofillManager::GetHost(const std::vector<AutofillProfile*>& profiles, 897 bool AutofillManager::GetHost(const std::vector<AutofillProfile*>& profiles,
853 const std::vector<CreditCard*>& credit_cards, 898 const std::vector<CreditCard*>& credit_cards,
854 RenderViewHost** host) const { 899 RenderViewHost** host) const {
855 if (!IsAutofillEnabled()) 900 if (!IsAutofillEnabled())
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 *profile_guid = IDToGUID(profile_id); 1372 *profile_guid = IDToGUID(profile_id);
1328 } 1373 }
1329 1374
1330 void AutofillManager::UpdateInitialInteractionTimestamp( 1375 void AutofillManager::UpdateInitialInteractionTimestamp(
1331 const TimeTicks& interaction_timestamp) { 1376 const TimeTicks& interaction_timestamp) {
1332 if (initial_interaction_timestamp_.is_null() || 1377 if (initial_interaction_timestamp_.is_null() ||
1333 interaction_timestamp < initial_interaction_timestamp_) { 1378 interaction_timestamp < initial_interaction_timestamp_) {
1334 initial_interaction_timestamp_ = interaction_timestamp; 1379 initial_interaction_timestamp_ = interaction_timestamp;
1335 } 1380 }
1336 } 1381 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698