| 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 <windows.h> // NOLINT | 5 #include <windows.h> // NOLINT |
| 6 #include <shlwapi.h> // NOLINT | 6 #include <shlwapi.h> // NOLINT |
| 7 | 7 |
| 8 #include "chrome/app/main_dll_loader_win.h" | 8 #include "chrome/app/main_dll_loader_win.h" |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| 11 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/environment.h" | 14 #include "base/environment.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/threading/platform_thread.h" | 23 #include "base/threading/platform_thread.h" |
| 24 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
| 25 #include "base/win/metro.h" | |
| 26 #include "base/win/scoped_handle.h" | 25 #include "base/win/scoped_handle.h" |
| 27 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
| 28 #include "chrome/app/chrome_crash_reporter_client.h" | 27 #include "chrome/app/chrome_crash_reporter_client.h" |
| 29 #include "chrome/app/chrome_watcher_client_win.h" | 28 #include "chrome/app/chrome_watcher_client_win.h" |
| 30 #include "chrome/app/chrome_watcher_command_line_win.h" | 29 #include "chrome/app/chrome_watcher_command_line_win.h" |
| 31 #include "chrome/app/file_pre_reader_win.h" | 30 #include "chrome/app/file_pre_reader_win.h" |
| 32 #include "chrome/app/kasko_client.h" | 31 #include "chrome/app/kasko_client.h" |
| 33 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" | 32 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" |
| 34 #include "chrome/common/chrome_constants.h" | 33 #include "chrome/common/chrome_constants.h" |
| 35 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
| 36 #include "chrome/common/chrome_result_codes.h" | 35 #include "chrome/common/chrome_result_codes.h" |
| 37 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/env_vars.h" | 37 #include "chrome/common/env_vars.h" |
| 39 #include "chrome/installer/util/browser_distribution.h" | 38 #include "chrome/installer/util/browser_distribution.h" |
| 40 #include "chrome/installer/util/google_update_constants.h" | 39 #include "chrome/installer/util/google_update_constants.h" |
| 41 #include "chrome/installer/util/google_update_settings.h" | 40 #include "chrome/installer/util/google_update_settings.h" |
| 42 #include "chrome/installer/util/install_util.h" | 41 #include "chrome/installer/util/install_util.h" |
| 43 #include "chrome/installer/util/module_util_win.h" | 42 #include "chrome/installer/util/module_util_win.h" |
| 44 #include "chrome/installer/util/util_constants.h" | 43 #include "chrome/installer/util/util_constants.h" |
| 44 #include "components/crash/content/app/breakpad_win.h" |
| 45 #include "components/crash/content/app/crash_reporter_client.h" | 45 #include "components/crash/content/app/crash_reporter_client.h" |
| 46 #include "components/crash/content/app/crashpad.h" | |
| 47 #include "components/startup_metric_utils/browser/pre_read_field_trial_utils_win
.h" | 46 #include "components/startup_metric_utils/browser/pre_read_field_trial_utils_win
.h" |
| 48 #include "content/public/app/sandbox_helper_win.h" | 47 #include "content/public/app/sandbox_helper_win.h" |
| 49 #include "content/public/common/content_switches.h" | 48 #include "content/public/common/content_switches.h" |
| 50 #include "sandbox/win/src/sandbox.h" | 49 #include "sandbox/win/src/sandbox.h" |
| 51 | 50 |
| 52 namespace { | 51 namespace { |
| 53 // The entry point signature of chrome.dll. | 52 // The entry point signature of chrome.dll. |
| 54 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); | 53 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*); |
| 55 | 54 |
| 56 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); | 55 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); |
| 57 | 56 |
| 57 base::LazyInstance<ChromeCrashReporterClient>::Leaky g_chrome_crash_client = |
| 58 LAZY_INSTANCE_INITIALIZER; |
| 59 |
| 58 // Loads |module| after setting the CWD to |module|'s directory. Returns a | 60 // Loads |module| after setting the CWD to |module|'s directory. Returns a |
| 59 // reference to the loaded module on success, or null on error. | 61 // reference to the loaded module on success, or null on error. |
| 60 HMODULE LoadModuleWithDirectory(const base::FilePath& module, bool pre_read) { | 62 HMODULE LoadModuleWithDirectory(const base::FilePath& module, bool pre_read) { |
| 61 ::SetCurrentDirectoryW(module.DirName().value().c_str()); | 63 ::SetCurrentDirectoryW(module.DirName().value().c_str()); |
| 62 | 64 |
| 63 // Get pre-read options from the PreRead field trial. | 65 // Get pre-read options from the PreRead field trial. |
| 64 bool trial_should_pre_read = true; | 66 bool trial_should_pre_read = true; |
| 65 bool trial_should_pre_read_high_priority = false; | 67 bool trial_should_pre_read_high_priority = false; |
| 66 startup_metric_utils::GetPreReadOptions( | 68 startup_metric_utils::GetPreReadOptions( |
| 67 BrowserDistribution::GetDistribution()->GetRegistryPath(), | 69 BrowserDistribution::GetDistribution()->GetRegistryPath(), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 91 void RecordDidRun(const base::FilePath& dll_path) { | 93 void RecordDidRun(const base::FilePath& dll_path) { |
| 92 bool system_level = !InstallUtil::IsPerUserInstall(dll_path); | 94 bool system_level = !InstallUtil::IsPerUserInstall(dll_path); |
| 93 GoogleUpdateSettings::UpdateDidRunState(true, system_level); | 95 GoogleUpdateSettings::UpdateDidRunState(true, system_level); |
| 94 } | 96 } |
| 95 | 97 |
| 96 void ClearDidRun(const base::FilePath& dll_path) { | 98 void ClearDidRun(const base::FilePath& dll_path) { |
| 97 bool system_level = !InstallUtil::IsPerUserInstall(dll_path); | 99 bool system_level = !InstallUtil::IsPerUserInstall(dll_path); |
| 98 GoogleUpdateSettings::UpdateDidRunState(false, system_level); | 100 GoogleUpdateSettings::UpdateDidRunState(false, system_level); |
| 99 } | 101 } |
| 100 | 102 |
| 103 bool InMetroMode() { |
| 104 return (wcsstr( |
| 105 ::GetCommandLineW(), L" -ServerName:DefaultBrowserServer") != nullptr); |
| 106 } |
| 107 |
| 101 typedef int (*InitMetro)(); | 108 typedef int (*InitMetro)(); |
| 102 | 109 |
| 103 } // namespace | 110 } // namespace |
| 104 | 111 |
| 105 //============================================================================= | 112 //============================================================================= |
| 106 | 113 |
| 107 MainDllLoader::MainDllLoader() | 114 MainDllLoader::MainDllLoader() |
| 108 : dll_(nullptr), metro_mode_(base::win::IsMetroProcess()) { | 115 : dll_(nullptr), metro_mode_(InMetroMode()) { |
| 109 } | 116 } |
| 110 | 117 |
| 111 MainDllLoader::~MainDllLoader() { | 118 MainDllLoader::~MainDllLoader() { |
| 112 } | 119 } |
| 113 | 120 |
| 114 // Loading chrome is an interesting affair. First we try loading from the | 121 // Loading chrome is an interesting affair. First we try loading from the |
| 115 // current directory to support run-what-you-compile and other development | 122 // current directory to support run-what-you-compile and other development |
| 116 // scenarios. | 123 // scenarios. |
| 117 // If that fails then we look at the version resource in the current | 124 // If that fails then we look at the version resource in the current |
| 118 // module. This is the expected path for chrome.exe browser instances in an | 125 // module. This is the expected path for chrome.exe browser instances in an |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 parent_process.Take(), main_thread_id, | 217 parent_process.Take(), main_thread_id, |
| 211 on_initialized_event.Take(), | 218 on_initialized_event.Take(), |
| 212 watcher_data_directory.value().c_str(), | 219 watcher_data_directory.value().c_str(), |
| 213 message_window_name.c_str(), channel_name.c_str()); | 220 message_window_name.c_str(), channel_name.c_str()); |
| 214 } | 221 } |
| 215 | 222 |
| 216 // Initialize the sandbox services. | 223 // Initialize the sandbox services. |
| 217 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | 224 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
| 218 content::InitializeSandboxInfo(&sandbox_info); | 225 content::InitializeSandboxInfo(&sandbox_info); |
| 219 | 226 |
| 227 crash_reporter::SetCrashReporterClient(g_chrome_crash_client.Pointer()); |
| 228 bool exit_now = true; |
| 229 if (process_type_.empty()) { |
| 230 if (breakpad::ShowRestartDialogIfCrashed(&exit_now)) { |
| 231 // We restarted because of a previous crash. Ask user if we should |
| 232 // Relaunch. Only for the browser process. See crbug.com/132119. |
| 233 if (exit_now) |
| 234 return content::RESULT_CODE_NORMAL_EXIT; |
| 235 } |
| 236 } |
| 237 breakpad::InitCrashReporter(process_type_); |
| 238 |
| 220 dll_ = Load(&version, &file); | 239 dll_ = Load(&version, &file); |
| 221 if (!dll_) | 240 if (!dll_) |
| 222 return chrome::RESULT_CODE_MISSING_DATA; | 241 return chrome::RESULT_CODE_MISSING_DATA; |
| 223 | 242 |
| 224 scoped_ptr<base::Environment> env(base::Environment::Create()); | 243 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 225 env->SetVar(chrome::kChromeVersionEnvVar, base::WideToUTF8(version)); | 244 env->SetVar(chrome::kChromeVersionEnvVar, base::WideToUTF8(version)); |
| 226 | 245 |
| 227 OnBeforeLaunch(process_type_, file); | 246 OnBeforeLaunch(process_type_, file); |
| 228 DLL_MAIN chrome_main = | 247 DLL_MAIN chrome_main = |
| 229 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain")); | 248 reinterpret_cast<DLL_MAIN>(::GetProcAddress(dll_, "ChromeMain")); |
| 230 int rc = chrome_main(instance, &sandbox_info); | 249 int rc = chrome_main(instance, &sandbox_info); |
| 231 rc = OnBeforeExit(rc, file); | 250 rc = OnBeforeExit(rc, file); |
| 251 // Sandboxed processes close some system DLL handles after lockdown so ignore |
| 252 // EXCEPTION_INVALID_HANDLE generated on Windows 10 during shutdown of these |
| 253 // processes. |
| 254 // TODO(wfh): Check whether MS have fixed this in Win10 RTM. crbug.com/456193 |
| 255 if (base::win::GetVersion() >= base::win::VERSION_WIN10) |
| 256 breakpad::ConsumeInvalidHandleExceptions(); |
| 232 return rc; | 257 return rc; |
| 233 } | 258 } |
| 234 | 259 |
| 235 void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { | 260 void MainDllLoader::RelaunchChromeBrowserWithNewCommandLineIfNeeded() { |
| 236 if (!dll_) | 261 if (!dll_) |
| 237 return; | 262 return; |
| 238 | 263 |
| 239 RelaunchChromeBrowserWithNewCommandLineIfNeededFunc relaunch_function = | 264 RelaunchChromeBrowserWithNewCommandLineIfNeededFunc relaunch_function = |
| 240 reinterpret_cast<RelaunchChromeBrowserWithNewCommandLineIfNeededFunc>( | 265 reinterpret_cast<RelaunchChromeBrowserWithNewCommandLineIfNeededFunc>( |
| 241 ::GetProcAddress(dll_, | 266 ::GetProcAddress(dll_, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 263 scoped_ptr<KaskoClient> kasko_client_; | 288 scoped_ptr<KaskoClient> kasko_client_; |
| 264 #endif // KASKO | 289 #endif // KASKO |
| 265 }; | 290 }; |
| 266 | 291 |
| 267 void ChromeDllLoader::OnBeforeLaunch(const std::string& process_type, | 292 void ChromeDllLoader::OnBeforeLaunch(const std::string& process_type, |
| 268 const base::FilePath& dll_path) { | 293 const base::FilePath& dll_path) { |
| 269 if (process_type.empty()) { | 294 if (process_type.empty()) { |
| 270 RecordDidRun(dll_path); | 295 RecordDidRun(dll_path); |
| 271 | 296 |
| 272 // Launch the watcher process if stats collection consent has been granted. | 297 // Launch the watcher process if stats collection consent has been granted. |
| 273 #if defined(GOOGLE_CHROME_BUILD) | 298 if (g_chrome_crash_client.Get().GetCollectStatsConsent()) { |
| 274 const bool stats_collection_consent = | |
| 275 GoogleUpdateSettings::GetCollectStatsConsent(); | |
| 276 #else | |
| 277 const bool stats_collection_consent = false; | |
| 278 #endif | |
| 279 if (stats_collection_consent) { | |
| 280 base::FilePath exe_path; | 299 base::FilePath exe_path; |
| 281 if (PathService::Get(base::FILE_EXE, &exe_path)) { | 300 if (PathService::Get(base::FILE_EXE, &exe_path)) { |
| 282 chrome_watcher_client_.reset(new ChromeWatcherClient( | 301 chrome_watcher_client_.reset(new ChromeWatcherClient( |
| 283 base::Bind(&GenerateChromeWatcherCommandLine, exe_path))); | 302 base::Bind(&GenerateChromeWatcherCommandLine, exe_path))); |
| 284 if (chrome_watcher_client_->LaunchWatcher()) { | 303 if (chrome_watcher_client_->LaunchWatcher()) { |
| 285 #if defined(KASKO) | 304 #if defined(KASKO) |
| 286 kasko::api::MinidumpType minidump_type = kasko::api::SMALL_DUMP_TYPE; | 305 kasko::api::MinidumpType minidump_type = kasko::api::SMALL_DUMP_TYPE; |
| 287 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 306 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 288 switches::kFullMemoryCrashReport)) { | 307 switches::kFullMemoryCrashReport)) { |
| 289 minidump_type = kasko::api::FULL_DUMP_TYPE; | 308 minidump_type = kasko::api::FULL_DUMP_TYPE; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } | 360 } |
| 342 }; | 361 }; |
| 343 | 362 |
| 344 MainDllLoader* MakeMainDllLoader() { | 363 MainDllLoader* MakeMainDllLoader() { |
| 345 #if defined(GOOGLE_CHROME_BUILD) | 364 #if defined(GOOGLE_CHROME_BUILD) |
| 346 return new ChromeDllLoader(); | 365 return new ChromeDllLoader(); |
| 347 #else | 366 #else |
| 348 return new ChromiumDllLoader(); | 367 return new ChromiumDllLoader(); |
| 349 #endif | 368 #endif |
| 350 } | 369 } |
| OLD | NEW |