Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1104)

Unified Diff: content/browser/child_process_launcher_helper.cc

Issue 2684433003: Files required by a service now listed in manifest. (Closed)
Patch Set: Fixed analysis. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/child_process_launcher_helper.cc
diff --git a/content/browser/child_process_launcher_helper.cc b/content/browser/child_process_launcher_helper.cc
index 9aa83459ba904dbf4e7db6a08f125a156cdda4a9..8b040cffdd00398dd92857789c74546c3b3e1581 100644
--- a/content/browser/child_process_launcher_helper.cc
+++ b/content/browser/child_process_launcher_helper.cc
@@ -4,8 +4,16 @@
#include "content/browser/child_process_launcher_helper.h"
+#include "base/base_paths.h"
+#include "base/files/file.h"
+#include "base/lazy_instance.h"
#include "base/metrics/histogram_macros.h"
+#include "base/path_service.h"
+#include "base/posix/global_descriptors.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
#include "content/browser/child_process_launcher.h"
+#include "content/public/common/content_descriptors.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
@@ -15,6 +23,18 @@ namespace internal {
namespace {
+base::LazyInstance<
+ std::map<std::string, std::unique_ptr<catalog::RequiredFileMap>>>
+ g_required_files_by_service = LAZY_INSTANCE_INITIALIZER;
+
+base::LazyInstance<std::map<std::string, std::string>>
+ g_process_name_to_service_name = LAZY_INSTANCE_INITIALIZER;
+
+typedef std::map<base::FilePath,
+ std::pair<base::PlatformFile, base::MemoryMappedFile::Region>>
+ OpenedFileMap;
+base::LazyInstance<OpenedFileMap> g_opened_files = LAZY_INSTANCE_INITIALIZER;
+
void RecordHistogramsOnLauncherThread(base::TimeDelta launch_time) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
// Log the launch time, separating out the first one (which will likely be
@@ -28,6 +48,23 @@ void RecordHistogramsOnLauncherThread(base::TimeDelta launch_time) {
}
}
+base::PlatformFile OpenFileIfNecessary(const base::FilePath& path,
+ base::MemoryMappedFile::Region* region) {
+ const auto& iter = g_opened_files.Get().find(path);
+ if (iter != g_opened_files.Get().end()) {
+ *region = iter->second.second;
+ return iter->second.first;
+ }
+ base::File file = ChildProcessLauncherHelper::OpenFile(path, region);
+ if (!file.IsValid()) {
+ return base::kInvalidPlatformFile;
+ }
+ // g_opened_files becomes the owner of the file descriptor.
+ base::PlatformFile fd = file.TakePlatformFile();
+ g_opened_files.Get()[path] = std::make_pair(fd, *region);
+ return fd;
+}
+
} // namespace
ChildProcessLauncherHelper::Process::Process(Process&& other)
@@ -91,6 +128,37 @@ void ChildProcessLauncherHelper::LaunchOnLauncherThread() {
std::unique_ptr<FileMappedForLaunch> files_to_register = GetFilesToMap();
+ // Also include the files specified in the services' manifests.
+ const auto& service_name_iter =
+ g_process_name_to_service_name.Get().find(GetProcessType());
+ CHECK(service_name_iter != g_process_name_to_service_name.Get().end());
+ std::string service_name = service_name_iter->second;
+ const auto& files_iter = g_required_files_by_service.Get().find(service_name);
+ if (files_iter != g_required_files_by_service.Get().end()) {
+ catalog::RequiredFileMap* required_files_map = files_iter->second.get();
+ base::GlobalDescriptors::Key key = kContentDynamicDescriptorStart;
+ std::string switch_value;
+ for (const auto& key_path_iter : *required_files_map) {
+ base::MemoryMappedFile::Region region;
+ base::PlatformFile file =
+ OpenFileIfNecessary(base::FilePath(key_path_iter.second), &region);
+ if (file == base::kInvalidPlatformFile) {
+ LOG(ERROR) << "Ignoring invalid file " << key_path_iter.second;
+ continue;
+ }
+ if (!switch_value.empty()) {
+ switch_value += ",";
+ }
+ switch_value += key_path_iter.first;
+ switch_value += ":";
+ switch_value += base::IntToString(key);
+ files_to_register->ShareWithRegion(key, file, region);
+ key++;
+ DCHECK(key < kContentDynamicDescriptorMax);
+ }
+ command_line()->AppendSwitchASCII(switches::kSharedFiles, switch_value);
+ }
+
bool is_synchronous_launch = true;
int launch_result = LAUNCH_RESULT_FAILURE;
base::LaunchOptions options;
@@ -161,5 +229,34 @@ void ChildProcessLauncherHelper::ForceNormalProcessTerminationAsync(
base::Passed(&process)));
}
+// static
+void ChildProcessLauncherHelper::SetRegisteredFilesForService(
+ const std::string& service_name,
+ std::unique_ptr<catalog::RequiredFileMap> required_files) {
+ if (required_files->empty())
+ return;
+
+ std::map<std::string, std::string>& service_name_resolver =
Ken Rockot(use gerrit already) 2017/02/09 17:17:28 I don't see this being used? Is the |service_name|
Jay Civelli 2017/02/09 22:08:27 It's a bit confusing, I am setting a local var tha
+ g_process_name_to_service_name.Get();
+ if (service_name_resolver.empty()) {
+ // Populate the process name to service name.
Ken Rockot(use gerrit already) 2017/02/09 17:17:28 nit: s/Populate/Translate/? Also maybe add a TODO
Jay Civelli 2017/02/09 22:08:27 Changed to populate map.
+ // The service names are defined in the JSON manifests, so we don't have a
+ // constant accessible for them.
+ service_name_resolver[switches::kRendererProcess] = "content_renderer";
+ service_name_resolver[switches::kGpuProcess] = "content_gpu";
+ service_name_resolver[switches::kPpapiPluginProcess] = "content_plugin";
+ service_name_resolver[switches::kUtilityProcess] = "content_utility";
+ }
+
+ if (!base::StartsWith(service_name, "content",
+ base::CompareCase::INSENSITIVE_ASCII)) {
+ // Not a content child service, ignore.
+ return;
+ }
+
+ DCHECK(g_required_files_by_service.Get().count(service_name) == 0);
+ g_required_files_by_service.Get()[service_name] = std::move(required_files);
+}
+
} // namespace internal
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698