0
Files
src/content/browser/v8_snapshot_files.cc
Matthew Denton c46d14cb0c Allow use of files_to_preload with existing file descriptors.
...so we can use FileDescriptorStore with fds that don't refer to
regular files. Right now ChildProcessLauncherFileData's files_to_preload
is the only way to pass a file via FileDescriptorStore without editing
child_process_launcher internals, so make it hold a
variant<FilePath, int> instead of just a FilePath.


NOTE:
At this point on Linux there are 3 ways to "name" file descriptors
passed to a child process:
1. Normal file descriptor table
2. base::GlobalDescriptors (integer keys map to fd numbers)
3. base::FileDescriptorStore (string keys map to base::GlobalDescriptors
   keys).

 can be modified with
ChildProcessLauncherFileData::additional_remapped_fds,  can be
modified with
ContentBrowserClient::GetAdditionalMappedFilesForChildProcess(), and
 can be modified with ChildProcessLauncherFileData::files_to_preload.

Bug: 692619
Change-Id: I1cc678887cb44830f74614ffbeb027791aeb6505
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4141862
Commit-Queue: Matthew Denton <mpdenton@chromium.org>
Reviewed-by: Bo Liu <boliu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1091118}
2023-01-11 00:59:21 +00:00

39 lines
1.4 KiB
C++

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/v8_snapshot_files.h"
#include "build/build_config.h"
#include "content/public/common/content_descriptor_keys.h"
#include "tools/v8_context_snapshot/buildflags.h"
namespace content {
std::map<std::string, absl::variant<base::FilePath, base::ScopedFD>>
GetV8SnapshotFilesToPreload() {
std::map<std::string, absl::variant<base::FilePath, base::ScopedFD>> files;
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT)
files[kV8ContextSnapshotDataDescriptor] = base::FilePath(
FILE_PATH_LITERAL(BUILDFLAG(V8_CONTEXT_SNAPSHOT_FILENAME)));
#else
files[kV8SnapshotDataDescriptor] =
base::FilePath(FILE_PATH_LITERAL("snapshot_blob.bin"));
#endif
#elif BUILDFLAG(IS_ANDROID)
#if !BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT)
files[kV8Snapshot64DataDescriptor] =
base::FilePath(FILE_PATH_LITERAL("assets/snapshot_blob_64.bin"));
files[kV8Snapshot32DataDescriptor] =
base::FilePath(FILE_PATH_LITERAL("assets/snapshot_blob_32.bin"));
#elif BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT)
// For USE_V8_CONTEXT_SNAPSHOT, the renderer reads the files directly.
return {};
#endif
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
return files;
}
} // namespace content