| 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 <utility> |
| 9 |
| 8 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 11 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
| 12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 13 #include "base/environment.h" | 15 #include "base/environment.h" |
| 14 #include "base/file_version_info.h" | 16 #include "base/file_version_info.h" |
| 15 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 16 #include "base/logging_win.h" | 18 #include "base/logging_win.h" |
| 17 #include "base/macros.h" | 19 #include "base/macros.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 main_thread_(base::ThreadTaskRunnerHandle::Get()) { | 112 main_thread_(base::ThreadTaskRunnerHandle::Get()) { |
| 111 } | 113 } |
| 112 | 114 |
| 113 BrowserMonitor::~BrowserMonitor() { | 115 BrowserMonitor::~BrowserMonitor() { |
| 114 } | 116 } |
| 115 | 117 |
| 116 bool BrowserMonitor::StartWatching( | 118 bool BrowserMonitor::StartWatching( |
| 117 const base::char16* registry_path, | 119 const base::char16* registry_path, |
| 118 base::Process process, | 120 base::Process process, |
| 119 base::win::ScopedHandle on_initialized_event) { | 121 base::win::ScopedHandle on_initialized_event) { |
| 120 if (!exit_code_watcher_.Initialize(process.Pass())) | 122 if (!exit_code_watcher_.Initialize(std::move(process))) |
| 121 return false; | 123 return false; |
| 122 | 124 |
| 123 if (!background_thread_.StartWithOptions( | 125 if (!background_thread_.StartWithOptions( |
| 124 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) { | 126 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) { |
| 125 return false; | 127 return false; |
| 126 } | 128 } |
| 127 | 129 |
| 128 if (!background_thread_.task_runner()->PostTask( | 130 if (!background_thread_.task_runner()->PostTask( |
| 129 FROM_HERE, base::Bind(&BrowserMonitor::Watch, base::Unretained(this), | 131 FROM_HERE, base::Bind(&BrowserMonitor::Watch, base::Unretained(this), |
| 130 base::Passed(on_initialized_event.Pass())))) { | 132 base::Passed(&on_initialized_event)))) { |
| 131 background_thread_.Stop(); | 133 background_thread_.Stop(); |
| 132 return false; | 134 return false; |
| 133 } | 135 } |
| 134 | 136 |
| 135 return true; | 137 return true; |
| 136 } | 138 } |
| 137 | 139 |
| 138 void BrowserMonitor::OnEndSessionMessage(UINT message, LPARAM lparam) { | 140 void BrowserMonitor::OnEndSessionMessage(UINT message, LPARAM lparam) { |
| 139 DCHECK_EQ(main_thread_, base::ThreadTaskRunnerHandle::Get()); | 141 DCHECK_EQ(main_thread_, base::ThreadTaskRunnerHandle::Get()); |
| 140 | 142 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 #endif // BUILDFLAG(ENABLE_KASKO_HANG_REPORTS) | 409 #endif // BUILDFLAG(ENABLE_KASKO_HANG_REPORTS) |
| 408 #endif // BUILDFLAG(ENABLE_KASKO) | 410 #endif // BUILDFLAG(ENABLE_KASKO) |
| 409 | 411 |
| 410 // Run a UI message loop on the main thread. | 412 // Run a UI message loop on the main thread. |
| 411 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); | 413 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); |
| 412 msg_loop.set_thread_name("WatcherMainThread"); | 414 msg_loop.set_thread_name("WatcherMainThread"); |
| 413 | 415 |
| 414 base::RunLoop run_loop; | 416 base::RunLoop run_loop; |
| 415 BrowserMonitor monitor(&run_loop, registry_path); | 417 BrowserMonitor monitor(&run_loop, registry_path); |
| 416 if (!monitor.StartWatching(registry_path, process.Duplicate(), | 418 if (!monitor.StartWatching(registry_path, process.Duplicate(), |
| 417 on_initialized_event.Pass())) { | 419 std::move(on_initialized_event))) { |
| 418 return 1; | 420 return 1; |
| 419 } | 421 } |
| 420 | 422 |
| 421 { | 423 { |
| 422 // Scoped to force |hang_monitor| destruction before Kasko is shut down. | 424 // Scoped to force |hang_monitor| destruction before Kasko is shut down. |
| 423 browser_watcher::WindowHangMonitor hang_monitor( | 425 browser_watcher::WindowHangMonitor hang_monitor( |
| 424 base::TimeDelta::FromSeconds(60), base::TimeDelta::FromSeconds(20), | 426 base::TimeDelta::FromSeconds(60), base::TimeDelta::FromSeconds(20), |
| 425 base::Bind(&OnWindowEvent, registry_path, | 427 base::Bind(&OnWindowEvent, registry_path, |
| 426 base::Passed(process.Duplicate()), on_hung_callback)); | 428 base::Passed(process.Duplicate()), on_hung_callback)); |
| 427 hang_monitor.Initialize(process.Duplicate()); | 429 hang_monitor.Initialize(process.Duplicate()); |
| 428 | 430 |
| 429 run_loop.Run(); | 431 run_loop.Run(); |
| 430 } | 432 } |
| 431 | 433 |
| 432 #if BUILDFLAG(ENABLE_KASKO) | 434 #if BUILDFLAG(ENABLE_KASKO) |
| 433 if (launched_kasko) | 435 if (launched_kasko) |
| 434 kasko::api::ShutdownReporter(); | 436 kasko::api::ShutdownReporter(); |
| 435 #endif // BUILDFLAG(ENABLE_KASKO) | 437 #endif // BUILDFLAG(ENABLE_KASKO) |
| 436 | 438 |
| 437 // Wind logging down. | 439 // Wind logging down. |
| 438 logging::LogEventProvider::Uninitialize(); | 440 logging::LogEventProvider::Uninitialize(); |
| 439 | 441 |
| 440 return 0; | 442 return 0; |
| 441 } | 443 } |
| 442 | 444 |
| 443 static_assert( | 445 static_assert( |
| 444 base::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, | 446 base::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, |
| 445 "WatcherMain() has wrong type"); | 447 "WatcherMain() has wrong type"); |
| OLD | NEW |