Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_manager.h" | 5 #include "components/autofill/core/browser/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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 true, | 207 true, |
| 208 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 208 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 209 #else // defined(OS_MACOSX) || defined(OS_ANDROID) | 209 #else // defined(OS_MACOSX) || defined(OS_ANDROID) |
| 210 registry->RegisterBooleanPref( | 210 registry->RegisterBooleanPref( |
| 211 prefs::kAutofillAuxiliaryProfilesEnabled, | 211 prefs::kAutofillAuxiliaryProfilesEnabled, |
| 212 false, | 212 false, |
| 213 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 213 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 214 #endif // defined(OS_MACOSX) || defined(OS_ANDROID) | 214 #endif // defined(OS_MACOSX) || defined(OS_ANDROID) |
| 215 #if defined(OS_MACOSX) | 215 #if defined(OS_MACOSX) |
| 216 registry->RegisterBooleanPref( | 216 registry->RegisterBooleanPref( |
| 217 prefs::kAutofillAuxiliaryProfilesQueried, | 217 prefs::kAutofillMacAddressBookQueried, |
| 218 false, | 218 false, |
| 219 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 219 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 220 #endif // defined(OS_MACOSX) | 220 #endif // defined(OS_MACOSX) |
| 221 registry->RegisterDoublePref( | 221 registry->RegisterDoublePref( |
| 222 prefs::kAutofillPositiveUploadRate, | 222 prefs::kAutofillPositiveUploadRate, |
| 223 kAutofillPositiveUploadRateDefaultValue, | 223 kAutofillPositiveUploadRateDefaultValue, |
| 224 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 224 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 225 registry->RegisterDoublePref( | 225 registry->RegisterDoublePref( |
| 226 prefs::kAutofillNegativeUploadRate, | 226 prefs::kAutofillNegativeUploadRate, |
| 227 kAutofillNegativeUploadRateDefaultValue, | 227 kAutofillNegativeUploadRateDefaultValue, |
| 228 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 228 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 229 | |
| 230 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
| 231 registry->RegisterBooleanPref( | |
| 232 prefs::kAutofillUseMacAddressBook, | |
| 233 false, | |
| 234 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 235 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | |
| 229 } | 236 } |
| 230 | 237 |
| 238 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
| 239 void AutofillManager::MigrateUserPrefs(PrefService* prefs) { | |
| 240 const PrefService::Preference* pref = | |
| 241 prefs->FindPreference(prefs::kAutofillUseMacAddressBook); | |
| 242 | |
| 243 // If the pref is not its default value, then the migration has already been | |
| 244 // performed. | |
| 245 if (!pref->IsDefaultValue()) | |
| 246 return; | |
| 247 | |
| 248 // Whether Chrome has already tried to access the user's Address Book. | |
| 249 const PrefService::Preference* pref_accessed = | |
| 250 prefs->FindPreference(prefs::kAutofillMacAddressBookQueried); | |
| 251 // Whether the user wants to use the Address Book to populate Autofill. | |
| 252 const PrefService::Preference* pref_enabled = | |
| 253 prefs->FindPreference(prefs::kAutofillAuxiliaryProfilesEnabled); | |
| 254 | |
| 255 if (pref_accessed->IsDefaultValue() && pref_enabled->IsDefaultValue()) { | |
| 256 // This is likely a new user. Reset the default value to prevent the | |
| 257 // migration from happening again. | |
| 258 prefs->SetBoolean(prefs::kAutofillUseMacAddressBook, | |
| 259 prefs->GetBoolean(prefs::kAutofillUseMacAddressBook)); | |
| 260 return; | |
| 261 } | |
| 262 | |
| 263 bool accessed; | |
| 264 bool enabled; | |
| 265 bool result = pref_accessed->GetValue()->GetAsBoolean(&accessed); | |
|
Ilya Sherman
2014/06/05 17:54:43
Optional nit: I typically write this as "bool succ
erikchen
2014/06/05 17:58:10
hm. "success" is more accurate. Done.
| |
| 266 DCHECK(result); | |
| 267 result = pref_enabled->GetValue()->GetAsBoolean(&enabled); | |
| 268 DCHECK(result); | |
| 269 | |
| 270 prefs->SetBoolean(prefs::kAutofillUseMacAddressBook, accessed && enabled); | |
| 271 } | |
| 272 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | |
| 273 | |
| 231 void AutofillManager::SetExternalDelegate(AutofillExternalDelegate* delegate) { | 274 void AutofillManager::SetExternalDelegate(AutofillExternalDelegate* delegate) { |
| 232 // TODO(jrg): consider passing delegate into the ctor. That won't | 275 // TODO(jrg): consider passing delegate into the ctor. That won't |
| 233 // work if the delegate has a pointer to the AutofillManager, but | 276 // work if the delegate has a pointer to the AutofillManager, but |
| 234 // future directions may not need such a pointer. | 277 // future directions may not need such a pointer. |
| 235 external_delegate_ = delegate; | 278 external_delegate_ = delegate; |
| 236 autocomplete_history_manager_->SetExternalDelegate(delegate); | 279 autocomplete_history_manager_->SetExternalDelegate(delegate); |
| 237 } | 280 } |
| 238 | 281 |
| 239 void AutofillManager::ShowAutofillSettings() { | 282 void AutofillManager::ShowAutofillSettings() { |
| 240 manager_delegate_->ShowAutofillSettings(); | 283 manager_delegate_->ShowAutofillSettings(); |
| (...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1160 return false; | 1203 return false; |
| 1161 | 1204 |
| 1162 // Disregard forms that we wouldn't ever autofill in the first place. | 1205 // Disregard forms that we wouldn't ever autofill in the first place. |
| 1163 if (!form.ShouldBeParsed(true)) | 1206 if (!form.ShouldBeParsed(true)) |
| 1164 return false; | 1207 return false; |
| 1165 | 1208 |
| 1166 return true; | 1209 return true; |
| 1167 } | 1210 } |
| 1168 | 1211 |
| 1169 } // namespace autofill | 1212 } // namespace autofill |
| OLD | NEW |