• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "mojo/public/cpp/base/file_mojom_traits.h"
6 #include "base/files/file.h"
7 #include "mojo/public/cpp/system/platform_handle.h"
8 
9 namespace mojo {
10 
fd(base::File & file)11 mojo::ScopedHandle StructTraits<mojo_base::mojom::FileDataView, base::File>::fd(
12     base::File& file) {
13   DCHECK(file.IsValid());
14 
15   return mojo::WrapPlatformFile(file.TakePlatformFile());
16 }
17 
Read(mojo_base::mojom::FileDataView data,base::File * file)18 bool StructTraits<mojo_base::mojom::FileDataView, base::File>::Read(
19     mojo_base::mojom::FileDataView data,
20     base::File* file) {
21   base::PlatformFile platform_handle = base::kInvalidPlatformFile;
22   if (mojo::UnwrapPlatformFile(data.TakeFd(), &platform_handle) !=
23       MOJO_RESULT_OK) {
24     return false;
25   }
26   *file = base::File(platform_handle, data.async());
27   return true;
28 }
29 
30 }  // namespace mojo
31