OLD | NEW |
---|---|
(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 | |
Evan Stade
2013/04/12 17:06:36
be consistent about the number of spaces after a p
aruslan
2013/04/12 20:43:30
Done.
| |
37 // point of time at most one of is active. | |
38 class AccountChooserModel : public ui::SimpleMenuModel, | |
39 public ui::SimpleMenuModel::Delegate { | |
40 public: | |
41 AccountChooserModel(AccountChooserModelDelegate* delegate, | |
42 PrefService* prefs); | |
43 virtual ~AccountChooserModel(); | |
44 | |
45 // ui::SimpleMenuModel::Delegate implementation. | |
46 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | |
47 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | |
48 virtual bool GetAcceleratorForCommandId( | |
49 int command_id, | |
50 ui::Accelerator* accelerator) OVERRIDE; | |
51 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; | |
52 | |
53 // Sets the selection to the currently active Online Wallet account. | |
54 // Should be called if the user attempts to sign into the Online Wallet | |
55 // (e.g. when the user clicks the "Sign-in" link). | |
56 void SelectActiveWalletAccount(); | |
57 | |
58 // Sets the selection to the local autofill data. | |
Evan Stade
2013/04/12 17:06:36
capitalize Autofill.
aruslan
2013/04/12 20:43:30
Done.
| |
59 void SelectAutofillData(); | |
Evan Stade
2013/04/12 17:06:36
how about SelectUseAutofill?
aruslan
2013/04/12 20:43:30
Done.
| |
60 | |
61 // Returns true if there are any accounts for the user to choose from. | |
62 bool HasAccountsToChoose() const; | |
63 | |
64 // Sets the name of the account used to communicate with the Online Wallet. | |
65 void SetActiveWalletAccountName(const string16& account); | |
66 | |
67 // Clears the name of the account used to communicate with the Online Wallet. | |
68 // Any Wallet error automatically clears the currently active account name. | |
69 void ClearActiveWalletAccountName(); | |
70 | |
71 // Returns the name of the currently active account, or an empty string. | |
72 const string16& active_wallet_account_name() const { | |
73 return active_wallet_account_name_; | |
74 } | |
75 | |
76 // Disables all Wallet accounts and switches to the autofill data. | |
77 // Should be called when the Wallet server returns an error. | |
78 void SetHadWalletError(); | |
79 | |
80 // Switches the dialog to the local autofill data. | |
81 // Should be called when the Online Wallet sign-in attempt has failed. | |
82 void SetHadWalletSigninError(); | |
83 | |
84 bool had_wallet_error() const { return had_wallet_error_; } | |
85 | |
86 // Returns true if the selected account is an Online Wallet account. | |
87 bool WalletIsSelected() const; | |
88 | |
89 // Returns true if the current selection matches the currently active | |
90 // Wallet account. | |
91 bool IsActiveWalletAccountSelected() const; | |
92 | |
93 // Returns the command id of the current selection. | |
94 int checked_item() const { return checked_item_; } | |
95 | |
96 protected: | |
97 // Command IDs of the items in this menu; protected for the tests. | |
98 // kActiveWalletItemId is the currently active account. | |
99 // kAutofillItemId is "Pay without the Wallet" (local autofill data). | |
100 // In the future, kFirstAdditionalItemId will be added as the first id | |
101 // for additional accounts. | |
102 static const int kActiveWalletItemId; | |
103 static const int kAutofillItemId; | |
104 | |
105 private: | |
106 // Reconstructs the set of menu items. | |
107 void ReconstructMenuItems(); | |
108 | |
109 AccountChooserModelDelegate* delegate_; | |
110 | |
111 // The command id of the currently selected item. | |
112 int checked_item_; | |
113 | |
114 // Whether there has been a Wallet error while the owning dialog has been | |
115 // open. | |
116 bool had_wallet_error_; | |
117 | |
118 // The name (email) of the account currently used in communications with the | |
119 // Online Wallet service. | |
120 string16 active_wallet_account_name_; | |
121 | |
122 DISALLOW_COPY_AND_ASSIGN(AccountChooserModel); | |
123 }; | |
124 | |
125 } // namespace autofill | |
126 | |
127 #endif // CHROME_BROWSER_UI_AUTOFILL_ACCOUNT_CHOOSER_MODEL_H_ | |
OLD | NEW |