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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 12221040: Interactive autofill: Handle Online Wallet being unavailable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
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 a32f09bed4b50e5f1b7107cc5eccc79633d28c48..8e01c41db8b4fad0ecee98d2262538984b968d1f 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -134,6 +134,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)),
@@ -221,7 +223,8 @@ void AutofillDialogControllerImpl::Show() {
view_->Show();
// Request sugar info after the view is showing to simplify code for now.
- wallet_client_.GetWalletItems(this);
+ if (CanPayWithWallet())
+ ScheduleRefreshWalletItems();
}
void AutofillDialogControllerImpl::Hide() {
@@ -258,14 +261,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 {
@@ -281,13 +288,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.
+ 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;
+
+ DialogSignedInState state = SignedInState();
+ return state != REQUIRES_RESPONSE && state != SIGNED_IN;
}
const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection(
@@ -559,14 +579,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("Oops, [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);
}
@@ -640,10 +668,8 @@ 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);
+ if (CanPayWithWallet())
+ ScheduleRefreshWalletItems();
}
}
@@ -678,33 +704,43 @@ 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::OnDidUpdateInstrument(
@@ -713,18 +749,15 @@ void AutofillDialogControllerImpl::OnDidUpdateInstrument(
}
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);
}
////////////////////////////////////////////////////////////////////////////////
@@ -766,6 +799,31 @@ bool AutofillDialogControllerImpl::HasRequiredAction(
return std::find(actions.begin(), actions.end(), action) != actions.end();
}
+void AutofillDialogControllerImpl::ScheduleRefreshWalletItems() {
+ DCHECK(CanPayWithWallet());
+
+ if (wallet_client_.HasRequestInProgress()) {
+ 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();
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.h ('k') | chrome/browser/ui/views/autofill/autofill_dialog_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698