| 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 <ostream> |
| 10 #include <string> | 11 #include <string> |
| 12 |
| 11 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 12 | 14 |
| 13 enum class AccountType { UNKNOWN, GOOGLE, ACTIVE_DIRECTORY }; | 15 enum class AccountType { UNKNOWN, GOOGLE, ACTIVE_DIRECTORY }; |
| 14 | 16 |
| 15 // Type that contains enough information to identify user. | 17 // Type that contains enough information to identify user. |
| 16 // | 18 // |
| 17 // TODO(alemate): we are in the process of moving away from std::string as a | 19 // TODO(alemate): we are in the process of moving away from std::string as a |
| 18 // type for storing user identifier to AccountId. At this time GaiaId is mostly | 20 // type for storing user identifier to AccountId. At this time GaiaId is mostly |
| 19 // empty, so this type is used as a replacement for e-mail string. | 21 // empty, so this type is used as a replacement for e-mail string. |
| 20 // But in near future AccountId will become full feature user identifier. | 22 // But in near future AccountId will become full feature user identifier. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 92 |
| 91 // These are (for now) unstable and cannot be used to store serialized data to | 93 // These are (for now) unstable and cannot be used to store serialized data to |
| 92 // persistent storage. Only in-memory storage is safe. | 94 // persistent storage. Only in-memory storage is safe. |
| 93 // Serialize() returns JSON dictionary, | 95 // Serialize() returns JSON dictionary, |
| 94 // Deserialize() restores AccountId after serialization. | 96 // Deserialize() restores AccountId after serialization. |
| 95 std::string Serialize() const; | 97 std::string Serialize() const; |
| 96 static bool Deserialize(const std::string& serialized, | 98 static bool Deserialize(const std::string& serialized, |
| 97 AccountId* out_account_id); | 99 AccountId* out_account_id); |
| 98 | 100 |
| 99 private: | 101 private: |
| 102 friend std::ostream& operator<<(std::ostream&, const AccountId&); |
| 103 |
| 100 AccountId(const std::string& id, | 104 AccountId(const std::string& id, |
| 101 const std::string& user_email, | 105 const std::string& user_email, |
| 102 const AccountType& account_type); | 106 const AccountType& account_type); |
| 103 | 107 |
| 104 std::string id_; | 108 std::string id_; |
| 105 std::string user_email_; | 109 std::string user_email_; |
| 106 AccountType account_type_ = AccountType::UNKNOWN; | 110 AccountType account_type_ = AccountType::UNKNOWN; |
| 107 }; | 111 }; |
| 108 | 112 |
| 113 // Overload << operator to allow logging of AccountIds. |
| 114 std::ostream& operator<<(std::ostream& stream, const AccountId& account_id); |
| 115 |
| 109 // Returns a reference to a singleton. | 116 // Returns a reference to a singleton. |
| 110 const AccountId& EmptyAccountId(); | 117 const AccountId& EmptyAccountId(); |
| 111 | 118 |
| 112 namespace BASE_HASH_NAMESPACE { | 119 namespace BASE_HASH_NAMESPACE { |
| 113 | 120 |
| 114 // Implement hashing of AccountId, so it can be used as a key in STL containers. | 121 // Implement hashing of AccountId, so it can be used as a key in STL containers. |
| 115 template <> | 122 template <> |
| 116 struct hash<AccountId> { | 123 struct hash<AccountId> { |
| 117 std::size_t operator()(const AccountId& user_id) const; | 124 std::size_t operator()(const AccountId& user_id) const; |
| 118 }; | 125 }; |
| 119 | 126 |
| 120 } // namespace BASE_HASH_NAMESPACE | 127 } // namespace BASE_HASH_NAMESPACE |
| 121 | 128 |
| 122 #endif // COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ | 129 #endif // COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ |
| OLD | NEW |