Index: content/app/content_main_runner.cc |
diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc |
index 0cedd5ffc4a3be0b58f631aa2dbacc585b3406d2..2888f3545deff91f18de83384d1149b4a615aaa8 100644 |
--- a/content/app/content_main_runner.cc |
+++ b/content/app/content_main_runner.cc |
@@ -56,6 +56,7 @@ |
#include "content/public/browser/content_browser_client.h" |
#include "content/public/common/content_client.h" |
#include "content/public/common/content_constants.h" |
+#include "content/public/common/content_descriptor_keys.h" |
#include "content/public/common/content_paths.h" |
#include "content/public/common/content_switches.h" |
#include "content/public/common/main_function_params.h" |
@@ -68,6 +69,7 @@ |
#include "ipc/ipc_descriptors.h" |
#include "media/base/media.h" |
#include "ppapi/features/features.h" |
+#include "services/service_manager/public/cpp/shared_file_util.h" |
#include "ui/base/ui_base_paths.h" |
#include "ui/base/ui_base_switches.h" |
@@ -96,6 +98,7 @@ |
#if defined(OS_POSIX) |
#include <signal.h> |
+#include "base/file_descriptor_store.h" |
#include "base/posix/global_descriptors.h" |
#include "content/public/common/content_descriptors.h" |
@@ -139,9 +142,9 @@ namespace { |
#if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID) |
#if defined __LP64__ |
-#define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor64 |
+#define kV8SnapshotDataDescriptor kV8Snapshot64DataDescriptor |
#else |
-#define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor32 |
+#define kV8SnapshotDataDescriptor kV8Snapshot32DataDescriptor |
#endif |
#endif |
@@ -186,35 +189,22 @@ void InitializeV8IfNeeded( |
#if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
#if defined(OS_POSIX) && !defined(OS_MACOSX) |
- base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); |
-#if !defined(OS_ANDROID) |
- // kV8NativesDataDescriptor and kV8SnapshotDataDescriptor could be shared |
- // with child processes via file descriptors. On Android they are set in |
- // ChildProcessService::InternalInitChildProcess, otherwise set them here. |
- if (command_line.HasSwitch(switches::kV8NativesPassedByFD)) { |
- g_fds->Set( |
- kV8NativesDataDescriptor, |
- kV8NativesDataDescriptor + base::GlobalDescriptors::kBaseDescriptor); |
- } |
- if (command_line.HasSwitch(switches::kV8SnapshotPassedByFD)) { |
- g_fds->Set( |
- kV8SnapshotDataDescriptor, |
- kV8SnapshotDataDescriptor + base::GlobalDescriptors::kBaseDescriptor); |
- } |
-#endif // !OS_ANDROID |
- int v8_natives_fd = g_fds->MaybeGet(kV8NativesDataDescriptor); |
- int v8_snapshot_fd = g_fds->MaybeGet(kV8SnapshotDataDescriptor); |
- if (v8_snapshot_fd != -1) { |
- auto v8_snapshot_region = g_fds->GetRegion(kV8SnapshotDataDescriptor); |
- gin::V8Initializer::LoadV8SnapshotFromFD( |
- v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size); |
+ base::FileDescriptorStore& file_descriptor_store = |
+ base::FileDescriptorStore::GetInstance(); |
+ base::MemoryMappedFile::Region region; |
+ base::ScopedFD v8_snapshot_fd = |
+ file_descriptor_store.MaybeTakeFD(kV8SnapshotDataDescriptor, ®ion); |
+ if (v8_snapshot_fd.is_valid()) { |
+ gin::V8Initializer::LoadV8SnapshotFromFD(v8_snapshot_fd.get(), |
+ region.offset, region.size); |
} else { |
gin::V8Initializer::LoadV8Snapshot(); |
} |
- if (v8_natives_fd != -1) { |
- auto v8_natives_region = g_fds->GetRegion(kV8NativesDataDescriptor); |
- gin::V8Initializer::LoadV8NativesFromFD( |
- v8_natives_fd, v8_natives_region.offset, v8_natives_region.size); |
+ base::ScopedFD v8_natives_fd = |
+ file_descriptor_store.MaybeTakeFD(kV8NativesDataDescriptor, ®ion); |
+ if (v8_natives_fd.is_valid()) { |
+ gin::V8Initializer::LoadV8NativesFromFD(v8_natives_fd.get(), |
+ region.offset, region.size); |
} else { |
gin::V8Initializer::LoadV8Natives(); |
} |
@@ -296,6 +286,27 @@ void CommonSubprocessInit() { |
#endif |
} |
+#if defined(OS_POSIX) |
+void PopulateFDsFromCommandLine() { |
+ const std::string& shared_file_param = |
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
+ switches::kSharedFiles); |
+ if (shared_file_param.empty()) |
+ return; |
+ |
+ std::map<int, std::string> shared_file_descriptors; |
+ service_manager::ParseSharedFileSwitchValue(shared_file_param, |
+ &shared_file_descriptors); |
+ for (const auto& descriptor : shared_file_descriptors) { |
+ base::MemoryMappedFile::Region region; |
+ std::string key = descriptor.second; |
+ base::ScopedFD fd = base::GlobalDescriptors::GetInstance()->TakeFD( |
+ descriptor.first, ®ion); |
+ base::FileDescriptorStore::GetInstance().Set(key, std::move(fd), region); |
+ } |
+} |
+#endif // defined(OS_POSIX) |
+ |
class ContentClientInitializer { |
public: |
static void Set(const std::string& process_type, |
@@ -586,8 +597,8 @@ class ContentMainRunnerImpl : public ContentMainRunner { |
InitializeMac(); |
#endif |
- // On Android, the command line is initialized when library is loaded and |
- // we have already started our TRACE_EVENT0. |
+// On Android, the command line is initialized and the FDs set when the |
+// library is loaded and we have already started our TRACE_EVENT0. |
#if !defined(OS_ANDROID) |
// argc/argv are ignored on Windows and Android; see command_line.h for |
// details. |
@@ -601,6 +612,10 @@ class ContentMainRunnerImpl : public ContentMainRunner { |
base::CommandLine::Init(argc, argv); |
+#if defined(OS_POSIX) |
+ PopulateFDsFromCommandLine(); |
+#endif |
+ |
base::EnableTerminationOnHeapCorruption(); |
// TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. |