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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/account_chooser_model.h
diff --git a/chrome/browser/ui/autofill/account_chooser_model.h b/chrome/browser/ui/autofill/account_chooser_model.h
new file mode 100644
index 0000000000000000000000000000000000000000..91ec69be8b2faada082c2b76f1348dddbd0e8076
--- /dev/null
+++ b/chrome/browser/ui/autofill/account_chooser_model.h
@@ -0,0 +1,139 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_AUTOFILL_ACCOUNT_CHOOSER_MODEL_H_
+#define CHROME_BROWSER_UI_AUTOFILL_ACCOUNT_CHOOSER_MODEL_H_
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/string16.h"
+#include "ui/base/models/simple_menu_model.h"
+
+class PrefService;
+
+namespace autofill {
+
+// A delegate interface to allow the AccountChooserModel to inform its owner
+// of changes.
+class AccountChooserModelDelegate {
+ public:
+ virtual ~AccountChooserModelDelegate();
+
+ // Called when the active account has changed.
+ virtual void AccountChoiceChanged() = 0;
+
+ // Called when the account chooser UI needs to be updated.
+ virtual void UpdateAccountChooserView() = 0;
+};
+
+// A menu model for the account chooser. This allows users to switch between
+// Online Wallet accounts and local Autofill data.
+// Terminology:
+// - "Active Wallet account": the account used for communications with the
+// Online Wallet service. There may be multiple signed-in accounts, but at any
+// point of time at most one of is active.
+// - "Additional accounts": the accounts the user could switch to in addition
+// to the currently active Wallet account (if any). On Android, selection of
+// any of these accounts causes the automatic sign-in into the selected account.
+class AccountChooserModel : public ui::SimpleMenuModel,
+ public ui::SimpleMenuModel::Delegate {
+ public:
+ AccountChooserModel(AccountChooserModelDelegate* delegate,
+ PrefService* prefs);
+ virtual ~AccountChooserModel();
+
+ // ui::SimpleMenuModel::Delegate implementation.
+ virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
+ virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
+ virtual bool GetAcceleratorForCommandId(
+ int command_id,
+ ui::Accelerator* accelerator) OVERRIDE;
+ virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
+
+ // Sets the selection to the currently active Online Wallet account.
+ // Should be called if the user attempts to sign into the Online Wallet
+ // (e.g. when the user clicks the "Sign-in" link).
+ void ForceSelectWalletAccount();
Evan Stade 2013/04/11 19:27:45 why ForceSelect...? Why not just Select...?
aruslan 2013/04/12 00:46:02 Done.
+
+ // Returns true if there are any accounts for the user to choose from.
+ bool HasAccountsToChoose() const;
+
+ // Establishes the set of accounts the user could select in addition
+ // to the currently active account (if any).
+ 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.
+
+ // Returns the set of all accounts in the account chooser.
+ // This is the union of the currently active account (if any) and
+ // additional accounts (if any).
+ std::vector<string16> GetAllAccounts() const;
+
+ // Sets the name of the account used to communicate with the Online Wallet.
+ 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.
+
+ // Clears the name of the account used to communicate with the Online Wallet.
+ // Any Wallet error automatically clears the currently active account name.
+ void ClearActiveWalletAccountName();
+
+ // Returns the name of the currently active account, or an empty string.
+ 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.
+
+ // Disables all Wallet accounts and switches to the autofill data.
+ // Should be called when the Wallet server returns an error.
+ void SetHadWalletError();
+
+ // Switches the dialog to the local autofill data.
+ // Should be called when the Online Wallet sign-in attempt has failed.
+ void SetHadWalletSigninError();
+
+ bool had_wallet_error() const { return had_wallet_error_; }
+
+ // Returns true if the selected account is an Online Wallet account.
+ bool WalletIsSelected() const;
+
+ // Returns true if the current selection matches the currently active
+ // Wallet account.
+ bool IsActiveWalletAccountSelected() const;
+
+ // Returns the command id of the current selection.
+ int checked_item() const { return checked_item_; }
+
+ // Command IDs of the items in this menu:
+ // kActiveWalletItemId is the currently active account.
+ // kAutofillItemId is "Pay without the Wallet" (local autofill data).
+ // In the future, the kAddNewAccountItemId will be added.
+ // Any other accounts go starting from kFirstAccountItemId.
+ 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.
+ static const int kAutofillItemId; // Local autofill data.
+ 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.
+
+ private:
+ // Reconstructs the set of menu items.
+ void ReconstructMenuItems();
+
+ AccountChooserModelDelegate* account_delegate_;
Evan Stade 2013/04/11 19:27:45 nit: just |delegate_|
aruslan 2013/04/12 00:46:02 Done.
+
+ // The command id of the currently selected item.
+ int checked_item_;
+
+ // Whether there has been a Wallet error while the owning dialog has been
+ // open.
+ bool had_wallet_error_;
+
+ // The name (email) of the account currently used in communications with the
+ // Online Wallet service. Set whenever the sign-in helper fetches the user
+ // info.
Evan Stade 2013/04/11 19:27:45 nit: remove final sentence
aruslan 2013/04/12 00:46:02 Done.
+ string16 current_username_;
+
+ // The set of accounts the user could choose from in addition to the currently
+ // active Wallet account (if any).
+ std::vector<string16> additional_accounts_;
+
+ DISALLOW_COPY_AND_ASSIGN(AccountChooserModel);
+};
+
+} // autofill
+
+#endif // CHROME_BROWSER_UI_AUTOFILL_ACCOUNT_CHOOSER_MODEL_H_

Powered by Google App Engine
This is Rietveld 408576698