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

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: Indent fix. 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 (c) 2012 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 <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/prefs/pref_change_registrar.h"
14 #include "base/string16.h"
15 #include "ui/base/models/simple_menu_model.h"
16
17 class PrefService;
18
19 namespace autofill {
20
21 // A delegate interface to allow the AccountChooserModel to inform its owner
22 // of changes.
23 class AccountChooserModelDelegate {
24 public:
25 virtual ~AccountChooserModelDelegate();
26
27 // Called when the active account has changed.
28 virtual void AccountChoiceChanged() = 0;
29 };
30
31 // A menu model for the account chooser. This allows users to switch between
32 // using Wallet and local Autofill.
33 class AccountChooserModel : public ui::SimpleMenuModel,
34 public ui::SimpleMenuModel::Delegate {
35 public:
36 AccountChooserModel(AccountChooserModelDelegate* delegate,
37 PrefService* prefs);
38 virtual ~AccountChooserModel();
39
40 // ui::SimpleMenuModel::Delegate implementation.
41 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
42 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
43 virtual bool GetAcceleratorForCommandId(
44 int command_id,
45 ui::Accelerator* accelerator) OVERRIDE;
46 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
47
48 // Should be called if the user attempts to sign into the Online Wallet
49 // (e.g. when the user clicks the "Sign-in" link).
50 // This function calls AccountChoiceChanged on the delegate.
Evan Stade 2013/04/01 23:54:34 nit: don't think this last line is necessary. It's
aruslan 2013/04/10 17:40:31 Done.
51 void ForceSelectWalletAccount();
52
53 // Returns true if there are any available accounts or if the currently
54 // signed-in account is known.
Evan Stade 2013/04/01 23:54:34 I don't know what you mean by "known" or what "ava
aruslan 2013/04/10 17:40:31 Done.
55 bool HasAccountsToChoose() const;
56
57 // Should be called if the set of available accounts is changed.
58 // The set doesn't have to include the currently signed-in account.
Evan Stade 2013/04/01 23:54:34 so you can have an account that's signed in but un
aruslan 2013/04/10 17:40:31 Done.
59 // The menu model will be reconstructed due to this call.
60 // It is the responsibility of the caller to update the view accordingly.
Evan Stade 2013/04/01 23:54:34 why does this one force the caller to know that th
aruslan 2013/04/10 17:40:31 Done.
61 void SetAvailableAccounts(const std::vector<std::string>& accounts);
62
63 // Should be called if the signed-in account in the content area is known.
Evan Stade 2013/04/01 23:54:34 I don't know what "content area" means here. Are y
aruslan 2013/04/10 17:40:31 Done.
64 // The menu model will be reconstructed due to this call.
65 // It is the responsibility of the caller to update the view accordingly.
Evan Stade 2013/04/01 23:54:34 ditto
aruslan 2013/04/10 17:40:31 Done.
66 void SetCurrentlySignedInAccount(const std::string& account);
67
68 // Should be called if the sign-in status of the content area is unknown.
69 // Any Wallet error automatically resets the currently signed-in account.
Evan Stade 2013/04/01 23:54:34 resets it to what?
aruslan 2013/04/10 17:40:31 Done.
70 // The menu model will be reconstructed due to this call.
71 // It is the responsibility of the caller to update the view accordingly.
Evan Stade 2013/04/01 23:54:34 ditto
aruslan 2013/04/10 17:40:31 Done.
72 void ResetCurrentlySignedInAccount();
73
74 // Returns the last known signed-in account, or an empty string.
75 // Returned account may be different from the currently selected account
76 // if the currently selected account is the autofill data.
77 std::string GetCurrentlySignedInAccount() const;
78
79 // Should be called when the Wallet server returns an error.
80 // This disables all Wallet accounts and switches to the autofill data.
81 // The AccountChoiceChanged() will be called on the delegate.
Evan Stade 2013/04/01 23:54:34 ditto
aruslan 2013/04/10 17:40:31 Done.
aruslan 2013/04/10 17:40:31 Done.
82 void SetHadWalletError();
83
84 // Should be called when the Online Wallet sign-in attempt has failed.
85 // This swithes the dialog to the autofill data.
86 // The AccountChoiceChanged() will be called on the delegate.
87 void SetHadWalletSigninError();
88
89 bool had_wallet_error() const { return had_wallet_error_; }
90
91 // Returns true if the selected account is an Online Wallet account.
92 bool WalletIsSelected() const;
93
94 // Returns true if the currently selected account matches the currently
95 // signed-in account.
96 bool IsCurrentlySignedInAccountSelected() const;
97
98 // Returns the command id of the currently selected account.
99 int checked_item() const { return checked_item_; }
100
101 private:
102 void PrefChanged(const std::string& pref);
103
104 // Sets |checked_item_| from the relevant pref.
105 void UpdateCheckmarkFromPref();
106
107 // Reconstructs the set of menu items.
108 void ReconstructMenuItems();
109
110 // Command IDs of the items in this menu:
111 // kSignedInWalletItemId is the currently signed-in account, or an account
112 // the user is attempting to sign into.
113 // kAutofillItemId is "Pay without the Wallet".
114 // In the future, the kAddNewAccountItemId will be added.
115 // Any other accounts go starting from kFirstAccountItemId.
116 static const int kSignedInWalletItemId; // The signed-in account.
117 static const int kAutofillItemId; // Local data.
118 static const int kFirstAccountItemId; // First command id for other accounts.
119
120 AccountChooserModelDelegate* account_delegate_;
121
122 PrefService* prefs_;
123
124 // The command id of the currently active item.
125 int checked_item_;
126
127 // Whether there has been a Wallet error while the owning dialog has been
128 // open.
129 bool had_wallet_error_;
130
131 PrefChangeRegistrar pref_change_registrar_;
132
133 // The user account name (email) that is currently signed into the content.
134 // May be different from the currently selected account (e.g. autofill data).
Evan Stade 2013/04/01 23:54:34 refering to autofill data as an account is a sourc
aruslan 2013/04/10 17:40:31 Done.
135 // Set whenever the sign-in helper fetches the user info.
136 std::string current_username_;
137
138 // The set of accounts the user could choose from (excluding autofill data).
139 // Doesn't have to include the account currently signed into the content.
140 std::vector<std::string> available_accounts_;
141
142 DISALLOW_COPY_AND_ASSIGN(AccountChooserModel);
143 };
144
145 } // autofill
146
147 #endif // CHROME_BROWSER_UI_AUTOFILL_ACCOUNT_CHOOSER_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698