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" |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "content/public/common/content_paths.h" | 40 #include "content/public/common/content_paths.h" |
41 #include "ui/base/ui_base_switches.h" | 41 #include "ui/base/ui_base_switches.h" |
42 | 42 |
43 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
44 #include <atlbase.h> | 44 #include <atlbase.h> |
45 #include <malloc.h> | 45 #include <malloc.h> |
46 #include <algorithm> | 46 #include <algorithm> |
47 #include "base/strings/string_util.h" | 47 #include "base/strings/string_util.h" |
48 #include "chrome/common/child_process_logging.h" | 48 #include "chrome/common/child_process_logging.h" |
49 #include "sandbox/win/src/sandbox.h" | 49 #include "sandbox/win/src/sandbox.h" |
50 #include "tools/memory_watcher/memory_watcher.h" | |
51 #include "ui/base/resource/resource_bundle_win.h" | 50 #include "ui/base/resource/resource_bundle_win.h" |
52 #endif | 51 #endif |
53 | 52 |
54 #if defined(OS_MACOSX) | 53 #if defined(OS_MACOSX) |
55 #include "base/mac/mac_util.h" | 54 #include "base/mac/mac_util.h" |
56 #include "base/mac/os_crash_dumps.h" | 55 #include "base/mac/os_crash_dumps.h" |
57 #include "chrome/app/chrome_main_mac.h" | 56 #include "chrome/app/chrome_main_mac.h" |
58 #include "chrome/browser/mac/relauncher.h" | 57 #include "chrome/browser/mac/relauncher.h" |
59 #include "chrome/common/chrome_paths_internal.h" | 58 #include "chrome/common/chrome_paths_internal.h" |
60 #include "chrome/common/mac/cfbundle_blocker.h" | 59 #include "chrome/common/mac/cfbundle_blocker.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 base::LazyInstance<chrome::ChromeBreakpadClient>::Leaky | 126 base::LazyInstance<chrome::ChromeBreakpadClient>::Leaky |
128 g_chrome_breakpad_client = LAZY_INSTANCE_INITIALIZER; | 127 g_chrome_breakpad_client = LAZY_INSTANCE_INITIALIZER; |
129 #endif | 128 #endif |
130 | 129 |
131 extern int NaClMain(const content::MainFunctionParams&); | 130 extern int NaClMain(const content::MainFunctionParams&); |
132 extern int ServiceProcessMain(const content::MainFunctionParams&); | 131 extern int ServiceProcessMain(const content::MainFunctionParams&); |
133 | 132 |
134 namespace { | 133 namespace { |
135 | 134 |
136 #if defined(OS_WIN) | 135 #if defined(OS_WIN) |
137 const wchar_t kProfilingDll[] = L"memory_watcher.dll"; | |
138 | |
139 // Load the memory profiling DLL. All it needs to be activated | |
140 // is to be loaded. Return true on success, false otherwise. | |
141 bool LoadMemoryProfiler() { | |
142 HMODULE prof_module = LoadLibrary(kProfilingDll); | |
143 return prof_module != NULL; | |
144 } | |
145 | |
146 // Early versions of Chrome incorrectly registered a chromehtml: URL handler, | 136 // Early versions of Chrome incorrectly registered a chromehtml: URL handler, |
147 // which gives us nothing but trouble. Avoid launching chrome this way since | 137 // which gives us nothing but trouble. Avoid launching chrome this way since |
148 // some apps fail to properly escape arguments. | 138 // some apps fail to properly escape arguments. |
149 bool HasDeprecatedArguments(const std::wstring& command_line) { | 139 bool HasDeprecatedArguments(const std::wstring& command_line) { |
150 const wchar_t kChromeHtml[] = L"chromehtml:"; | 140 const wchar_t kChromeHtml[] = L"chromehtml:"; |
151 std::wstring command_line_lower = command_line; | 141 std::wstring command_line_lower = command_line; |
152 // We are only searching for ASCII characters so this is OK. | 142 // We are only searching for ASCII characters so this is OK. |
153 StringToLowerASCII(&command_line_lower); | 143 StringToLowerASCII(&command_line_lower); |
154 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); | 144 std::wstring::size_type pos = command_line_lower.find(kChromeHtml); |
155 return (pos != std::wstring::npos); | 145 return (pos != std::wstring::npos); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // we want to assign a score that is somewhat representative for debugging. | 208 // we want to assign a score that is somewhat representative for debugging. |
219 score = kRendererScore; | 209 score = kRendererScore; |
220 } else { | 210 } else { |
221 NOTREACHED() << "Unknown process type"; | 211 NOTREACHED() << "Unknown process type"; |
222 } | 212 } |
223 if (score > -1) | 213 if (score > -1) |
224 base::AdjustOOMScore(base::GetCurrentProcId(), score); | 214 base::AdjustOOMScore(base::GetCurrentProcId(), score); |
225 } | 215 } |
226 #endif // defined(OS_LINUX) | 216 #endif // defined(OS_LINUX) |
227 | 217 |
228 // Enable the heap profiler if the appropriate command-line switch is | |
229 // present, bailing out of the app we can't. | |
230 void EnableHeapProfiler(const CommandLine& command_line) { | |
231 #if defined(OS_WIN) | |
232 if (command_line.HasSwitch(switches::kMemoryProfiling)) | |
233 if (!LoadMemoryProfiler()) | |
234 exit(-1); | |
235 #endif | |
236 } | |
237 | |
238 // Returns true if this subprocess type needs the ResourceBundle initialized | 218 // Returns true if this subprocess type needs the ResourceBundle initialized |
239 // and resources loaded. | 219 // and resources loaded. |
240 bool SubprocessNeedsResourceBundle(const std::string& process_type) { | 220 bool SubprocessNeedsResourceBundle(const std::string& process_type) { |
241 return | 221 return |
242 #if defined(OS_WIN) || defined(OS_MACOSX) | 222 #if defined(OS_WIN) || defined(OS_MACOSX) |
243 // Windows needs resources for the default/null plugin. | 223 // Windows needs resources for the default/null plugin. |
244 // Mac needs them for the plugin process name. | 224 // Mac needs them for the plugin process name. |
245 process_type == switches::kPluginProcess || | 225 process_type == switches::kPluginProcess || |
246 // Needed for scrollbar related images. | 226 // Needed for scrollbar related images. |
247 process_type == switches::kWorkerProcess || | 227 process_type == switches::kWorkerProcess || |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 #endif | 645 #endif |
666 | 646 |
667 // Initialize the user data dir for any process type that needs it. | 647 // Initialize the user data dir for any process type that needs it. |
668 if (chrome::ProcessNeedsProfileDir(process_type)) | 648 if (chrome::ProcessNeedsProfileDir(process_type)) |
669 InitializeUserDataDir(); | 649 InitializeUserDataDir(); |
670 | 650 |
671 stats_counter_timer_.reset(new base::StatsCounterTimer("Chrome.Init")); | 651 stats_counter_timer_.reset(new base::StatsCounterTimer("Chrome.Init")); |
672 startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer> | 652 startup_timer_.reset(new base::StatsScope<base::StatsCounterTimer> |
673 (*stats_counter_timer_)); | 653 (*stats_counter_timer_)); |
674 | 654 |
675 // Enable the heap profiler as early as possible! | |
676 EnableHeapProfiler(command_line); | |
677 | |
678 // Enable Message Loop related state asap. | 655 // Enable Message Loop related state asap. |
679 if (command_line.HasSwitch(switches::kMessageLoopHistogrammer)) | 656 if (command_line.HasSwitch(switches::kMessageLoopHistogrammer)) |
680 base::MessageLoop::EnableHistogrammer(true); | 657 base::MessageLoop::EnableHistogrammer(true); |
681 | 658 |
682 #if !defined(OS_ANDROID) | 659 #if !defined(OS_ANDROID) |
683 // Android does InitLogging when library is loaded. Skip here. | 660 // Android does InitLogging when library is loaded. Skip here. |
684 logging::OldFileDeletionState file_state = | 661 logging::OldFileDeletionState file_state = |
685 logging::APPEND_TO_OLD_LOG_FILE; | 662 logging::APPEND_TO_OLD_LOG_FILE; |
686 if (process_type.empty()) { | 663 if (process_type.empty()) { |
687 file_state = logging::DELETE_OLD_LOG_FILE; | 664 file_state = logging::DELETE_OLD_LOG_FILE; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 } | 895 } |
919 | 896 |
920 content::ContentUtilityClient* | 897 content::ContentUtilityClient* |
921 ChromeMainDelegate::CreateContentUtilityClient() { | 898 ChromeMainDelegate::CreateContentUtilityClient() { |
922 #if defined(CHROME_MULTIPLE_DLL_BROWSER) | 899 #if defined(CHROME_MULTIPLE_DLL_BROWSER) |
923 return NULL; | 900 return NULL; |
924 #else | 901 #else |
925 return g_chrome_content_utility_client.Pointer(); | 902 return g_chrome_content_utility_client.Pointer(); |
926 #endif | 903 #endif |
927 } | 904 } |
OLD | NEW |