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/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #import <AddressBook/AddressBook.h> | 9 #import <AddressBook/AddressBook.h> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "components/autofill/core/browser/form_structure.h" | 24 #include "components/autofill/core/browser/form_structure.h" |
| 25 #include "components/autofill/core/browser/phone_number.h" | 25 #include "components/autofill/core/browser/phone_number.h" |
| 26 #include "components/autofill/core/common/autofill_pref_names.h" | 26 #include "components/autofill/core/common/autofill_pref_names.h" |
| 27 #include "components/autofill/core/common/form_data.h" | 27 #include "components/autofill/core/common/form_data.h" |
| 28 #include "grit/components_strings.h" | 28 #include "grit/components_strings.h" |
| 29 #include "ui/base/l10n/l10n_util_mac.h" | 29 #include "ui/base/l10n/l10n_util_mac.h" |
| 30 | 30 |
| 31 namespace autofill { | 31 namespace autofill { |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // The following two variables are intended to be shared across all instances | |
| 35 // of the personal_data_manager, and reset when Chrome is first launched. They | |
| 36 // are only intended to be accessed from the main thread. | |
|
Ilya Sherman
2014/06/14 01:18:51
There's generally no need to document that somethi
erikchen
2014/06/16 20:30:46
okay. I've removed comments about thread safety.
| |
| 37 // | |
| 38 // After each fresh launch of Chrome, if the Address Book is accessed for the | |
| 39 // first time after the binary has been changed, then the Address Book | |
| 40 // permissions dialog is guaranteed to appear. Chrome should never attempt to | |
| 41 // automatically access the Address Book on behalf of the user in this case, | |
| 42 // since it presents a blocking dialog. | |
|
Ilya Sherman
2014/06/14 01:18:51
I found it kind of hard to understand what this co
erikchen
2014/06/16 20:30:46
I've completely rewritten the comments.
| |
| 43 static bool kAccessedAddressBook = false; | |
| 44 static bool kBinaryChanged = false; | |
|
Ilya Sherman
2014/06/14 01:18:51
These are not constants, so they should not be nam
erikchen
2014/06/16 20:30:46
I renamed them as global variables. If you strongl
| |
| 45 | |
| 34 const char kAddressBookOrigin[] = "OS X Address Book"; | 46 const char kAddressBookOrigin[] = "OS X Address Book"; |
| 35 | 47 |
| 36 // Whether Chrome has prompted the user for permission to access the user's | 48 // Whether Chrome has prompted the user for permission to access the user's |
| 37 // address book. | 49 // address book. |
| 38 bool HasPromptedForAccessToAddressBook(PrefService* pref_service) { | 50 bool HasPromptedForAccessToAddressBook(PrefService* pref_service) { |
| 39 return pref_service->GetBoolean(prefs::kAutofillMacAddressBookQueried); | 51 return pref_service->GetBoolean(prefs::kAutofillMacAddressBookQueried); |
| 40 } | 52 } |
| 41 | 53 |
| 42 // Whether the user wants Chrome to use the AddressBook to populate Autofill | 54 // Whether the user wants Chrome to use the AddressBook to populate Autofill |
| 43 // entries. | 55 // entries. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 55 // crashing. http://crbug.com/129022 | 67 // crashing. http://crbug.com/129022 |
| 56 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions( | 68 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions( |
| 57 ^{ return [ABAddressBook sharedAddressBook]; }); | 69 ^{ return [ABAddressBook sharedAddressBook]; }); |
| 58 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailable", addressBook != nil); | 70 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailable", addressBook != nil); |
| 59 | 71 |
| 60 if (first_access) { | 72 if (first_access) { |
| 61 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailableOnFirstAttempt", | 73 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailableOnFirstAttempt", |
| 62 addressBook != nil); | 74 addressBook != nil); |
| 63 } | 75 } |
| 64 | 76 |
| 77 kAccessedAddressBook = true; | |
| 65 pref_service->SetBoolean(prefs::kAutofillMacAddressBookQueried, true); | 78 pref_service->SetBoolean(prefs::kAutofillMacAddressBookQueried, true); |
| 66 return addressBook; | 79 return addressBook; |
| 67 } | 80 } |
| 68 | 81 |
| 69 // This implementation makes use of the Address Book API. Profiles are | 82 // This implementation makes use of the Address Book API. Profiles are |
| 70 // generated that correspond to addresses in the "me" card that reside in the | 83 // generated that correspond to addresses in the "me" card that reside in the |
| 71 // user's Address Book. The caller passes a vector of profiles into the | 84 // user's Address Book. The caller passes a vector of profiles into the |
| 72 // the constructer and then initiate the fetch from the Mac Address Book "me" | 85 // the constructer and then initiate the fetch from the Mac Address Book "me" |
| 73 // card using the main |GetAddressBookMeCard()| method. This clears any | 86 // card using the main |GetAddressBookMeCard()| method. This clears any |
| 74 // existing addresses and populates new addresses derived from the data found | 87 // existing addresses and populates new addresses derived from the data found |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 // structures. | 127 // structures. |
| 115 void AuxiliaryProfilesImpl::GetAddressBookMeCard(const std::string& app_locale, | 128 void AuxiliaryProfilesImpl::GetAddressBookMeCard(const std::string& app_locale, |
| 116 PrefService* pref_service) { | 129 PrefService* pref_service) { |
| 117 profiles_.clear(); | 130 profiles_.clear(); |
| 118 | 131 |
| 119 // The user does not want Chrome to use the AddressBook to populate Autofill | 132 // The user does not want Chrome to use the AddressBook to populate Autofill |
| 120 // entries. | 133 // entries. |
| 121 if (!ShouldUseAddressBook(pref_service)) | 134 if (!ShouldUseAddressBook(pref_service)) |
| 122 return; | 135 return; |
| 123 | 136 |
| 137 // Do not attempt to access the Address Book on behalf of the user if this is | |
| 138 // the first access attempt since Chrome was launched, and the binary has | |
| 139 // changed. | |
|
Ilya Sherman
2014/06/14 01:18:51
Same comment applies here. If you find that it's
erikchen
2014/06/16 20:30:46
I've used your suggestion and changed the comment
| |
| 140 if (kBinaryChanged && !kAccessedAddressBook) | |
| 141 return; | |
| 142 | |
| 124 ABAddressBook* addressBook = GetAddressBook(pref_service); | 143 ABAddressBook* addressBook = GetAddressBook(pref_service); |
| 125 | 144 |
| 126 ABPerson* me = [addressBook me]; | 145 ABPerson* me = [addressBook me]; |
| 127 if (!me) | 146 if (!me) |
| 128 return; | 147 return; |
| 129 | 148 |
| 130 ABMultiValue* addresses = [me valueForProperty:kABAddressProperty]; | 149 ABMultiValue* addresses = [me valueForProperty:kABAddressProperty]; |
| 131 | 150 |
| 132 // The number of characters at the end of the GUID to reserve for | 151 // The number of characters at the end of the GUID to reserve for |
| 133 // distinguishing addresses within the "me" card. Cap the number of addresses | 152 // distinguishing addresses within the "me" card. Cap the number of addresses |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 case NO_GROUP: | 355 case NO_GROUP: |
| 337 case COMPANY: | 356 case COMPANY: |
| 338 case CREDIT_CARD: | 357 case CREDIT_CARD: |
| 339 case PASSWORD_FIELD: | 358 case PASSWORD_FIELD: |
| 340 return false; | 359 return false; |
| 341 } | 360 } |
| 342 | 361 |
| 343 return false; | 362 return false; |
| 344 } | 363 } |
| 345 | 364 |
| 365 void PersonalDataManager::BinaryChanging() { | |
| 366 kBinaryChanged = true; | |
| 367 } | |
| 368 | |
| 346 } // namespace autofill | 369 } // namespace autofill |
| OLD | NEW |