Commit 1ee38359 authored by Jiaquan He's avatar Jiaquan He Committed by Commit Bot

syncer: add mojo for StringOrdinal.

After migrating app_list from Chrome to Ash, we'll need to pass
StringOrdinal objects between processes for setting app list item
positions, e.g. AppListModel::SetItemPosition.

This commit creates a mojo struct for StringOrdinal so that
//ash/public/interfaces:interfaces_internal can depend on it.

Bug: 733662
Change-Id: I96bbd81a82a53462aa0eb2cdcf9e327045a70051
Reviewed-on: https://chromium-review.googlesource.com/780696Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Commit-Queue: Jiaquan He <hejq@google.com>
Cr-Commit-Position: refs/heads/master@{#521386}
parent 557e241c
......@@ -14,8 +14,17 @@
#include "base/json/string_escape.h"
#include "base/logging.h"
namespace mojo {
template <typename DataViewType, typename T>
struct StructTraits;
}
namespace syncer {
namespace mojom {
class StringOrdinalDataView;
}
// An Ordinal<T> is an object that can be used for ordering. The
// Ordinal<T> class has an unbounded dense strict total order, which
// mean for any Ordinal<T>s a, b and c:
......@@ -151,6 +160,9 @@ class Ordinal {
static_assert(kRadix == kMaxDigitValue + 1, "incorrect ordinal radix");
private:
friend struct mojo::StructTraits<syncer::mojom::StringOrdinalDataView,
Ordinal<Traits>>;
// Returns true iff the given byte string satisfies the criteria for
// a valid Ordinal.
static bool IsValidOrdinalBytes(const std::string& bytes);
......
# Copyright 2017 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.
import("//mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") {
sources = [
"syncer.mojom",
]
}
include_rules = [
"+components/sync",
]
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
per-file *_struct_traits*.*=set noparent
per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS
per-file *.typemap=set noparent
per-file *.typemap=file://ipc/SECURITY_OWNERS
// Copyright 2017 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 syncer.mojom;
// A StringOrdinal is an Ordinal with range 'a'-'z' for printability
// of its internal byte string representation. (Think of
// StringOrdinal as being short for PrintableStringOrdinal.) It
// should be used for data types that want to maintain one or more
// orderings for sync nodes.
struct StringOrdinal {
array<uint8> bytes;
};
# Copyright 2017 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 = "//components/sync/mojo/syncer.mojom"
public_headers = [ "//components/sync/model/string_ordinal.h" ]
traits_headers = [ "//components/sync/mojo/syncer_struct_traits.h" ]
type_mappings = [ "syncer.mojom.StringOrdinal=syncer::StringOrdinal" ]
// Copyright 2017 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 COMPONENTS_SYNC_MOJO_SYNCER_STRUCT_TRAITS_H_
#define COMPONENTS_SYNC_MOJO_SYNCER_STRUCT_TRAITS_H_
#include <string>
#include "components/sync/model/string_ordinal.h"
#include "components/sync/mojo/syncer.mojom-shared.h"
namespace mojo {
template <>
struct StructTraits<syncer::mojom::StringOrdinalDataView,
syncer::StringOrdinal> {
static base::span<const uint8_t> bytes(const syncer::StringOrdinal& ordinal) {
return base::make_span(
reinterpret_cast<const uint8_t*>(ordinal.bytes_.data()),
ordinal.bytes_.length());
}
static bool Read(syncer::mojom::StringOrdinalDataView data,
syncer::StringOrdinal* out) {
mojo::ArrayDataView<uint8_t> bytes;
data.GetBytesDataView(&bytes);
*out = syncer::StringOrdinal(reinterpret_cast<const char*>(bytes.data()));
return true;
}
};
} // namespace mojo
#endif // COMPONENTS_SYNC_MOJO_SYNCER_STRUCT_TRAITS_H_
# Copyright 2017 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.
typemaps = [ "//components/sync/mojo/syncer.typemap" ]
......@@ -11,6 +11,7 @@ _typemap_imports = [
"//chrome/typemaps.gni",
"//components/arc/common/typemaps.gni",
"//components/metrics/public/cpp/typemaps.gni",
"//components/sync/mojo/typemaps.gni",
"//components/typemaps.gni",
"//content/common/bluetooth/typemaps.gni",
"//content/common/indexed_db/typemaps.gni",
......
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