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 |
| 11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #import "base/mac/scoped_nsexception_enabler.h" | 14 #import "base/mac/scoped_nsexception_enabler.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/sys_string_conversions.h" | 20 #include "base/strings/sys_string_conversions.h" |
| 21 #include "base/time/time.h" | |
| 21 #include "components/autofill/core/browser/autofill_country.h" | 22 #include "components/autofill/core/browser/autofill_country.h" |
| 22 #include "components/autofill/core/browser/autofill_profile.h" | 23 #include "components/autofill/core/browser/autofill_profile.h" |
| 23 #include "components/autofill/core/browser/autofill_type.h" | 24 #include "components/autofill/core/browser/autofill_type.h" |
| 24 #include "components/autofill/core/browser/form_structure.h" | 25 #include "components/autofill/core/browser/form_structure.h" |
| 25 #include "components/autofill/core/browser/phone_number.h" | 26 #include "components/autofill/core/browser/phone_number.h" |
| 26 #include "components/autofill/core/common/autofill_pref_names.h" | 27 #include "components/autofill/core/common/autofill_pref_names.h" |
| 27 #include "components/autofill/core/common/form_data.h" | 28 #include "components/autofill/core/common/form_data.h" |
| 28 #include "grit/components_strings.h" | 29 #include "grit/components_strings.h" |
| 29 #include "ui/base/l10n/l10n_util_mac.h" | 30 #include "ui/base/l10n/l10n_util_mac.h" |
| 30 | 31 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 // Records a UMA metric indicating whether an attempt to access the Address | 73 // Records a UMA metric indicating whether an attempt to access the Address |
| 73 // Book was skipped because doing so would cause the Address Book permissions | 74 // Book was skipped because doing so would cause the Address Book permissions |
| 74 // prompt to incorrectly appear. | 75 // prompt to incorrectly appear. |
| 75 void RecordAccessSkipped(bool skipped) { | 76 void RecordAccessSkipped(bool skipped) { |
| 76 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBook.AccessSkipped", skipped); | 77 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBook.AccessSkipped", skipped); |
| 77 } | 78 } |
| 78 | 79 |
| 79 ABAddressBook* GetAddressBook(PrefService* pref_service) { | 80 ABAddressBook* GetAddressBook(PrefService* pref_service) { |
| 80 bool first_access = !HasQueriedMacAddressBook(pref_service); | 81 bool first_access = !HasQueriedMacAddressBook(pref_service); |
| 81 | 82 |
| 83 base::Time start_time = base::Time::Now(); | |
| 82 // +[ABAddressBook sharedAddressBook] throws an exception internally in | 84 // +[ABAddressBook sharedAddressBook] throws an exception internally in |
| 83 // circumstances that aren't clear. The exceptions are only observed in crash | 85 // circumstances that aren't clear. The exceptions are only observed in crash |
| 84 // reports, so it is unknown whether they would be caught by AppKit and nil | 86 // reports, so it is unknown whether they would be caught by AppKit and nil |
| 85 // returned, or if they would take down the app. In either case, avoid | 87 // returned, or if they would take down the app. In either case, avoid |
| 86 // crashing. http://crbug.com/129022 | 88 // crashing. http://crbug.com/129022 |
| 87 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions( | 89 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions( |
| 88 ^{ return [ABAddressBook sharedAddressBook]; }); | 90 ^{ return [ABAddressBook sharedAddressBook]; }); |
| 89 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailable", addressBook != nil); | 91 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailable", addressBook != nil); |
| 90 | 92 |
| 93 if (!g_accessed_address_book) { | |
| 94 // The amount of time that the access takes gives a good indication as to | |
| 95 // whether the user was shown a prompt. | |
| 96 UMA_HISTOGRAM_TIMES("Autofill.AddressBook.AccessTime", | |
| 97 base::Time::Now() - start_time); | |
| 98 } | |
| 99 | |
| 91 if (first_access) { | 100 if (first_access) { |
| 92 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailableOnFirstAttempt", | 101 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailableOnFirstAttempt", |
| 93 addressBook != nil); | 102 addressBook != nil); |
| 94 } | 103 } |
| 95 | 104 |
| 96 g_accessed_address_book = true; | 105 g_accessed_address_book = true; |
| 97 pref_service->SetBoolean(prefs::kAutofillMacAddressBookQueried, true); | 106 pref_service->SetBoolean(prefs::kAutofillMacAddressBookQueried, true); |
| 98 return addressBook; | 107 return addressBook; |
| 99 } | 108 } |
| 100 | 109 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 RecordAccessSkipped(true); | 171 RecordAccessSkipped(true); |
| 163 return; | 172 return; |
| 164 } | 173 } |
| 165 | 174 |
| 166 if (record_metrics) | 175 if (record_metrics) |
| 167 RecordAccessSkipped(false); | 176 RecordAccessSkipped(false); |
| 168 | 177 |
| 169 ABAddressBook* addressBook = GetAddressBook(pref_service); | 178 ABAddressBook* addressBook = GetAddressBook(pref_service); |
| 170 | 179 |
| 171 ABPerson* me = [addressBook me]; | 180 ABPerson* me = [addressBook me]; |
| 172 if (!me) | 181 if (!me) { |
| 182 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBook.ContainedUsefulInformation", | |
|
Ilya Sherman
2015/05/14 21:46:28
For parallelism with existing histograms, please u
erikchen
2015/05/15 21:04:50
Done.
| |
| 183 false); | |
| 173 return; | 184 return; |
| 185 } | |
| 174 | 186 |
| 175 ABMultiValue* addresses = [me valueForProperty:kABAddressProperty]; | 187 ABMultiValue* addresses = [me valueForProperty:kABAddressProperty]; |
| 176 | 188 |
| 177 // The number of characters at the end of the GUID to reserve for | 189 // The number of characters at the end of the GUID to reserve for |
| 178 // distinguishing addresses within the "me" card. Cap the number of addresses | 190 // distinguishing addresses within the "me" card. Cap the number of addresses |
| 179 // we will fetch to the number that can be distinguished by this fragment of | 191 // we will fetch to the number that can be distinguished by this fragment of |
| 180 // the GUID. | 192 // the GUID. |
| 181 const size_t kNumAddressGUIDChars = 2; | 193 const size_t kNumAddressGUIDChars = 2; |
| 182 const size_t kNumHexDigits = 16; | 194 const size_t kNumHexDigits = 16; |
| 183 const size_t kMaxAddressCount = pow(kNumHexDigits, kNumAddressGUIDChars); | 195 const size_t kMaxAddressCount = pow(kNumHexDigits, kNumAddressGUIDChars); |
| 184 NSUInteger count = MIN([addresses count], kMaxAddressCount); | 196 NSUInteger count = MIN([addresses count], kMaxAddressCount); |
| 197 | |
| 198 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBook.ContainedUsefulInformation", | |
|
Ilya Sherman
2015/05/14 21:46:28
I'd prefer not to repeat the string constant, to a
erikchen
2015/05/15 21:04:50
Done.
| |
| 199 count != 0); | |
| 200 | |
| 185 for (NSUInteger i = 0; i < count; i++) { | 201 for (NSUInteger i = 0; i < count; i++) { |
| 186 NSDictionary* address = [addresses valueAtIndex:i]; | 202 NSDictionary* address = [addresses valueAtIndex:i]; |
| 187 NSString* addressLabelRaw = [addresses labelAtIndex:i]; | 203 NSString* addressLabelRaw = [addresses labelAtIndex:i]; |
| 188 | 204 |
| 189 // Create a new profile where the guid is set to the guid portion of the | 205 // Create a new profile where the guid is set to the guid portion of the |
| 190 // |kABUIDProperty| taken from from the "me" address. The format of | 206 // |kABUIDProperty| taken from from the "me" address. The format of |
| 191 // the |kABUIDProperty| is "<guid>:ABPerson", so we're stripping off the | 207 // the |kABUIDProperty| is "<guid>:ABPerson", so we're stripping off the |
| 192 // raw guid here and using it directly, with one modification: we update the | 208 // raw guid here and using it directly, with one modification: we update the |
| 193 // last |kNumAddressGUIDChars| characters in the GUID to reflect the address | 209 // last |kNumAddressGUIDChars| characters in the GUID to reflect the address |
| 194 // variant. Note that we capped the number of addresses above, so this is | 210 // variant. Note that we capped the number of addresses above, so this is |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 | 425 |
| 410 int PersonalDataManager::AccessAddressBookPromptCount() { | 426 int PersonalDataManager::AccessAddressBookPromptCount() { |
| 411 return pref_service_->GetInteger(prefs::kAutofillMacAddressBookShowedCount); | 427 return pref_service_->GetInteger(prefs::kAutofillMacAddressBookShowedCount); |
| 412 } | 428 } |
| 413 | 429 |
| 414 void PersonalDataManager::BinaryChanging() { | 430 void PersonalDataManager::BinaryChanging() { |
| 415 g_binary_changed = true; | 431 g_binary_changed = true; |
| 416 } | 432 } |
| 417 | 433 |
| 418 } // namespace autofill | 434 } // namespace autofill |
| OLD | NEW |