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_FILE_PATH_MOJOM_TRAITS_H_ 6 #define MOJO_PUBLIC_CPP_BASE_FILE_PATH_MOJOM_TRAITS_H_ 7 8 #include "base/component_export.h" 9 #include "base/containers/span.h" 10 #include "base/files/file_path.h" 11 #include "build/build_config.h" 12 #include "mojo/public/cpp/bindings/struct_traits.h" 13 #include "mojo/public/mojom/base/file_path.mojom-shared.h" 14 15 namespace mojo { 16 17 template <> COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)18struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS) 19 StructTraits<mojo_base::mojom::FilePathDataView, base::FilePath> { 20 #if defined(OS_WIN) 21 static base::span<const uint16_t> path(const base::FilePath& path) { 22 return base::make_span( 23 reinterpret_cast<const uint16_t*>(path.value().data()), 24 path.value().size()); 25 } 26 #else 27 static const base::FilePath::StringType& path(const base::FilePath& path) { 28 return path.value(); 29 } 30 #endif 31 32 static bool Read(mojo_base::mojom::FilePathDataView data, 33 base::FilePath* out); 34 }; 35 36 } // namespace mojo 37 38 #endif // MOJO_PUBLIC_CPP_BASE_FILE_PATH_MOJOM_TRAITS_H_ 39