Commit 82ad2be0 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

[mojo-base] Add Token mojom

Adds mojo_base.mojom.Token to serialize the new base::Token type.

Bug: 895591
Change-Id: I7e982d75a9e5d40b4df7e49645d7bf4791e8d57e
Reviewed-on: https://chromium-review.googlesource.com/c/1321191
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606227}
parent e730ea4c
......@@ -40,6 +40,8 @@ component("shared_typemap_traits") {
"shared_memory_mojom_traits.h",
"time_mojom_traits.cc",
"time_mojom_traits.h",
"token_mojom_traits.cc",
"token_mojom_traits.h",
"unguessable_token_mojom_traits.cc",
"unguessable_token_mojom_traits.h",
"values_mojom_traits.cc",
......@@ -72,6 +74,7 @@ source_set("tests") {
"text_direction_unittest.cc",
"thread_priority_unittest.cc",
"time_unittest.cc",
"token_unittest.cc",
"unguessable_token_unittest.cc",
"values_unittest.cc",
]
......
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
mojom = "//mojo/public/mojom/base/token.mojom"
public_headers = [ "//base/token.h" ]
traits_headers = [ "//mojo/public/cpp/base/token_mojom_traits.h" ]
public_deps = [
"//base",
"//mojo/public/cpp/base:shared_typemap_traits",
]
type_mappings = [ "mojo_base.mojom.Token=base::Token" ]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/public/cpp/base/token_mojom_traits.h"
namespace mojo {
// static
bool StructTraits<mojo_base::mojom::TokenDataView, base::Token>::Read(
mojo_base::mojom::TokenDataView data,
base::Token* out) {
*out = base::Token{data.high(), data.low()};
return true;
}
} // namespace mojo
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_PUBLIC_CPP_BASE_TOKEN_MOJOM_TRAITS_H_
#define MOJO_PUBLIC_CPP_BASE_TOKEN_MOJOM_TRAITS_H_
#include "base/component_export.h"
#include "base/token.h"
#include "mojo/public/mojom/base/token.mojom-shared.h"
namespace mojo {
template <>
struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)
StructTraits<mojo_base::mojom::TokenDataView, base::Token> {
static uint64_t high(const base::Token& token) { return token.high(); }
static uint64_t low(const base::Token& token) { return token.low(); }
static bool Read(mojo_base::mojom::TokenDataView data, base::Token* out);
};
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BASE_TOKEN_MOJOM_TRAITS_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/public/cpp/base/token_mojom_traits.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "mojo/public/mojom/base/token.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo_base {
namespace token_unittest {
TEST(TokenTest, Token) {
base::Token in;
base::Token out;
ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::Token>(&in, &out));
EXPECT_EQ(in, out);
constexpr uint64_t kTestHigh = 0x0123456789abcdefull;
constexpr uint64_t kTestLow = 0x5a5a5a5aa5a5a5a5ull;
in = base::Token{kTestHigh, kTestLow};
ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::Token>(&in, &out));
EXPECT_EQ(in, out);
in = base::Token::CreateRandom();
ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::Token>(&in, &out));
EXPECT_EQ(in, out);
}
} // namespace token_unittest
} // namespace mojo_base
......@@ -19,6 +19,7 @@ typemaps = [
"//mojo/public/cpp/base/text_direction.typemap",
"//mojo/public/cpp/base/thread_priority.typemap",
"//mojo/public/cpp/base/time.typemap",
"//mojo/public/cpp/base/token.typemap",
"//mojo/public/cpp/base/unguessable_token.typemap",
"//mojo/public/cpp/base/values.typemap",
]
......@@ -20,6 +20,7 @@ mojom_component("base") {
"text_direction.mojom",
"thread_priority.mojom",
"time.mojom",
"token.mojom",
"unguessable_token.mojom",
"values.mojom",
]
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module mojo_base.mojom;
// Corresponds to |base::Token| defined in base/token.h
struct Token {
uint64 high;
uint64 low;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment