Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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( | |
| 238 content::RenderViewHost* host, bool enabled) { | |
| 239 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), | |
| 240 enabled)); | |
| 241 } | |
| 242 | |
| 243 void AutofillManager::UpdatePasswordGenerationState( | 242 void AutofillManager::UpdatePasswordGenerationState( |
| 244 content::RenderViewHost* host, | 243 content::RenderViewHost* host, |
| 245 bool new_renderer) { | 244 bool new_renderer) { |
| 245 // In order for password generation to be enabled, we need to make sure: | |
| 246 // (1) Password sync is enabled, and | |
|
Ilya Sherman
2012/05/01 22:27:48
nit: No need for "and" on this line -- just on the
zysxqn
2012/05/03 00:57:24
Done.
| |
| 247 // (2) Password manager is enabled, and | |
| 248 // (3) Password generation preference check box is checked. | |
|
Ilya Sherman
2012/05/01 22:27:48
nit: Please move this comment a bit further up sti
zysxqn
2012/05/03 00:57:24
Done.
| |
| 246 if (!sync_service_) | 249 if (!sync_service_) |
| 247 return; | 250 return; |
|
Ilya Sherman
2012/05/01 22:27:48
nit: Please add a blank line after this if-stmt.
zysxqn
2012/05/03 00:57:24
Done.
| |
| 251 syncable::ModelTypeSet sync_set = sync_service_->GetPreferredDataTypes(); | |
| 252 bool new_password_sync_enabled = | |
|
Ilya Sherman
2012/05/01 22:27:48
nit: There is no "old_password_sync_enabled" to co
zysxqn
2012/05/03 00:57:24
Done.
| |
| 253 sync_service_->HasSyncSetupCompleted() && | |
| 254 sync_set.Has(syncable::PASSWORDS); | |
| 248 | 255 |
| 249 // Password generation requires sync for passwords and the password manager | 256 bool new_password_manager_enabled = |
| 250 // to both be enabled. | 257 tab_contents_wrapper_->password_manager()->IsEnabled(); |
| 251 syncable::ModelTypeSet sync_set = sync_service_->GetPreferredDataTypes(); | 258 |
| 252 bool password_sync_enabled = (sync_service_->HasSyncSetupCompleted() && | 259 Profile* profile = Profile::FromBrowserContext( |
| 253 sync_set.Has(syncable::PASSWORDS)); | 260 web_contents()->GetBrowserContext()); |
| 261 bool new_preference_checked = | |
| 262 profile->GetPrefs()->GetBoolean(prefs::kPasswordGenerationEnabled); | |
| 263 | |
| 254 bool new_password_generation_enabled = | 264 bool new_password_generation_enabled = |
| 255 password_sync_enabled && | 265 new_password_sync_enabled && |
| 256 tab_contents_wrapper_->password_manager()->IsEnabled(); | 266 new_password_manager_enabled && |
| 267 new_preference_checked; | |
| 268 | |
| 257 if (new_password_generation_enabled != password_generation_enabled_ || | 269 if (new_password_generation_enabled != password_generation_enabled_ || |
| 258 new_renderer) { | 270 new_renderer) { |
| 259 password_generation_enabled_ = new_password_generation_enabled; | 271 password_generation_enabled_ = new_password_generation_enabled; |
| 260 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_); | 272 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_); |
| 261 } | 273 } |
| 262 } | 274 } |
| 263 | 275 |
| 276 void AutofillManager::SendPasswordGenerationStateToRenderer( | |
| 277 content::RenderViewHost* host, bool enabled) { | |
| 278 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), | |
| 279 enabled)); | |
| 280 } | |
| 281 | |
| 264 void AutofillManager::RenderViewCreated(content::RenderViewHost* host) { | 282 void AutofillManager::RenderViewCreated(content::RenderViewHost* host) { |
| 265 UpdatePasswordGenerationState(host, true); | 283 UpdatePasswordGenerationState(host, true); |
| 284 } | |
| 285 | |
| 286 void AutofillManager::Observe( | |
| 287 int type, | |
| 288 const content::NotificationSource& source, | |
| 289 const content::NotificationDetails& details) { | |
| 290 switch (type) { | |
|
Ilya Sherman
2012/05/01 22:27:48
nit: Since this code currently only listens for ex
zysxqn
2012/05/03 00:57:24
Done.
| |
| 291 case chrome::NOTIFICATION_PREF_CHANGED: { | |
| 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 293 std::string* pref = content::Details<std::string>(details).ptr(); | |
| 294 DCHECK(*pref == prefs::kPasswordGenerationEnabled); | |
|
Ilya Sherman
2012/05/01 22:27:48
nit: DCHECK_EQ(prefs::kPasswordGenerationEnabled,
zysxqn
2012/05/03 00:57:24
Done.
| |
| 295 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), false); | |
|
Ilya Sherman
2012/05/01 22:27:48
Why do you always pass |false| for the second para
zysxqn
2012/05/03 00:57:24
In AutofillManager::RenderViewCreated() we call th
Ilya Sherman
2012/05/04 06:04:50
Sorry, I misread this as calling SendPasswordGener
| |
| 296 break; | |
| 297 } | |
| 298 default: | |
| 299 NOTREACHED(); | |
| 300 } | |
| 266 } | 301 } |
| 267 | 302 |
| 268 void AutofillManager::OnStateChanged() { | 303 void AutofillManager::OnStateChanged() { |
| 269 // It is possible for sync state to change during tab contents destruction. | 304 // 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. | 305 // In this case, we don't need to update the renderer since it's going away. |
| 271 if (web_contents() && web_contents()->GetRenderViewHost()) { | 306 if (web_contents() && web_contents()->GetRenderViewHost()) { |
| 272 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), | 307 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), |
| 273 false); | 308 false); |
| 274 } | 309 } |
| 275 } | 310 } |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 836 has_logged_autofill_enabled_(false), | 871 has_logged_autofill_enabled_(false), |
| 837 has_logged_address_suggestions_count_(false), | 872 has_logged_address_suggestions_count_(false), |
| 838 did_show_suggestions_(false), | 873 did_show_suggestions_(false), |
| 839 user_did_type_(false), | 874 user_did_type_(false), |
| 840 user_did_autofill_(false), | 875 user_did_autofill_(false), |
| 841 user_did_edit_autofilled_field_(false), | 876 user_did_edit_autofilled_field_(false), |
| 842 password_generation_enabled_(false), | 877 password_generation_enabled_(false), |
| 843 external_delegate_(NULL) { | 878 external_delegate_(NULL) { |
| 844 DCHECK(tab_contents); | 879 DCHECK(tab_contents); |
| 845 RegisterWithSyncService(); | 880 RegisterWithSyncService(); |
| 881 // Test code doens't need registrar_. | |
|
Ilya Sherman
2012/05/01 22:27:48
nit: "doens't" -> "doesn't"
zysxqn
2012/05/03 00:57:24
Done.
| |
| 846 } | 882 } |
| 847 | 883 |
| 848 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { | 884 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { |
| 849 metric_logger_.reset(metric_logger); | 885 metric_logger_.reset(metric_logger); |
| 850 } | 886 } |
| 851 | 887 |
| 852 bool AutofillManager::GetHost(const std::vector<AutofillProfile*>& profiles, | 888 bool AutofillManager::GetHost(const std::vector<AutofillProfile*>& profiles, |
| 853 const std::vector<CreditCard*>& credit_cards, | 889 const std::vector<CreditCard*>& credit_cards, |
| 854 RenderViewHost** host) const { | 890 RenderViewHost** host) const { |
| 855 if (!IsAutofillEnabled()) | 891 if (!IsAutofillEnabled()) |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1327 *profile_guid = IDToGUID(profile_id); | 1363 *profile_guid = IDToGUID(profile_id); |
| 1328 } | 1364 } |
| 1329 | 1365 |
| 1330 void AutofillManager::UpdateInitialInteractionTimestamp( | 1366 void AutofillManager::UpdateInitialInteractionTimestamp( |
| 1331 const TimeTicks& interaction_timestamp) { | 1367 const TimeTicks& interaction_timestamp) { |
| 1332 if (initial_interaction_timestamp_.is_null() || | 1368 if (initial_interaction_timestamp_.is_null() || |
| 1333 interaction_timestamp < initial_interaction_timestamp_) { | 1369 interaction_timestamp < initial_interaction_timestamp_) { |
| 1334 initial_interaction_timestamp_ = interaction_timestamp; | 1370 initial_interaction_timestamp_ = interaction_timestamp; |
| 1335 } | 1371 } |
| 1336 } | 1372 } |
| OLD | NEW |