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

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

Issue 578383002: mac: Only show the access Address Book prompt a fixed number of times. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@autofill-contacts
Patch Set: Comments from isherman, round 2. Created 6 years, 3 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
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 // The maximum number of instances when the access Address Book prompt should
35 // be shown.
36 int kMaxTimesToShowMacAddressBook = 5;
37
34 // There is an uncommon sequence of events that causes the Address Book 38 // 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. 39 // permissions dialog to appear more than once for a given install of Chrome.
36 // 1. Chrome has previously presented the Address Book permissions dialog. 40 // 1. Chrome has previously presented the Address Book permissions dialog.
37 // 2. Chrome is launched. 41 // 2. Chrome is launched.
38 // 3. Chrome performs an auto-update, and changes its binary. 42 // 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). 43 // 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 44 // 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 45 // Book when the user focuses most form fields, so (4) generally occurs before
42 // (3). For more details, see http://crbug.com/381763. 46 // (3). For more details, see http://crbug.com/381763.
43 // 47 //
44 // When this sequence of events does occur, Chrome should not attempt to access 48 // 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 49 // 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 50 // jarring nature of the permissions dialog is worse than the potential benefit
47 // of pulling information from the Address Book. 51 // of pulling information from the Address Book.
48 // 52 //
49 // Set to true after the Address Book is accessed for the first time. 53 // Set to true after the Address Book is accessed for the first time.
50 static bool g_accessed_address_book = false; 54 static bool g_accessed_address_book = false;
51 55
52 // Set to true after the Chrome binary has been changed. 56 // Set to true after the Chrome binary has been changed.
53 static bool g_binary_changed = false; 57 static bool g_binary_changed = false;
54 58
55 const char kAddressBookOrigin[] = "OS X Address Book"; 59 const char kAddressBookOrigin[] = "OS X Address Book";
56 60
57 // Whether Chrome has prompted the user for permission to access the user's 61 // Whether Chrome has attempted to access the Mac Address Book.
58 // address book. 62 bool HasQueriedMacAddressBook(PrefService* pref_service) {
59 bool HasPromptedForAccessToAddressBook(PrefService* pref_service) {
60 return pref_service->GetBoolean(prefs::kAutofillMacAddressBookQueried); 63 return pref_service->GetBoolean(prefs::kAutofillMacAddressBookQueried);
61 } 64 }
62 65
63 // Whether the user wants Chrome to use the AddressBook to populate Autofill 66 // Whether the user wants Chrome to use the AddressBook to populate Autofill
64 // entries. 67 // entries.
65 bool ShouldUseAddressBook(PrefService* pref_service) { 68 bool ShouldUseAddressBook(PrefService* pref_service) {
66 return pref_service->GetBoolean(prefs::kAutofillUseMacAddressBook); 69 return pref_service->GetBoolean(prefs::kAutofillUseMacAddressBook);
67 } 70 }
68 71
69 // Records a UMA metric indicating whether an attempt to access the Address 72 // 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 73 // Book was skipped because doing so would cause the Address Book permissions
71 // prompt to incorrectly appear. 74 // prompt to incorrectly appear.
72 void RecordAccessSkipped(bool skipped) { 75 void RecordAccessSkipped(bool skipped) {
73 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBook.AccessSkipped", skipped); 76 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBook.AccessSkipped", skipped);
74 } 77 }
75 78
76 ABAddressBook* GetAddressBook(PrefService* pref_service) { 79 ABAddressBook* GetAddressBook(PrefService* pref_service) {
77 bool first_access = !HasPromptedForAccessToAddressBook(pref_service); 80 bool first_access = !HasQueriedMacAddressBook(pref_service);
78 81
79 // +[ABAddressBook sharedAddressBook] throws an exception internally in 82 // +[ABAddressBook sharedAddressBook] throws an exception internally in
80 // circumstances that aren't clear. The exceptions are only observed in crash 83 // circumstances that aren't clear. The exceptions are only observed in crash
81 // reports, so it is unknown whether they would be caught by AppKit and nil 84 // reports, so it is unknown whether they would be caught by AppKit and nil
82 // returned, or if they would take down the app. In either case, avoid 85 // returned, or if they would take down the app. In either case, avoid
83 // crashing. http://crbug.com/129022 86 // crashing. http://crbug.com/129022
84 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions( 87 ABAddressBook* addressBook = base::mac::RunBlockIgnoringExceptions(
85 ^{ return [ABAddressBook sharedAddressBook]; }); 88 ^{ return [ABAddressBook sharedAddressBook]; });
86 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailable", addressBook != nil); 89 UMA_HISTOGRAM_BOOLEAN("Autofill.AddressBookAvailable", addressBook != nil);
87 90
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 bool PersonalDataManager::ShouldShowAccessAddressBookSuggestion( 367 bool PersonalDataManager::ShouldShowAccessAddressBookSuggestion(
365 AutofillType type) { 368 AutofillType type) {
366 // Don't show the access Address Book prompt if the user has built up any 369 // Don't show the access Address Book prompt if the user has built up any
367 // Autofill state. 370 // Autofill state.
368 if (!web_profiles_.empty()) 371 if (!web_profiles_.empty())
369 return false; 372 return false;
370 373
371 if (!enabled_pref_->GetValue()) 374 if (!enabled_pref_->GetValue())
372 return false; 375 return false;
373 376
374 if (HasPromptedForAccessToAddressBook(pref_service_)) 377 if (HasQueriedMacAddressBook(pref_service_))
378 return false;
379
380 if (AccessAddressBookPromptCount() >= kMaxTimesToShowMacAddressBook)
375 return false; 381 return false;
376 382
377 switch (type.group()) { 383 switch (type.group()) {
378 case ADDRESS_BILLING: 384 case ADDRESS_BILLING:
379 case ADDRESS_HOME: 385 case ADDRESS_HOME:
380 case EMAIL: 386 case EMAIL:
381 case NAME: 387 case NAME:
382 case NAME_BILLING: 388 case NAME_BILLING:
383 case PHONE_BILLING: 389 case PHONE_BILLING:
384 case PHONE_HOME: 390 case PHONE_HOME:
385 return true; 391 return true;
386 case NO_GROUP: 392 case NO_GROUP:
387 case COMPANY: 393 case COMPANY:
388 case CREDIT_CARD: 394 case CREDIT_CARD:
389 case PASSWORD_FIELD: 395 case PASSWORD_FIELD:
390 case TRANSACTION: 396 case TRANSACTION:
391 return false; 397 return false;
392 } 398 }
393 399
394 return false; 400 return false;
395 } 401 }
396 402
403 void PersonalDataManager::ShowedAccessAddressBookPrompt() {
404 pref_service_->SetInteger(prefs::kAutofillMacAddressBookShowedCount,
405 AccessAddressBookPromptCount() + 1);
406 }
407
408 int PersonalDataManager::AccessAddressBookPromptCount() {
409 return pref_service_->GetInteger(prefs::kAutofillMacAddressBookShowedCount);
410 }
411
397 void PersonalDataManager::BinaryChanging() { 412 void PersonalDataManager::BinaryChanging() {
398 g_binary_changed = true; 413 g_binary_changed = true;
399 } 414 }
400 415
401 } // namespace autofill 416 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698