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