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" |
| 18 #include "base/process/process_handle.h" |
17 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
18 #include "base/sequenced_task_runner.h" | 20 #include "base/sequenced_task_runner.h" |
19 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
20 #include "base/template_util.h" | 22 #include "base/template_util.h" |
21 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
22 #include "base/time/time.h" | 24 #include "base/time/time.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 #include "syzygy/kasko/api/reporter.h" |
| 31 |
28 namespace { | 32 namespace { |
29 | 33 |
30 // Use the same log facility as Chrome for convenience. | 34 // Use the same log facility as Chrome for convenience. |
31 // {7FE69228-633E-4f06-80C1-527FEA23E3A7} | 35 // {7FE69228-633E-4f06-80C1-527FEA23E3A7} |
32 const GUID kChromeWatcherTraceProviderName = { | 36 const GUID kChromeWatcherTraceProviderName = { |
33 0x7fe69228, 0x633e, 0x4f06, | 37 0x7fe69228, 0x633e, 0x4f06, |
34 { 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } }; | 38 { 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } }; |
35 | 39 |
36 // Takes care of monitoring a browser. This class watches for a browser's exit | 40 // Takes care of monitoring a browser. This class watches for a browser's exit |
37 // code, as well as listening for WM_ENDSESSION messages. Events are recorded in | 41 // code, as well as listening for WM_ENDSESSION messages. Events are recorded in |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 base::TimeDelta::FromSeconds(30)); | 182 base::TimeDelta::FromSeconds(30)); |
179 } | 183 } |
180 } | 184 } |
181 | 185 |
182 } // namespace | 186 } // namespace |
183 | 187 |
184 // The main entry point to the watcher, declared as extern "C" to avoid name | 188 // The main entry point to the watcher, declared as extern "C" to avoid name |
185 // mangling. | 189 // mangling. |
186 extern "C" int WatcherMain(const base::char16* registry_path, | 190 extern "C" int WatcherMain(const base::char16* registry_path, |
187 HANDLE process_handle, | 191 HANDLE process_handle, |
188 HANDLE on_initialized_event_handle) { | 192 HANDLE on_initialized_event_handle, |
| 193 const base::char16* browser_data_directory) { |
189 base::Process process(process_handle); | 194 base::Process process(process_handle); |
190 base::win::ScopedHandle on_initialized_event(on_initialized_event_handle); | 195 base::win::ScopedHandle on_initialized_event(on_initialized_event_handle); |
191 | 196 |
192 // The exit manager is in charge of calling the dtors of singletons. | 197 // The exit manager is in charge of calling the dtors of singletons. |
193 base::AtExitManager exit_manager; | 198 base::AtExitManager exit_manager; |
194 // Initialize the commandline singleton from the environment. | 199 // Initialize the commandline singleton from the environment. |
195 base::CommandLine::Init(0, nullptr); | 200 base::CommandLine::Init(0, nullptr); |
196 | 201 |
197 logging::LogEventProvider::Initialize(kChromeWatcherTraceProviderName); | 202 logging::LogEventProvider::Initialize(kChromeWatcherTraceProviderName); |
198 | 203 |
199 // Arrange to be shut down as late as possible, as we want to outlive | 204 // Arrange to be shut down as late as possible, as we want to outlive |
200 // chrome.exe in order to report its exit status. | 205 // chrome.exe in order to report its exit status. |
201 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); | 206 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); |
202 | 207 |
| 208 #ifdef SYZYASAN |
| 209 bool launched_kasko = kasko::api::InitializeReporter( |
| 210 GetKaskoEndpoint(process.pid()).c_str(), |
| 211 L"http://clients2.google.com/cr/staging_report", |
| 212 base::FilePath(browser_data_directory) |
| 213 .Append(L"Crash Reports") |
| 214 .value() |
| 215 .c_str(), |
| 216 base::FilePath(browser_data_directory) |
| 217 .Append(L"Crash Reports Fallback") |
| 218 .value() |
| 219 .c_str()); |
| 220 #endif // SYZYASAN |
| 221 |
203 // Run a UI message loop on the main thread. | 222 // Run a UI message loop on the main thread. |
204 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); | 223 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); |
205 msg_loop.set_thread_name("WatcherMainThread"); | 224 msg_loop.set_thread_name("WatcherMainThread"); |
206 | 225 |
207 base::RunLoop run_loop; | 226 base::RunLoop run_loop; |
208 BrowserMonitor monitor(&run_loop, registry_path); | 227 BrowserMonitor monitor(&run_loop, registry_path); |
209 if (!monitor.StartWatching(registry_path, process.Pass(), | 228 if (!monitor.StartWatching(registry_path, process.Pass(), |
210 on_initialized_event.Pass())) { | 229 on_initialized_event.Pass())) { |
211 return 1; | 230 return 1; |
212 } | 231 } |
213 | 232 |
214 run_loop.Run(); | 233 run_loop.Run(); |
215 | 234 |
| 235 #ifdef SYZYASAN |
| 236 if (launched_kasko) |
| 237 kasko::api::ShutdownReporter(); |
| 238 #endif // SYZYASAN |
| 239 |
216 // Wind logging down. | 240 // Wind logging down. |
217 logging::LogEventProvider::Uninitialize(); | 241 logging::LogEventProvider::Uninitialize(); |
218 | 242 |
219 return 0; | 243 return 0; |
220 } | 244 } |
221 | 245 |
222 static_assert( | 246 static_assert( |
223 base::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, | 247 base::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, |
224 "WatcherMain() has wrong type"); | 248 "WatcherMain() has wrong type"); |
OLD | NEW |