Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Ken Rockot | 8dda8888 | 2019-12-04 05:56:22 | [diff] [blame] | 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 "content/browser/v8_snapshot_files.h" |
| 6 | |
Victor Hugo Vianna Silva | 0069272 | 2025-03-18 19:51:48 | [diff] [blame] | 7 | #include <variant> |
| 8 | |
Leszek Swirski | c062a07f | 2024-05-02 10:51:09 | [diff] [blame] | 9 | #include "base/command_line.h" |
| 10 | #include "base/feature_list.h" |
Ken Rockot | 8dda8888 | 2019-12-04 05:56:22 | [diff] [blame] | 11 | #include "build/build_config.h" |
| 12 | #include "content/public/common/content_descriptor_keys.h" |
Leszek Swirski | c062a07f | 2024-05-02 10:51:09 | [diff] [blame] | 13 | #include "content/public/common/content_features.h" |
| 14 | #include "content/public/common/content_switches.h" |
Nico Weber | 8f59b10 | 2022-11-30 03:48:39 | [diff] [blame] | 15 | #include "tools/v8_context_snapshot/buildflags.h" |
Ken Rockot | 8dda8888 | 2019-12-04 05:56:22 | [diff] [blame] | 16 | |
| 17 | namespace content { |
| 18 | |
Sam Maier | 40b73fc | 2025-05-30 14:15:56 | [diff] [blame] | 19 | #if BUILDFLAG(IS_ANDROID) && BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) |
| 20 | namespace { |
| 21 | void registerContextSnapshotAndroid( |
| 22 | std::map<std::string, std::variant<base::FilePath, base::ScopedFD>>& |
| 23 | files) { |
| 24 | #ifdef __LP64__ |
| 25 | files[kV8ContextSnapshot64DataDescriptor] = |
| 26 | #else |
| 27 | files[kV8ContextSnapshot32DataDescriptor] = |
| 28 | #endif // __LP64__ |
| 29 | base::FilePath(FILE_PATH_LITERAL("assets")) |
| 30 | .Append(FILE_PATH_LITERAL(BUILDFLAG(V8_CONTEXT_SNAPSHOT_FILENAME))); |
| 31 | } |
| 32 | } // namespace |
| 33 | #endif // BUILDFLAG(IS_ANDROID) |
| 34 | |
Victor Hugo Vianna Silva | 0069272 | 2025-03-18 19:51:48 | [diff] [blame] | 35 | std::map<std::string, std::variant<base::FilePath, base::ScopedFD>> |
Leszek Swirski | c062a07f | 2024-05-02 10:51:09 | [diff] [blame] | 36 | GetV8SnapshotFilesToPreload(base::CommandLine& process_command_line) { |
Victor Hugo Vianna Silva | 0069272 | 2025-03-18 19:51:48 | [diff] [blame] | 37 | std::map<std::string, std::variant<base::FilePath, base::ScopedFD>> files; |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 38 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
Nico Weber | 8f59b10 | 2022-11-30 03:48:39 | [diff] [blame] | 39 | #if BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) |
Matthew Denton | c46d14cb | 2023-01-11 00:59:21 | [diff] [blame] | 40 | files[kV8ContextSnapshotDataDescriptor] = base::FilePath( |
| 41 | FILE_PATH_LITERAL(BUILDFLAG(V8_CONTEXT_SNAPSHOT_FILENAME))); |
Ken Rockot | 8dda8888 | 2019-12-04 05:56:22 | [diff] [blame] | 42 | #else |
Matthew Denton | c46d14cb | 2023-01-11 00:59:21 | [diff] [blame] | 43 | files[kV8SnapshotDataDescriptor] = |
| 44 | base::FilePath(FILE_PATH_LITERAL("snapshot_blob.bin")); |
Ken Rockot | 8dda8888 | 2019-12-04 05:56:22 | [diff] [blame] | 45 | #endif |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 46 | #elif BUILDFLAG(IS_ANDROID) |
Leszek Swirski | c062a07f | 2024-05-02 10:51:09 | [diff] [blame] | 47 | #if !BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) || BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS) |
| 48 | #if BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS) |
| 49 | if (base::FeatureList::IsEnabled(features::kUseContextSnapshot)) { |
| 50 | process_command_line.AppendSwitch(switches::kUseContextSnapshotSwitch); |
Sam Maier | 40b73fc | 2025-05-30 14:15:56 | [diff] [blame] | 51 | registerContextSnapshotAndroid(files); |
Leszek Swirski | c062a07f | 2024-05-02 10:51:09 | [diff] [blame] | 52 | } |
| 53 | #endif // BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS) |
Sam Maier | 40b73fc | 2025-05-30 14:15:56 | [diff] [blame] | 54 | #ifdef __LP64__ |
Matthew Denton | c46d14cb | 2023-01-11 00:59:21 | [diff] [blame] | 55 | files[kV8Snapshot64DataDescriptor] = |
| 56 | base::FilePath(FILE_PATH_LITERAL("assets/snapshot_blob_64.bin")); |
Sam Maier | 40b73fc | 2025-05-30 14:15:56 | [diff] [blame] | 57 | #else |
Matthew Denton | c46d14cb | 2023-01-11 00:59:21 | [diff] [blame] | 58 | files[kV8Snapshot32DataDescriptor] = |
| 59 | base::FilePath(FILE_PATH_LITERAL("assets/snapshot_blob_32.bin")); |
Sam Maier | 40b73fc | 2025-05-30 14:15:56 | [diff] [blame] | 60 | #endif // __LP64__ |
Nico Weber | 8f59b10 | 2022-11-30 03:48:39 | [diff] [blame] | 61 | #elif BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) |
Sam Maier | 40b73fc | 2025-05-30 14:15:56 | [diff] [blame] | 62 | registerContextSnapshotAndroid(files); |
| 63 | #endif // !BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) || |
| 64 | // BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS) |
Matthew Denton | c46d14cb | 2023-01-11 00:59:21 | [diff] [blame] | 65 | #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
| 66 | return files; |
Ken Rockot | 8dda8888 | 2019-12-04 05:56:22 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | } // namespace content |