| 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 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" |
| 11 #include "base/logging_win.h" | 12 #include "base/logging_win.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 15 #include "base/message_loop/message_loop_proxy.h" | 16 #include "base/message_loop/message_loop_proxy.h" |
| 16 #include "base/process/process.h" | 17 #include "base/process/process.h" |
| 17 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 18 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
| 19 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/template_util.h" | 21 #include "base/template_util.h" |
| 21 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 24 #include "base/win/scoped_handle.h" |
| 23 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" | 25 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" |
| 24 #include "components/browser_watcher/endsession_watcher_window_win.h" | 26 #include "components/browser_watcher/endsession_watcher_window_win.h" |
| 25 #include "components/browser_watcher/exit_code_watcher_win.h" | 27 #include "components/browser_watcher/exit_code_watcher_win.h" |
| 26 #include "components/browser_watcher/exit_funnel_win.h" | 28 #include "components/browser_watcher/exit_funnel_win.h" |
| 27 | 29 |
| 30 #ifdef SYZYASAN |
| 31 #include "syzygy/kasko/api/reporter.h" |
| 32 #endif |
| 33 |
| 28 namespace { | 34 namespace { |
| 29 | 35 |
| 30 // Use the same log facility as Chrome for convenience. | 36 // Use the same log facility as Chrome for convenience. |
| 31 // {7FE69228-633E-4f06-80C1-527FEA23E3A7} | 37 // {7FE69228-633E-4f06-80C1-527FEA23E3A7} |
| 32 const GUID kChromeWatcherTraceProviderName = { | 38 const GUID kChromeWatcherTraceProviderName = { |
| 33 0x7fe69228, 0x633e, 0x4f06, | 39 0x7fe69228, 0x633e, 0x4f06, |
| 34 { 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } }; | 40 { 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } }; |
| 35 | 41 |
| 36 // The amount of time we wait around for a WM_ENDSESSION or a process exit. | 42 // The amount of time we wait around for a WM_ENDSESSION or a process exit. |
| 37 const int kDelayTimeSeconds = 30; | 43 const int kDelayTimeSeconds = 30; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 base::TimeDelta::FromSeconds(kDelayTimeSeconds)); | 196 base::TimeDelta::FromSeconds(kDelayTimeSeconds)); |
| 191 } | 197 } |
| 192 } | 198 } |
| 193 | 199 |
| 194 } // namespace | 200 } // namespace |
| 195 | 201 |
| 196 // The main entry point to the watcher, declared as extern "C" to avoid name | 202 // The main entry point to the watcher, declared as extern "C" to avoid name |
| 197 // mangling. | 203 // mangling. |
| 198 extern "C" int WatcherMain(const base::char16* registry_path, | 204 extern "C" int WatcherMain(const base::char16* registry_path, |
| 199 HANDLE process_handle, | 205 HANDLE process_handle, |
| 200 HANDLE on_initialized_event_handle) { | 206 HANDLE on_initialized_event_handle, |
| 207 const base::char16* browser_data_directory) { |
| 201 base::Process process(process_handle); | 208 base::Process process(process_handle); |
| 202 base::win::ScopedHandle on_initialized_event(on_initialized_event_handle); | 209 base::win::ScopedHandle on_initialized_event(on_initialized_event_handle); |
| 203 | 210 |
| 204 // The exit manager is in charge of calling the dtors of singletons. | 211 // The exit manager is in charge of calling the dtors of singletons. |
| 205 base::AtExitManager exit_manager; | 212 base::AtExitManager exit_manager; |
| 206 // Initialize the commandline singleton from the environment. | 213 // Initialize the commandline singleton from the environment. |
| 207 base::CommandLine::Init(0, nullptr); | 214 base::CommandLine::Init(0, nullptr); |
| 208 | 215 |
| 209 logging::LogEventProvider::Initialize(kChromeWatcherTraceProviderName); | 216 logging::LogEventProvider::Initialize(kChromeWatcherTraceProviderName); |
| 210 | 217 |
| 211 // Arrange to be shut down as late as possible, as we want to outlive | 218 // Arrange to be shut down as late as possible, as we want to outlive |
| 212 // chrome.exe in order to report its exit status. | 219 // chrome.exe in order to report its exit status. |
| 213 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); | 220 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); |
| 214 | 221 |
| 222 #ifdef SYZYASAN |
| 223 bool launched_kasko = kasko::api::InitializeReporter( |
| 224 GetKaskoEndpoint(process.Pid()).c_str(), |
| 225 L"https://clients2.google.com/cr/staging_report", |
| 226 base::FilePath(browser_data_directory) |
| 227 .Append(L"Crash Reports") |
| 228 .value() |
| 229 .c_str(), |
| 230 base::FilePath(browser_data_directory) |
| 231 .Append(kPermanentlyFailedReportsSubdir) |
| 232 .value() |
| 233 .c_str()); |
| 234 #endif // SYZYASAN |
| 235 |
| 215 // Run a UI message loop on the main thread. | 236 // Run a UI message loop on the main thread. |
| 216 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); | 237 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); |
| 217 msg_loop.set_thread_name("WatcherMainThread"); | 238 msg_loop.set_thread_name("WatcherMainThread"); |
| 218 | 239 |
| 219 base::RunLoop run_loop; | 240 base::RunLoop run_loop; |
| 220 BrowserMonitor monitor(&run_loop, registry_path); | 241 BrowserMonitor monitor(&run_loop, registry_path); |
| 221 if (!monitor.StartWatching(registry_path, process.Pass(), | 242 if (!monitor.StartWatching(registry_path, process.Pass(), |
| 222 on_initialized_event.Pass())) { | 243 on_initialized_event.Pass())) { |
| 223 return 1; | 244 return 1; |
| 224 } | 245 } |
| 225 | 246 |
| 226 run_loop.Run(); | 247 run_loop.Run(); |
| 227 | 248 |
| 249 #ifdef SYZYASAN |
| 250 if (launched_kasko) |
| 251 kasko::api::ShutdownReporter(); |
| 252 #endif // SYZYASAN |
| 253 |
| 228 // Wind logging down. | 254 // Wind logging down. |
| 229 logging::LogEventProvider::Uninitialize(); | 255 logging::LogEventProvider::Uninitialize(); |
| 230 | 256 |
| 231 return 0; | 257 return 0; |
| 232 } | 258 } |
| 233 | 259 |
| 234 static_assert( | 260 static_assert( |
| 235 base::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, | 261 base::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, |
| 236 "WatcherMain() has wrong type"); | 262 "WatcherMain() has wrong type"); |
| OLD | NEW |