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

Side by Side 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: Rebase after https://chromiumcodereview.appspot.com/13870019 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"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
14 #include "components/autofill/browser/autofill_country.h" 14 #include "components/autofill/browser/autofill_country.h"
15 #include "components/autofill/browser/autofill_metrics.h"
16 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
17 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
18 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
20 19
21 namespace autofill { 20 namespace autofill {
22 21
23 SuggestionsMenuModelDelegate::~SuggestionsMenuModelDelegate() {} 22 SuggestionsMenuModelDelegate::~SuggestionsMenuModelDelegate() {}
24 23
25 // SuggestionsMenuModel ---------------------------------------------------- 24 // SuggestionsMenuModel ----------------------------------------------------
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 int command_id, 89 int command_id,
91 ui::Accelerator* accelerator) { 90 ui::Accelerator* accelerator) {
92 return false; 91 return false;
93 } 92 }
94 93
95 void SuggestionsMenuModel::ExecuteCommand(int command_id, int event_flags) { 94 void SuggestionsMenuModel::ExecuteCommand(int command_id, int event_flags) {
96 checked_item_ = command_id; 95 checked_item_ = command_id;
97 delegate_->SuggestionItemSelected(*this); 96 delegate_->SuggestionItemSelected(*this);
98 } 97 }
99 98
100 // AccountChooserModel ---------------------------------------------------------
101
102 const int AccountChooserModel::kWalletItemId = 0;
103 const int AccountChooserModel::kAutofillItemId = 1;
104
105 AccountChooserModelDelegate::~AccountChooserModelDelegate() {}
106
107 AccountChooserModel::AccountChooserModel(
108 AccountChooserModelDelegate* delegate,
109 PrefService* prefs,
110 const AutofillMetrics& metric_logger,
111 DialogType dialog_type)
112 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
113 account_delegate_(delegate),
114 checked_item_(
115 prefs->GetBoolean(::prefs::kAutofillDialogPayWithoutWallet) ?
116 kAutofillItemId : kWalletItemId),
117 had_wallet_error_(false),
118 metric_logger_(metric_logger),
119 dialog_type_(dialog_type) {
120 AddCheckItem(kWalletItemId,
121 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_GOOGLE_WALLET));
122 SetIcon(
123 kWalletItemId,
124 ui::ResourceBundle::GetSharedInstance().GetImageNamed(IDR_WALLET_ICON));
125 AddCheckItemWithStringId(kAutofillItemId,
126 IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET);
127 }
128
129 AccountChooserModel::~AccountChooserModel() {
130 }
131
132 bool AccountChooserModel::IsCommandIdChecked(int command_id) const {
133 return command_id == checked_item_;
134 }
135
136 bool AccountChooserModel::IsCommandIdEnabled(int command_id) const {
137 if (command_id == kWalletItemId && had_wallet_error_)
138 return false;
139
140 return true;
141 }
142
143 bool AccountChooserModel::GetAcceleratorForCommandId(
144 int command_id,
145 ui::Accelerator* accelerator) {
146 return false;
147 }
148
149 void AccountChooserModel::ExecuteCommand(int command_id, int event_flags) {
150 if (checked_item_ == command_id)
151 return;
152
153 // Log metrics.
154 AutofillMetrics::DialogUiEvent chooser_event;
155 if (command_id == kAutofillItemId) {
156 chooser_event =
157 AutofillMetrics::DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_TO_AUTOFILL;
158 } else if (checked_item_ == kAutofillItemId) {
159 chooser_event =
160 AutofillMetrics::DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_TO_WALLET;
161 } else {
162 chooser_event =
163 AutofillMetrics::DIALOG_UI_ACCOUNT_CHOOSER_SWITCHED_WALLET_ACCOUNT;
164 }
165 metric_logger_.LogDialogUiEvent(dialog_type_, chooser_event);
166
167 checked_item_ = command_id;
168 account_delegate_->AccountChoiceChanged();
169 }
170
171 void AccountChooserModel::SetHadWalletError() {
172 had_wallet_error_ = true;
173 ExecuteCommand(kAutofillItemId, 0);
174 }
175
176 void AccountChooserModel::SetHadWalletSigninError() {
177 ExecuteCommand(kAutofillItemId, 0);
178 }
179
180 bool AccountChooserModel::WalletIsSelected() const {
181 return checked_item_ == kWalletItemId;
182 }
183
184 // MonthComboboxModel ---------------------------------------------------------- 99 // MonthComboboxModel ----------------------------------------------------------
185 100
186 MonthComboboxModel::MonthComboboxModel() {} 101 MonthComboboxModel::MonthComboboxModel() {}
187 102
188 MonthComboboxModel::~MonthComboboxModel() {} 103 MonthComboboxModel::~MonthComboboxModel() {}
189 104
190 int MonthComboboxModel::GetItemCount() const { 105 int MonthComboboxModel::GetItemCount() const {
191 // 12 months plus the empty entry. 106 // 12 months plus the empty entry.
192 return 13; 107 return 13;
193 } 108 }
(...skipping 24 matching lines...) Expand all
218 } 133 }
219 134
220 string16 YearComboboxModel::GetItemAt(int index) { 135 string16 YearComboboxModel::GetItemAt(int index) {
221 if (index == 0) 136 if (index == 0)
222 return string16(); 137 return string16();
223 138
224 return base::IntToString16(this_year_ + index - 1); 139 return base::IntToString16(this_year_ + index - 1);
225 } 140 }
226 141
227 } // autofill 142 } // 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