Home | History | Annotate | Download | only in base
      1 // Copyright 2018 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 MOJO_PUBLIC_CPP_BASE_UNGUESSABLE_TOKEN_MOJOM_TRAITS_H_
      6 #define MOJO_PUBLIC_CPP_BASE_UNGUESSABLE_TOKEN_MOJOM_TRAITS_H_
      7 
      8 #include "base/component_export.h"
      9 #include "base/unguessable_token.h"
     10 #include "mojo/public/mojom/base/unguessable_token.mojom-shared.h"
     11 
     12 namespace mojo {
     13 
     14 // If base::UnguessableToken is no longer 128 bits, the logic below and the
     15 // mojom::UnguessableToken type should be updated.
     16 static_assert(sizeof(base::UnguessableToken) == 2 * sizeof(uint64_t),
     17               "base::UnguessableToken should be of size 2 * sizeof(uint64_t).");
     18 
     19 template <>
     20 struct COMPONENT_EXPORT(MOJO_BASE_MOJOM)
     21     StructTraits<mojo_base::mojom::UnguessableTokenDataView,
     22                  base::UnguessableToken> {
     23   static uint64_t high(const base::UnguessableToken& token) {
     24     return token.GetHighForSerialization();
     25   }
     26 
     27   static uint64_t low(const base::UnguessableToken& token) {
     28     return token.GetLowForSerialization();
     29   }
     30 
     31   static bool Read(mojo_base::mojom::UnguessableTokenDataView data,
     32                    base::UnguessableToken* out);
     33 };
     34 
     35 }  // namespace mojo
     36 
     37 #endif  // MOJO_PUBLIC_CPP_BASE_UNGUESSABLE_TOKEN_MOJOM_TRAITS_H_