OLD | NEW |
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 |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/allocator/allocator_check.h" | 16 #include "base/allocator/allocator_check.h" |
17 #include "base/allocator/allocator_extension.h" | 17 #include "base/allocator/allocator_extension.h" |
18 #include "base/at_exit.h" | 18 #include "base/at_exit.h" |
19 #include "base/base_switches.h" | 19 #include "base/base_switches.h" |
20 #include "base/command_line.h" | 20 #include "base/command_line.h" |
21 #include "base/debug/debugger.h" | 21 #include "base/debug/debugger.h" |
22 #include "base/debug/stack_trace.h" | 22 #include "base/debug/stack_trace.h" |
23 #include "base/feature_list.h" | 23 #include "base/feature_list.h" |
| 24 #include "base/file_descriptor_store.h" |
24 #include "base/files/file_path.h" | 25 #include "base/files/file_path.h" |
25 #include "base/i18n/icu_util.h" | 26 #include "base/i18n/icu_util.h" |
26 #include "base/lazy_instance.h" | 27 #include "base/lazy_instance.h" |
27 #include "base/logging.h" | 28 #include "base/logging.h" |
28 #include "base/macros.h" | 29 #include "base/macros.h" |
29 #include "base/memory/scoped_vector.h" | 30 #include "base/memory/scoped_vector.h" |
30 #include "base/metrics/field_trial.h" | 31 #include "base/metrics/field_trial.h" |
31 #include "base/metrics/histogram_base.h" | 32 #include "base/metrics/histogram_base.h" |
32 #include "base/metrics/statistics_recorder.h" | 33 #include "base/metrics/statistics_recorder.h" |
33 #include "base/path_service.h" | 34 #include "base/path_service.h" |
(...skipping 15 matching lines...) Expand all Loading... |
49 #include "content/browser/renderer_host/render_process_host_impl.h" | 50 #include "content/browser/renderer_host/render_process_host_impl.h" |
50 #include "content/browser/utility_process_host_impl.h" | 51 #include "content/browser/utility_process_host_impl.h" |
51 #include "content/common/set_process_title.h" | 52 #include "content/common/set_process_title.h" |
52 #include "content/common/url_schemes.h" | 53 #include "content/common/url_schemes.h" |
53 #include "content/gpu/in_process_gpu_thread.h" | 54 #include "content/gpu/in_process_gpu_thread.h" |
54 #include "content/public/app/content_main.h" | 55 #include "content/public/app/content_main.h" |
55 #include "content/public/app/content_main_delegate.h" | 56 #include "content/public/app/content_main_delegate.h" |
56 #include "content/public/browser/content_browser_client.h" | 57 #include "content/public/browser/content_browser_client.h" |
57 #include "content/public/common/content_client.h" | 58 #include "content/public/common/content_client.h" |
58 #include "content/public/common/content_constants.h" | 59 #include "content/public/common/content_constants.h" |
| 60 #include "content/public/common/content_descriptor_keys.h" |
59 #include "content/public/common/content_paths.h" | 61 #include "content/public/common/content_paths.h" |
60 #include "content/public/common/content_switches.h" | 62 #include "content/public/common/content_switches.h" |
61 #include "content/public/common/main_function_params.h" | 63 #include "content/public/common/main_function_params.h" |
62 #include "content/public/common/sandbox_init.h" | 64 #include "content/public/common/sandbox_init.h" |
63 #include "content/public/gpu/content_gpu_client.h" | 65 #include "content/public/gpu/content_gpu_client.h" |
64 #include "content/public/renderer/content_renderer_client.h" | 66 #include "content/public/renderer/content_renderer_client.h" |
65 #include "content/public/utility/content_utility_client.h" | 67 #include "content/public/utility/content_utility_client.h" |
66 #include "content/renderer/in_process_renderer_thread.h" | 68 #include "content/renderer/in_process_renderer_thread.h" |
67 #include "content/utility/in_process_utility_thread.h" | 69 #include "content/utility/in_process_utility_thread.h" |
68 #include "ipc/ipc_descriptors.h" | 70 #include "ipc/ipc_descriptors.h" |
69 #include "media/base/media.h" | 71 #include "media/base/media.h" |
70 #include "ppapi/features/features.h" | 72 #include "ppapi/features/features.h" |
| 73 #include "services/service_manager/public/cpp/shared_file_util.h" |
71 #include "ui/base/ui_base_paths.h" | 74 #include "ui/base/ui_base_paths.h" |
72 #include "ui/base/ui_base_switches.h" | 75 #include "ui/base/ui_base_switches.h" |
73 | 76 |
74 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && \ | 77 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && \ |
75 !defined(CHROME_MULTIPLE_DLL_BROWSER) | 78 !defined(CHROME_MULTIPLE_DLL_BROWSER) |
76 #include "gin/v8_initializer.h" | 79 #include "gin/v8_initializer.h" |
77 #endif | 80 #endif |
78 | 81 |
79 #if defined(OS_WIN) | 82 #if defined(OS_WIN) |
80 #include <malloc.h> | 83 #include <malloc.h> |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 const std::string& shared_file_param = |
| 255 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 256 switches::kSharedFiles); |
| 257 if (shared_file_param.empty()) |
| 258 return; |
| 259 |
| 260 std::map<int, std::string> shared_file_descriptors; |
| 261 service_manager::ParseSharedFileSwitchValue(shared_file_param, |
| 262 &shared_file_descriptors); |
| 263 for (const auto& descriptor : shared_file_descriptors) { |
| 264 base::FileDescriptorStore::GetInstance()->Set(descriptor.second, |
| 265 descriptor.first); |
| 266 } |
| 267 } |
| 268 |
250 class ContentClientInitializer { | 269 class ContentClientInitializer { |
251 public: | 270 public: |
252 static void Set(const std::string& process_type, | 271 static void Set(const std::string& process_type, |
253 ContentMainDelegate* delegate) { | 272 ContentMainDelegate* delegate) { |
254 ContentClient* content_client = GetContentClient(); | 273 ContentClient* content_client = GetContentClient(); |
255 #if !defined(CHROME_MULTIPLE_DLL_CHILD) | 274 #if !defined(CHROME_MULTIPLE_DLL_CHILD) |
256 if (process_type.empty()) { | 275 if (process_type.empty()) { |
257 if (delegate) | 276 if (delegate) |
258 content_client->browser_ = delegate->CreateContentBrowserClient(); | 277 content_client->browser_ = delegate->CreateContentBrowserClient(); |
259 if (!content_client->browser_) | 278 if (!content_client->browser_) |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 549 |
531 #if defined(OS_MACOSX) | 550 #if defined(OS_MACOSX) |
532 // We need this pool for all the objects created before we get to the | 551 // 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 | 552 // 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 | 553 // 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. | 554 // its main event loop to get rid of the cruft. |
536 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); | 555 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); |
537 InitializeMac(); | 556 InitializeMac(); |
538 #endif | 557 #endif |
539 | 558 |
540 // On Android, the command line is initialized when library is loaded and | 559 // On Android, the command line is initialized and the FDs set when the |
541 // we have already started our TRACE_EVENT0. | 560 // library is loaded and we have already started our TRACE_EVENT0. |
542 #if !defined(OS_ANDROID) | 561 #if !defined(OS_ANDROID) |
543 // argc/argv are ignored on Windows and Android; see command_line.h for | 562 // argc/argv are ignored on Windows and Android; see command_line.h for |
544 // details. | 563 // details. |
545 int argc = 0; | 564 int argc = 0; |
546 const char** argv = NULL; | 565 const char** argv = NULL; |
547 | 566 |
548 #if !defined(OS_WIN) | 567 #if !defined(OS_WIN) |
549 argc = params.argc; | 568 argc = params.argc; |
550 argv = params.argv; | 569 argv = params.argv; |
551 #endif | 570 #endif |
552 | 571 |
553 base::CommandLine::Init(argc, argv); | 572 base::CommandLine::Init(argc, argv); |
554 | 573 |
| 574 PopulateFDsFromCommandLine(); |
| 575 |
555 base::EnableTerminationOnHeapCorruption(); | 576 base::EnableTerminationOnHeapCorruption(); |
556 | 577 |
557 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. | 578 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. |
558 // Enable profiler recording right after command line is initialized so that | 579 // Enable profiler recording right after command line is initialized so that |
559 // browser startup can be instrumented. | 580 // browser startup can be instrumented. |
560 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) | 581 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) |
561 tracked_objects::ScopedTracker::Enable(); | 582 tracked_objects::ScopedTracker::Enable(); |
562 | 583 |
563 SetProcessTitleFromCommandLine(argv); | 584 SetProcessTitleFromCommandLine(argv); |
564 #endif // !OS_ANDROID | 585 #endif // !OS_ANDROID |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 CHECK(base::i18n::InitializeICU()); | 723 CHECK(base::i18n::InitializeICU()); |
703 } | 724 } |
704 #else | 725 #else |
705 CHECK(base::i18n::InitializeICU()); | 726 CHECK(base::i18n::InitializeICU()); |
706 #endif // OS_ANDROID && (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) | 727 #endif // OS_ANDROID && (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) |
707 | 728 |
708 base::StatisticsRecorder::Initialize(); | 729 base::StatisticsRecorder::Initialize(); |
709 | 730 |
710 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 731 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
711 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 732 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
712 #if !defined(OS_ANDROID) | 733 base::FileDescriptorStore* file_descriptor_store = |
713 // kV8NativesDataDescriptor and kV8SnapshotDataDescriptor could be shared | 734 base::FileDescriptorStore::GetInstance(); |
714 // with child processes via file descriptors. On Android they are set in | 735 int v8_snapshot_fd = |
715 // ChildProcessService::InternalInitChildProcess, otherwise set them here. | 736 file_descriptor_store->MaybeGet(kV8SnapshotDataDescriptor); |
716 if (command_line.HasSwitch(switches::kV8NativesPassedByFD)) { | |
717 g_fds->Set( | |
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) { | 737 if (v8_snapshot_fd != -1) { |
730 auto v8_snapshot_region = g_fds->GetRegion(kV8SnapshotDataDescriptor); | 738 auto v8_snapshot_region = |
| 739 file_descriptor_store->GetRegion(kV8SnapshotDataDescriptor); |
731 gin::V8Initializer::LoadV8SnapshotFromFD( | 740 gin::V8Initializer::LoadV8SnapshotFromFD( |
732 v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size); | 741 v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size); |
733 } else { | 742 } else { |
734 gin::V8Initializer::LoadV8Snapshot(); | 743 gin::V8Initializer::LoadV8Snapshot(); |
735 } | 744 } |
| 745 int v8_natives_fd = |
| 746 file_descriptor_store->MaybeGet(kV8NativesDataDescriptor); |
736 if (v8_natives_fd != -1) { | 747 if (v8_natives_fd != -1) { |
737 auto v8_natives_region = g_fds->GetRegion(kV8NativesDataDescriptor); | 748 auto v8_natives_region = |
| 749 file_descriptor_store->GetRegion(kV8NativesDataDescriptor); |
738 gin::V8Initializer::LoadV8NativesFromFD( | 750 gin::V8Initializer::LoadV8NativesFromFD( |
739 v8_natives_fd, v8_natives_region.offset, v8_natives_region.size); | 751 v8_natives_fd, v8_natives_region.offset, v8_natives_region.size); |
740 } else { | 752 } else { |
741 gin::V8Initializer::LoadV8Natives(); | 753 gin::V8Initializer::LoadV8Natives(); |
742 } | 754 } |
743 #else | 755 #else |
744 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) | 756 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) |
745 gin::V8Initializer::LoadV8Snapshot(); | 757 gin::V8Initializer::LoadV8Snapshot(); |
746 gin::V8Initializer::LoadV8Natives(); | 758 gin::V8Initializer::LoadV8Natives(); |
747 #endif // !CHROME_MULTIPLE_DLL_BROWSER | 759 #endif // !CHROME_MULTIPLE_DLL_BROWSER |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 | 893 |
882 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 894 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
883 }; | 895 }; |
884 | 896 |
885 // static | 897 // static |
886 ContentMainRunner* ContentMainRunner::Create() { | 898 ContentMainRunner* ContentMainRunner::Create() { |
887 return new ContentMainRunnerImpl(); | 899 return new ContentMainRunnerImpl(); |
888 } | 900 } |
889 | 901 |
890 } // namespace content | 902 } // namespace content |
OLD | NEW |