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

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

Issue 13331007: Multi-account AccountChooser for interactive autocomplete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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_models.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_models.cc b/chrome/browser/ui/autofill/autofill_dialog_models.cc
index 78d7d35aa792fe7427dd444487c760d40e2b0436..4e153b9179fcdba134449af83f87f87601368c24 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_models.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_models.cc
@@ -98,8 +98,9 @@ void SuggestionsMenuModel::ExecuteCommand(int command_id, int event_flags) {
// AccountChooserModel ---------------------------------------------------------
-const int AccountChooserModel::kWalletItemId = 0;
+const int AccountChooserModel::kContentAreaWalletItemId = 0;
Evan Stade 2013/03/29 23:08:45 I do not understand this variable name or its purp
aruslan 2013/03/30 00:07:47 Done.
const int AccountChooserModel::kAutofillItemId = 1;
+const int AccountChooserModel::kFirstAccountItemId = 2;
AccountChooserModelDelegate::~AccountChooserModelDelegate() {}
@@ -109,32 +110,58 @@ AccountChooserModel::AccountChooserModel(
: ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
account_delegate_(delegate),
prefs_(prefs),
- checked_item_(kWalletItemId),
+ checked_item_(kContentAreaWalletItemId),
had_wallet_error_(false) {
pref_change_registrar_.Init(prefs);
pref_change_registrar_.Add(
prefs::kAutofillDialogPayWithoutWallet,
base::Bind(&AccountChooserModel::PrefChanged, base::Unretained(this)));
-
- // TODO(estade): proper strings and l10n.
- AddCheckItem(kWalletItemId, ASCIIToUTF16("Google Wallet"));
- SetIcon(
- kWalletItemId,
- ui::ResourceBundle::GetSharedInstance().GetImageNamed(IDR_WALLET_ICON));
- AddCheckItemWithStringId(kAutofillItemId,
- IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET);
UpdateCheckmarkFromPref();
+ ReconstructMenuItems();
}
AccountChooserModel::~AccountChooserModel() {
}
+void AccountChooserModel::ForceWalletAccountSelected() {
+ if (checked_item_ == kContentAreaWalletItemId) return;
Evan Stade 2013/03/29 23:08:45 please put return on a new line.
aruslan 2013/03/30 00:07:47 Done.
+ checked_item_ = kContentAreaWalletItemId;
+ account_delegate_->AccountChoiceChanged();
+}
+
+bool AccountChooserModel::HasAccountsToChoose() const {
+ return !had_wallet_error_ &&
+ !(current_username_.empty() && available_accounts_.empty());
+}
+
+void AccountChooserModel::SetAvailableAccounts(
+ const std::vector<std::string>& accounts) {
+ available_accounts_ = accounts;
+ ReconstructMenuItems();
+}
+
+void AccountChooserModel::SetCurrentlySignedInAccount(
+ const std::string& account) {
+ current_username_ = account;
+ ReconstructMenuItems();
+}
+
+std::string AccountChooserModel::GetCurrentlySignedInAccount() const {
+ return current_username_;
+}
+
+void AccountChooserModel::ResetCurrentlySignedInAccount() {
+ current_username_.clear();
+ ReconstructMenuItems();
+}
+
bool AccountChooserModel::IsCommandIdChecked(int command_id) const {
return command_id == checked_item_;
}
bool AccountChooserModel::IsCommandIdEnabled(int command_id) const {
- if (command_id == kWalletItemId && had_wallet_error_)
+ // Currently, _any_ (non-sign-in) error disables _all_ Wallet accounts.
+ if (command_id != kAutofillItemId && had_wallet_error_)
return false;
return true;
@@ -155,18 +182,25 @@ void AccountChooserModel::ExecuteCommand(int command_id, int event_flags) {
}
void AccountChooserModel::SetHadWalletError() {
+ // Any non-sign-in error disables all Wallet accounts.
had_wallet_error_ = true;
checked_item_ = kAutofillItemId;
+ ResetCurrentlySignedInAccount();
account_delegate_->AccountChoiceChanged();
}
void AccountChooserModel::SetHadWalletSigninError() {
checked_item_ = kAutofillItemId;
+ ResetCurrentlySignedInAccount();
account_delegate_->AccountChoiceChanged();
}
bool AccountChooserModel::WalletIsSelected() const {
- return checked_item_ == kWalletItemId;
+ return checked_item_ != kAutofillItemId;
+}
+
+bool AccountChooserModel::IsCurrentlySignedInAccountSelected() const {
+ return checked_item_ == kContentAreaWalletItemId;
}
void AccountChooserModel::PrefChanged(const std::string& pref) {
@@ -179,7 +213,32 @@ void AccountChooserModel::UpdateCheckmarkFromPref() {
if (prefs_->GetBoolean(prefs::kAutofillDialogPayWithoutWallet))
checked_item_ = kAutofillItemId;
else
- checked_item_ = kWalletItemId;
+ checked_item_ = kContentAreaWalletItemId;
+}
+
+void AccountChooserModel::ReconstructMenuItems() {
+ // If menu has to be reconstructed, either the currently sign-in account
+ // should be selected, or the autofill data should be used.
+ DCHECK_GE(kAutofillItemId, checked_item_);
+ Clear();
+ const gfx::Image& wallet_icon =
+ ui::ResourceBundle::GetSharedInstance().GetImageNamed(IDR_WALLET_ICON);
+
+ if (!current_username_.empty()) {
+ AddCheckItem(kContentAreaWalletItemId, ASCIIToUTF16(current_username_));
+ SetIcon(GetIndexOfCommandId(kContentAreaWalletItemId), wallet_icon);
+ }
+
+ for (size_t i = 0; i < available_accounts_.size(); ++i) {
+ if (available_accounts_[i] != current_username_) {
+ AddCheckItem(kFirstAccountItemId + i,
+ ASCIIToUTF16(available_accounts_[i]));
+ SetIcon(GetIndexOfCommandId(kFirstAccountItemId + i), wallet_icon);
+ }
+ }
+
+ AddCheckItemWithStringId(kAutofillItemId,
+ IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET);
}
// MonthComboboxModel ----------------------------------------------------------

Powered by Google App Engine
This is Rietveld 408576698