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

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: Indent fix. Created 7 years, 9 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..925d66ce0258201629e56a3044850c31a3be8366
--- /dev/null
+++ b/chrome/browser/ui/autofill/account_chooser_model.h
@@ -0,0 +1,147 @@
+// Copyright (c) 2012 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 <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/prefs/pref_change_registrar.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;
+};
+
+// A menu model for the account chooser. This allows users to switch between
+// using Wallet and local Autofill.
+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;
+
+ // Should be called if the user attempts to sign into the Online Wallet
+ // (e.g. when the user clicks the "Sign-in" link).
+ // 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.
+ void ForceSelectWalletAccount();
+
+ // Returns true if there are any available accounts or if the currently
+ // 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.
+ bool HasAccountsToChoose() const;
+
+ // Should be called if the set of available accounts is changed.
+ // 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.
+ // The menu model will be reconstructed due to this call.
+ // 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.
+ void SetAvailableAccounts(const std::vector<std::string>& accounts);
+
+ // 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.
+ // The menu model will be reconstructed due to this call.
+ // 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.
+ void SetCurrentlySignedInAccount(const std::string& account);
+
+ // Should be called if the sign-in status of the content area is unknown.
+ // 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.
+ // The menu model will be reconstructed due to this call.
+ // 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.
+ void ResetCurrentlySignedInAccount();
+
+ // Returns the last known signed-in account, or an empty string.
+ // Returned account may be different from the currently selected account
+ // if the currently selected account is the autofill data.
+ std::string GetCurrentlySignedInAccount() const;
+
+ // Should be called when the Wallet server returns an error.
+ // This disables all Wallet accounts and switches to the autofill data.
+ // 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.
+ void SetHadWalletError();
+
+ // Should be called when the Online Wallet sign-in attempt has failed.
+ // This swithes the dialog to the autofill data.
+ // The AccountChoiceChanged() will be called on the delegate.
+ 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 currently selected account matches the currently
+ // signed-in account.
+ bool IsCurrentlySignedInAccountSelected() const;
+
+ // Returns the command id of the currently selected account.
+ int checked_item() const { return checked_item_; }
+
+ private:
+ void PrefChanged(const std::string& pref);
+
+ // Sets |checked_item_| from the relevant pref.
+ void UpdateCheckmarkFromPref();
+
+ // Reconstructs the set of menu items.
+ void ReconstructMenuItems();
+
+ // Command IDs of the items in this menu:
+ // kSignedInWalletItemId is the currently signed-in account, or an account
+ // the user is attempting to sign into.
+ // kAutofillItemId is "Pay without the Wallet".
+ // In the future, the kAddNewAccountItemId will be added.
+ // Any other accounts go starting from kFirstAccountItemId.
+ static const int kSignedInWalletItemId; // The signed-in account.
+ static const int kAutofillItemId; // Local data.
+ static const int kFirstAccountItemId; // First command id for other accounts.
+
+ AccountChooserModelDelegate* account_delegate_;
+
+ PrefService* prefs_;
+
+ // The command id of the currently active item.
+ int checked_item_;
+
+ // Whether there has been a Wallet error while the owning dialog has been
+ // open.
+ bool had_wallet_error_;
+
+ PrefChangeRegistrar pref_change_registrar_;
+
+ // The user account name (email) that is currently signed into the content.
+ // 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.
+ // Set whenever the sign-in helper fetches the user info.
+ std::string current_username_;
+
+ // The set of accounts the user could choose from (excluding autofill data).
+ // Doesn't have to include the account currently signed into the content.
+ std::vector<std::string> available_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