Commit b5e470c2 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Change FilePath to use EnableIf instead of native typemapping.

Bug: 676224
Change-Id: I101d138ac8ca72815cc6aa0a1b5ad4218b3c3001
Reviewed-on: https://chromium-review.googlesource.com/1065753Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560839}
parent c2de5cf5
......@@ -5,6 +5,7 @@
mojom = "//chrome/services/util_win/public/mojom/shell_util_win.mojom"
public_headers = [ "//base/strings/string16.h" ]
traits_headers = [ "//ipc/ipc_message_utils.h" ]
deps = [
"//base",
......
......@@ -30,6 +30,8 @@ component("shared_typemap_traits") {
sources = [
"big_buffer_mojom_traits.cc",
"big_buffer_mojom_traits.h",
"file_path_mojom_traits.cc",
"file_path_mojom_traits.h",
"shared_memory_mojom_traits.cc",
"shared_memory_mojom_traits.h",
"values_mojom_traits.cc",
......
......@@ -4,9 +4,9 @@
mojom = "//mojo/public/mojom/base/file_path.mojom"
public_headers = [ "//base/files/file_path.h" ]
traits_headers = [ "//ipc/ipc_message_utils.h" ]
traits_headers = [ "//mojo/public/cpp/base/file_path_mojom_traits.h" ]
public_deps = [
"//ipc",
"//mojo/public/cpp/base:shared_typemap_traits",
]
type_mappings = [ "mojo_base.mojom.FilePath=base::FilePath" ]
// 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/file_path_mojom_traits.h"
namespace mojo {
// static
bool StructTraits<mojo_base::mojom::FilePathDataView, base::FilePath>::Read(
mojo_base::mojom::FilePathDataView data,
base::FilePath* out) {
base::FilePath::StringPieceType path_view;
#if defined(OS_WIN)
ArrayDataView<uint16_t> view;
data.GetPathDataView(&view);
path_view.set(reinterpret_cast<const base::char16*>(view.data()),
view.size());
#else
if (!data.ReadPath(&path_view)) {
return false;
}
#endif
*out = base::FilePath(path_view);
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_FILE_PATH_MOJOM_TRAITS_H_
#define MOJO_PUBLIC_CPP_BASE_FILE_PATH_MOJOM_TRAITS_H_
#include "base/component_export.h"
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "mojo/public/mojom/base/file_path.mojom-shared.h"
namespace mojo {
template <>
struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)
StructTraits<mojo_base::mojom::FilePathDataView, base::FilePath> {
#if defined(OS_WIN)
static base::span<const uint16_t> path(const base::FilePath& path) {
return base::make_span(
reinterpret_cast<const uint16_t*>(path.value().data()),
path.value().size());
}
#else
static const base::FilePath::StringType& path(const base::FilePath& path) {
return path.value();
}
#endif
static bool Read(mojo_base::mojom::FilePathDataView data,
base::FilePath* out);
};
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BASE_FILE_PATH_MOJOM_TRAITS_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ipc/ipc_message_utils.h"
#include "mojo/public/cpp/base/file_path_mojom_traits.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "mojo/public/mojom/base/file_path.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -27,9 +27,11 @@ mojom_component("base") {
if (is_win) {
sources += [ "logfont_win.mojom" ]
}
if (is_posix && !is_android && !is_fuchsia && !is_mac) {
enabled_features = [ "shared_memory_region_uses_fd_pair" ]
enabled_features = []
if (is_win) {
enabled_features += [ "file_path_is_string16" ]
} else {
enabled_features += [ "file_path_is_string" ]
}
output_prefix = "mojo_base_mojom"
......
......@@ -4,5 +4,15 @@
module mojo_base.mojom;
[Native]
struct FilePath;
struct FilePath {
[EnableIf=file_path_is_string]
string path;
// This duplicates the contents of mojo_base.mojom.String16. String16 isn't
// used here due to typemapping dependency problems. base::FilePath is
// used for the typemap for both variants, but base::string16 and WTF::String
// are used for mojo_base.mojom.String16 typemapping. This mismatch causes
// problems with dependencies.
[EnableIf=file_path_is_string16]
array<uint16> path;
};
......@@ -4,6 +4,7 @@
#include "ui/display/mojo/display_snapshot_struct_traits.h"
#include "mojo/public/cpp/base/file_path_mojom_traits.h"
#include "ui/display/types/display_constants.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/size.h"
......
......@@ -8,6 +8,7 @@
#include <vector>
#include "base/macros.h"
#include "mojo/public/cpp/base/file_path_mojom_traits.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/display.h"
#include "ui/display/display_layout.h"
......
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