| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/autofill/account_chooser_model.h" | 5 #include "chrome/browser/ui/autofill/account_chooser_model.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 AccountChooserModel::AccountChooserModel( | 27 AccountChooserModel::AccountChooserModel( |
| 28 AccountChooserModelDelegate* delegate, | 28 AccountChooserModelDelegate* delegate, |
| 29 PrefService* prefs, | 29 PrefService* prefs, |
| 30 const AutofillMetrics& metric_logger, | 30 const AutofillMetrics& metric_logger, |
| 31 DialogType dialog_type) | 31 DialogType dialog_type) |
| 32 : ui::SimpleMenuModel(this), | 32 : ui::SimpleMenuModel(this), |
| 33 delegate_(delegate), | 33 delegate_(delegate), |
| 34 checked_item_( | 34 checked_item_( |
| 35 prefs->GetBoolean(::prefs::kAutofillDialogPayWithoutWallet) ? | 35 prefs->GetBoolean(::prefs::kAutofillDialogPayWithoutWallet) ? |
| 36 kAutofillItemId : kActiveWalletItemId), | 36 kAutofillItemId : kActiveWalletItemId), |
| 37 had_wallet_error_(false), |
| 37 metric_logger_(metric_logger), | 38 metric_logger_(metric_logger), |
| 38 dialog_type_(dialog_type) { | 39 dialog_type_(dialog_type) { |
| 39 ReconstructMenuItems(); | 40 ReconstructMenuItems(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 AccountChooserModel::~AccountChooserModel() { | 43 AccountChooserModel::~AccountChooserModel() { |
| 43 } | 44 } |
| 44 | 45 |
| 45 void AccountChooserModel::SelectActiveWalletAccount() { | 46 void AccountChooserModel::SelectActiveWalletAccount() { |
| 46 ExecuteCommand(kActiveWalletItemId, 0); | 47 ExecuteCommand(kActiveWalletItemId, 0); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 66 ReconstructMenuItems(); | 67 ReconstructMenuItems(); |
| 67 delegate_->UpdateAccountChooserView(); | 68 delegate_->UpdateAccountChooserView(); |
| 68 } | 69 } |
| 69 | 70 |
| 70 bool AccountChooserModel::IsCommandIdChecked(int command_id) const { | 71 bool AccountChooserModel::IsCommandIdChecked(int command_id) const { |
| 71 return command_id == checked_item_; | 72 return command_id == checked_item_; |
| 72 } | 73 } |
| 73 | 74 |
| 74 bool AccountChooserModel::IsCommandIdEnabled(int command_id) const { | 75 bool AccountChooserModel::IsCommandIdEnabled(int command_id) const { |
| 75 // Currently, _any_ (non-sign-in) error disables _all_ Wallet accounts. | 76 // Currently, _any_ (non-sign-in) error disables _all_ Wallet accounts. |
| 76 if (command_id != kAutofillItemId && HadWalletError()) | 77 if (command_id != kAutofillItemId && had_wallet_error_) |
| 77 return false; | 78 return false; |
| 78 | 79 |
| 79 return true; | 80 return true; |
| 80 } | 81 } |
| 81 | 82 |
| 82 bool AccountChooserModel::GetAcceleratorForCommandId( | 83 bool AccountChooserModel::GetAcceleratorForCommandId( |
| 83 int command_id, | 84 int command_id, |
| 84 ui::Accelerator* accelerator) { | 85 ui::Accelerator* accelerator) { |
| 85 return false; | 86 return false; |
| 86 } | 87 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 101 chooser_event = | 102 chooser_event = |
| 102 AutofillMetrics::DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_WALLET_ACCOUNT; | 103 AutofillMetrics::DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_WALLET_ACCOUNT; |
| 103 } | 104 } |
| 104 metric_logger_.LogDialogUiEvent(dialog_type_, chooser_event); | 105 metric_logger_.LogDialogUiEvent(dialog_type_, chooser_event); |
| 105 | 106 |
| 106 checked_item_ = command_id; | 107 checked_item_ = command_id; |
| 107 ReconstructMenuItems(); | 108 ReconstructMenuItems(); |
| 108 delegate_->AccountChoiceChanged(); | 109 delegate_->AccountChoiceChanged(); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void AccountChooserModel::SetHadWalletError(const base::string16& message) { | 112 void AccountChooserModel::SetHadWalletError() { |
| 112 // Any non-sign-in error disables all Wallet accounts. | 113 // Any non-sign-in error disables all Wallet accounts. |
| 113 wallet_error_message_ = message; | 114 had_wallet_error_ = true; |
| 114 ClearActiveWalletAccountName(); | 115 ClearActiveWalletAccountName(); |
| 115 ExecuteCommand(kAutofillItemId, 0); | 116 ExecuteCommand(kAutofillItemId, 0); |
| 116 } | 117 } |
| 117 | 118 |
| 118 bool AccountChooserModel::HadWalletError() const { | |
| 119 return !wallet_error_message_.empty(); | |
| 120 } | |
| 121 | |
| 122 void AccountChooserModel::SetHadWalletSigninError() { | 119 void AccountChooserModel::SetHadWalletSigninError() { |
| 123 ClearActiveWalletAccountName(); | 120 ClearActiveWalletAccountName(); |
| 124 ExecuteCommand(kAutofillItemId, 0); | 121 ExecuteCommand(kAutofillItemId, 0); |
| 125 } | 122 } |
| 126 | 123 |
| 127 bool AccountChooserModel::WalletIsSelected() const { | 124 bool AccountChooserModel::WalletIsSelected() const { |
| 128 return checked_item_ != kAutofillItemId; | 125 return checked_item_ != kAutofillItemId; |
| 129 } | 126 } |
| 130 | 127 |
| 131 bool AccountChooserModel::IsActiveWalletAccountSelected() const { | 128 bool AccountChooserModel::IsActiveWalletAccountSelected() const { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 147 // A throbber should be shown until the Wallet account name is set. | 144 // A throbber should be shown until the Wallet account name is set. |
| 148 AddCheckItem(kActiveWalletItemId, | 145 AddCheckItem(kActiveWalletItemId, |
| 149 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_GOOGLE_WALLET)); | 146 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_GOOGLE_WALLET)); |
| 150 } | 147 } |
| 151 | 148 |
| 152 AddCheckItemWithStringId(kAutofillItemId, | 149 AddCheckItemWithStringId(kAutofillItemId, |
| 153 IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET); | 150 IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET); |
| 154 } | 151 } |
| 155 | 152 |
| 156 } // namespace autofill | 153 } // namespace autofill |
| OLD | NEW |