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

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

Issue 13331007: Multi-account AccountChooser for interactive autocomplete. (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
(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 #ifndef CHROME_BROWSER_UI_AUTOFILL_ACCOUNT_CHOOSER_MODEL_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_ACCOUNT_CHOOSER_MODEL_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/string16.h"
13 #include "ui/base/models/simple_menu_model.h"
14
15 class PrefService;
16
17 namespace autofill {
18
19 // A delegate interface to allow the AccountChooserModel to inform its owner
20 // of changes.
21 class AccountChooserModelDelegate {
22 public:
23 virtual ~AccountChooserModelDelegate();
24
25 // Called when the active account has changed.
26 virtual void AccountChoiceChanged() = 0;
27
28 // Called when the account chooser UI needs to be updated.
29 virtual void UpdateAccountChooserView() = 0;
30 };
31
32 // A menu model for the account chooser. This allows users to switch between
33 // Online Wallet accounts and local Autofill data.
34 // Terminology:
35 // - "Active Wallet account": the account used for communications with the
36 // Online Wallet service. There may be multiple signed-in accounts, but at any
37 // point of time at most one of is active.
38 // - "Additional accounts": the accounts the user could switch to in addition
39 // to the currently active Wallet account (if any). On Android, selection of
40 // any of these accounts causes the automatic sign-in into the selected account.
41 class AccountChooserModel : public ui::SimpleMenuModel,
42 public ui::SimpleMenuModel::Delegate {
43 public:
44 AccountChooserModel(AccountChooserModelDelegate* delegate,
45 PrefService* prefs);
46 virtual ~AccountChooserModel();
47
48 // ui::SimpleMenuModel::Delegate implementation.
49 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
50 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
51 virtual bool GetAcceleratorForCommandId(
52 int command_id,
53 ui::Accelerator* accelerator) OVERRIDE;
54 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
55
56 // Sets the selection to the currently active Online Wallet account.
57 // Should be called if the user attempts to sign into the Online Wallet
58 // (e.g. when the user clicks the "Sign-in" link).
59 void ForceSelectWalletAccount();
Evan Stade 2013/04/11 19:27:45 why ForceSelect...? Why not just Select...?
aruslan 2013/04/12 00:46:02 Done.
60
61 // Returns true if there are any accounts for the user to choose from.
62 bool HasAccountsToChoose() const;
63
64 // Establishes the set of accounts the user could select in addition
65 // to the currently active account (if any).
66 void SetAdditionalAccounts(const std::vector<string16>& accounts);
Evan Stade 2013/04/11 19:27:45 it seems this is only exercised by tests. Could yo
aruslan 2013/04/12 00:46:02 Done.
67
68 // Returns the set of all accounts in the account chooser.
69 // This is the union of the currently active account (if any) and
70 // additional accounts (if any).
71 std::vector<string16> GetAllAccounts() const;
72
73 // Sets the name of the account used to communicate with the Online Wallet.
74 void SetActiveWalletAccountName(const string16& account);
Evan Stade 2013/04/11 19:27:45 So is it the "active wallet account name" or the "
aruslan 2013/04/12 00:46:02 Done.
75
76 // Clears the name of the account used to communicate with the Online Wallet.
77 // Any Wallet error automatically clears the currently active account name.
78 void ClearActiveWalletAccountName();
79
80 // Returns the name of the currently active account, or an empty string.
81 string16 GetActiveWalletAccountName() const;
Evan Stade 2013/04/11 19:27:45 should return const string16&. Should be called cu
aruslan 2013/04/12 00:46:02 Done.
82
83 // Disables all Wallet accounts and switches to the autofill data.
84 // Should be called when the Wallet server returns an error.
85 void SetHadWalletError();
86
87 // Switches the dialog to the local autofill data.
88 // Should be called when the Online Wallet sign-in attempt has failed.
89 void SetHadWalletSigninError();
90
91 bool had_wallet_error() const { return had_wallet_error_; }
92
93 // Returns true if the selected account is an Online Wallet account.
94 bool WalletIsSelected() const;
95
96 // Returns true if the current selection matches the currently active
97 // Wallet account.
98 bool IsActiveWalletAccountSelected() const;
99
100 // Returns the command id of the current selection.
101 int checked_item() const { return checked_item_; }
102
103 // Command IDs of the items in this menu:
104 // kActiveWalletItemId is the currently active account.
105 // kAutofillItemId is "Pay without the Wallet" (local autofill data).
106 // In the future, the kAddNewAccountItemId will be added.
107 // Any other accounts go starting from kFirstAccountItemId.
108 static const int kActiveWalletItemId; // The active Wallet account.
Evan Stade 2013/04/11 19:27:45 you seem to double-document each of these
aruslan 2013/04/12 00:46:02 Done.
109 static const int kAutofillItemId; // Local autofill data.
110 static const int kFirstAdditionalItemId; // First id for additional accounts.
Evan Stade 2013/04/11 19:27:45 you shouldn't need to expose these publicly.
aruslan 2013/04/12 00:46:02 Done.
111
112 private:
113 // Reconstructs the set of menu items.
114 void ReconstructMenuItems();
115
116 AccountChooserModelDelegate* account_delegate_;
Evan Stade 2013/04/11 19:27:45 nit: just |delegate_|
aruslan 2013/04/12 00:46:02 Done.
117
118 // The command id of the currently selected item.
119 int checked_item_;
120
121 // Whether there has been a Wallet error while the owning dialog has been
122 // open.
123 bool had_wallet_error_;
124
125 // The name (email) of the account currently used in communications with the
126 // Online Wallet service. Set whenever the sign-in helper fetches the user
127 // info.
Evan Stade 2013/04/11 19:27:45 nit: remove final sentence
aruslan 2013/04/12 00:46:02 Done.
128 string16 current_username_;
129
130 // The set of accounts the user could choose from in addition to the currently
131 // active Wallet account (if any).
132 std::vector<string16> additional_accounts_;
133
134 DISALLOW_COPY_AND_ASSIGN(AccountChooserModel);
135 };
136
137 } // autofill
138
139 #endif // CHROME_BROWSER_UI_AUTOFILL_ACCOUNT_CHOOSER_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698