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

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

Issue 13331007: Multi-account AccountChooser for interactive autocomplete. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge. 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/autofill/account_chooser_model.h"
6
7 #include "base/bind.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/stringprintf.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/time.h"
12 #include "base/utf_string_conversions.h"
13 #include "chrome/common/pref_names.h"
14 #include "components/autofill/browser/autofill_country.h"
15 #include "grit/generated_resources.h"
16 #include "grit/theme_resources.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/resource/resource_bundle.h"
19
20 namespace autofill {
21
22 const int AccountChooserModel::kActiveWalletItemId = 0;
23 const int AccountChooserModel::kAutofillItemId = 1;
24
25 AccountChooserModelDelegate::~AccountChooserModelDelegate() {}
26
27 AccountChooserModel::AccountChooserModel(
28 AccountChooserModelDelegate* delegate,
29 PrefService* prefs)
30 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
31 delegate_(delegate),
32 checked_item_(prefs->GetBoolean(prefs::kAutofillDialogPayWithoutWallet) ?
33 kAutofillItemId : kActiveWalletItemId),
34 had_wallet_error_(false) {
35 ReconstructMenuItems();
36 }
37
38 AccountChooserModel::~AccountChooserModel() {
39 }
40
41 void AccountChooserModel::SelectActiveWalletAccount() {
42 ExecuteCommand(kActiveWalletItemId, 0);
43 }
44
45 void AccountChooserModel::SelectAutofillData() {
46 ExecuteCommand(kAutofillItemId, 0);
47 }
48
49 bool AccountChooserModel::HasAccountsToChoose() const {
50 return !active_wallet_account_name_.empty();
51 }
52
53 void AccountChooserModel::SetActiveWalletAccountName(
54 const string16& account) {
55 active_wallet_account_name_ = account;
56 ReconstructMenuItems();
57 delegate_->UpdateAccountChooserView();
58 }
59
60 void AccountChooserModel::ClearActiveWalletAccountName() {
61 active_wallet_account_name_.clear();
62 ReconstructMenuItems();
63 delegate_->UpdateAccountChooserView();
64 }
65
66 bool AccountChooserModel::IsCommandIdChecked(int command_id) const {
67 return command_id == checked_item_;
68 }
69
70 bool AccountChooserModel::IsCommandIdEnabled(int command_id) const {
71 // Currently, _any_ (non-sign-in) error disables _all_ Wallet accounts.
72 if (command_id != kAutofillItemId && had_wallet_error_)
73 return false;
74
75 return true;
76 }
77
78 bool AccountChooserModel::GetAcceleratorForCommandId(
79 int command_id,
80 ui::Accelerator* accelerator) {
81 return false;
82 }
83
84 void AccountChooserModel::ExecuteCommand(int command_id, int event_flags) {
85 if (checked_item_ == command_id)
86 return;
87
88 checked_item_ = command_id;
89 ReconstructMenuItems();
90 delegate_->AccountChoiceChanged();
91 }
92
93 void AccountChooserModel::SetHadWalletError() {
94 // Any non-sign-in error disables all Wallet accounts.
95 had_wallet_error_ = true;
96 ClearActiveWalletAccountName();
97 ExecuteCommand(kAutofillItemId, 0);
98 }
99
100 void AccountChooserModel::SetHadWalletSigninError() {
101 ClearActiveWalletAccountName();
102 ExecuteCommand(kAutofillItemId, 0);
103 }
104
105 bool AccountChooserModel::WalletIsSelected() const {
106 return checked_item_ != kAutofillItemId;
107 }
108
109 bool AccountChooserModel::IsActiveWalletAccountSelected() const {
110 return checked_item_ == kActiveWalletItemId;
111 }
112
113 void AccountChooserModel::ReconstructMenuItems() {
114 Clear();
115 const gfx::Image& wallet_icon =
116 ui::ResourceBundle::GetSharedInstance().GetImageNamed(IDR_WALLET_ICON);
117
118 if (!active_wallet_account_name_.empty()) {
119 AddCheckItem(kActiveWalletItemId, active_wallet_account_name_);
120 SetIcon(GetIndexOfCommandId(kActiveWalletItemId), wallet_icon);
121 } else if (checked_item_ == kActiveWalletItemId) {
122 // A selected active Wallet account with an empty account name means
123 // that the sign-in attempt is in progress.
124 // A throbber should be shown until the Wallet account name is set.
Evan Stade 2013/04/12 17:06:36 is there a bug filed specifically for this?
aruslan 2013/04/12 20:43:30 Done.
125 AddCheckItem(kActiveWalletItemId,
126 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_GOOGLE_WALLET));
127 }
128
129 AddCheckItemWithStringId(kAutofillItemId,
130 IDS_AUTOFILL_DIALOG_PAY_WITHOUT_WALLET);
131 }
132
133 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698