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

Side by Side Diff: content/app/content_main_runner.cc

Issue 2684433003: Files required by a service now listed in manifest. (Closed)
Patch Set: Synced 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/public/app/content_main_runner.h" 5 #include "content/public/app/content_main_runner.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "content/browser/renderer_host/render_process_host_impl.h" 50 #include "content/browser/renderer_host/render_process_host_impl.h"
51 #include "content/browser/utility_process_host_impl.h" 51 #include "content/browser/utility_process_host_impl.h"
52 #include "content/common/set_process_title.h" 52 #include "content/common/set_process_title.h"
53 #include "content/common/url_schemes.h" 53 #include "content/common/url_schemes.h"
54 #include "content/gpu/in_process_gpu_thread.h" 54 #include "content/gpu/in_process_gpu_thread.h"
55 #include "content/public/app/content_main.h" 55 #include "content/public/app/content_main.h"
56 #include "content/public/app/content_main_delegate.h" 56 #include "content/public/app/content_main_delegate.h"
57 #include "content/public/browser/content_browser_client.h" 57 #include "content/public/browser/content_browser_client.h"
58 #include "content/public/common/content_client.h" 58 #include "content/public/common/content_client.h"
59 #include "content/public/common/content_constants.h" 59 #include "content/public/common/content_constants.h"
60 #include "content/public/common/content_descriptor_keys.h"
60 #include "content/public/common/content_paths.h" 61 #include "content/public/common/content_paths.h"
61 #include "content/public/common/content_switches.h" 62 #include "content/public/common/content_switches.h"
62 #include "content/public/common/main_function_params.h" 63 #include "content/public/common/main_function_params.h"
63 #include "content/public/common/sandbox_init.h" 64 #include "content/public/common/sandbox_init.h"
64 #include "content/public/gpu/content_gpu_client.h" 65 #include "content/public/gpu/content_gpu_client.h"
65 #include "content/public/renderer/content_renderer_client.h" 66 #include "content/public/renderer/content_renderer_client.h"
66 #include "content/public/utility/content_utility_client.h" 67 #include "content/public/utility/content_utility_client.h"
67 #include "content/renderer/in_process_renderer_thread.h" 68 #include "content/renderer/in_process_renderer_thread.h"
68 #include "content/utility/in_process_utility_thread.h" 69 #include "content/utility/in_process_utility_thread.h"
69 #include "ipc/ipc_descriptors.h" 70 #include "ipc/ipc_descriptors.h"
70 #include "media/base/media.h" 71 #include "media/base/media.h"
71 #include "ppapi/features/features.h" 72 #include "ppapi/features/features.h"
73 #include "services/service_manager/public/cpp/shared_file_util.h"
72 #include "ui/base/ui_base_paths.h" 74 #include "ui/base/ui_base_paths.h"
73 #include "ui/base/ui_base_switches.h" 75 #include "ui/base/ui_base_switches.h"
74 76
75 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && \ 77 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && \
76 !defined(CHROME_MULTIPLE_DLL_BROWSER) 78 !defined(CHROME_MULTIPLE_DLL_BROWSER)
77 #include "gin/v8_initializer.h" 79 #include "gin/v8_initializer.h"
78 #endif 80 #endif
79 81
80 #if defined(OS_WIN) 82 #if defined(OS_WIN)
81 #include <malloc.h> 83 #include <malloc.h>
82 #include <cstring> 84 #include <cstring>
83 85
84 #include "base/trace_event/trace_event_etw_export_win.h" 86 #include "base/trace_event/trace_event_etw_export_win.h"
85 #include "base/win/process_startup_helper.h" 87 #include "base/win/process_startup_helper.h"
86 #include "sandbox/win/src/sandbox_types.h" 88 #include "sandbox/win/src/sandbox_types.h"
87 #include "ui/base/win/atl_module.h" 89 #include "ui/base/win/atl_module.h"
88 #include "ui/display/win/dpi.h" 90 #include "ui/display/win/dpi.h"
89 #elif defined(OS_MACOSX) 91 #elif defined(OS_MACOSX)
90 #include "base/allocator/allocator_shim.h" 92 #include "base/allocator/allocator_shim.h"
91 #include "base/mac/scoped_nsautorelease_pool.h" 93 #include "base/mac/scoped_nsautorelease_pool.h"
92 #include "base/power_monitor/power_monitor_device_source.h" 94 #include "base/power_monitor/power_monitor_device_source.h"
93 #include "content/app/mac/mac_init.h" 95 #include "content/app/mac/mac_init.h"
94 #include "content/browser/mach_broker_mac.h" 96 #include "content/browser/mach_broker_mac.h"
95 #include "content/common/sandbox_init_mac.h" 97 #include "content/common/sandbox_init_mac.h"
96 #endif // OS_WIN 98 #endif // OS_WIN
97 99
98 #if defined(OS_POSIX) 100 #if defined(OS_POSIX)
99 #include <signal.h> 101 #include <signal.h>
100 102
103 #include "base/file_descriptor_store.h"
101 #include "base/posix/global_descriptors.h" 104 #include "base/posix/global_descriptors.h"
102 #include "content/public/common/content_descriptors.h" 105 #include "content/public/common/content_descriptors.h"
103 106
104 #if !defined(OS_MACOSX) 107 #if !defined(OS_MACOSX)
105 #include "content/public/common/zygote_fork_delegate_linux.h" 108 #include "content/public/common/zygote_fork_delegate_linux.h"
106 #endif 109 #endif
107 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) 110 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
108 #include "content/zygote/zygote_main.h" 111 #include "content/zygote/zygote_main.h"
109 #endif 112 #endif
110 113
(...skipping 23 matching lines...) Expand all
134 extern int RendererMain(const content::MainFunctionParams&); 137 extern int RendererMain(const content::MainFunctionParams&);
135 extern int UtilityMain(const MainFunctionParams&); 138 extern int UtilityMain(const MainFunctionParams&);
136 } // namespace content 139 } // namespace content
137 140
138 namespace content { 141 namespace content {
139 142
140 namespace { 143 namespace {
141 144
142 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID) 145 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID)
143 #if defined __LP64__ 146 #if defined __LP64__
144 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor64 147 #define kV8SnapshotDataDescriptor kV8Snapshot64DataDescriptor
145 #else 148 #else
146 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor32 149 #define kV8SnapshotDataDescriptor kV8Snapshot32DataDescriptor
147 #endif 150 #endif
148 #endif 151 #endif
149 152
150 // This sets up two singletons responsible for managing field trials. The 153 // This sets up two singletons responsible for managing field trials. The
151 // |field_trial_list| singleton lives on the stack and must outlive the Run() 154 // |field_trial_list| singleton lives on the stack and must outlive the Run()
152 // method of the process. 155 // method of the process.
153 void InitializeFieldTrialAndFeatureList( 156 void InitializeFieldTrialAndFeatureList(
154 std::unique_ptr<base::FieldTrialList>* field_trial_list) { 157 std::unique_ptr<base::FieldTrialList>* field_trial_list) {
155 const base::CommandLine& command_line = 158 const base::CommandLine& command_line =
156 *base::CommandLine::ForCurrentProcess(); 159 *base::CommandLine::ForCurrentProcess();
(...skipping 24 matching lines...) Expand all
181 } 184 }
182 185
183 void InitializeV8IfNeeded( 186 void InitializeV8IfNeeded(
184 const base::CommandLine& command_line, 187 const base::CommandLine& command_line,
185 const std::string& process_type) { 188 const std::string& process_type) {
186 if (process_type == switches::kGpuProcess) 189 if (process_type == switches::kGpuProcess)
187 return; 190 return;
188 191
189 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) 192 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
190 #if defined(OS_POSIX) && !defined(OS_MACOSX) 193 #if defined(OS_POSIX) && !defined(OS_MACOSX)
191 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); 194 base::FileDescriptorStore& file_descriptor_store =
192 #if !defined(OS_ANDROID) 195 base::FileDescriptorStore::GetInstance();
193 // kV8NativesDataDescriptor and kV8SnapshotDataDescriptor could be shared 196 base::MemoryMappedFile::Region region;
194 // with child processes via file descriptors. On Android they are set in 197 base::ScopedFD v8_snapshot_fd =
195 // ChildProcessService::InternalInitChildProcess, otherwise set them here. 198 file_descriptor_store.MaybeTakeFD(kV8SnapshotDataDescriptor, &region);
196 if (command_line.HasSwitch(switches::kV8NativesPassedByFD)) { 199 if (v8_snapshot_fd.is_valid()) {
197 g_fds->Set( 200 gin::V8Initializer::LoadV8SnapshotFromFD(v8_snapshot_fd.get(),
198 kV8NativesDataDescriptor, 201 region.offset, region.size);
199 kV8NativesDataDescriptor + base::GlobalDescriptors::kBaseDescriptor);
200 }
201 if (command_line.HasSwitch(switches::kV8SnapshotPassedByFD)) {
202 g_fds->Set(
203 kV8SnapshotDataDescriptor,
204 kV8SnapshotDataDescriptor + base::GlobalDescriptors::kBaseDescriptor);
205 }
206 #endif // !OS_ANDROID
207 int v8_natives_fd = g_fds->MaybeGet(kV8NativesDataDescriptor);
208 int v8_snapshot_fd = g_fds->MaybeGet(kV8SnapshotDataDescriptor);
209 if (v8_snapshot_fd != -1) {
210 auto v8_snapshot_region = g_fds->GetRegion(kV8SnapshotDataDescriptor);
211 gin::V8Initializer::LoadV8SnapshotFromFD(
212 v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size);
213 } else { 202 } else {
214 gin::V8Initializer::LoadV8Snapshot(); 203 gin::V8Initializer::LoadV8Snapshot();
215 } 204 }
216 if (v8_natives_fd != -1) { 205 base::ScopedFD v8_natives_fd =
217 auto v8_natives_region = g_fds->GetRegion(kV8NativesDataDescriptor); 206 file_descriptor_store.MaybeTakeFD(kV8NativesDataDescriptor, &region);
218 gin::V8Initializer::LoadV8NativesFromFD( 207 if (v8_natives_fd.is_valid()) {
219 v8_natives_fd, v8_natives_region.offset, v8_natives_region.size); 208 gin::V8Initializer::LoadV8NativesFromFD(v8_natives_fd.get(),
209 region.offset, region.size);
220 } else { 210 } else {
221 gin::V8Initializer::LoadV8Natives(); 211 gin::V8Initializer::LoadV8Natives();
222 } 212 }
223 #else 213 #else
224 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) 214 #if !defined(CHROME_MULTIPLE_DLL_BROWSER)
225 gin::V8Initializer::LoadV8Snapshot(); 215 gin::V8Initializer::LoadV8Snapshot();
226 gin::V8Initializer::LoadV8Natives(); 216 gin::V8Initializer::LoadV8Natives();
227 #endif // !CHROME_MULTIPLE_DLL_BROWSER 217 #endif // !CHROME_MULTIPLE_DLL_BROWSER
228 #endif // OS_POSIX && !OS_MACOSX 218 #endif // OS_POSIX && !OS_MACOSX
229 #endif // V8_USE_EXTERNAL_STARTUP_DATA 219 #endif // V8_USE_EXTERNAL_STARTUP_DATA
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 // surface UI -- but it's likely they get this wrong too so why not. 281 // surface UI -- but it's likely they get this wrong too so why not.
292 setlocale(LC_NUMERIC, "C"); 282 setlocale(LC_NUMERIC, "C");
293 #endif 283 #endif
294 284
295 #if !defined(OFFICIAL_BUILD) && defined(OS_WIN) 285 #if !defined(OFFICIAL_BUILD) && defined(OS_WIN)
296 base::RouteStdioToConsole(false); 286 base::RouteStdioToConsole(false);
297 LoadLibraryA("dbghelp.dll"); 287 LoadLibraryA("dbghelp.dll");
298 #endif 288 #endif
299 } 289 }
300 290
291 #if defined(OS_POSIX)
292 void PopulateFDsFromCommandLine() {
jam 2017/02/13 23:10:59 nit: move to existing posix block on line 262
Jay Civelli 2017/02/13 23:51:58 Done.
293 const std::string& shared_file_param =
294 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
295 switches::kSharedFiles);
296 if (shared_file_param.empty())
297 return;
298
299 std::map<int, std::string> shared_file_descriptors;
300 service_manager::ParseSharedFileSwitchValue(shared_file_param,
301 &shared_file_descriptors);
302 for (const auto& descriptor : shared_file_descriptors) {
303 base::MemoryMappedFile::Region region;
304 std::string key = descriptor.second;
305 base::ScopedFD fd = base::GlobalDescriptors::GetInstance()->TakeFD(
306 descriptor.first, &region);
307 base::FileDescriptorStore::GetInstance().Set(key, std::move(fd), region);
308 }
309 }
310 #endif // defined(OS_POSIX)
311
301 class ContentClientInitializer { 312 class ContentClientInitializer {
302 public: 313 public:
303 static void Set(const std::string& process_type, 314 static void Set(const std::string& process_type,
304 ContentMainDelegate* delegate) { 315 ContentMainDelegate* delegate) {
305 ContentClient* content_client = GetContentClient(); 316 ContentClient* content_client = GetContentClient();
306 #if !defined(CHROME_MULTIPLE_DLL_CHILD) 317 #if !defined(CHROME_MULTIPLE_DLL_CHILD)
307 if (process_type.empty()) { 318 if (process_type.empty()) {
308 if (delegate) 319 if (delegate)
309 content_client->browser_ = delegate->CreateContentBrowserClient(); 320 content_client->browser_ = delegate->CreateContentBrowserClient();
310 if (!content_client->browser_) 321 if (!content_client->browser_)
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 595
585 #if defined(OS_MACOSX) 596 #if defined(OS_MACOSX)
586 // We need this pool for all the objects created before we get to the 597 // We need this pool for all the objects created before we get to the
587 // event loop, but we don't want to leave them hanging around until the 598 // event loop, but we don't want to leave them hanging around until the
588 // app quits. Each "main" needs to flush this pool right before it goes into 599 // app quits. Each "main" needs to flush this pool right before it goes into
589 // its main event loop to get rid of the cruft. 600 // its main event loop to get rid of the cruft.
590 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); 601 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool());
591 InitializeMac(); 602 InitializeMac();
592 #endif 603 #endif
593 604
594 // On Android, the command line is initialized when library is loaded and 605 // On Android, the command line is initialized and the FDs set when the
595 // we have already started our TRACE_EVENT0. 606 // library is loaded and we have already started our TRACE_EVENT0.
596 #if !defined(OS_ANDROID) 607 #if !defined(OS_ANDROID)
597 // argc/argv are ignored on Windows and Android; see command_line.h for 608 // argc/argv are ignored on Windows and Android; see command_line.h for
598 // details. 609 // details.
599 int argc = 0; 610 int argc = 0;
600 const char** argv = NULL; 611 const char** argv = NULL;
601 612
602 #if !defined(OS_WIN) 613 #if !defined(OS_WIN)
603 argc = params.argc; 614 argc = params.argc;
604 argv = params.argv; 615 argv = params.argv;
605 #endif 616 #endif
606 617
607 base::CommandLine::Init(argc, argv); 618 base::CommandLine::Init(argc, argv);
608 619
620 #if defined(OS_POSIX)
621 PopulateFDsFromCommandLine();
622 #endif
623
609 base::EnableTerminationOnHeapCorruption(); 624 base::EnableTerminationOnHeapCorruption();
610 625
611 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. 626 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed.
612 // Enable profiler recording right after command line is initialized so that 627 // Enable profiler recording right after command line is initialized so that
613 // browser startup can be instrumented. 628 // browser startup can be instrumented.
614 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) 629 if (delegate_ && delegate_->ShouldEnableProfilerRecording())
615 tracked_objects::ScopedTracker::Enable(); 630 tracked_objects::ScopedTracker::Enable();
616 631
617 SetProcessTitleFromCommandLine(argv); 632 SetProcessTitleFromCommandLine(argv);
618 #endif // !OS_ANDROID 633 #endif // !OS_ANDROID
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 911
897 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 912 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
898 }; 913 };
899 914
900 // static 915 // static
901 ContentMainRunner* ContentMainRunner::Create() { 916 ContentMainRunner* ContentMainRunner::Create() {
902 return new ContentMainRunnerImpl(); 917 return new ContentMainRunnerImpl();
903 } 918 }
904 919
905 } // namespace content 920 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698