Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 | |
| 5 #ifndef COMPONENTS_SIGNIN_PUBLIC_INTERFACES_ACCOUNT_ID_TRAITS_H_ | |
| 6 #define COMPONENTS_SIGNIN_PUBLIC_INTERFACES_ACCOUNT_ID_TRAITS_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "components/signin/core/account_id/account_id.h" | |
| 11 #include "components/signin/public/interfaces/account_id.mojom.h" | |
| 12 | |
| 13 namespace mojo { | |
| 14 | |
| 15 template <> | |
| 16 struct EnumTraits<signin::mojom::AccountType, AccountType> { | |
| 17 static signin::mojom::AccountType ToMojom(AccountType input) { | |
| 18 switch (input) { | |
| 19 case AccountType::UNKNOWN: | |
| 20 return signin::mojom::AccountType::UNKNOWN; | |
| 21 case AccountType::GOOGLE: | |
| 22 return signin::mojom::AccountType::GOOGLE; | |
| 23 case AccountType::ACTIVE_DIRECTORY: | |
| 24 return signin::mojom::AccountType::ACTIVE_DIRECTORY; | |
| 25 } | |
| 26 NOTREACHED(); | |
| 27 return signin::mojom::AccountType::UNKNOWN; | |
| 28 } | |
| 29 | |
| 30 static bool FromMojom(signin::mojom::AccountType input, | |
| 31 AccountType* out) { | |
| 32 switch (input) { | |
| 33 case signin::mojom::AccountType::UNKNOWN: | |
| 34 *out = AccountType::UNKNOWN; | |
| 35 return true; | |
| 36 case signin::mojom::AccountType::GOOGLE: | |
| 37 *out = AccountType::GOOGLE; | |
| 38 return true; | |
| 39 case signin::mojom::AccountType::ACTIVE_DIRECTORY: | |
| 40 *out = AccountType::ACTIVE_DIRECTORY; | |
| 41 return true; | |
| 42 } | |
| 43 NOTREACHED(); | |
| 44 return false; | |
| 45 } | |
| 46 }; | |
| 47 | |
| 48 | |
| 49 template <> | |
| 50 struct StructTraits<signin::mojom::AccountIdDataView, AccountId> { | |
| 51 static AccountType account_type(const AccountId& r) { | |
| 52 return r.GetAccountType(); | |
| 53 } | |
| 54 static std::string id(const AccountId& r) { | |
| 55 switch (r.GetAccountType()) { | |
| 56 case AccountType::GOOGLE: | |
| 57 return r.GetGaiaId(); | |
| 58 case AccountType::ACTIVE_DIRECTORY: | |
| 59 return r.GetObjGuid(); | |
| 60 case AccountType::UNKNOWN: | |
| 61 break; | |
|
James Cook
2017/01/06 20:54:32
Question: So trying to get an id() of an unknown a
xiyuan
2017/01/06 21:49:35
Good question. And we actually have use of such Ac
| |
| 62 } | |
| 63 NOTREACHED(); | |
| 64 return ""; | |
| 65 } | |
| 66 static std::string user_email(const AccountId& r) { | |
| 67 return r.GetUserEmail(); | |
| 68 } | |
| 69 | |
| 70 static bool Read(signin::mojom::AccountIdDataView data, AccountId* out) { | |
| 71 AccountType account_type; | |
| 72 std::string id; | |
| 73 std::string user_email; | |
| 74 if (!data.ReadAccountType(&account_type) || | |
| 75 !data.ReadId(&id) || | |
| 76 !data.ReadUserEmail(&user_email)) { | |
| 77 return false; | |
| 78 } | |
| 79 | |
| 80 switch (account_type) { | |
| 81 case AccountType::GOOGLE: | |
| 82 *out = AccountId::FromUserEmailGaiaId(user_email, id); | |
| 83 break; | |
| 84 case AccountType::ACTIVE_DIRECTORY: | |
| 85 *out = AccountId::AdFromUserEmailObjGuid(user_email, id); | |
| 86 break; | |
| 87 case AccountType::UNKNOWN: | |
| 88 return false; | |
| 89 } | |
| 90 | |
| 91 return out->is_valid(); | |
| 92 } | |
| 93 }; | |
| 94 | |
| 95 } // namespace mojo | |
| 96 | |
| 97 #endif // COMPONENTS_SIGNIN_PUBLIC_INTERFACES_ACCOUNT_ID_TRAITS_H_ | |
| OLD | NEW |