| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 <sddl.h> | 6 #include <sddl.h> |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 347 |
| 348 } // namespace | 348 } // namespace |
| 349 | 349 |
| 350 // The main entry point to the watcher, declared as extern "C" to avoid name | 350 // The main entry point to the watcher, declared as extern "C" to avoid name |
| 351 // mangling. | 351 // mangling. |
| 352 extern "C" int WatcherMain(const base::char16* registry_path, | 352 extern "C" int WatcherMain(const base::char16* registry_path, |
| 353 HANDLE process_handle, | 353 HANDLE process_handle, |
| 354 DWORD main_thread_id, | 354 DWORD main_thread_id, |
| 355 HANDLE on_initialized_event_handle, | 355 HANDLE on_initialized_event_handle, |
| 356 const base::char16* browser_data_directory, | 356 const base::char16* browser_data_directory, |
| 357 const base::char16* message_window_name, | |
| 358 const base::char16* channel_name) { | 357 const base::char16* channel_name) { |
| 359 base::Process process(process_handle); | 358 base::Process process(process_handle); |
| 360 base::win::ScopedHandle on_initialized_event(on_initialized_event_handle); | 359 base::win::ScopedHandle on_initialized_event(on_initialized_event_handle); |
| 361 | 360 |
| 362 // The exit manager is in charge of calling the dtors of singletons. | 361 // The exit manager is in charge of calling the dtors of singletons. |
| 363 base::AtExitManager exit_manager; | 362 base::AtExitManager exit_manager; |
| 364 // Initialize the commandline singleton from the environment. | 363 // Initialize the commandline singleton from the environment. |
| 365 base::CommandLine::Init(0, nullptr); | 364 base::CommandLine::Init(0, nullptr); |
| 366 | 365 |
| 367 logging::LogEventProvider::Initialize(kChromeWatcherTraceProviderName); | 366 logging::LogEventProvider::Initialize(kChromeWatcherTraceProviderName); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 384 crash_reports_base_dir | 383 crash_reports_base_dir |
| 385 .Append(L"Crash Reports") | 384 .Append(L"Crash Reports") |
| 386 .value() | 385 .value() |
| 387 .c_str(), | 386 .c_str(), |
| 388 crash_reports_base_dir | 387 crash_reports_base_dir |
| 389 .Append(kPermanentlyFailedReportsSubdir) | 388 .Append(kPermanentlyFailedReportsSubdir) |
| 390 .value() | 389 .value() |
| 391 .c_str(), | 390 .c_str(), |
| 392 &OnCrashReportUpload, nullptr); | 391 &OnCrashReportUpload, nullptr); |
| 393 #if BUILDFLAG(ENABLE_KASKO_HANG_REPORTS) | 392 #if BUILDFLAG(ENABLE_KASKO_HANG_REPORTS) |
| 393 // Only activate hang reports for the canary channel. For testing purposes, |
| 394 // Chrome instances with no channels will also report hangs. |
| 394 if (launched_kasko && | 395 if (launched_kasko && |
| 395 base::StringPiece16(channel_name) == installer::kChromeChannelCanary) { | 396 (base::StringPiece16(channel_name) == L"" || |
| 397 base::StringPiece16(channel_name) == installer::kChromeChannelCanary)) { |
| 396 on_hung_callback = | 398 on_hung_callback = |
| 397 base::Bind(&DumpHungBrowserProcess, main_thread_id, channel_name); | 399 base::Bind(&DumpHungBrowserProcess, main_thread_id, channel_name); |
| 398 } | 400 } |
| 399 #endif // BUILDFLAG(ENABLE_KASKO_HANG_REPORTS) | 401 #endif // BUILDFLAG(ENABLE_KASKO_HANG_REPORTS) |
| 400 #endif // BUILDFLAG(ENABLE_KASKO) | 402 #endif // BUILDFLAG(ENABLE_KASKO) |
| 401 | 403 |
| 402 // Run a UI message loop on the main thread. | 404 // Run a UI message loop on the main thread. |
| 403 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); | 405 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); |
| 404 msg_loop.set_thread_name("WatcherMainThread"); | 406 msg_loop.set_thread_name("WatcherMainThread"); |
| 405 | 407 |
| 406 base::RunLoop run_loop; | 408 base::RunLoop run_loop; |
| 407 BrowserMonitor monitor(&run_loop, registry_path); | 409 BrowserMonitor monitor(&run_loop, registry_path); |
| 408 if (!monitor.StartWatching(registry_path, process.Duplicate(), | 410 if (!monitor.StartWatching(registry_path, process.Duplicate(), |
| 409 on_initialized_event.Pass())) { | 411 on_initialized_event.Pass())) { |
| 410 return 1; | 412 return 1; |
| 411 } | 413 } |
| 412 | 414 |
| 413 { | 415 { |
| 414 // Scoped to force |hang_monitor| destruction before Kasko is shut down. | 416 // Scoped to force |hang_monitor| destruction before Kasko is shut down. |
| 415 browser_watcher::WindowHangMonitor hang_monitor( | 417 browser_watcher::WindowHangMonitor hang_monitor( |
| 416 base::TimeDelta::FromSeconds(60), base::TimeDelta::FromSeconds(20), | 418 base::TimeDelta::FromSeconds(60), base::TimeDelta::FromSeconds(20), |
| 417 base::Bind(&OnWindowEvent, registry_path, | 419 base::Bind(&OnWindowEvent, registry_path, |
| 418 base::Passed(process.Duplicate()), on_hung_callback)); | 420 base::Passed(process.Duplicate()), on_hung_callback)); |
| 419 hang_monitor.Initialize(process.Duplicate(), message_window_name); | 421 hang_monitor.Initialize(process.Duplicate()); |
| 420 | 422 |
| 421 run_loop.Run(); | 423 run_loop.Run(); |
| 422 } | 424 } |
| 423 | 425 |
| 424 #if BUILDFLAG(ENABLE_KASKO) | 426 #if BUILDFLAG(ENABLE_KASKO) |
| 425 if (launched_kasko) | 427 if (launched_kasko) |
| 426 kasko::api::ShutdownReporter(); | 428 kasko::api::ShutdownReporter(); |
| 427 #endif // BUILDFLAG(ENABLE_KASKO) | 429 #endif // BUILDFLAG(ENABLE_KASKO) |
| 428 | 430 |
| 429 // Wind logging down. | 431 // Wind logging down. |
| 430 logging::LogEventProvider::Uninitialize(); | 432 logging::LogEventProvider::Uninitialize(); |
| 431 | 433 |
| 432 return 0; | 434 return 0; |
| 433 } | 435 } |
| 434 | 436 |
| 435 static_assert( | 437 static_assert( |
| 436 base::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, | 438 base::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, |
| 437 "WatcherMain() has wrong type"); | 439 "WatcherMain() has wrong type"); |
| OLD | NEW |