Commit d81963c3 authored by bondd's avatar bondd Committed by Commit bot

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}
parent c8f2137a
......@@ -4,39 +4,18 @@
#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"
#include "components/autofill/core/browser/options_util.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();
return WalletIntegrationAvailable(
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile),
*profile->GetPrefs(),
*PersonalDataManagerFactory::GetForProfile(profile));
}
} // namespace autofill
......@@ -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',
......
......@@ -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",
......
......@@ -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",
......
// 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
// 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_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment