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

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 estade. 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 //
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 bool PersonalDataManager::ShouldShowAccessAddressBookSuggestion( 368 bool PersonalDataManager::ShouldShowAccessAddressBookSuggestion(
365 AutofillType type) { 369 AutofillType type) {
366 // Don't show the access Address Book prompt if the user has built up any 370 // Don't show the access Address Book prompt if the user has built up any
367 // Autofill state. 371 // Autofill state.
368 if (!web_profiles_.empty()) 372 if (!web_profiles_.empty())
369 return false; 373 return false;
370 374
371 if (!enabled_pref_->GetValue()) 375 if (!enabled_pref_->GetValue())
372 return false; 376 return false;
373 377
374 if (HasPromptedForAccessToAddressBook(pref_service_)) 378 if (HasPromptedForAccessToAddressBook(pref_service_))
Evan Stade 2014/09/18 22:06:09 this is pretty confusing function naming. HasPromp
erikchen 2014/09/18 22:49:50 I went with the name of the preference, which uses
375 return false; 379 return false;
376 380
381 if (AccessAddressBookPromptCount() >= kMaxTimesToShowMacAddressBook)
382 return false;
383
377 switch (type.group()) { 384 switch (type.group()) {
378 case ADDRESS_BILLING: 385 case ADDRESS_BILLING:
379 case ADDRESS_HOME: 386 case ADDRESS_HOME:
380 case EMAIL: 387 case EMAIL:
381 case NAME: 388 case NAME:
382 case NAME_BILLING: 389 case NAME_BILLING:
383 case PHONE_BILLING: 390 case PHONE_BILLING:
384 case PHONE_HOME: 391 case PHONE_HOME:
385 return true; 392 return true;
386 case NO_GROUP: 393 case NO_GROUP:
387 case COMPANY: 394 case COMPANY:
388 case CREDIT_CARD: 395 case CREDIT_CARD:
389 case PASSWORD_FIELD: 396 case PASSWORD_FIELD:
390 case TRANSACTION: 397 case TRANSACTION:
391 return false; 398 return false;
392 } 399 }
393 400
394 return false; 401 return false;
395 } 402 }
396 403
404 void PersonalDataManager::ShowedAccessAddressBookPrompt() {
405 pref_service_->SetInteger(prefs::kAutofillMacAddressBookShowedCount,
406 AccessAddressBookPromptCount() + 1);
407 }
408
409 int PersonalDataManager::AccessAddressBookPromptCount() {
410 return pref_service_->GetInteger(prefs::kAutofillMacAddressBookShowedCount);
411 }
412
397 void PersonalDataManager::BinaryChanging() { 413 void PersonalDataManager::BinaryChanging() {
398 g_binary_changed = true; 414 g_binary_changed = true;
399 } 415 }
400 416
401 } // namespace autofill 417 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698