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 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 AccountId(); | |
|
msarda
2017/01/09 10:28:50
Why is this change needed?
xiyuan
2017/01/09 17:42:57
This is needed for mojo deserialization. The code
msarda
2017/01/10 15:04:22
Thank you for the explanation. I am fine with us a
xiyuan
2017/01/12 00:06:54
Done.
| |
| 27 AccountId(const AccountId& other); | 28 AccountId(const AccountId& other); |
| 28 | 29 |
| 29 // If any of the comparable AccountIds has AccountType == UNKNOWN then it | 30 // If any of the comparable AccountIds has AccountType == UNKNOWN then it |
| 30 // compares emails. | 31 // compares emails. |
| 31 // If both are not UNKNOWN and not equal then it returns false. | 32 // 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. | 33 // 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 | 34 // If AccountType == ACTIVE_DIRECTORY then it checks if ids and emails are |
| 34 // equal. | 35 // equal. |
| 35 bool operator==(const AccountId& other) const; | 36 bool operator==(const AccountId& other) const; |
| 36 bool operator!=(const AccountId& other) const; | 37 bool operator!=(const AccountId& other) const; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 | 84 |
| 84 // These are (for now) unstable and cannot be used to store serialized data to | 85 // These are (for now) unstable and cannot be used to store serialized data to |
| 85 // persistent storage. Only in-memory storage is safe. | 86 // persistent storage. Only in-memory storage is safe. |
| 86 // Serialize() returns JSON dictionary, | 87 // Serialize() returns JSON dictionary, |
| 87 // Deserialize() restores AccountId after serialization. | 88 // Deserialize() restores AccountId after serialization. |
| 88 std::string Serialize() const; | 89 std::string Serialize() const; |
| 89 static bool Deserialize(const std::string& serialized, | 90 static bool Deserialize(const std::string& serialized, |
| 90 AccountId* out_account_id); | 91 AccountId* out_account_id); |
| 91 | 92 |
| 92 private: | 93 private: |
| 93 AccountId(); | |
| 94 AccountId(const std::string& id, | 94 AccountId(const std::string& id, |
| 95 const std::string& user_email, | 95 const std::string& user_email, |
| 96 const AccountType& account_type); | 96 const AccountType& account_type); |
| 97 | 97 |
| 98 std::string id_; | 98 std::string id_; |
| 99 std::string user_email_; | 99 std::string user_email_; |
| 100 AccountType account_type_ = AccountType::UNKNOWN; | 100 AccountType account_type_ = AccountType::UNKNOWN; |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 // Returns a reference to a singleton. | 103 // Returns a reference to a singleton. |
| 104 const AccountId& EmptyAccountId(); | 104 const AccountId& EmptyAccountId(); |
| 105 | 105 |
| 106 namespace BASE_HASH_NAMESPACE { | 106 namespace BASE_HASH_NAMESPACE { |
| 107 | 107 |
| 108 // Implement hashing of AccountId, so it can be used as a key in STL containers. | 108 // Implement hashing of AccountId, so it can be used as a key in STL containers. |
| 109 template <> | 109 template <> |
| 110 struct hash<AccountId> { | 110 struct hash<AccountId> { |
| 111 std::size_t operator()(const AccountId& user_id) const; | 111 std::size_t operator()(const AccountId& user_id) const; |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 } // namespace BASE_HASH_NAMESPACE | 114 } // namespace BASE_HASH_NAMESPACE |
| 115 | 115 |
| 116 #endif // COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ | 116 #endif // COMPONENTS_SIGNIN_CORE_ACCOUNT_ID_ACCOUNT_ID_H_ |
| OLD | NEW |