chromium/services/network/public/cpp/transferable_directory.h

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SERVICES_NETWORK_PUBLIC_CPP_TRANSFERABLE_DIRECTORY_H_
#define SERVICES_NETWORK_PUBLIC_CPP_TRANSFERABLE_DIRECTORY_H_

#include "base/component_export.h"
#include "base/files/file_path.h"
#include "base/functional/callback_helpers.h"
#include "mojo/public/cpp/bindings/union_traits.h"
#include "mojo/public/cpp/platform/platform_handle.h"

namespace network {
class TransferableDirectory;
}
namespace network::mojom {
class TransferableDirectoryDataView;
}
namespace mojo {
template <>
struct UnionTraits<network::mojom::TransferableDirectoryDataView,
                   network::TransferableDirectory>;
}

namespace network {

// Represents a directory that, on some platforms, can be sent as a handle
// across process boundaries to be later mounted to a process-local path.
//
// Platforms which use the same filesystem across process boundaries can simply
// use the path as-is, with no handle marshaling steps required.
//
// Example usage:
//  SENDER:
//   TransferableDirectory dir = base::FilePath("/dir/to/share");
//   if (dir.IsOpenForTransferRequired())
//     dir.OpenForTransfer();
//   mojo_client->UseDirectory(std::move(dir));
//
//  RECEIVER:
//   AutoClosureRunner dismounter;
//   if (dir.NeedsMount())
//     dismounter = AutoClosureRunner(dir.Mount());
//
//   base::File file(dir.path().Append("shared_file.txt"));
//   ...use |file| normally...
class COMPONENT_EXPORT(NETWORK_CPP_BASE) TransferableDirectory {};

}  // namespace network

#endif  // SERVICES_NETWORK_PUBLIC_CPP_TRANSFERABLE_DIRECTORY_H_