Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <malloc.h> | 6 #include <malloc.h> |
| 7 #include <shellscalingapi.h> | 7 #include <shellscalingapi.h> |
| 8 #include <tchar.h> | 8 #include <tchar.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/at_exit.h" | 12 #include "base/at_exit.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/strings/utf_string_conversions.h" | |
| 16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 17 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
| 18 #include "chrome/app/main_dll_loader_win.h" | 19 #include "chrome/app/main_dll_loader_win.h" |
| 19 #include "chrome/browser/chrome_process_finder_win.h" | 20 #include "chrome/browser/chrome_process_finder_win.h" |
| 20 #include "chrome/browser/policy/policy_path_parser.h" | 21 #include "chrome/browser/policy/policy_path_parser.h" |
| 21 #include "chrome/common/chrome_paths_internal.h" | 22 #include "chrome/common/chrome_paths_internal.h" |
| 22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome_elf/chrome_elf_main.h" | 24 #include "chrome_elf/chrome_elf_main.h" |
| 24 #include "components/startup_metric_utils/startup_metric_utils.h" | 25 #include "components/startup_metric_utils/startup_metric_utils.h" |
| 25 #include "content/public/common/result_codes.h" | 26 #include "content/public/common/result_codes.h" |
| 27 #include "third_party/crashpad/crashpad/handler/handler_main.h" | |
| 26 #include "ui/gfx/win/dpi.h" | 28 #include "ui/gfx/win/dpi.h" |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 // List of switches that it's safe to rendezvous early with. Fast start should | 31 // List of switches that it's safe to rendezvous early with. Fast start should |
| 30 // not be done if a command line contains a switch not in this set. | 32 // not be done if a command line contains a switch not in this set. |
| 31 // Note this is currently stored as a list of two because it's probably faster | 33 // Note this is currently stored as a list of two because it's probably faster |
| 32 // to iterate over this small array than building a map for constant time | 34 // to iterate over this small array than building a map for constant time |
| 33 // lookups. | 35 // lookups. |
| 34 const char* const kFastStartSwitches[] = { | 36 const char* const kFastStartSwitches[] = { |
| 35 switches::kProfileDirectory, | 37 switches::kProfileDirectory, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 // Only needed on XP but harmless on other Windows flavors. | 116 // Only needed on XP but harmless on other Windows flavors. |
| 115 auto crt_heap = _get_heap_handle(); | 117 auto crt_heap = _get_heap_handle(); |
| 116 ULONG enable_LFH = 2; | 118 ULONG enable_LFH = 2; |
| 117 if (HeapSetInformation(reinterpret_cast<HANDLE>(crt_heap), | 119 if (HeapSetInformation(reinterpret_cast<HANDLE>(crt_heap), |
| 118 HeapCompatibilityInformation, | 120 HeapCompatibilityInformation, |
| 119 &enable_LFH, sizeof(enable_LFH))) { | 121 &enable_LFH, sizeof(enable_LFH))) { |
| 120 VLOG(1) << "Low fragmentation heap enabled."; | 122 VLOG(1) << "Low fragmentation heap enabled."; |
| 121 } | 123 } |
| 122 } | 124 } |
| 123 | 125 |
| 126 bool RunAsCrashpadHandler(const base::CommandLine& command_line, int* rc) { | |
| 127 if (command_line.HasSwitch("crashpad_handler")) { | |
| 128 std::vector<base::string16> argv = command_line.argv(); | |
| 129 argv.erase(std::remove(argv.begin(), argv.end(), L"--crashpad_handler"), | |
| 130 argv.end()); | |
| 131 | |
| 132 scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); | |
| 133 std::vector<std::string> storage; | |
| 134 storage.reserve(argv.size()); | |
| 135 for (size_t i = 0; i < argv.size(); ++i) { | |
| 136 storage.push_back(base::UTF16ToUTF8(argv[i])); | |
| 137 argv_as_utf8[i] = &storage[i][0]; | |
| 138 } | |
| 139 argv_as_utf8[argv.size()] = nullptr; | |
| 140 *rc = crashpad::HandlerMain(argv.size(), argv_as_utf8.get()); | |
| 141 return true; | |
| 142 } | |
| 143 return false; | |
| 144 } | |
| 145 | |
| 124 } // namespace | 146 } // namespace |
| 125 | 147 |
| 126 #if !defined(ADDRESS_SANITIZER) | 148 #if !defined(ADDRESS_SANITIZER) |
| 127 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { | 149 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { |
| 128 #else | 150 #else |
| 129 // The AddressSanitizer build should be a console program as it prints out stuff | 151 // The AddressSanitizer build should be a console program as it prints out stuff |
| 130 // on stderr. | 152 // on stderr. |
| 131 int main() { | 153 int main() { |
| 132 HINSTANCE instance = GetModuleHandle(NULL); | 154 HINSTANCE instance = GetModuleHandle(NULL); |
| 133 #endif | 155 #endif |
| 156 // Initialize the commandline singleton from the environment. | |
| 157 base::CommandLine::Init(0, NULL); | |
|
cpu_(ooo_6.6-7.5)
2015/11/07 01:53:17
lets move this Init(0, NULL) inside the RunAsCrash
scottmg
2015/11/09 18:29:56
I think it's better out here, since it's also init
| |
| 158 | |
| 159 int rc; | |
| 160 if (RunAsCrashpadHandler(*base::CommandLine::ForCurrentProcess(), &rc)) | |
| 161 return rc; | |
| 162 | |
| 134 SwitchToLFHeap(); | 163 SwitchToLFHeap(); |
| 135 | 164 |
| 136 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); | 165 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); |
| 137 | 166 |
| 138 // Signal Chrome Elf that Chrome has begun to start. | 167 // Signal Chrome Elf that Chrome has begun to start. |
| 139 SignalChromeElf(); | 168 SignalChromeElf(); |
| 140 | 169 |
| 141 // Initialize the commandline singleton from the environment. | |
| 142 base::CommandLine::Init(0, NULL); | |
| 143 // The exit manager is in charge of calling the dtors of singletons. | 170 // The exit manager is in charge of calling the dtors of singletons. |
| 144 base::AtExitManager exit_manager; | 171 base::AtExitManager exit_manager; |
| 145 | 172 |
| 146 // We don't want to set DPI awareness on pre-Win7 because we don't support | 173 // We don't want to set DPI awareness on pre-Win7 because we don't support |
| 147 // DirectWrite there. GDI fonts are kerned very badly, so better to leave | 174 // DirectWrite there. GDI fonts are kerned very badly, so better to leave |
| 148 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). | 175 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). |
| 149 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | 176 if (base::win::GetVersion() >= base::win::VERSION_WIN7) |
| 150 EnableHighDPISupport(); | 177 EnableHighDPISupport(); |
| 151 | 178 |
| 152 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess())) | 179 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess())) |
| 153 return 0; | 180 return 0; |
| 154 | 181 |
| 155 // Load and launch the chrome dll. *Everything* happens inside. | 182 // Load and launch the chrome dll. *Everything* happens inside. |
| 156 VLOG(1) << "About to load main DLL."; | 183 VLOG(1) << "About to load main DLL."; |
| 157 MainDllLoader* loader = MakeMainDllLoader(); | 184 MainDllLoader* loader = MakeMainDllLoader(); |
| 158 int rc = loader->Launch(instance); | 185 rc = loader->Launch(instance); |
| 159 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 186 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
| 160 delete loader; | 187 delete loader; |
| 161 return rc; | 188 return rc; |
| 162 } | 189 } |
| OLD | NEW |