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

Side by Side Diff: components/autofill/core/browser/personal_data_manager_mac.mm

Issue 334653006: mac: Prevent Address Book permissions dialog from erroneously appearing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to isherman comments. Created 6 years, 6 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 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
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 // There is an uncommon sequence of events that causes the Address Book
35 // permissions dialog to appear more than once for a given install of Chrome.
36 // 1. Chrome has previously presented the Address Book permissions dialog.
37 // 2. Chrome is launched.
38 // 3. Chrome performs an auto-update, and changes its binary.
39 // 4. Chrome attempts to access the Address Book for the first time since (2).
40 // This sequence of events is rare because Chrome attempts to acess the Address
41 // Book when the user focuses most form fields, so (4) generally occurs before
42 // (3). For more details, see http://crbug.com/381763.
43 //
44 // When this sequence of events does occur, Chrome should not attempt to access
45 // the Address Book unless the user explicitly asks Chrome to do so. The
46 // jarring nature of the permissions dialog is worse than the potential benefit
47 // of pulling information from the Address Book.
48 //
49 // Set to true after the Address Book is accessed for the first time.
50 static bool g_accessed_address_book = false;
51
52 // Set to true after the Chrome binary has been changed.
53 static bool g_binary_changed = false;
54
34 const char kAddressBookOrigin[] = "OS X Address Book"; 55 const char kAddressBookOrigin[] = "OS X Address Book";
35 56
36 // Whether Chrome has prompted the user for permission to access the user's 57 // Whether Chrome has prompted the user for permission to access the user's
37 // address book. 58 // address book.
38 bool HasPromptedForAccessToAddressBook(PrefService* pref_service) { 59 bool HasPromptedForAccessToAddressBook(PrefService* pref_service) {
39 return pref_service->GetBoolean(prefs::kAutofillMacAddressBookQueried); 60 return pref_service->GetBoolean(prefs::kAutofillMacAddressBookQueried);
40 } 61 }
41 62
42 // Whether the user wants Chrome to use the AddressBook to populate Autofill 63 // Whether the user wants Chrome to use the AddressBook to populate Autofill
43 // entries. 64 // entries.
44 bool ShouldUseAddressBook(PrefService* pref_service) { 65 bool ShouldUseAddressBook(PrefService* pref_service) {
45 return pref_service->GetBoolean(prefs::kAutofillUseMacAddressBook); 66 return pref_service->GetBoolean(prefs::kAutofillUseMacAddressBook);
46 } 67 }
47 68
69 // Records a UMA metric indicating whether an attempt to access the Address
70 // Book was skipped because doing so would cause the Address Book permissions
71 // prompt to incorrectly appear.
72 void RecordSkipReprompt(bool skip) {
73 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookReprompt", skip);
74 }
75
48 ABAddressBook* GetAddressBook(PrefService* pref_service) { 76 ABAddressBook* GetAddressBook(PrefService* pref_service) {
49 bool first_access = !HasPromptedForAccessToAddressBook(pref_service); 77 bool first_access = !HasPromptedForAccessToAddressBook(pref_service);
50 78
51 // +[ABAddressBook sharedAddressBook] throws an exception internally in 79 // +[ABAddressBook sharedAddressBook] throws an exception internally in
52 // circumstances that aren't clear. The exceptions are only observed in crash 80 // circumstances that aren't clear. The exceptions are only observed in crash
53 // reports, so it is unknown whether they would be caught by AppKit and nil 81 // reports, so it is unknown whether they would be caught by AppKit and nil
54 // returned, or if they would take down the app. In either case, avoid 82 // returned, or if they would take down the app. In either case, avoid
55 // crashing. http://crbug.com/129022 83 // crashing. http://crbug.com/129022
56 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions( 84 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions(
57 ^{ return [ABAddressBook sharedAddressBook]; }); 85 ^{ return [ABAddressBook sharedAddressBook]; });
58 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailable", addressBook != nil); 86 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailable", addressBook != nil);
59 87
60 if (first_access) { 88 if (first_access) {
61 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailableOnFirstAttempt", 89 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailableOnFirstAttempt",
62 addressBook != nil); 90 addressBook != nil);
63 } 91 }
64 92
93 g_accessed_address_book = true;
65 pref_service->SetBoolean(prefs::kAutofillMacAddressBookQueried, true); 94 pref_service->SetBoolean(prefs::kAutofillMacAddressBookQueried, true);
66 return addressBook; 95 return addressBook;
67 } 96 }
68 97
69 // This implementation makes use of the Address Book API. Profiles are 98 // 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 99 // 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 100 // 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" 101 // the constructer and then initiate the fetch from the Mac Address Book "me"
73 // card using the main |GetAddressBookMeCard()| method. This clears any 102 // card using the main |GetAddressBookMeCard()| method. This clears any
74 // existing addresses and populates new addresses derived from the data found 103 // existing addresses and populates new addresses derived from the data found
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // structures. 143 // structures.
115 void AuxiliaryProfilesImpl::GetAddressBookMeCard(const std::string& app_locale, 144 void AuxiliaryProfilesImpl::GetAddressBookMeCard(const std::string& app_locale,
116 PrefService* pref_service) { 145 PrefService* pref_service) {
117 profiles_.clear(); 146 profiles_.clear();
118 147
119 // The user does not want Chrome to use the AddressBook to populate Autofill 148 // The user does not want Chrome to use the AddressBook to populate Autofill
120 // entries. 149 // entries.
121 if (!ShouldUseAddressBook(pref_service)) 150 if (!ShouldUseAddressBook(pref_service))
122 return; 151 return;
123 152
153 // See the comment at the definition of g_accessed_address_book for an
154 // explanation of this logic.
155 if (g_binary_changed && !g_accessed_address_book) {
156 RecordSkipReprompt(true);
157 return;
158 }
159 RecordSkipReprompt(false);
Ilya Sherman 2014/06/17 19:55:01 This isn't actually guaranteed to be called only w
erikchen 2014/06/17 22:36:06 I think that the question you are trying to answer
Ilya Sherman 2014/06/17 23:50:34 The trouble with this approximation is that we cur
160
124 ABAddressBook* addressBook = GetAddressBook(pref_service); 161 ABAddressBook* addressBook = GetAddressBook(pref_service);
125 162
126 ABPerson* me = [addressBook me]; 163 ABPerson* me = [addressBook me];
127 if (!me) 164 if (!me)
128 return; 165 return;
129 166
130 ABMultiValue* addresses = [me valueForProperty:kABAddressProperty]; 167 ABMultiValue* addresses = [me valueForProperty:kABAddressProperty];
131 168
132 // The number of characters at the end of the GUID to reserve for 169 // 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 170 // distinguishing addresses within the "me" card. Cap the number of addresses
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 case NO_GROUP: 373 case NO_GROUP:
337 case COMPANY: 374 case COMPANY:
338 case CREDIT_CARD: 375 case CREDIT_CARD:
339 case PASSWORD_FIELD: 376 case PASSWORD_FIELD:
340 return false; 377 return false;
341 } 378 }
342 379
343 return false; 380 return false;
344 } 381 }
345 382
383 void PersonalDataManager::BinaryChanging() {
384 g_binary_changed = true;
385 }
386
346 } // namespace autofill 387 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698