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 "chrome/app/chrome_main_delegate.h" | 5 #include "chrome/app/chrome_main_delegate.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/cpu.h" | 9 #include "base/cpu.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/statistics_recorder.h" | 14 #include "base/metrics/statistics_recorder.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/process/memory.h" | 16 #include "base/process/memory.h" |
17 #include "base/process/process_handle.h" | 17 #include "base/process/process_handle.h" |
18 #include "base/process/process_info.h" | 18 #include "base/process/process_info.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "base/trace_event/trace_event_impl.h" | 21 #include "base/trace_event/trace_event_impl.h" |
22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "chrome/app/chrome_crash_reporter_client.h" |
23 #include "chrome/browser/chrome_content_browser_client.h" | 24 #include "chrome/browser/chrome_content_browser_client.h" |
24 #include "chrome/browser/defaults.h" | 25 #include "chrome/browser/defaults.h" |
25 #include "chrome/common/channel_info.h" | 26 #include "chrome/common/channel_info.h" |
26 #include "chrome/common/chrome_constants.h" | 27 #include "chrome/common/chrome_constants.h" |
27 #include "chrome/common/chrome_content_client.h" | 28 #include "chrome/common/chrome_content_client.h" |
28 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
29 #include "chrome/common/chrome_paths_internal.h" | 30 #include "chrome/common/chrome_paths_internal.h" |
30 #include "chrome/common/chrome_result_codes.h" | 31 #include "chrome/common/chrome_result_codes.h" |
31 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/crash_keys.h" | 33 #include "chrome/common/crash_keys.h" |
33 #include "chrome/common/logging_chrome.h" | 34 #include "chrome/common/logging_chrome.h" |
34 #include "chrome/common/profiling.h" | 35 #include "chrome/common/profiling.h" |
35 #include "chrome/common/switch_utils.h" | 36 #include "chrome/common/switch_utils.h" |
36 #include "chrome/common/trace_event_args_whitelist.h" | 37 #include "chrome/common/trace_event_args_whitelist.h" |
37 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
38 #include "chrome/plugin/chrome_content_plugin_client.h" | 39 #include "chrome/plugin/chrome_content_plugin_client.h" |
39 #include "chrome/renderer/chrome_content_renderer_client.h" | 40 #include "chrome/renderer/chrome_content_renderer_client.h" |
40 #include "chrome/utility/chrome_content_utility_client.h" | 41 #include "chrome/utility/chrome_content_utility_client.h" |
41 #include "components/component_updater/component_updater_paths.h" | 42 #include "components/component_updater/component_updater_paths.h" |
42 #include "components/content_settings/core/common/content_settings_pattern.h" | 43 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 44 #include "components/crash/content/app/crash_reporter_client.h" |
43 #include "components/version_info/version_info.h" | 45 #include "components/version_info/version_info.h" |
44 #include "content/public/common/content_client.h" | 46 #include "content/public/common/content_client.h" |
45 #include "content/public/common/content_paths.h" | 47 #include "content/public/common/content_paths.h" |
46 #include "content/public/common/content_switches.h" | 48 #include "content/public/common/content_switches.h" |
47 #include "extensions/common/constants.h" | 49 #include "extensions/common/constants.h" |
48 #include "ui/base/resource/resource_bundle.h" | 50 #include "ui/base/resource/resource_bundle.h" |
49 #include "ui/base/ui_base_switches.h" | 51 #include "ui/base/ui_base_switches.h" |
50 | 52 |
51 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
52 #include <atlbase.h> | 54 #include <atlbase.h> |
53 #include <malloc.h> | 55 #include <malloc.h> |
54 #include <algorithm> | 56 #include <algorithm> |
55 #include "chrome/app/close_handle_hook_win.h" | 57 #include "chrome/app/close_handle_hook_win.h" |
56 #include "chrome/common/child_process_logging.h" | 58 #include "chrome/common/child_process_logging.h" |
57 #include "chrome/common/v8_breakpad_support_win.h" | 59 #include "chrome/common/v8_breakpad_support_win.h" |
| 60 #include "components/crash/content/app/crashpad.h" |
58 #include "sandbox/win/src/sandbox.h" | 61 #include "sandbox/win/src/sandbox.h" |
59 #include "ui/base/resource/resource_bundle_win.h" | 62 #include "ui/base/resource/resource_bundle_win.h" |
60 #endif | 63 #endif |
61 | 64 |
62 #if defined(OS_MACOSX) | 65 #if defined(OS_MACOSX) |
63 #include "base/mac/foundation_util.h" | 66 #include "base/mac/foundation_util.h" |
64 #include "chrome/app/chrome_main_mac.h" | 67 #include "chrome/app/chrome_main_mac.h" |
65 #include "chrome/browser/mac/relauncher.h" | 68 #include "chrome/browser/mac/relauncher.h" |
66 #include "chrome/common/mac/cfbundle_blocker.h" | 69 #include "chrome/common/mac/cfbundle_blocker.h" |
67 #include "components/crash/content/app/crashpad_mac.h" | 70 #include "components/crash/content/app/crashpad.h" |
68 #include "components/crash/core/common/objc_zombie.h" | 71 #include "components/crash/core/common/objc_zombie.h" |
69 #include "ui/base/l10n/l10n_util_mac.h" | 72 #include "ui/base/l10n/l10n_util_mac.h" |
70 #endif | 73 #endif |
71 | 74 |
72 #if defined(OS_POSIX) | 75 #if defined(OS_POSIX) |
73 #include <locale.h> | 76 #include <locale.h> |
74 #include <signal.h> | 77 #include <signal.h> |
75 #include "chrome/app/chrome_crash_reporter_client.h" | |
76 #include "components/crash/content/app/crash_reporter_client.h" | |
77 #endif | 78 #endif |
78 | 79 |
79 #if !defined(DISABLE_NACL) && defined(OS_LINUX) | 80 #if !defined(DISABLE_NACL) && defined(OS_LINUX) |
80 #include "components/nacl/common/nacl_paths.h" | 81 #include "components/nacl/common/nacl_paths.h" |
81 #include "components/nacl/zygote/nacl_fork_delegate_linux.h" | 82 #include "components/nacl/zygote/nacl_fork_delegate_linux.h" |
82 #endif | 83 #endif |
83 | 84 |
84 #if defined(OS_CHROMEOS) | 85 #if defined(OS_CHROMEOS) |
85 #include "base/sys_info.h" | 86 #include "base/sys_info.h" |
86 #include "chrome/browser/chromeos/boot_times_recorder.h" | 87 #include "chrome/browser/chromeos/boot_times_recorder.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 g_chrome_content_utility_client = LAZY_INSTANCE_INITIALIZER; | 139 g_chrome_content_utility_client = LAZY_INSTANCE_INITIALIZER; |
139 base::LazyInstance<ChromeContentPluginClient> | 140 base::LazyInstance<ChromeContentPluginClient> |
140 g_chrome_content_plugin_client = LAZY_INSTANCE_INITIALIZER; | 141 g_chrome_content_plugin_client = LAZY_INSTANCE_INITIALIZER; |
141 #endif | 142 #endif |
142 | 143 |
143 #if !defined(CHROME_MULTIPLE_DLL_CHILD) | 144 #if !defined(CHROME_MULTIPLE_DLL_CHILD) |
144 base::LazyInstance<ChromeContentBrowserClient> g_chrome_content_browser_client = | 145 base::LazyInstance<ChromeContentBrowserClient> g_chrome_content_browser_client = |
145 LAZY_INSTANCE_INITIALIZER; | 146 LAZY_INSTANCE_INITIALIZER; |
146 #endif | 147 #endif |
147 | 148 |
148 #if defined(OS_POSIX) | 149 #if defined(OS_POSIX) || defined(OS_WIN) |
149 base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = | 150 base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = |
150 LAZY_INSTANCE_INITIALIZER; | 151 LAZY_INSTANCE_INITIALIZER; |
151 #endif | 152 #endif |
152 | 153 |
153 extern int NaClMain(const content::MainFunctionParams&); | 154 extern int NaClMain(const content::MainFunctionParams&); |
154 extern int ServiceProcessMain(const content::MainFunctionParams&); | 155 extern int ServiceProcessMain(const content::MainFunctionParams&); |
155 | 156 |
156 namespace { | 157 namespace { |
157 | 158 |
158 #if defined(OS_WIN) | 159 #if defined(OS_WIN) |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 } | 442 } |
442 | 443 |
443 bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) { | 444 bool ChromeMainDelegate::BasicStartupComplete(int* exit_code) { |
444 #if defined(OS_CHROMEOS) | 445 #if defined(OS_CHROMEOS) |
445 chromeos::BootTimesRecorder::Get()->SaveChromeMainStats(); | 446 chromeos::BootTimesRecorder::Get()->SaveChromeMainStats(); |
446 #endif | 447 #endif |
447 | 448 |
448 const base::CommandLine& command_line = | 449 const base::CommandLine& command_line = |
449 *base::CommandLine::ForCurrentProcess(); | 450 *base::CommandLine::ForCurrentProcess(); |
450 | 451 |
451 | |
452 #if defined(OS_WIN) | 452 #if defined(OS_WIN) |
453 // Browser should not be sandboxed. | 453 // Browser should not be sandboxed. |
454 const bool is_browser = !command_line.HasSwitch(switches::kProcessType); | 454 const bool is_browser = !command_line.HasSwitch(switches::kProcessType); |
455 if (is_browser && IsSandboxedProcess()) { | 455 if (is_browser && IsSandboxedProcess()) { |
456 *exit_code = chrome::RESULT_CODE_INVALID_SANDBOX_STATE; | 456 *exit_code = chrome::RESULT_CODE_INVALID_SANDBOX_STATE; |
457 return true; | 457 return true; |
458 } | 458 } |
459 #endif | 459 #endif |
460 | 460 |
461 #if defined(OS_MACOSX) | 461 #if defined(OS_MACOSX) |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 } | 658 } |
659 } | 659 } |
660 #endif // defined(OS_MACOSX) | 660 #endif // defined(OS_MACOSX) |
661 | 661 |
662 void ChromeMainDelegate::PreSandboxStartup() { | 662 void ChromeMainDelegate::PreSandboxStartup() { |
663 const base::CommandLine& command_line = | 663 const base::CommandLine& command_line = |
664 *base::CommandLine::ForCurrentProcess(); | 664 *base::CommandLine::ForCurrentProcess(); |
665 std::string process_type = | 665 std::string process_type = |
666 command_line.GetSwitchValueASCII(switches::kProcessType); | 666 command_line.GetSwitchValueASCII(switches::kProcessType); |
667 | 667 |
668 #if defined(OS_POSIX) | 668 #if defined(OS_POSIX) || defined(OS_WIN) |
669 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); | 669 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); |
670 #endif | 670 #endif |
671 | 671 |
672 #if defined(OS_MACOSX) | 672 #if defined(OS_MACOSX) |
673 // On the Mac, the child executable lives at a predefined location within | 673 // On the Mac, the child executable lives at a predefined location within |
674 // the app bundle's versioned directory. | 674 // the app bundle's versioned directory. |
675 PathService::Override(content::CHILD_PROCESS_EXE, | 675 PathService::Override(content::CHILD_PROCESS_EXE, |
676 chrome::GetVersionedDirectory(). | 676 chrome::GetVersionedDirectory(). |
677 Append(chrome::kHelperProcessExecutablePath)); | 677 Append(chrome::kHelperProcessExecutablePath)); |
678 | 678 |
679 InitMacCrashReporter(command_line, process_type); | 679 InitMacCrashReporter(command_line, process_type); |
680 #endif | 680 #endif |
681 | 681 |
682 #if defined(OS_WIN) | 682 #if defined(OS_WIN) |
| 683 // TODO(scottmg): It would be nice to do this earlier to catch early crashes, |
| 684 // perhaps as early as WinMain in chrome.exe. This would require some code |
| 685 // restructuring to have paths and command lines set up, and also to handle |
| 686 // having some of the code live in chrome.exe, while having the database be |
| 687 // accessed by browser code in chrome.dll (to get a list of uploaded crashes |
| 688 // for chrome://crashes). |
| 689 crash_reporter::InitializeCrashpad(process_type.empty(), process_type); |
| 690 #endif // OS_WIN |
| 691 |
| 692 #if defined(OS_WIN) |
683 child_process_logging::Init(); | 693 child_process_logging::Init(); |
684 #endif | 694 #endif |
685 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) | 695 #if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX)) |
686 // Create an instance of the CPU class to parse /proc/cpuinfo and cache | 696 // Create an instance of the CPU class to parse /proc/cpuinfo and cache |
687 // cpu_brand info. | 697 // cpu_brand info. |
688 base::CPU cpu_info; | 698 base::CPU cpu_info; |
689 #endif | 699 #endif |
690 | 700 |
691 // Initialize the user data dir for any process type that needs it. | 701 // Initialize the user data dir for any process type that needs it. |
692 if (chrome::ProcessNeedsProfileDir(process_type)) | 702 if (chrome::ProcessNeedsProfileDir(process_type)) |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 case version_info::Channel::CANARY: | 990 case version_info::Channel::CANARY: |
981 return true; | 991 return true; |
982 case version_info::Channel::DEV: | 992 case version_info::Channel::DEV: |
983 case version_info::Channel::BETA: | 993 case version_info::Channel::BETA: |
984 case version_info::Channel::STABLE: | 994 case version_info::Channel::STABLE: |
985 default: | 995 default: |
986 // Don't enable instrumentation. | 996 // Don't enable instrumentation. |
987 return false; | 997 return false; |
988 } | 998 } |
989 } | 999 } |
OLD | NEW |