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

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

Issue 2684433003: Files required by a service now listed in manifest. (Closed)
Patch Set: Clean-up + Windows' build fix 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 base::LazyInstance<ContentGpuClient> 184 base::LazyInstance<ContentGpuClient>
182 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; 185 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER;
183 base::LazyInstance<ContentRendererClient> 186 base::LazyInstance<ContentRendererClient>
184 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; 187 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER;
185 base::LazyInstance<ContentUtilityClient> 188 base::LazyInstance<ContentUtilityClient>
186 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; 189 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER;
187 #endif // !CHROME_MULTIPLE_DLL_BROWSER 190 #endif // !CHROME_MULTIPLE_DLL_BROWSER
188 191
189 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID) 192 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID)
190 #if defined __LP64__ 193 #if defined __LP64__
191 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor64 194 #define kV8SnapshotDataDescriptor kV8Snapshot64DataDescriptor
192 #else 195 #else
193 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor32 196 #define kV8SnapshotDataDescriptor kV8Snapshot32DataDescriptor
194 #endif 197 #endif
195 #endif 198 #endif
196 199
197 #if defined(OS_POSIX) 200 #if defined(OS_POSIX)
198 201
199 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE. 202 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE.
200 void SetupSignalHandlers() { 203 void SetupSignalHandlers() {
201 // Sanitise our signal handling state. Signals that were ignored by our 204 // Sanitise our signal handling state. Signals that were ignored by our
202 // parent will also be ignored by us. We also inherit our parent's sigmask. 205 // parent will also be ignored by us. We also inherit our parent's sigmask.
203 sigset_t empty_signal_set; 206 sigset_t empty_signal_set;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // surface UI -- but it's likely they get this wrong too so why not. 243 // surface UI -- but it's likely they get this wrong too so why not.
241 setlocale(LC_NUMERIC, "C"); 244 setlocale(LC_NUMERIC, "C");
242 #endif 245 #endif
243 246
244 #if !defined(OFFICIAL_BUILD) && defined(OS_WIN) 247 #if !defined(OFFICIAL_BUILD) && defined(OS_WIN)
245 base::RouteStdioToConsole(false); 248 base::RouteStdioToConsole(false);
246 LoadLibraryA("dbghelp.dll"); 249 LoadLibraryA("dbghelp.dll");
247 #endif 250 #endif
248 } 251 }
249 252
253 void PopulateFDsFromCommandLine() {
254 #if defined(OS_POSIX)
255 const std::string& shared_file_param =
256 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
257 switches::kSharedFiles);
258 if (shared_file_param.empty())
259 return;
260
261 std::map<int, std::string> shared_file_descriptors;
262 service_manager::ParseSharedFileSwitchValue(shared_file_param,
263 &shared_file_descriptors);
264 for (const auto& descriptor : shared_file_descriptors) {
265 base::MemoryMappedFile::Region region;
266 std::string key = descriptor.second;
267 base::ScopedFD fd = base::GlobalDescriptors::GetInstance()->
268 TakeFD(descriptor.first, &region);
269 base::FileDescriptorStore::GetInstance().Set(key, std::move(fd), region);
270 }
271 #endif
272 }
273
250 class ContentClientInitializer { 274 class ContentClientInitializer {
251 public: 275 public:
252 static void Set(const std::string& process_type, 276 static void Set(const std::string& process_type,
253 ContentMainDelegate* delegate) { 277 ContentMainDelegate* delegate) {
254 ContentClient* content_client = GetContentClient(); 278 ContentClient* content_client = GetContentClient();
255 #if !defined(CHROME_MULTIPLE_DLL_CHILD) 279 #if !defined(CHROME_MULTIPLE_DLL_CHILD)
256 if (process_type.empty()) { 280 if (process_type.empty()) {
257 if (delegate) 281 if (delegate)
258 content_client->browser_ = delegate->CreateContentBrowserClient(); 282 content_client->browser_ = delegate->CreateContentBrowserClient();
259 if (!content_client->browser_) 283 if (!content_client->browser_)
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 554
531 #if defined(OS_MACOSX) 555 #if defined(OS_MACOSX)
532 // We need this pool for all the objects created before we get to the 556 // We need this pool for all the objects created before we get to the
533 // event loop, but we don't want to leave them hanging around until the 557 // event loop, but we don't want to leave them hanging around until the
534 // app quits. Each "main" needs to flush this pool right before it goes into 558 // app quits. Each "main" needs to flush this pool right before it goes into
535 // its main event loop to get rid of the cruft. 559 // its main event loop to get rid of the cruft.
536 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); 560 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool());
537 InitializeMac(); 561 InitializeMac();
538 #endif 562 #endif
539 563
540 // On Android, the command line is initialized when library is loaded and 564 // On Android, the command line is initialized and the FDs set when the
541 // we have already started our TRACE_EVENT0. 565 // library is loaded and we have already started our TRACE_EVENT0.
542 #if !defined(OS_ANDROID) 566 #if !defined(OS_ANDROID)
543 // argc/argv are ignored on Windows and Android; see command_line.h for 567 // argc/argv are ignored on Windows and Android; see command_line.h for
544 // details. 568 // details.
545 int argc = 0; 569 int argc = 0;
546 const char** argv = NULL; 570 const char** argv = NULL;
547 571
548 #if !defined(OS_WIN) 572 #if !defined(OS_WIN)
549 argc = params.argc; 573 argc = params.argc;
550 argv = params.argv; 574 argv = params.argv;
551 #endif 575 #endif
552 576
553 base::CommandLine::Init(argc, argv); 577 base::CommandLine::Init(argc, argv);
554 578
579 PopulateFDsFromCommandLine();
580
555 base::EnableTerminationOnHeapCorruption(); 581 base::EnableTerminationOnHeapCorruption();
556 582
557 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. 583 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed.
558 // Enable profiler recording right after command line is initialized so that 584 // Enable profiler recording right after command line is initialized so that
559 // browser startup can be instrumented. 585 // browser startup can be instrumented.
560 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) 586 if (delegate_ && delegate_->ShouldEnableProfilerRecording())
561 tracked_objects::ScopedTracker::Enable(); 587 tracked_objects::ScopedTracker::Enable();
562 588
563 SetProcessTitleFromCommandLine(argv); 589 SetProcessTitleFromCommandLine(argv);
564 #endif // !OS_ANDROID 590 #endif // !OS_ANDROID
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 CHECK(base::i18n::InitializeICU()); 728 CHECK(base::i18n::InitializeICU());
703 } 729 }
704 #else 730 #else
705 CHECK(base::i18n::InitializeICU()); 731 CHECK(base::i18n::InitializeICU());
706 #endif // OS_ANDROID && (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) 732 #endif // OS_ANDROID && (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE)
707 733
708 base::StatisticsRecorder::Initialize(); 734 base::StatisticsRecorder::Initialize();
709 735
710 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) 736 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
711 #if defined(OS_POSIX) && !defined(OS_MACOSX) 737 #if defined(OS_POSIX) && !defined(OS_MACOSX)
712 #if !defined(OS_ANDROID) 738 base::FileDescriptorStore& file_descriptor_store =
713 // kV8NativesDataDescriptor and kV8SnapshotDataDescriptor could be shared 739 base::FileDescriptorStore::GetInstance();
714 // with child processes via file descriptors. On Android they are set in 740 base::MemoryMappedFile::Region region;
715 // ChildProcessService::InternalInitChildProcess, otherwise set them here. 741 base::ScopedFD v8_snapshot_fd =
716 if (command_line.HasSwitch(switches::kV8NativesPassedByFD)) { 742 file_descriptor_store.MaybeTakeFD(kV8SnapshotDataDescriptor, &region);
717 g_fds->Set( 743 if (v8_snapshot_fd.is_valid()) {
718 kV8NativesDataDescriptor,
719 kV8NativesDataDescriptor + base::GlobalDescriptors::kBaseDescriptor);
720 }
721 if (command_line.HasSwitch(switches::kV8SnapshotPassedByFD)) {
722 g_fds->Set(
723 kV8SnapshotDataDescriptor,
724 kV8SnapshotDataDescriptor + base::GlobalDescriptors::kBaseDescriptor);
725 }
726 #endif // !OS_ANDROID
727 int v8_natives_fd = g_fds->MaybeGet(kV8NativesDataDescriptor);
728 int v8_snapshot_fd = g_fds->MaybeGet(kV8SnapshotDataDescriptor);
729 if (v8_snapshot_fd != -1) {
730 auto v8_snapshot_region = g_fds->GetRegion(kV8SnapshotDataDescriptor);
731 gin::V8Initializer::LoadV8SnapshotFromFD( 744 gin::V8Initializer::LoadV8SnapshotFromFD(
732 v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size); 745 v8_snapshot_fd.get(), region.offset, region.size);
733 } else { 746 } else {
734 gin::V8Initializer::LoadV8Snapshot(); 747 gin::V8Initializer::LoadV8Snapshot();
735 } 748 }
736 if (v8_natives_fd != -1) { 749 base::ScopedFD v8_natives_fd =
737 auto v8_natives_region = g_fds->GetRegion(kV8NativesDataDescriptor); 750 file_descriptor_store.MaybeTakeFD(kV8NativesDataDescriptor, &region);
751 if (v8_natives_fd.is_valid()) {
738 gin::V8Initializer::LoadV8NativesFromFD( 752 gin::V8Initializer::LoadV8NativesFromFD(
739 v8_natives_fd, v8_natives_region.offset, v8_natives_region.size); 753 v8_natives_fd.get(), region.offset, region.size);
740 } else { 754 } else {
741 gin::V8Initializer::LoadV8Natives(); 755 gin::V8Initializer::LoadV8Natives();
742 } 756 }
743 #else 757 #else
744 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) 758 #if !defined(CHROME_MULTIPLE_DLL_BROWSER)
745 gin::V8Initializer::LoadV8Snapshot(); 759 gin::V8Initializer::LoadV8Snapshot();
746 gin::V8Initializer::LoadV8Natives(); 760 gin::V8Initializer::LoadV8Natives();
747 #endif // !CHROME_MULTIPLE_DLL_BROWSER 761 #endif // !CHROME_MULTIPLE_DLL_BROWSER
748 #endif // OS_POSIX && !OS_MACOSX 762 #endif // OS_POSIX && !OS_MACOSX
749 #endif // V8_USE_EXTERNAL_STARTUP_DATA 763 #endif // V8_USE_EXTERNAL_STARTUP_DATA
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 895
882 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 896 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
883 }; 897 };
884 898
885 // static 899 // static
886 ContentMainRunner* ContentMainRunner::Create() { 900 ContentMainRunner* ContentMainRunner::Create() {
887 return new ContentMainRunnerImpl(); 901 return new ContentMainRunnerImpl();
888 } 902 }
889 903
890 } // namespace content 904 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698