Chromium Code Reviews| Index: mojo/common/common_custom_types_struct_traits.h |
| diff --git a/mojo/common/common_custom_types_struct_traits.h b/mojo/common/common_custom_types_struct_traits.h |
| index 5244cf7a2a6108280136a03f9a3bc385c49a5cb2..987c708087c8965a5991bffb48a3e9329d0d4bc4 100644 |
| --- a/mojo/common/common_custom_types_struct_traits.h |
| +++ b/mojo/common/common_custom_types_struct_traits.h |
| @@ -5,6 +5,7 @@ |
| #ifndef MOJO_COMMON_COMMON_CUSTOM_TYPES_STRUCT_TRAITS_H_ |
| #define MOJO_COMMON_COMMON_CUSTOM_TYPES_STRUCT_TRAITS_H_ |
| +#include "base/unguessable_token.h" |
| #include "base/version.h" |
| #include "mojo/common/common_custom_types.mojom-shared.h" |
| @@ -23,6 +24,38 @@ struct StructTraits<mojo::common::mojom::VersionDataView, base::Version> { |
| base::Version* out); |
| }; |
| +// If base::UnguessableToken is no longer 128 bits, the logic below and the |
| +// mojom::UnguessableToken type should be updated. |
| +static_assert(sizeof(base::UnguessableToken) == 2 * sizeof(uint64_t), |
| + "base::UnguessableToken should be of size 2 * sizeof(uint64_t)."); |
| + |
| +template <> |
| +struct StructTraits<mojo::common::mojom::UnguessableTokenDataView, |
| + base::UnguessableToken> { |
| + static uint64_t high(const base::UnguessableToken& token) { |
| + DCHECK(token); |
|
dcheng
2016/09/17 00:22:20
Nit: remove these DCHECKs, we already check them i
tguilbert
2016/09/17 00:49:49
Done.
|
| + return token.GetHighForSerialization(); |
| + } |
| + |
| + static uint64_t low(const base::UnguessableToken& token) { |
| + DCHECK(token); |
| + return token.GetLowForSerialization(); |
| + } |
| + |
| + static bool Read(mojo::common::mojom::UnguessableTokenDataView data, |
| + base::UnguessableToken* out) { |
| + uint64_t high = data.high(); |
| + uint64_t low = data.low(); |
| + |
| + // Receiving a zeroed UnguessableToken is a security issue. |
| + if (high == 0 && low == 0) |
| + return false; |
| + |
| + *out = base::UnguessableToken::Deserialize(high, low); |
| + return true; |
|
dcheng
2016/09/17 00:22:20
Please out-of-line the Read() method into the .cc
tguilbert
2016/09/17 00:49:49
Done.
|
| + } |
| +}; |
| + |
| template <> |
| struct StructTraits<mojo::common::mojom::TimeDeltaDataView, base::TimeDelta> { |
| static int64_t microseconds(const base::TimeDelta& delta) { |