Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ | 5 #ifndef COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ |
| 6 #define COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ | 6 #define COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 | 12 |
| 13 // Type that contains enough information to identify user. | 13 // Type that contains enough information to identify user. |
| 14 // | 14 // |
| 15 // TODO(alemate): we are in the process of moving away from std::string as a | 15 // TODO(alemate): we are in the process of moving away from std::string as a |
| 16 // type for storing user identifier to AccountId. At this time GaiaId is mostly | 16 // type for storing user identifier to AccountId. At this time GaiaId is mostly |
| 17 // empty, so this type is used as a replacement for e-mail string. | 17 // empty, so this type is used as a replacement for e-mail string. |
| 18 // But in near future AccountId will become full feature user identifier. | 18 // But in near future AccountId will become full feature user identifier. |
| 19 class AccountId { | 19 class AccountId { |
| 20 public: | 20 public: |
| 21 // Known account types. | |
| 22 static const std::string kGoogle; | |
|
Andrew T Wilson (Slow)
2016/11/29 11:05:36
Why are we defining account types as strings and n
Roman Sorokin (ftl)
2016/12/02 11:13:11
Switched to enum class AccountType
| |
| 23 static const std::string kAd; | |
| 24 | |
| 21 struct EmptyAccountId; | 25 struct EmptyAccountId; |
| 22 | 26 |
| 23 AccountId(const AccountId& other); | 27 AccountId(const AccountId& other); |
| 24 | 28 |
| 25 bool operator==(const AccountId& other) const; | 29 bool operator==(const AccountId& other) const; |
| 26 bool operator!=(const AccountId& other) const; | 30 bool operator!=(const AccountId& other) const; |
| 27 bool operator<(const AccountId& right) const; | 31 bool operator<(const AccountId& right) const; |
| 28 | 32 |
| 29 // empty() is deprecated. Use !is_valid() instead. | 33 // empty() is deprecated. Use !is_valid() instead. |
| 30 bool empty() const; | 34 bool empty() const; |
| 31 bool is_valid() const; | 35 bool is_valid() const; |
| 32 void clear(); | 36 void clear(); |
| 33 | 37 |
| 34 const std::string& GetAccountType() const; | 38 const std::string& GetAccountType() const; |
| 35 const std::string& GetGaiaId() const; | 39 const std::string& GetGaiaId() const; |
| 36 // Users of AccountId should make no assumptions on the format of email. | 40 // Users of AccountId should make no assumptions on the format of email. |
| 37 // I.e. it cannot be used as account identifier, because it is (in general) | 41 // I.e. it cannot be used as account identifier, because it is (in general) |
| 38 // non-comparable. | 42 // non-comparable. |
| 39 const std::string& GetUserEmail() const; | 43 const std::string& GetUserEmail() const; |
| 40 | 44 |
| 41 // This returns prefixed some string that can be used as a storage key. | 45 // This returns prefixed some string that can be used as a storage key. |
| 42 // You should make no assumptions on the format of this string. | 46 // You should make no assumptions on the format of this string. |
| 43 const std::string GetAccountIdKey() const; | 47 const std::string GetAccountIdKey() const; |
| 44 | 48 |
| 45 void SetGaiaId(const std::string& gaia_id); | 49 void SetGaiaId(const std::string& gaia_id); |
| 46 void SetUserEmail(const std::string& email); | 50 void SetUserEmail(const std::string& email); |
| 51 void SetAccountType(const std::string& account_type); | |
| 47 | 52 |
| 48 // This method is to be used during transition period only. | 53 // This method is to be used during transition period only. |
| 49 static AccountId FromUserEmail(const std::string& user_email); | 54 static AccountId FromUserEmail(const std::string& user_email); |
| 50 // This method is to be used during transition period only. | 55 // This method is to be used during transition period only. |
| 51 static AccountId FromGaiaId(const std::string& gaia_id); | 56 static AccountId FromGaiaId(const std::string& gaia_id); |
| 52 // This method is the preferred way to construct AccountId if you have | 57 // This method is the preferred way to construct AccountId if you have |
| 53 // full account information. | 58 // full account information. |
| 54 static AccountId FromUserEmailGaiaId(const std::string& user_email, | 59 static AccountId FromUserEmailGaiaId(const std::string& user_email, |
| 55 const std::string& gaia_id); | 60 const std::string& gaia_id); |
| 61 // This method is used to construct AccountId with specific types. | |
| 62 static AccountId FromUserEmailGaiaIdAccountType( | |
| 63 const std::string& email, | |
| 64 const std::string& gaia_id, | |
| 65 const std::string& account_type); | |
| 66 static AccountId FromGaiaIdAccountType(const std::string& gaia_id, | |
| 67 const std::string& account_type); | |
| 56 | 68 |
| 57 // These are (for now) unstable and cannot be used to store serialized data to | 69 // These are (for now) unstable and cannot be used to store serialized data to |
| 58 // persistent storage. Only in-memory storage is safe. | 70 // persistent storage. Only in-memory storage is safe. |
| 59 // Serialize() returns JSON dictionary, | 71 // Serialize() returns JSON dictionary, |
| 60 // Deserialize() restores AccountId after serialization. | 72 // Deserialize() restores AccountId after serialization. |
| 61 std::string Serialize() const; | 73 std::string Serialize() const; |
| 62 static bool Deserialize(const std::string& serialized, | 74 static bool Deserialize(const std::string& serialized, |
| 63 AccountId* out_account_id); | 75 AccountId* out_account_id); |
| 64 | 76 |
| 65 private: | 77 private: |
| 66 AccountId(); | 78 AccountId(); |
| 67 AccountId(const std::string& gaia_id, const std::string& user_email); | 79 AccountId(const std::string& gaia_id, const std::string& user_email); |
| 80 AccountId(const std::string& gaia_id, | |
| 81 const std::string& user_email, | |
| 82 const std::string& account_type); | |
| 68 | 83 |
| 69 std::string gaia_id_; | 84 std::string gaia_id_; |
| 70 std::string user_email_; | 85 std::string user_email_; |
| 86 std::string account_type_ = kGoogle; | |
| 71 }; | 87 }; |
| 72 | 88 |
| 73 // Returns a reference to a singleton. | 89 // Returns a reference to a singleton. |
| 74 const AccountId& EmptyAccountId(); | 90 const AccountId& EmptyAccountId(); |
| 75 | 91 |
| 76 namespace BASE_HASH_NAMESPACE { | 92 namespace BASE_HASH_NAMESPACE { |
| 77 | 93 |
| 78 // Implement hashing of AccountId, so it can be used as a key in STL containers. | 94 // Implement hashing of AccountId, so it can be used as a key in STL containers. |
| 79 template <> | 95 template <> |
| 80 struct hash<AccountId> { | 96 struct hash<AccountId> { |
| 81 std::size_t operator()(const AccountId& user_id) const; | 97 std::size_t operator()(const AccountId& user_id) const; |
| 82 }; | 98 }; |
| 83 | 99 |
| 84 } // namespace BASE_HASH_NAMESPACE | 100 } // namespace BASE_HASH_NAMESPACE |
| 85 | 101 |
| 86 #endif // COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ | 102 #endif // COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ |
| OLD | NEW |