OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/child_process_launcher_helper_posix.h" | 5 #include "content/browser/child_process_launcher_helper_posix.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/posix/global_descriptors.h" | 9 #include "base/posix/global_descriptors.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "content/browser/file_descriptor_info_impl.h" | 12 #include "content/browser/file_descriptor_info_impl.h" |
13 #include "content/public/browser/content_browser_client.h" | 13 #include "content/public/browser/content_browser_client.h" |
14 #include "content/public/common/content_client.h" | 14 #include "content/public/common/content_client.h" |
15 #include "content/public/common/content_descriptors.h" | 15 #include "content/public/common/content_descriptors.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 #include "mojo/edk/embedder/platform_handle.h" | 17 #include "mojo/edk/embedder/platform_handle.h" |
18 #include "services/catalog/public/cpp/manifest_parsing_util.h" | 18 #include "services/catalog/public/cpp/manifest_parsing_util.h" |
19 #include "services/service_manager/public/cpp/shared_file_util.h" | 19 #include "services/service_manager/public/cpp/shared_file_util.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 namespace internal { | 22 namespace internal { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 using RequiredFilesByServiceMap = | 26 using RequiredFilesByServiceMap = |
27 std::map<std::string, catalog::RequiredFileMap>; | 27 std::map<std::string, catalog::RequiredFileMap>; |
28 | 28 |
29 RequiredFilesByServiceMap& GetRequiredFilesByServiceMap() { | 29 RequiredFilesByServiceMap& GetRequiredFilesByServiceMap() { |
30 static auto* required_files_by_service = new RequiredFilesByServiceMap(); | 30 static auto required_files_by_service = new RequiredFilesByServiceMap(); |
31 return *required_files_by_service; | 31 return *required_files_by_service; |
32 } | 32 } |
33 | 33 |
34 std::map<std::string, std::string>& GetServiceNameByProcessTypeMap() { | 34 std::map<std::string, std::string>& GetServiceNameByProcessTypeMap() { |
35 static auto* service_name_resolver = new std::map<std::string, std::string>( | 35 static auto service_name_resolver = new std::map<std::string, std::string>( |
36 {// The service names are defined in the JSON manifests, so we don't have | 36 {// The service names are defined in the JSON manifests, so we don't have |
37 // a constant accessible for them. | 37 // a constant accessible for them. |
38 // TODO(jcivelli): remove this map once the service name is accessible | 38 // TODO(jcivelli): remove this map once the service name is accessible |
39 // from the command line crbug.com/687250 | 39 // from the command line crbug.com/687250 |
40 {switches::kGpuProcess, "content_gpu"}, | 40 {switches::kGpuProcess, "content_gpu"}, |
41 {switches::kPpapiPluginProcess, "content_plugin"}, | 41 {switches::kPpapiPluginProcess, "content_plugin"}, |
42 {switches::kRendererProcess, "content_renderer"}, | 42 {switches::kRendererProcess, "content_renderer"}, |
43 {switches::kUtilityProcess, "content_utility"}, | 43 {switches::kUtilityProcess, "content_utility"}, |
44 {"ppapi-broker", "ppapi_broker"}, | 44 {"ppapi-broker", "ppapi_broker"}, |
45 {"nacl-loader", "nacl_loader"}, | 45 {"nacl-loader", "nacl_loader"}, |
46 {"nacl-loader-nonsfi", "nacl_loader_nonsfi"}}); | 46 {"nacl-loader-nonsfi", "nacl_loader_nonsfi"}}); |
47 return *service_name_resolver; | 47 return *service_name_resolver; |
48 } | 48 } |
49 | 49 |
50 base::PlatformFile OpenFileIfNecessary(const base::FilePath& path, | 50 base::PlatformFile OpenFileIfNecessary(const base::FilePath& path, |
51 base::MemoryMappedFile::Region* region) { | 51 base::MemoryMappedFile::Region* region) { |
52 static auto* opened_files = new std::map< | 52 static auto opened_files = |
53 base::FilePath, | 53 new std::map<base::FilePath, std::pair<base::PlatformFile, |
54 std::pair<base::PlatformFile, base::MemoryMappedFile::Region>>; | 54 base::MemoryMappedFile::Region>>; |
55 | 55 |
56 const auto& iter = opened_files->find(path); | 56 const auto& iter = opened_files->find(path); |
57 if (iter != opened_files->end()) { | 57 if (iter != opened_files->end()) { |
58 *region = iter->second.second; | 58 *region = iter->second.second; |
59 return iter->second.first; | 59 return iter->second.first; |
60 } | 60 } |
61 base::File file = OpenFileToShare(path, region); | 61 base::File file = OpenFileToShare(path, region); |
62 if (!file.IsValid()) { | 62 if (!file.IsValid()) { |
63 return base::kInvalidPlatformFile; | 63 return base::kInvalidPlatformFile; |
64 } | 64 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // Not a content child service, ignore. | 136 // Not a content child service, ignore. |
137 return; | 137 return; |
138 } | 138 } |
139 | 139 |
140 DCHECK(GetRequiredFilesByServiceMap().count(service_name) == 0); | 140 DCHECK(GetRequiredFilesByServiceMap().count(service_name) == 0); |
141 GetRequiredFilesByServiceMap()[service_name] = std::move(required_files); | 141 GetRequiredFilesByServiceMap()[service_name] = std::move(required_files); |
142 } | 142 } |
143 | 143 |
144 } // namespace internal | 144 } // namespace internal |
145 } // namespace content | 145 } // namespace content |
OLD | NEW |