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

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 + addressed comment from @rockot 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "content/browser/renderer_host/render_process_host_impl.h" 49 #include "content/browser/renderer_host/render_process_host_impl.h"
50 #include "content/browser/utility_process_host_impl.h" 50 #include "content/browser/utility_process_host_impl.h"
51 #include "content/common/set_process_title.h" 51 #include "content/common/set_process_title.h"
52 #include "content/common/url_schemes.h" 52 #include "content/common/url_schemes.h"
53 #include "content/gpu/in_process_gpu_thread.h" 53 #include "content/gpu/in_process_gpu_thread.h"
54 #include "content/public/app/content_main.h" 54 #include "content/public/app/content_main.h"
55 #include "content/public/app/content_main_delegate.h" 55 #include "content/public/app/content_main_delegate.h"
56 #include "content/public/browser/content_browser_client.h" 56 #include "content/public/browser/content_browser_client.h"
57 #include "content/public/common/content_client.h" 57 #include "content/public/common/content_client.h"
58 #include "content/public/common/content_constants.h" 58 #include "content/public/common/content_constants.h"
59 #include "content/public/common/content_descriptor_keys.h"
59 #include "content/public/common/content_paths.h" 60 #include "content/public/common/content_paths.h"
60 #include "content/public/common/content_switches.h" 61 #include "content/public/common/content_switches.h"
61 #include "content/public/common/main_function_params.h" 62 #include "content/public/common/main_function_params.h"
62 #include "content/public/common/sandbox_init.h" 63 #include "content/public/common/sandbox_init.h"
63 #include "content/public/gpu/content_gpu_client.h" 64 #include "content/public/gpu/content_gpu_client.h"
64 #include "content/public/renderer/content_renderer_client.h" 65 #include "content/public/renderer/content_renderer_client.h"
65 #include "content/public/utility/content_utility_client.h" 66 #include "content/public/utility/content_utility_client.h"
66 #include "content/renderer/in_process_renderer_thread.h" 67 #include "content/renderer/in_process_renderer_thread.h"
67 #include "content/utility/in_process_utility_thread.h" 68 #include "content/utility/in_process_utility_thread.h"
68 #include "ipc/ipc_descriptors.h" 69 #include "ipc/ipc_descriptors.h"
69 #include "media/base/media.h" 70 #include "media/base/media.h"
70 #include "ppapi/features/features.h" 71 #include "ppapi/features/features.h"
72 #include "services/service_manager/public/cpp/shared_file_util.h"
71 #include "ui/base/ui_base_paths.h" 73 #include "ui/base/ui_base_paths.h"
72 #include "ui/base/ui_base_switches.h" 74 #include "ui/base/ui_base_switches.h"
73 75
74 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && \ 76 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && \
75 !defined(CHROME_MULTIPLE_DLL_BROWSER) 77 !defined(CHROME_MULTIPLE_DLL_BROWSER)
76 #include "gin/v8_initializer.h" 78 #include "gin/v8_initializer.h"
77 #endif 79 #endif
78 80
79 #if defined(OS_WIN) 81 #if defined(OS_WIN)
80 #include <malloc.h> 82 #include <malloc.h>
81 #include <cstring> 83 #include <cstring>
82 84
83 #include "base/trace_event/trace_event_etw_export_win.h" 85 #include "base/trace_event/trace_event_etw_export_win.h"
84 #include "base/win/process_startup_helper.h" 86 #include "base/win/process_startup_helper.h"
85 #include "sandbox/win/src/sandbox_types.h" 87 #include "sandbox/win/src/sandbox_types.h"
86 #include "ui/base/win/atl_module.h" 88 #include "ui/base/win/atl_module.h"
87 #include "ui/display/win/dpi.h" 89 #include "ui/display/win/dpi.h"
88 #elif defined(OS_MACOSX) 90 #elif defined(OS_MACOSX)
89 #include "base/mac/scoped_nsautorelease_pool.h" 91 #include "base/mac/scoped_nsautorelease_pool.h"
90 #include "base/power_monitor/power_monitor_device_source.h" 92 #include "base/power_monitor/power_monitor_device_source.h"
91 #include "content/app/mac/mac_init.h" 93 #include "content/app/mac/mac_init.h"
92 #include "content/browser/mach_broker_mac.h" 94 #include "content/browser/mach_broker_mac.h"
93 #include "content/common/sandbox_init_mac.h" 95 #include "content/common/sandbox_init_mac.h"
94 #endif // OS_WIN 96 #endif // OS_WIN
95 97
96 #if defined(OS_POSIX) 98 #if defined(OS_POSIX)
97 #include <signal.h> 99 #include <signal.h>
98 100
101 #include "base/file_descriptor_store.h"
99 #include "base/posix/global_descriptors.h" 102 #include "base/posix/global_descriptors.h"
100 #include "content/public/common/content_descriptors.h" 103 #include "content/public/common/content_descriptors.h"
101 104
102 #if !defined(OS_MACOSX) 105 #if !defined(OS_MACOSX)
103 #include "content/public/common/zygote_fork_delegate_linux.h" 106 #include "content/public/common/zygote_fork_delegate_linux.h"
104 #endif 107 #endif
105 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) 108 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
106 #include "content/zygote/zygote_main.h" 109 #include "content/zygote/zygote_main.h"
107 #endif 110 #endif
108 111
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 182 }
180 183
181 void InitializeV8IfNeeded( 184 void InitializeV8IfNeeded(
182 const base::CommandLine& command_line, 185 const base::CommandLine& command_line,
183 const std::string& process_type) { 186 const std::string& process_type) {
184 if (process_type == switches::kGpuProcess) 187 if (process_type == switches::kGpuProcess)
185 return; 188 return;
186 189
187 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) 190 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
188 #if defined(OS_POSIX) && !defined(OS_MACOSX) 191 #if defined(OS_POSIX) && !defined(OS_MACOSX)
189 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); 192 base::FileDescriptorStore& file_descriptor_store =
190 #if !defined(OS_ANDROID) 193 base::FileDescriptorStore::GetInstance();
191 // kV8NativesDataDescriptor and kV8SnapshotDataDescriptor could be shared 194 base::MemoryMappedFile::Region region;
192 // with child processes via file descriptors. On Android they are set in 195 base::ScopedFD v8_snapshot_fd =
193 // ChildProcessService::InternalInitChildProcess, otherwise set them here. 196 file_descriptor_store.MaybeTakeFD(kV8SnapshotDataDescriptor, &region);
194 if (command_line.HasSwitch(switches::kV8NativesPassedByFD)) { 197 if (v8_snapshot_fd.is_valid()) {
195 g_fds->Set( 198 gin::V8Initializer::LoadV8SnapshotFromFD(v8_snapshot_fd.get(),
196 kV8NativesDataDescriptor, 199 region.offset, region.size);
197 kV8NativesDataDescriptor + base::GlobalDescriptors::kBaseDescriptor);
198 }
199 if (command_line.HasSwitch(switches::kV8SnapshotPassedByFD)) {
200 g_fds->Set(
201 kV8SnapshotDataDescriptor,
202 kV8SnapshotDataDescriptor + base::GlobalDescriptors::kBaseDescriptor);
203 }
204 #endif // !OS_ANDROID
205 int v8_natives_fd = g_fds->MaybeGet(kV8NativesDataDescriptor);
206 int v8_snapshot_fd = g_fds->MaybeGet(kV8SnapshotDataDescriptor);
207 if (v8_snapshot_fd != -1) {
208 auto v8_snapshot_region = g_fds->GetRegion(kV8SnapshotDataDescriptor);
209 gin::V8Initializer::LoadV8SnapshotFromFD(
210 v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size);
211 } else { 200 } else {
212 gin::V8Initializer::LoadV8Snapshot(); 201 gin::V8Initializer::LoadV8Snapshot();
213 } 202 }
214 if (v8_natives_fd != -1) { 203 base::ScopedFD v8_natives_fd =
215 auto v8_natives_region = g_fds->GetRegion(kV8NativesDataDescriptor); 204 file_descriptor_store.MaybeTakeFD(kV8NativesDataDescriptor, &region);
216 gin::V8Initializer::LoadV8NativesFromFD( 205 if (v8_natives_fd.is_valid()) {
217 v8_natives_fd, v8_natives_region.offset, v8_natives_region.size); 206 gin::V8Initializer::LoadV8NativesFromFD(v8_natives_fd.get(),
207 region.offset, region.size);
218 } else { 208 } else {
219 gin::V8Initializer::LoadV8Natives(); 209 gin::V8Initializer::LoadV8Natives();
220 } 210 }
221 #else 211 #else
222 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) 212 #if !defined(CHROME_MULTIPLE_DLL_BROWSER)
223 gin::V8Initializer::LoadV8Snapshot(); 213 gin::V8Initializer::LoadV8Snapshot();
224 gin::V8Initializer::LoadV8Natives(); 214 gin::V8Initializer::LoadV8Natives();
225 #endif // !CHROME_MULTIPLE_DLL_BROWSER 215 #endif // !CHROME_MULTIPLE_DLL_BROWSER
226 #endif // OS_POSIX && !OS_MACOSX 216 #endif // OS_POSIX && !OS_MACOSX
227 #endif // V8_USE_EXTERNAL_STARTUP_DATA 217 #endif // V8_USE_EXTERNAL_STARTUP_DATA
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // surface UI -- but it's likely they get this wrong too so why not. 279 // surface UI -- but it's likely they get this wrong too so why not.
290 setlocale(LC_NUMERIC, "C"); 280 setlocale(LC_NUMERIC, "C");
291 #endif 281 #endif
292 282
293 #if !defined(OFFICIAL_BUILD) && defined(OS_WIN) 283 #if !defined(OFFICIAL_BUILD) && defined(OS_WIN)
294 base::RouteStdioToConsole(false); 284 base::RouteStdioToConsole(false);
295 LoadLibraryA("dbghelp.dll"); 285 LoadLibraryA("dbghelp.dll");
296 #endif 286 #endif
297 } 287 }
298 288
289 void PopulateFDsFromCommandLine() {
290 #if defined(OS_POSIX)
291 const std::string& shared_file_param =
292 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
293 switches::kSharedFiles);
294 if (shared_file_param.empty())
295 return;
296
297 std::map<int, std::string> shared_file_descriptors;
298 service_manager::ParseSharedFileSwitchValue(shared_file_param,
299 &shared_file_descriptors);
300 for (const auto& descriptor : shared_file_descriptors) {
301 base::MemoryMappedFile::Region region;
302 std::string key = descriptor.second;
303 base::ScopedFD fd = base::GlobalDescriptors::GetInstance()->TakeFD(
304 descriptor.first, &region);
305 base::FileDescriptorStore::GetInstance().Set(key, std::move(fd), region);
306 }
307 #endif
308 }
309
299 class ContentClientInitializer { 310 class ContentClientInitializer {
300 public: 311 public:
301 static void Set(const std::string& process_type, 312 static void Set(const std::string& process_type,
302 ContentMainDelegate* delegate) { 313 ContentMainDelegate* delegate) {
303 ContentClient* content_client = GetContentClient(); 314 ContentClient* content_client = GetContentClient();
304 #if !defined(CHROME_MULTIPLE_DLL_CHILD) 315 #if !defined(CHROME_MULTIPLE_DLL_CHILD)
305 if (process_type.empty()) { 316 if (process_type.empty()) {
306 if (delegate) 317 if (delegate)
307 content_client->browser_ = delegate->CreateContentBrowserClient(); 318 content_client->browser_ = delegate->CreateContentBrowserClient();
308 if (!content_client->browser_) 319 if (!content_client->browser_)
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 590
580 #if defined(OS_MACOSX) 591 #if defined(OS_MACOSX)
581 // We need this pool for all the objects created before we get to the 592 // We need this pool for all the objects created before we get to the
582 // event loop, but we don't want to leave them hanging around until the 593 // event loop, but we don't want to leave them hanging around until the
583 // app quits. Each "main" needs to flush this pool right before it goes into 594 // app quits. Each "main" needs to flush this pool right before it goes into
584 // its main event loop to get rid of the cruft. 595 // its main event loop to get rid of the cruft.
585 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); 596 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool());
586 InitializeMac(); 597 InitializeMac();
587 #endif 598 #endif
588 599
589 // On Android, the command line is initialized when library is loaded and 600 // On Android, the command line is initialized and the FDs set when the
590 // we have already started our TRACE_EVENT0. 601 // library is loaded and we have already started our TRACE_EVENT0.
591 #if !defined(OS_ANDROID) 602 #if !defined(OS_ANDROID)
592 // argc/argv are ignored on Windows and Android; see command_line.h for 603 // argc/argv are ignored on Windows and Android; see command_line.h for
593 // details. 604 // details.
594 int argc = 0; 605 int argc = 0;
595 const char** argv = NULL; 606 const char** argv = NULL;
596 607
597 #if !defined(OS_WIN) 608 #if !defined(OS_WIN)
598 argc = params.argc; 609 argc = params.argc;
599 argv = params.argv; 610 argv = params.argv;
600 #endif 611 #endif
601 612
602 base::CommandLine::Init(argc, argv); 613 base::CommandLine::Init(argc, argv);
603 614
615 PopulateFDsFromCommandLine();
jam 2017/02/10 00:44:52 nit: it's the same whether the ifdef goes here, an
Jay Civelli 2017/02/10 06:32:34 Done.
616
604 base::EnableTerminationOnHeapCorruption(); 617 base::EnableTerminationOnHeapCorruption();
605 618
606 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. 619 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed.
607 // Enable profiler recording right after command line is initialized so that 620 // Enable profiler recording right after command line is initialized so that
608 // browser startup can be instrumented. 621 // browser startup can be instrumented.
609 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) 622 if (delegate_ && delegate_->ShouldEnableProfilerRecording())
610 tracked_objects::ScopedTracker::Enable(); 623 tracked_objects::ScopedTracker::Enable();
611 624
612 SetProcessTitleFromCommandLine(argv); 625 SetProcessTitleFromCommandLine(argv);
613 #endif // !OS_ANDROID 626 #endif // !OS_ANDROID
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 904
892 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 905 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
893 }; 906 };
894 907
895 // static 908 // static
896 ContentMainRunner* ContentMainRunner::Create() { 909 ContentMainRunner* ContentMainRunner::Create() {
897 return new ContentMainRunnerImpl(); 910 return new ContentMainRunnerImpl();
898 } 911 }
899 912
900 } // namespace content 913 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698