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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_models.cc

Issue 13625002: Change the behavior of the [X] Save details to Wallet checkbox notification to: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/autofill_dialog_models.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_models.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/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 const int AccountChooserModel::kWalletItemId = 0; 101 const int AccountChooserModel::kWalletItemId = 0;
102 const int AccountChooserModel::kAutofillItemId = 1; 102 const int AccountChooserModel::kAutofillItemId = 1;
103 103
104 AccountChooserModelDelegate::~AccountChooserModelDelegate() {} 104 AccountChooserModelDelegate::~AccountChooserModelDelegate() {}
105 105
106 AccountChooserModel::AccountChooserModel( 106 AccountChooserModel::AccountChooserModel(
107 AccountChooserModelDelegate* delegate, 107 AccountChooserModelDelegate* delegate,
108 PrefService* prefs) 108 PrefService* prefs)
109 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), 109 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
110 account_delegate_(delegate), 110 account_delegate_(delegate),
111 prefs_(prefs), 111 checked_item_(prefs->GetBoolean(prefs::kAutofillDialogPayWithoutWallet) ?
112 checked_item_(kWalletItemId), 112 kAutofillItemId : kWalletItemId),
113 had_wallet_error_(false) { 113 had_wallet_error_(false) {
114 pref_change_registrar_.Init(prefs);
115 pref_change_registrar_.Add(
116 prefs::kAutofillDialogPayWithoutWallet,
117 base::Bind(&AccountChooserModel::PrefChanged, base::Unretained(this)));
118
119 AddCheckItem(kWalletItemId, 114 AddCheckItem(kWalletItemId,
120 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_GOOGLE_WALLET)); 115 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_GOOGLE_WALLET));
121 SetIcon( 116 SetIcon(
122 kWalletItemId, 117 kWalletItemId,
123 ui::ResourceBundle::GetSharedInstance().GetImageNamed(IDR_WALLET_ICON)); 118 ui::ResourceBundle::GetSharedInstance().GetImageNamed(IDR_WALLET_ICON));
124 AddCheckItemWithStringId(kAutofillItemId, 119 AddCheckItemWithStringId(kAutofillItemId,
125 IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET); 120 IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET);
126 UpdateCheckmarkFromPref();
127 } 121 }
128 122
129 AccountChooserModel::~AccountChooserModel() { 123 AccountChooserModel::~AccountChooserModel() {
130 } 124 }
131 125
132 bool AccountChooserModel::IsCommandIdChecked(int command_id) const { 126 bool AccountChooserModel::IsCommandIdChecked(int command_id) const {
133 return command_id == checked_item_; 127 return command_id == checked_item_;
134 } 128 }
135 129
136 bool AccountChooserModel::IsCommandIdEnabled(int command_id) const { 130 bool AccountChooserModel::IsCommandIdEnabled(int command_id) const {
(...skipping 12 matching lines...) Expand all
149 void AccountChooserModel::ExecuteCommand(int command_id, int event_flags) { 143 void AccountChooserModel::ExecuteCommand(int command_id, int event_flags) {
150 if (checked_item_ == command_id) 144 if (checked_item_ == command_id)
151 return; 145 return;
152 146
153 checked_item_ = command_id; 147 checked_item_ = command_id;
154 account_delegate_->AccountChoiceChanged(); 148 account_delegate_->AccountChoiceChanged();
155 } 149 }
156 150
157 void AccountChooserModel::SetHadWalletError() { 151 void AccountChooserModel::SetHadWalletError() {
158 had_wallet_error_ = true; 152 had_wallet_error_ = true;
159 checked_item_ = kAutofillItemId; 153 ExecuteCommand(kAutofillItemId, 0);
160 account_delegate_->AccountChoiceChanged();
161 } 154 }
162 155
163 void AccountChooserModel::SetHadWalletSigninError() { 156 void AccountChooserModel::SetHadWalletSigninError() {
164 checked_item_ = kAutofillItemId; 157 ExecuteCommand(kAutofillItemId, 0);
165 account_delegate_->AccountChoiceChanged();
166 } 158 }
167 159
168 bool AccountChooserModel::WalletIsSelected() const { 160 bool AccountChooserModel::WalletIsSelected() const {
169 return checked_item_ == kWalletItemId; 161 return checked_item_ == kWalletItemId;
170 } 162 }
171 163
172 void AccountChooserModel::PrefChanged(const std::string& pref) {
173 DCHECK(pref == prefs::kAutofillDialogPayWithoutWallet);
174 UpdateCheckmarkFromPref();
175 account_delegate_->AccountChoiceChanged();
176 }
177
178 void AccountChooserModel::UpdateCheckmarkFromPref() {
179 if (prefs_->GetBoolean(prefs::kAutofillDialogPayWithoutWallet))
180 checked_item_ = kAutofillItemId;
181 else
182 checked_item_ = kWalletItemId;
183 }
184
185 // MonthComboboxModel ---------------------------------------------------------- 164 // MonthComboboxModel ----------------------------------------------------------
186 165
187 MonthComboboxModel::MonthComboboxModel() {} 166 MonthComboboxModel::MonthComboboxModel() {}
188 167
189 MonthComboboxModel::~MonthComboboxModel() {} 168 MonthComboboxModel::~MonthComboboxModel() {}
190 169
191 int MonthComboboxModel::GetItemCount() const { 170 int MonthComboboxModel::GetItemCount() const {
192 // 12 months plus the empty entry. 171 // 12 months plus the empty entry.
193 return 13; 172 return 13;
194 } 173 }
(...skipping 24 matching lines...) Expand all
219 } 198 }
220 199
221 string16 YearComboboxModel::GetItemAt(int index) { 200 string16 YearComboboxModel::GetItemAt(int index) {
222 if (index == 0) 201 if (index == 0)
223 return string16(); 202 return string16();
224 203
225 return base::IntToString16(this_year_ + index - 1); 204 return base::IntToString16(this_year_ + index - 1);
226 } 205 }
227 206
228 } // autofill 207 } // autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_models.h ('k') | chrome/browser/ui/autofill/autofill_dialog_models_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698