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 enum class AccountType { UNKNOWN, GOOGLE, ACTIVE_DIRECTORY }; | 13 enum class AccountType { UNKNOWN, GOOGLE, ACTIVE_DIRECTORY }; |
14 | 14 |
15 // Type that contains enough information to identify user. | 15 // Type that contains enough information to identify user. |
16 // | 16 // |
17 // TODO(alemate): we are in the process of moving away from std::string as a | 17 // 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 | 18 // 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. | 19 // 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. | 20 // But in near future AccountId will become full feature user identifier. |
21 // TODO(alemate): Rename functions and fields to reflect different types of | 21 // TODO(alemate): Rename functions and fields to reflect different types of |
22 // accounts. (see crbug.com/672253) | 22 // accounts. (see crbug.com/672253) |
23 class AccountId { | 23 class AccountId { |
24 public: | 24 public: |
25 struct EmptyAccountId; | 25 struct EmptyAccountId; |
26 | 26 |
| 27 // Creates an empty account id. |
| 28 // |
| 29 // Note: This constructor is public as it is required for mojo serialization |
| 30 // To create an AccountId object, prefer using the static FromXXXX methods or |
| 31 // the EmptyAccountId method when creating an empty account id. |
| 32 AccountId(); |
| 33 |
27 AccountId(const AccountId& other); | 34 AccountId(const AccountId& other); |
28 | 35 |
29 // If any of the comparable AccountIds has AccountType == UNKNOWN then it | 36 // If any of the comparable AccountIds has AccountType == UNKNOWN then it |
30 // compares emails. | 37 // compares emails. |
31 // If both are not UNKNOWN and not equal then it returns false. | 38 // If both are not UNKNOWN and not equal then it returns false. |
32 // If AccountType == GOOGLE then it checks if either ids or emails are equal. | 39 // If AccountType == GOOGLE then it checks if either ids or emails are equal. |
33 // If AccountType == ACTIVE_DIRECTORY then it checks if ids and emails are | 40 // If AccountType == ACTIVE_DIRECTORY then it checks if ids and emails are |
34 // equal. | 41 // equal. |
35 bool operator==(const AccountId& other) const; | 42 bool operator==(const AccountId& other) const; |
36 bool operator!=(const AccountId& other) const; | 43 bool operator!=(const AccountId& other) const; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 90 |
84 // These are (for now) unstable and cannot be used to store serialized data to | 91 // These are (for now) unstable and cannot be used to store serialized data to |
85 // persistent storage. Only in-memory storage is safe. | 92 // persistent storage. Only in-memory storage is safe. |
86 // Serialize() returns JSON dictionary, | 93 // Serialize() returns JSON dictionary, |
87 // Deserialize() restores AccountId after serialization. | 94 // Deserialize() restores AccountId after serialization. |
88 std::string Serialize() const; | 95 std::string Serialize() const; |
89 static bool Deserialize(const std::string& serialized, | 96 static bool Deserialize(const std::string& serialized, |
90 AccountId* out_account_id); | 97 AccountId* out_account_id); |
91 | 98 |
92 private: | 99 private: |
93 AccountId(); | |
94 AccountId(const std::string& id, | 100 AccountId(const std::string& id, |
95 const std::string& user_email, | 101 const std::string& user_email, |
96 const AccountType& account_type); | 102 const AccountType& account_type); |
97 | 103 |
98 std::string id_; | 104 std::string id_; |
99 std::string user_email_; | 105 std::string user_email_; |
100 AccountType account_type_ = AccountType::UNKNOWN; | 106 AccountType account_type_ = AccountType::UNKNOWN; |
101 }; | 107 }; |
102 | 108 |
103 // Returns a reference to a singleton. | 109 // Returns a reference to a singleton. |
104 const AccountId& EmptyAccountId(); | 110 const AccountId& EmptyAccountId(); |
105 | 111 |
106 namespace BASE_HASH_NAMESPACE { | 112 namespace BASE_HASH_NAMESPACE { |
107 | 113 |
108 // Implement hashing of AccountId, so it can be used as a key in STL containers. | 114 // Implement hashing of AccountId, so it can be used as a key in STL containers. |
109 template <> | 115 template <> |
110 struct hash<AccountId> { | 116 struct hash<AccountId> { |
111 std::size_t operator()(const AccountId& user_id) const; | 117 std::size_t operator()(const AccountId& user_id) const; |
112 }; | 118 }; |
113 | 119 |
114 } // namespace BASE_HASH_NAMESPACE | 120 } // namespace BASE_HASH_NAMESPACE |
115 | 121 |
116 #endif // COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ | 122 #endif // COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ |
OLD | NEW |