account.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2020 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. #ifndef COMPONENTS_ACCOUNT_MANAGER_CORE_ACCOUNT_H_
  5. #define COMPONENTS_ACCOUNT_MANAGER_CORE_ACCOUNT_H_
  6. #include <ostream>
  7. #include <string>
  8. #include "base/component_export.h"
  9. namespace account_manager {
  10. // Type of an account, based on the authentication backend of the account.
  11. // Loosely based on //components/account_manager_core/chromeos/tokens.proto.
  12. enum class AccountType : int {
  13. // Gaia account (aka Google account) - including enterprise and consumer
  14. // accounts.
  15. kGaia = 1,
  16. // Microsoft Active Directory accounts.
  17. kActiveDirectory = 2,
  18. };
  19. // Uniquely identifies an account.
  20. class COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE) AccountKey {
  21. public:
  22. // `id` cannot be empty.
  23. AccountKey(const std::string& id, AccountType type);
  24. // |id| is obfuscated GAIA id for |AccountType::kGaia|, and cannot be empty.
  25. // |id| is object GUID (|AccountId::GetObjGuid|) for
  26. // |AccountType::kActiveDirectory|.
  27. const std::string& id() const { return id_; }
  28. AccountType account_type() const { return account_type_; }
  29. bool operator<(const AccountKey& other) const;
  30. bool operator==(const AccountKey& other) const;
  31. bool operator!=(const AccountKey& other) const;
  32. private:
  33. // Fields are not const to allow assignment operator.
  34. std::string id_;
  35. AccountType account_type_;
  36. };
  37. // Publicly viewable information about an account.
  38. struct COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE) Account {
  39. // A unique identifier for this account.
  40. AccountKey key;
  41. // The raw, un-canonicalized email id for this account.
  42. std::string raw_email;
  43. bool operator<(const Account& other) const;
  44. bool operator==(const Account& other) const;
  45. bool operator!=(const Account& other) const;
  46. };
  47. // For logging.
  48. COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
  49. std::ostream& operator<<(std::ostream& os, const AccountType& account_type);
  50. COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
  51. std::ostream& operator<<(std::ostream& os, const AccountKey& account_key);
  52. } // namespace account_manager
  53. #endif // COMPONENTS_ACCOUNT_MANAGER_CORE_ACCOUNT_H_