| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <tchar.h> | 9 #include <tchar.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/at_exit.h" | 14 #include "base/at_exit.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/strings/string16.h" |
| 21 #include "base/strings/string_util.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 22 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
| 23 #include "chrome/app/chrome_crash_reporter_client.h" | 25 #include "chrome/app/chrome_crash_reporter_client.h" |
| 24 #include "chrome/app/main_dll_loader_win.h" | 26 #include "chrome/app/main_dll_loader_win.h" |
| 25 #include "chrome/browser/chrome_process_finder_win.h" | 27 #include "chrome/browser/chrome_process_finder_win.h" |
| 26 #include "chrome/browser/policy/policy_path_parser.h" | 28 #include "chrome/browser/policy/policy_path_parser.h" |
| 27 #include "chrome/common/chrome_paths_internal.h" | 29 #include "chrome/common/chrome_paths_internal.h" |
| 28 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/installer/util/browser_distribution.h" |
| 29 #include "chrome_elf/chrome_elf_main.h" | 32 #include "chrome_elf/chrome_elf_main.h" |
| 30 #include "components/crash/content/app/crash_reporter_client.h" | 33 #include "components/crash/content/app/crash_reporter_client.h" |
| 31 #include "components/crash/content/app/crashpad.h" | 34 #include "components/crash/content/app/crashpad.h" |
| 32 #include "components/startup_metric_utils/browser/startup_metric_utils.h" | 35 #include "components/startup_metric_utils/browser/startup_metric_utils.h" |
| 36 #include "components/startup_metric_utils/common/pre_read_field_trial_utils_win.
h" |
| 33 #include "content/public/common/content_switches.h" | 37 #include "content/public/common/content_switches.h" |
| 34 #include "content/public/common/result_codes.h" | 38 #include "content/public/common/result_codes.h" |
| 35 #include "third_party/crashpad/crashpad/handler/handler_main.h" | 39 #include "third_party/crashpad/crashpad/handler/handler_main.h" |
| 36 #include "ui/gfx/win/dpi.h" | 40 #include "ui/gfx/win/dpi.h" |
| 37 | 41 |
| 38 namespace { | 42 namespace { |
| 39 | 43 |
| 40 base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = | 44 base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = |
| 41 LAZY_INSTANCE_INITIALIZER; | 45 LAZY_INSTANCE_INITIALIZER; |
| 42 | 46 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 argv.erase(std::remove_if(argv.begin(), argv.end(), | 149 argv.erase(std::remove_if(argv.begin(), argv.end(), |
| 146 [&process_type](const base::string16& str) { | 150 [&process_type](const base::string16& str) { |
| 147 return str.compare(0, process_type.size(), | 151 return str.compare(0, process_type.size(), |
| 148 process_type) == 0; | 152 process_type) == 0; |
| 149 }), | 153 }), |
| 150 argv.end()); | 154 argv.end()); |
| 151 | 155 |
| 152 scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); | 156 scoped_ptr<char* []> argv_as_utf8(new char*[argv.size() + 1]); |
| 153 std::vector<std::string> storage; | 157 std::vector<std::string> storage; |
| 154 storage.reserve(argv.size()); | 158 storage.reserve(argv.size()); |
| 159 |
| 160 size_t arg_append_index = 0; |
| 155 for (size_t i = 0; i < argv.size(); ++i) { | 161 for (size_t i = 0; i < argv.size(); ++i) { |
| 162 // Remove arguments starting with '/' as they are not supported by crashpad. |
| 163 if (!argv[i].empty() && argv[i].front() == L'/') |
| 164 continue; |
| 165 |
| 156 storage.push_back(base::UTF16ToUTF8(argv[i])); | 166 storage.push_back(base::UTF16ToUTF8(argv[i])); |
| 157 argv_as_utf8[i] = &storage[i][0]; | 167 argv_as_utf8[arg_append_index] = &storage[arg_append_index][0]; |
| 168 ++arg_append_index; |
| 158 } | 169 } |
| 159 argv_as_utf8[argv.size()] = nullptr; | 170 argv_as_utf8[arg_append_index] = nullptr; |
| 160 return crashpad::HandlerMain(static_cast<int>(argv.size()), | 171 |
| 172 return crashpad::HandlerMain(static_cast<int>(storage.size()), |
| 161 argv_as_utf8.get()); | 173 argv_as_utf8.get()); |
| 162 } | 174 } |
| 163 | 175 |
| 176 // Returns true if |command_line| contains a /prefetch:# argument where # is in |
| 177 // [1, 8]. |
| 178 bool HasValidWindowsPrefetchArgument(const base::CommandLine& command_line) { |
| 179 const base::char16 kPrefetchArgumentPrefix[] = L"/prefetch:"; |
| 180 |
| 181 for (const auto& arg : command_line.argv()) { |
| 182 if (arg.size() == arraysize(kPrefetchArgumentPrefix) && |
| 183 base::StartsWith(arg, kPrefetchArgumentPrefix, |
| 184 base::CompareCase::SENSITIVE)) { |
| 185 return arg[arraysize(kPrefetchArgumentPrefix) - 1] >= L'1' && |
| 186 arg[arraysize(kPrefetchArgumentPrefix) - 1] <= L'8'; |
| 187 } |
| 188 } |
| 189 return false; |
| 190 } |
| 191 |
| 164 } // namespace | 192 } // namespace |
| 165 | 193 |
| 166 // This helper is looked up in the browser to retrieve the crash reports. See | 194 // This helper is looked up in the browser to retrieve the crash reports. See |
| 167 // CrashUploadListCrashpad. Note that we do not pass an std::vector here, | 195 // CrashUploadListCrashpad. Note that we do not pass an std::vector here, |
| 168 // because we do not want to allocate/free in different modules. The returned | 196 // because we do not want to allocate/free in different modules. The returned |
| 169 // pointer is read-only. | 197 // pointer is read-only. |
| 170 extern "C" __declspec(dllexport) void GetUploadedReportsImpl( | 198 extern "C" __declspec(dllexport) void GetUploadedReportsImpl( |
| 171 const crash_reporter::UploadedReport** reports, | 199 const crash_reporter::UploadedReport** reports, |
| 172 size_t* report_count) { | 200 size_t* report_count) { |
| 173 crash_reporter::GetUploadedReports(g_uploaded_reports.Pointer()); | 201 crash_reporter::GetUploadedReports(g_uploaded_reports.Pointer()); |
| 174 *reports = g_uploaded_reports.Pointer()->data(); | 202 *reports = g_uploaded_reports.Pointer()->data(); |
| 175 *report_count = g_uploaded_reports.Pointer()->size(); | 203 *report_count = g_uploaded_reports.Pointer()->size(); |
| 176 } | 204 } |
| 177 | 205 |
| 178 #if !defined(WIN_CONSOLE_APP) | 206 #if !defined(WIN_CONSOLE_APP) |
| 179 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { | 207 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prev, wchar_t*, int) { |
| 180 #else | 208 #else |
| 181 int main() { | 209 int main() { |
| 182 HINSTANCE instance = GetModuleHandle(nullptr); | 210 HINSTANCE instance = GetModuleHandle(nullptr); |
| 183 #endif | 211 #endif |
| 184 // Initialize the CommandLine singleton from the environment. | 212 // Initialize the CommandLine singleton from the environment. |
| 185 base::CommandLine::Init(0, nullptr); | 213 base::CommandLine::Init(0, nullptr); |
| 214 const base::CommandLine* command_line = |
| 215 base::CommandLine::ForCurrentProcess(); |
| 186 | 216 |
| 187 std::string process_type = | 217 const std::string process_type = |
| 188 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 218 command_line->GetSwitchValueASCII(switches::kProcessType); |
| 189 switches::kProcessType); | 219 |
| 220 startup_metric_utils::InitializePreReadOptions( |
| 221 BrowserDistribution::GetDistribution()->GetRegistryPath()); |
| 222 |
| 223 // Confirm that an explicit prefetch profile is used for all process types |
| 224 // except for the browser process. Any new process type will have to assign |
| 225 // itself a prefetch id. See kPrefetchArgument* constants in |
| 226 // content_switches.cc for details. |
| 227 DCHECK(!startup_metric_utils::GetPreReadOptions().use_prefetch_argument || |
| 228 process_type.empty() || |
| 229 HasValidWindowsPrefetchArgument(*command_line)); |
| 190 | 230 |
| 191 if (process_type == switches::kCrashpadHandler) | 231 if (process_type == switches::kCrashpadHandler) |
| 192 return RunAsCrashpadHandler(*base::CommandLine::ForCurrentProcess()); | 232 return RunAsCrashpadHandler(*base::CommandLine::ForCurrentProcess()); |
| 193 | 233 |
| 194 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); | 234 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); |
| 195 crash_reporter::InitializeCrashpad(process_type.empty(), process_type); | 235 crash_reporter::InitializeCrashpad(process_type.empty(), process_type); |
| 196 | 236 |
| 197 SwitchToLFHeap(); | 237 SwitchToLFHeap(); |
| 198 | 238 |
| 199 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); | 239 startup_metric_utils::RecordExeMainEntryPointTime(base::Time::Now()); |
| 200 | 240 |
| 201 // Signal Chrome Elf that Chrome has begun to start. | 241 // Signal Chrome Elf that Chrome has begun to start. |
| 202 SignalChromeElf(); | 242 SignalChromeElf(); |
| 203 | 243 |
| 204 // The exit manager is in charge of calling the dtors of singletons. | 244 // The exit manager is in charge of calling the dtors of singletons. |
| 205 base::AtExitManager exit_manager; | 245 base::AtExitManager exit_manager; |
| 206 | 246 |
| 207 // We don't want to set DPI awareness on pre-Win7 because we don't support | 247 // We don't want to set DPI awareness on pre-Win7 because we don't support |
| 208 // DirectWrite there. GDI fonts are kerned very badly, so better to leave | 248 // DirectWrite there. GDI fonts are kerned very badly, so better to leave |
| 209 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). | 249 // DPI-unaware and at effective 1.0. See also ShouldUseDirectWrite(). |
| 210 if (base::win::GetVersion() >= base::win::VERSION_WIN7) | 250 if (base::win::GetVersion() >= base::win::VERSION_WIN7) |
| 211 EnableHighDPISupport(); | 251 EnableHighDPISupport(); |
| 212 | 252 |
| 213 if (AttemptFastNotify(*base::CommandLine::ForCurrentProcess())) | 253 if (AttemptFastNotify(*command_line)) |
| 214 return 0; | 254 return 0; |
| 215 | 255 |
| 216 // Load and launch the chrome dll. *Everything* happens inside. | 256 // Load and launch the chrome dll. *Everything* happens inside. |
| 217 VLOG(1) << "About to load main DLL."; | 257 VLOG(1) << "About to load main DLL."; |
| 218 MainDllLoader* loader = MakeMainDllLoader(); | 258 MainDllLoader* loader = MakeMainDllLoader(); |
| 219 int rc = loader->Launch(instance); | 259 int rc = loader->Launch(instance); |
| 220 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 260 loader->RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
| 221 delete loader; | 261 delete loader; |
| 222 return rc; | 262 return rc; |
| 223 } | 263 } |
| OLD | NEW |