From d81963c3cea4912a9cdd9decc5910749374f0701 Mon Sep 17 00:00:00 2001 From: bondd Date: Fri, 8 May 2015 09:45:53 -0700 Subject: [PATCH] Autofill: Add WalletIntegrationAvailable() to components. Move logic of WalletIntegrationAvailableForProfile() function to components dir. BUG=482268 Review URL: https://codereview.chromium.org/1137513002 Cr-Commit-Position: refs/heads/master@{#328969} --- chrome/browser/autofill/options_util.cc | 63 ++++++++---------------- components/autofill.gypi | 2 + components/autofill/core/browser/BUILD.gn | 2 + components/autofill/core/browser/DEPS | 1 + components/autofill/core/browser/options_util.cc | 40 +++++++++++++++ components/autofill/core/browser/options_util.h | 27 ++++++++++ 6 files changed, 93 insertions(+), 42 deletions(-) rewrite chrome/browser/autofill/options_util.cc (64%) create mode 100644 components/autofill/core/browser/options_util.cc create mode 100644 components/autofill/core/browser/options_util.h diff --git a/chrome/browser/autofill/options_util.cc b/chrome/browser/autofill/options_util.cc dissimilarity index 64% index 389d40e44bee..e19b78f34518 100644 --- a/chrome/browser/autofill/options_util.cc +++ b/chrome/browser/autofill/options_util.cc @@ -1,42 +1,21 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/autofill/options_util.h" - -#include "base/prefs/pref_service.h" -#include "chrome/browser/autofill/personal_data_manager_factory.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/sync/profile_sync_service_factory.h" -#include "components/autofill/core/browser/personal_data_manager.h" -#include "components/autofill/core/common/autofill_pref_names.h" - -namespace autofill { - -bool WalletIntegrationAvailableForProfile(Profile* profile) { - ProfileSyncService* service = - ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); - if (!(service && service->IsSyncEnabledAndLoggedIn() && - service->GetPreferredDataTypes().Has(syncer::AUTOFILL_PROFILE))) { - return false; - } - - PersonalDataManager* pdm = PersonalDataManagerFactory::GetForProfile(profile); - if (!pdm->IsExperimentalWalletIntegrationEnabled()) - return false; - - // If the user is signed in and the feature is enabled, but no data is being - // synced, hide the option. The user doesn't have a Wallet account. If the - // feature is disabled, we can't know, so show the checkbox. - if (!profile->GetPrefs()->GetBoolean(prefs::kAutofillWalletImportEnabled)) - return true; - - // If wallet is preferred but we haven't gotten the sync data yet, we don't - // know, so show the checkbox. - if (!service->GetActiveDataTypes().Has(syncer::AUTOFILL_WALLET_DATA)) - return true; - - return pdm->HasServerData(); -} - -} // namespace autofill +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/autofill/options_util.h" + +#include "chrome/browser/autofill/personal_data_manager_factory.h" +#include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/browser/sync/profile_sync_service_factory.h" +#include "components/autofill/core/browser/options_util.h" + +namespace autofill { + +bool WalletIntegrationAvailableForProfile(Profile* profile) { + return WalletIntegrationAvailable( + ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile), + *profile->GetPrefs(), + *PersonalDataManagerFactory::GetForProfile(profile)); +} + +} // namespace autofill diff --git a/components/autofill.gypi b/components/autofill.gypi index 5e2c2bf06dae..c3c5ad2cedd4 100644 --- a/components/autofill.gypi +++ b/components/autofill.gypi @@ -162,6 +162,8 @@ 'autofill/core/browser/form_structure.h', 'autofill/core/browser/name_field.cc', 'autofill/core/browser/name_field.h', + 'autofill/core/browser/options_util.cc', + 'autofill/core/browser/options_util.h', 'autofill/core/browser/password_generator.cc', 'autofill/core/browser/password_generator.h', 'autofill/core/browser/personal_data_manager.cc', diff --git a/components/autofill/core/browser/BUILD.gn b/components/autofill/core/browser/BUILD.gn index 4500de48c4b2..2d4c79e61efd 100644 --- a/components/autofill/core/browser/BUILD.gn +++ b/components/autofill/core/browser/BUILD.gn @@ -73,6 +73,8 @@ static_library("browser") { "form_structure.h", "name_field.cc", "name_field.h", + "options_util.cc", + "options_util.h", "password_generator.cc", "password_generator.h", "personal_data_manager.cc", diff --git a/components/autofill/core/browser/DEPS b/components/autofill/core/browser/DEPS index 41b846a3752a..3e93aa1e7c84 100644 --- a/components/autofill/core/browser/DEPS +++ b/components/autofill/core/browser/DEPS @@ -3,6 +3,7 @@ include_rules = [ "+components/keyed_service/core", "+components/signin/core/browser", "+components/signin/core/common", + "+components/sync_driver", "+components/webdata/common", "+components/webdata_services", "+crypto/random.h", diff --git a/components/autofill/core/browser/options_util.cc b/components/autofill/core/browser/options_util.cc new file mode 100644 index 000000000000..fa2718649c8e --- /dev/null +++ b/components/autofill/core/browser/options_util.cc @@ -0,0 +1,40 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/autofill/core/browser/options_util.h" + +#include "base/prefs/pref_service.h" +#include "components/autofill/core/browser/personal_data_manager.h" +#include "components/autofill/core/common/autofill_pref_names.h" +#include "components/sync_driver/sync_service.h" + +namespace autofill { + +bool WalletIntegrationAvailable( + sync_driver::SyncService* sync_service, + const PrefService& pref_service, + const PersonalDataManager& personal_data_manager) { + if (!(sync_service && sync_service->IsSyncEnabledAndLoggedIn() && + sync_service->GetPreferredDataTypes().Has(syncer::AUTOFILL_PROFILE))) { + return false; + } + + if (!personal_data_manager.IsExperimentalWalletIntegrationEnabled()) + return false; + + // If the user is signed in and the feature is enabled, but no data is being + // synced, hide the option. The user doesn't have a Wallet account. If the + // feature is disabled, we can't know, so show the checkbox. + if (pref_service.GetBoolean(prefs::kAutofillWalletImportEnabled)) + return true; + + // If wallet is preferred but we haven't gotten the sync data yet, we don't + // know, so show the checkbox. + if (!sync_service->GetActiveDataTypes().Has(syncer::AUTOFILL_WALLET_DATA)) + return true; + + return personal_data_manager.HasServerData(); +} + +} // namespace autofill diff --git a/components/autofill/core/browser/options_util.h b/components/autofill/core/browser/options_util.h new file mode 100644 index 000000000000..63d38b36e61e --- /dev/null +++ b/components/autofill/core/browser/options_util.h @@ -0,0 +1,27 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_OPTIONS_UTIL_H_ +#define COMPONENTS_AUTOFILL_CORE_BROWSER_OPTIONS_UTIL_H_ + +class PrefService; + +namespace sync_driver { +class SyncService; +} + +namespace autofill { + +class PersonalDataManager; + +// Decides whether the Autofill Wallet integration is available (i.e. can be +// enabled or disabled by the user). +bool WalletIntegrationAvailable( + sync_driver::SyncService* sync_service, + const PrefService& pref_service, + const PersonalDataManager& personal_data_manager); + +} // namespace autofill + +#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_OPTIONS_UTIL_H_ -- 2.11.4.GIT