Commit 316283d4 authored by estade's avatar estade Committed by Commit bot

Hide Wallet checkbox when user signs out of sync.

BUG=467775

Review URL: https://codereview.chromium.org/1014913003

Cr-Commit-Position: refs/heads/master@{#321482}
parent dbcd3d6b
......@@ -89,9 +89,8 @@ cr.define('options', function() {
return true; // Always follow the href
};
var enableWalletIntegration =
loadTimeData.getBoolean('enableAutofillWalletIntegration');
$('autofill-wallet-setting-area').hidden = !enableWalletIntegration;
this.walletIntegrationAvailableStateChanged_(
loadTimeData.getBoolean('autofillWalletIntegrationAvailable'));
// TODO(jhawkins): What happens when Autofill is disabled whilst on the
// Autofill options page?
......@@ -229,6 +228,16 @@ cr.define('options', function() {
AutofillEditCreditCardOverlay.loadCreditCard(creditCard);
PageManager.showPageByName('autofillEditCreditCard');
},
/**
* Toggles the visibility of the Wallet integration checkbox.
* @param {boolean} available Whether the user has the option of using
* Wallet data.
* @private
*/
walletIntegrationAvailableStateChanged_: function(available) {
$('autofill-wallet-setting-area').hidden = !available;
},
};
AutofillOptions.setAddressList = function(entries) {
......@@ -255,6 +264,11 @@ cr.define('options', function() {
AutofillOptions.getInstance().showEditAddressOverlay_(address);
};
AutofillOptions.walletIntegrationAvailableStateChanged = function(available) {
AutofillOptions.getInstance().
walletIntegrationAvailableStateChanged_(available);
};
/**
* @param {CreditCardData} creditCard
*/
......
......@@ -19,7 +19,6 @@
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/autofill/country_combobox_model.h"
#include "chrome/common/url_constants.h"
......@@ -316,7 +315,8 @@ scoped_ptr<base::ListValue> ValidatePhoneArguments(
namespace options {
AutofillOptionsHandler::AutofillOptionsHandler()
: personal_data_(NULL) {}
: personal_data_(NULL), observer_(this) {
}
AutofillOptionsHandler::~AutofillOptionsHandler() {
if (personal_data_)
......@@ -361,19 +361,24 @@ void AutofillOptionsHandler::GetLocalizedValues(
SetAddressOverlayStrings(localized_strings);
SetCreditCardOverlayStrings(localized_strings);
ProfileSyncService* service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(
Profile::FromWebUI(web_ui()));
localized_strings->SetBoolean(
"enableAutofillWalletIntegration",
service && service->IsSyncEnabledAndLoggedIn() &&
personal_data_->IsExperimentalWalletIntegrationEnabled());
localized_strings->SetString(
"manageWalletAddressesUrl",
autofill::wallet::GetManageAddressesUrl(0).spec());
localized_strings->SetString(
"manageWalletPaymentMethodsUrl",
autofill::wallet::GetManageInstrumentsUrl(0).spec());
// This is set in loadTimeData to minimize the chance of a load-time flash of
// content.
ProfileSyncService* service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(
Profile::FromWebUI(web_ui()));
if (service)
observer_.Add(service);
localized_strings->SetBoolean(
"autofillWalletIntegrationAvailable",
service && service->IsSyncEnabledAndLoggedIn() &&
personal_data_->IsExperimentalWalletIntegrationEnabled());
}
void AutofillOptionsHandler::InitializeHandler() {
......@@ -385,6 +390,10 @@ void AutofillOptionsHandler::InitializeHandler() {
void AutofillOptionsHandler::InitializePage() {
if (personal_data_)
LoadAutofillData();
// Also update the visibility of the Wallet checkbox (which may have
// changed since the localized string dictionary was built).
OnStateChanged();
}
void AutofillOptionsHandler::RegisterMessages() {
......@@ -433,6 +442,15 @@ void AutofillOptionsHandler::OnPersonalDataChanged() {
LoadAutofillData();
}
void AutofillOptionsHandler::OnStateChanged() {
ProfileSyncService* service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(
Profile::FromWebUI(web_ui()));
web_ui()->CallJavascriptFunction(
"AutofillOptions.walletIntegrationAvailableStateChanged",
base::FundamentalValue(service && service->IsSyncEnabledAndLoggedIn()));
}
void AutofillOptionsHandler::SetAddressOverlayStrings(
base::DictionaryValue* localized_strings) {
localized_strings->SetString("autofillEditAddressTitle",
......
......@@ -8,6 +8,8 @@
#include <string>
#include "base/compiler_specific.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_observer.h"
#include "chrome/browser/ui/webui/options/options_ui.h"
#include "components/autofill/core/browser/personal_data_manager_observer.h"
......@@ -24,7 +26,8 @@ class ListValue;
namespace options {
class AutofillOptionsHandler : public OptionsPageUIHandler,
public autofill::PersonalDataManagerObserver {
public autofill::PersonalDataManagerObserver,
public ProfileSyncServiceObserver {
public:
AutofillOptionsHandler();
~AutofillOptionsHandler() override;
......@@ -38,6 +41,9 @@ class AutofillOptionsHandler : public OptionsPageUIHandler,
// PersonalDataManagerObserver implementation.
void OnPersonalDataChanged() override;
// ProfileSyncServiceObserver implementation.
void OnStateChanged() override;
private:
FRIEND_TEST_ALL_PREFIXES(AutofillOptionsHandlerTest, AddressToDictionary);
......@@ -110,6 +116,9 @@ class AutofillOptionsHandler : public OptionsPageUIHandler,
// Unowned pointer, may not be NULL.
autofill::PersonalDataManager* personal_data_;
ScopedObserver<ProfileSyncService, ProfileSyncServiceBase::Observer>
observer_;
DISALLOW_COPY_AND_ASSIGN(AutofillOptionsHandler);
};
......
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