OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <atlbase.h> | 5 #include <atlbase.h> |
6 #include <atlapp.h> | 6 #include <atlapp.h> |
7 #include <malloc.h> | 7 #include <malloc.h> |
8 #include <new.h> | 8 #include <new.h> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/icu_util.h" | 12 #include "base/icu_util.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/stats_table.h" | 15 #include "base/stats_table.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/win_util.h" | 17 #include "base/win_util.h" |
18 #include "chrome/browser/render_process_host.h" | 18 #include "chrome/browser/render_process_host.h" |
19 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
20 #include "chrome/common/chrome_counters.h" | 20 #include "chrome/common/chrome_counters.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/common/logging_chrome.h" | 23 #include "chrome/common/logging_chrome.h" |
24 #include "chrome/common/resource_bundle.h" | 24 #include "chrome/common/resource_bundle.h" |
25 #include "sandbox/src/sandbox.h" | 25 #include "sandbox/src/sandbox.h" |
26 #include "tools/memory_watcher/memory_watcher.h" | 26 #include "tools/memory_watcher/memory_watcher.h" |
27 | 27 |
28 extern int BrowserMain(CommandLine &, int, sandbox::BrokerServices*); | 28 extern int BrowserMain(CommandLine&, sandbox::BrokerServices*); |
29 extern int RendererMain(CommandLine &, int, sandbox::TargetServices*); | 29 extern int RendererMain(CommandLine&, sandbox::TargetServices*); |
30 extern int PluginMain(CommandLine &, int, sandbox::TargetServices*); | 30 extern int PluginMain(CommandLine&, sandbox::TargetServices*); |
31 | 31 |
32 // TODO(erikkay): isn't this already defined somewhere? | 32 // TODO(erikkay): isn't this already defined somewhere? |
33 #define DLLEXPORT __declspec(dllexport) | 33 #define DLLEXPORT __declspec(dllexport) |
34 | 34 |
35 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. | 35 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. |
36 extern "C" { | 36 extern "C" { |
37 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, | 37 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, |
38 sandbox::SandboxInterfaceInfo* sandbox_info, | 38 sandbox::SandboxInterfaceInfo* sandbox_info, |
39 TCHAR* command_line, int show_command); | 39 TCHAR* command_line); |
40 } | 40 } |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 const wchar_t kProfilingDll[] = L"memory_watcher.dll"; | 44 const wchar_t kProfilingDll[] = L"memory_watcher.dll"; |
45 | 45 |
46 // Load the memory profiling DLL. All it needs to be activated | 46 // Load the memory profiling DLL. All it needs to be activated |
47 // is to be loaded. Return true on success, false otherwise. | 47 // is to be loaded. Return true on success, false otherwise. |
48 bool LoadMemoryProfiler() { | 48 bool LoadMemoryProfiler() { |
49 HMODULE prof_module = LoadLibrary(kProfilingDll); | 49 HMODULE prof_module = LoadLibrary(kProfilingDll); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 if (DumpProcess) | 83 if (DumpProcess) |
84 DumpProcess(); | 84 DumpProcess(); |
85 } | 85 } |
86 | 86 |
87 #pragma optimize("", on) | 87 #pragma optimize("", on) |
88 | 88 |
89 } // namespace | 89 } // namespace |
90 | 90 |
91 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, | 91 DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, |
92 sandbox::SandboxInterfaceInfo* sandbox_info, | 92 sandbox::SandboxInterfaceInfo* sandbox_info, |
93 TCHAR* command_line, int show_command) { | 93 TCHAR* command_line) { |
94 // Register the invalid param handler and pure call handler to be able to | 94 // Register the invalid param handler and pure call handler to be able to |
95 // notify breakpad when it happens. | 95 // notify breakpad when it happens. |
96 _set_invalid_parameter_handler(InvalidParameter); | 96 _set_invalid_parameter_handler(InvalidParameter); |
97 _set_purecall_handler(PureCall); | 97 _set_purecall_handler(PureCall); |
98 // Gather allocation failure. | 98 // Gather allocation failure. |
99 _set_new_handler(&OnNoMemory); | 99 _set_new_handler(&OnNoMemory); |
100 // Make sure malloc() calls the new handler too. | 100 // Make sure malloc() calls the new handler too. |
101 _set_new_mode(1); | 101 _set_new_mode(1); |
102 | 102 |
103 // The exit manager is in charge of calling the dtors of singleton objects. | 103 // The exit manager is in charge of calling the dtors of singleton objects. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 // Initialize ResourceBundle which handles files loaded from external | 208 // Initialize ResourceBundle which handles files loaded from external |
209 // sources. The language should have been passed in to us from the | 209 // sources. The language should have been passed in to us from the |
210 // browser process as a command line flag. | 210 // browser process as a command line flag. |
211 ResourceBundle::InitSharedInstance(std::wstring()); | 211 ResourceBundle::InitSharedInstance(std::wstring()); |
212 } | 212 } |
213 | 213 |
214 startup_timer.Stop(); // End of Startup Time Measurement. | 214 startup_timer.Stop(); // End of Startup Time Measurement. |
215 | 215 |
216 int rv; | 216 int rv; |
217 if (process_type == switches::kRendererProcess) { | 217 if (process_type == switches::kRendererProcess) { |
218 rv = RendererMain(parsed_command_line, show_command, target_services); | 218 rv = RendererMain(parsed_command_line, target_services); |
219 } else if (process_type == switches::kPluginProcess) { | 219 } else if (process_type == switches::kPluginProcess) { |
220 rv = PluginMain(parsed_command_line, show_command, target_services); | 220 rv = PluginMain(parsed_command_line, target_services); |
221 } else if (process_type.empty()) { | 221 } else if (process_type.empty()) { |
222 int ole_result = OleInitialize(NULL); | 222 int ole_result = OleInitialize(NULL); |
223 DCHECK(ole_result == S_OK); | 223 DCHECK(ole_result == S_OK); |
224 rv = BrowserMain(parsed_command_line, show_command, broker_services); | 224 rv = BrowserMain(parsed_command_line, broker_services); |
225 OleUninitialize(); | 225 OleUninitialize(); |
226 } else { | 226 } else { |
227 NOTREACHED() << "Unknown process type"; | 227 NOTREACHED() << "Unknown process type"; |
228 rv = -1; | 228 rv = -1; |
229 } | 229 } |
230 | 230 |
231 if (!process_type.empty()) { | 231 if (!process_type.empty()) { |
232 ResourceBundle::CleanupSharedInstance(); | 232 ResourceBundle::CleanupSharedInstance(); |
233 } | 233 } |
234 | 234 |
235 #ifdef _CRTDBG_MAP_ALLOC | 235 #ifdef _CRTDBG_MAP_ALLOC |
236 _CrtDumpMemoryLeaks(); | 236 _CrtDumpMemoryLeaks(); |
237 #endif // _CRTDBG_MAP_ALLOC | 237 #endif // _CRTDBG_MAP_ALLOC |
238 | 238 |
239 _Module.Term(); | 239 _Module.Term(); |
240 | 240 |
241 logging::CleanupChromeLogging(); | 241 logging::CleanupChromeLogging(); |
242 | 242 |
243 return rv; | 243 return rv; |
244 } | 244 } |
245 | 245 |
OLD | NEW |