OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 SERVICES_SHELL_PUBLIC_CPP_IDENTITY_STRUCT_TRAITS_H_ | |
6 #define SERVICES_SHELL_PUBLIC_CPP_IDENTITY_STRUCT_TRAITS_H_ | |
7 | |
8 #include "services/shell/public/cpp/identity.h" | |
9 #include "services/shell/public/interfaces/connector.mojom.h" | |
10 | |
11 namespace mojo { | |
12 | |
13 template <> | |
14 struct StructTraits<shell::mojom::IdentityDataView, shell::Identity> { | |
15 static const std::string& name(const shell::Identity& identity) { | |
16 return identity.name(); | |
17 } | |
18 static const std::string& user_id(const shell::Identity& identity) { | |
19 return identity.user_id(); | |
20 } | |
21 static const std::string& instance(const shell::Identity& identity) { | |
22 return identity.instance(); | |
23 } | |
24 static bool Read(shell::mojom::IdentityDataView data, shell::Identity* out) { | |
25 std::string name, user_id, instance; | |
26 if (!data.ReadName(&name)) | |
27 return false; | |
28 | |
29 if (!data.ReadUserId(&user_id)) | |
30 return false; | |
31 | |
32 if (!data.ReadInstance(&instance)) | |
33 return false; | |
34 | |
35 *out = shell::Identity(name, user_id, instance); | |
36 return true; | |
37 } | |
38 }; | |
39 | |
40 } // namespace mojo | |
41 | |
42 #endif // SERVICES_SHELL_PUBLIC_CPP_IDENTITY_STRUCT_TRAITS_H_ | |
OLD | NEW |