| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 switches::kDisableInProcessStackTraces)) { | 251 switches::kDisableInProcessStackTraces)) { |
| 249 base::debug::EnableInProcessStackDumping(); | 252 base::debug::EnableInProcessStackDumping(); |
| 250 } | 253 } |
| 251 #if defined(OS_WIN) | 254 #if defined(OS_WIN) |
| 252 base::RouteStdioToConsole(false); | 255 base::RouteStdioToConsole(false); |
| 253 LoadLibraryA("dbghelp.dll"); | 256 LoadLibraryA("dbghelp.dll"); |
| 254 #endif | 257 #endif |
| 255 #endif | 258 #endif |
| 256 } | 259 } |
| 257 | 260 |
| 261 void PopulateFDsFromCommandLine() { |
| 262 const std::string& shared_file_param = |
| 263 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 264 switches::kSharedFiles); |
| 265 if (shared_file_param.empty()) |
| 266 return; |
| 267 |
| 268 std::map<int, std::string> shared_file_descriptors; |
| 269 service_manager::ParseSharedFileSwitchValue(shared_file_param, |
| 270 &shared_file_descriptors); |
| 271 for (const auto& descriptor : shared_file_descriptors) { |
| 272 base::FileDescriptorStore::GetInstance()->Set(descriptor.second, |
| 273 descriptor.first); |
| 274 } |
| 275 } |
| 276 |
| 258 class ContentClientInitializer { | 277 class ContentClientInitializer { |
| 259 public: | 278 public: |
| 260 static void Set(const std::string& process_type, | 279 static void Set(const std::string& process_type, |
| 261 ContentMainDelegate* delegate) { | 280 ContentMainDelegate* delegate) { |
| 262 ContentClient* content_client = GetContentClient(); | 281 ContentClient* content_client = GetContentClient(); |
| 263 #if !defined(CHROME_MULTIPLE_DLL_CHILD) | 282 #if !defined(CHROME_MULTIPLE_DLL_CHILD) |
| 264 if (process_type.empty()) { | 283 if (process_type.empty()) { |
| 265 if (delegate) | 284 if (delegate) |
| 266 content_client->browser_ = delegate->CreateContentBrowserClient(); | 285 content_client->browser_ = delegate->CreateContentBrowserClient(); |
| 267 if (!content_client->browser_) | 286 if (!content_client->browser_) |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 557 |
| 539 #if defined(OS_MACOSX) | 558 #if defined(OS_MACOSX) |
| 540 // We need this pool for all the objects created before we get to the | 559 // We need this pool for all the objects created before we get to the |
| 541 // event loop, but we don't want to leave them hanging around until the | 560 // event loop, but we don't want to leave them hanging around until the |
| 542 // app quits. Each "main" needs to flush this pool right before it goes into | 561 // app quits. Each "main" needs to flush this pool right before it goes into |
| 543 // its main event loop to get rid of the cruft. | 562 // its main event loop to get rid of the cruft. |
| 544 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); | 563 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); |
| 545 InitializeMac(); | 564 InitializeMac(); |
| 546 #endif | 565 #endif |
| 547 | 566 |
| 548 // On Android, the command line is initialized when library is loaded and | 567 // On Android, the command line is initialized and the FDs set when the |
| 549 // we have already started our TRACE_EVENT0. | 568 // library is loaded and we have already started our TRACE_EVENT0. |
| 550 #if !defined(OS_ANDROID) | 569 #if !defined(OS_ANDROID) |
| 551 // argc/argv are ignored on Windows and Android; see command_line.h for | 570 // argc/argv are ignored on Windows and Android; see command_line.h for |
| 552 // details. | 571 // details. |
| 553 int argc = 0; | 572 int argc = 0; |
| 554 const char** argv = NULL; | 573 const char** argv = NULL; |
| 555 | 574 |
| 556 #if !defined(OS_WIN) | 575 #if !defined(OS_WIN) |
| 557 argc = params.argc; | 576 argc = params.argc; |
| 558 argv = params.argv; | 577 argv = params.argv; |
| 559 #endif | 578 #endif |
| 560 | 579 |
| 561 base::CommandLine::Init(argc, argv); | 580 base::CommandLine::Init(argc, argv); |
| 562 | 581 |
| 582 PopulateFDsFromCommandLine(); |
| 583 |
| 563 base::EnableTerminationOnHeapCorruption(); | 584 base::EnableTerminationOnHeapCorruption(); |
| 564 | 585 |
| 565 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. | 586 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. |
| 566 // Enable profiler recording right after command line is initialized so that | 587 // Enable profiler recording right after command line is initialized so that |
| 567 // browser startup can be instrumented. | 588 // browser startup can be instrumented. |
| 568 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) | 589 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) |
| 569 tracked_objects::ScopedTracker::Enable(); | 590 tracked_objects::ScopedTracker::Enable(); |
| 570 | 591 |
| 571 SetProcessTitleFromCommandLine(argv); | 592 SetProcessTitleFromCommandLine(argv); |
| 572 #endif // !OS_ANDROID | 593 #endif // !OS_ANDROID |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 CHECK(base::i18n::InitializeICU()); | 731 CHECK(base::i18n::InitializeICU()); |
| 711 } | 732 } |
| 712 #else | 733 #else |
| 713 CHECK(base::i18n::InitializeICU()); | 734 CHECK(base::i18n::InitializeICU()); |
| 714 #endif // OS_ANDROID && (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) | 735 #endif // OS_ANDROID && (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) |
| 715 | 736 |
| 716 base::StatisticsRecorder::Initialize(); | 737 base::StatisticsRecorder::Initialize(); |
| 717 | 738 |
| 718 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 739 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 719 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 740 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 720 #if !defined(OS_ANDROID) | 741 base::FileDescriptorStore* file_descriptor_store = |
| 721 // kV8NativesDataDescriptor and kV8SnapshotDataDescriptor could be shared | 742 base::FileDescriptorStore::GetInstance(); |
| 722 // with child processes via file descriptors. On Android they are set in | 743 int v8_snapshot_fd = |
| 723 // ChildProcessService::InternalInitChildProcess, otherwise set them here. | 744 file_descriptor_store->MaybeGet(kV8SnapshotDataDescriptor); |
| 724 if (command_line.HasSwitch(switches::kV8NativesPassedByFD)) { | |
| 725 g_fds->Set( | |
| 726 kV8NativesDataDescriptor, | |
| 727 kV8NativesDataDescriptor + base::GlobalDescriptors::kBaseDescriptor); | |
| 728 } | |
| 729 if (command_line.HasSwitch(switches::kV8SnapshotPassedByFD)) { | |
| 730 g_fds->Set( | |
| 731 kV8SnapshotDataDescriptor, | |
| 732 kV8SnapshotDataDescriptor + base::GlobalDescriptors::kBaseDescriptor); | |
| 733 } | |
| 734 #endif // !OS_ANDROID | |
| 735 int v8_natives_fd = g_fds->MaybeGet(kV8NativesDataDescriptor); | |
| 736 int v8_snapshot_fd = g_fds->MaybeGet(kV8SnapshotDataDescriptor); | |
| 737 if (v8_snapshot_fd != -1) { | 745 if (v8_snapshot_fd != -1) { |
| 738 auto v8_snapshot_region = g_fds->GetRegion(kV8SnapshotDataDescriptor); | 746 auto v8_snapshot_region = |
| 747 file_descriptor_store->GetRegion(kV8SnapshotDataDescriptor); |
| 739 gin::V8Initializer::LoadV8SnapshotFromFD( | 748 gin::V8Initializer::LoadV8SnapshotFromFD( |
| 740 v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size); | 749 v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size); |
| 741 } else { | 750 } else { |
| 742 gin::V8Initializer::LoadV8Snapshot(); | 751 gin::V8Initializer::LoadV8Snapshot(); |
| 743 } | 752 } |
| 753 int v8_natives_fd = |
| 754 file_descriptor_store->MaybeGet(kV8NativesDataDescriptor); |
| 744 if (v8_natives_fd != -1) { | 755 if (v8_natives_fd != -1) { |
| 745 auto v8_natives_region = g_fds->GetRegion(kV8NativesDataDescriptor); | 756 auto v8_natives_region = |
| 757 file_descriptor_store->GetRegion(kV8NativesDataDescriptor); |
| 746 gin::V8Initializer::LoadV8NativesFromFD( | 758 gin::V8Initializer::LoadV8NativesFromFD( |
| 747 v8_natives_fd, v8_natives_region.offset, v8_natives_region.size); | 759 v8_natives_fd, v8_natives_region.offset, v8_natives_region.size); |
| 748 } else { | 760 } else { |
| 749 gin::V8Initializer::LoadV8Natives(); | 761 gin::V8Initializer::LoadV8Natives(); |
| 750 } | 762 } |
| 751 #else | 763 #else |
| 752 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) | 764 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 753 gin::V8Initializer::LoadV8Snapshot(); | 765 gin::V8Initializer::LoadV8Snapshot(); |
| 754 gin::V8Initializer::LoadV8Natives(); | 766 gin::V8Initializer::LoadV8Natives(); |
| 755 #endif // !CHROME_MULTIPLE_DLL_BROWSER | 767 #endif // !CHROME_MULTIPLE_DLL_BROWSER |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 | 884 |
| 873 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 885 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
| 874 }; | 886 }; |
| 875 | 887 |
| 876 // static | 888 // static |
| 877 ContentMainRunner* ContentMainRunner::Create() { | 889 ContentMainRunner* ContentMainRunner::Create() { |
| 878 return new ContentMainRunnerImpl(); | 890 return new ContentMainRunnerImpl(); |
| 879 } | 891 } |
| 880 | 892 |
| 881 } // namespace content | 893 } // namespace content |
| OLD | NEW |