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