| Index: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
|
| diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
|
| index 123704ec7aba365ae787d035aad3804121a4b06e..9090c8f024d33f355c4a86048eea7fad98d0bf4f 100644
|
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
|
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
|
| @@ -133,6 +133,8 @@ AutofillDialogControllerImpl::AutofillDialogControllerImpl(
|
| ssl_status_(ssl_status),
|
| callback_(callback),
|
| wallet_client_(profile_->GetRequestContext()),
|
| + refresh_wallet_items_queued_(false),
|
| + had_wallet_error_(false),
|
| ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)),
|
| ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)),
|
| ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)),
|
| @@ -223,7 +225,7 @@ void AutofillDialogControllerImpl::Show() {
|
| view_->Show();
|
|
|
| // Request sugar info after the view is showing to simplify code for now.
|
| - wallet_client_.GetWalletItems(this);
|
| + ScheduleRefreshWalletItems();
|
| }
|
|
|
| void AutofillDialogControllerImpl::Hide() {
|
| @@ -260,14 +262,18 @@ string16 AutofillDialogControllerImpl::ConfirmButtonText() const {
|
| return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON);
|
| }
|
|
|
| -string16 AutofillDialogControllerImpl::SignInText() const {
|
| +string16 AutofillDialogControllerImpl::CancelSignInText() const {
|
| // TODO(abodenha): real strings and l10n.
|
| - return string16(ASCIIToUTF16("Sign in to use Google Wallet"));
|
| + return ASCIIToUTF16("Don't sign in.");
|
| }
|
|
|
| -string16 AutofillDialogControllerImpl::CancelSignInText() const {
|
| - // TODO(abodenha): real strings and l10n.
|
| - return string16(ASCIIToUTF16("Don't sign in."));
|
| +string16 AutofillDialogControllerImpl::SaveLocallyText() const {
|
| + return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX);
|
| +}
|
| +
|
| +string16 AutofillDialogControllerImpl::ProgressBarText() const {
|
| + return l10n_util::GetStringUTF16(
|
| + IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR);
|
| }
|
|
|
| DialogSignedInState AutofillDialogControllerImpl::SignedInState() const {
|
| @@ -283,13 +289,26 @@ DialogSignedInState AutofillDialogControllerImpl::SignedInState() const {
|
| return SIGNED_IN;
|
| }
|
|
|
| -string16 AutofillDialogControllerImpl::SaveLocallyText() const {
|
| - return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX);
|
| +bool AutofillDialogControllerImpl::CanPayWithWallet() const {
|
| + return !had_wallet_error_;
|
| }
|
|
|
| -string16 AutofillDialogControllerImpl::ProgressBarText() const {
|
| - return l10n_util::GetStringUTF16(
|
| - IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR);
|
| +string16 AutofillDialogControllerImpl::AccountChooserText() const {
|
| + if (!CanPayWithWallet())
|
| + return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET);
|
| +
|
| + // TODO(dbeam): real strings and l10n.
|
| + const DialogSignedInState& state = SignedInState();
|
| + return state != SIGNED_IN ? ASCIIToUTF16("Sign in to use Google Wallet") :
|
| + ASCIIToUTF16("user@example.com");
|
| +}
|
| +
|
| +bool AutofillDialogControllerImpl::AccountChooserEnabled() const {
|
| + if (!CanPayWithWallet())
|
| + return false;
|
| +
|
| + const DialogSignedInState& state = SignedInState();
|
| + return state != REQUIRES_RESPONSE && state != SIGNED_IN;
|
| }
|
|
|
| const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection(
|
| @@ -554,14 +573,22 @@ DialogNotification AutofillDialogControllerImpl::CurrentNotification() const {
|
| IDS_AUTOFILL_DIALOG_SITE_WARNING, UTF8ToUTF16(source_url_.host())));
|
| }
|
|
|
| + if (!CanPayWithWallet()) {
|
| + // TODO(dbeam): pass along the Wallet error or remove from the translation.
|
| + return DialogNotification(
|
| + DialogNotification::WALLET_ERROR,
|
| + l10n_util::GetStringFUTF16(
|
| + IDS_AUTOFILL_DIALOG_COMPLETE_WITHOUT_WALLET,
|
| + ASCIIToUTF16("[Wallet-Error].")));
|
| + }
|
| +
|
| return DialogNotification();
|
| }
|
|
|
| void AutofillDialogControllerImpl::StartSignInFlow() {
|
| DCHECK(registrar_.IsEmpty());
|
|
|
| - content::Source<content::NavigationController> source(
|
| - &view_->ShowSignIn());
|
| + content::Source<content::NavigationController> source(&view_->ShowSignIn());
|
| registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source);
|
| }
|
|
|
| @@ -633,10 +660,7 @@ void AutofillDialogControllerImpl::Observe(
|
| content::Details<content::LoadCommittedDetails>(details).ptr();
|
| if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) {
|
| EndSignInFlow();
|
| - // TODO(dbeam): the fetcher can't handle being called multiple times.
|
| - // Address this soon as we will be re-fetching wallet items after every
|
| - // required action is resolved.
|
| - wallet_client_.GetWalletItems(this);
|
| + ScheduleRefreshWalletItems();
|
| }
|
| }
|
|
|
| @@ -671,48 +695,55 @@ void AutofillDialogControllerImpl::OnDidEscrowSensitiveInformation(
|
| void AutofillDialogControllerImpl::OnDidGetFullWallet(
|
| scoped_ptr<wallet::FullWallet> full_wallet) {
|
| NOTIMPLEMENTED();
|
| + WalletRequestCompleted(true);
|
| }
|
|
|
| void AutofillDialogControllerImpl::OnDidGetWalletItems(
|
| scoped_ptr<wallet::WalletItems> wallet_items) {
|
| + bool items_changed = !wallet_items_ || *wallet_items != *wallet_items_;
|
| wallet_items_ = wallet_items.Pass();
|
| - view_->UpdateAccountChooser();
|
| - view_->UpdateNotificationArea();
|
| + WalletRequestCompleted(true);
|
| +
|
| + if (items_changed) {
|
| + view_->UpdateAccountChooser();
|
| + view_->UpdateNotificationArea();
|
| + }
|
| }
|
|
|
| void AutofillDialogControllerImpl::OnDidSaveAddress(
|
| const std::string& address_id) {
|
| NOTIMPLEMENTED() << " address_id=" << address_id;
|
| + WalletRequestCompleted(true);
|
| }
|
|
|
| void AutofillDialogControllerImpl::OnDidSaveInstrument(
|
| const std::string& instrument_id) {
|
| NOTIMPLEMENTED() << " instrument_id=" << instrument_id;
|
| + WalletRequestCompleted(true);
|
| }
|
|
|
| void AutofillDialogControllerImpl::OnDidSaveInstrumentAndAddress(
|
| const std::string& instrument_id, const std::string& address_id) {
|
| NOTIMPLEMENTED() << " instrument_id=" << instrument_id
|
| << ", address_id=" << address_id;
|
| + WalletRequestCompleted(true);
|
| }
|
|
|
| void AutofillDialogControllerImpl::OnDidSendAutocheckoutStatus() {
|
| NOTIMPLEMENTED();
|
| + WalletRequestCompleted(true);
|
| }
|
|
|
| void AutofillDialogControllerImpl::OnWalletError() {
|
| - NOTIMPLEMENTED();
|
| - wallet_items_.reset();
|
| + WalletRequestCompleted(false);
|
| }
|
|
|
| void AutofillDialogControllerImpl::OnMalformedResponse() {
|
| - NOTIMPLEMENTED();
|
| - wallet_items_.reset();
|
| + WalletRequestCompleted(false);
|
| }
|
|
|
| void AutofillDialogControllerImpl::OnNetworkError(int response_code) {
|
| - NOTIMPLEMENTED() << " response_code=" << response_code;
|
| - wallet_items_.reset();
|
| + WalletRequestCompleted(false);
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -754,6 +785,32 @@ bool AutofillDialogControllerImpl::HasRequiredAction(
|
| return std::find(actions.begin(), actions.end(), action) != actions.end();
|
| }
|
|
|
| +void AutofillDialogControllerImpl::ScheduleRefreshWalletItems() {
|
| + if (!CanPayWithWallet())
|
| + return;
|
| +
|
| + if (wallet_client_.IsRequestInProgress()) {
|
| + refresh_wallet_items_queued_ = true;
|
| + return;
|
| + }
|
| +
|
| + wallet_client_.GetWalletItems(this);
|
| + refresh_wallet_items_queued_ = false;
|
| +}
|
| +
|
| +void AutofillDialogControllerImpl::WalletRequestCompleted(bool success) {
|
| + if (!success) {
|
| + had_wallet_error_ = true;
|
| + wallet_items_.reset();
|
| + view_->UpdateAccountChooser();
|
| + view_->UpdateNotificationArea();
|
| + return;
|
| + }
|
| +
|
| + if (refresh_wallet_items_queued_)
|
| + ScheduleRefreshWalletItems();
|
| +}
|
| +
|
| void AutofillDialogControllerImpl::GenerateSuggestionsModels() {
|
| PersonalDataManager* manager = GetManager();
|
| const std::vector<CreditCard*>& cards = manager->credit_cards();
|
|
|