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> | 8 #include <utility> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
30 #include "base/synchronization/waitable_event.h" | 30 #include "base/synchronization/waitable_event.h" |
31 #include "base/threading/platform_thread.h" | 31 #include "base/threading/platform_thread.h" |
32 #include "base/threading/thread.h" | 32 #include "base/threading/thread.h" |
33 #include "base/threading/thread_task_runner_handle.h" | 33 #include "base/threading/thread_task_runner_handle.h" |
34 #include "base/time/time.h" | 34 #include "base/time/time.h" |
35 #include "base/win/process_startup_helper.h" | 35 #include "base/win/process_startup_helper.h" |
36 #include "base/win/scoped_handle.h" | 36 #include "base/win/scoped_handle.h" |
37 #include "base/win/win_util.h" | 37 #include "base/win/win_util.h" |
38 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" | 38 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" |
| 39 #include "chrome/common/logging_chrome.h" |
39 #include "chrome/install_static/initialize_from_primary_module.h" | 40 #include "chrome/install_static/initialize_from_primary_module.h" |
40 #include "components/browser_watcher/endsession_watcher_window_win.h" | 41 #include "components/browser_watcher/endsession_watcher_window_win.h" |
41 #include "components/browser_watcher/exit_code_watcher_win.h" | 42 #include "components/browser_watcher/exit_code_watcher_win.h" |
42 #include "components/browser_watcher/window_hang_monitor_win.h" | 43 #include "components/browser_watcher/window_hang_monitor_win.h" |
43 | 44 |
44 namespace { | 45 namespace { |
45 | 46 |
46 // Use the same log facility as Chrome for convenience. | 47 // Use the same log facility as Chrome for convenience. |
47 // {7FE69228-633E-4f06-80C1-527FEA23E3A7} | 48 // {7FE69228-633E-4f06-80C1-527FEA23E3A7} |
48 const GUID kChromeWatcherTraceProviderName = { | 49 const GUID kChromeWatcherTraceProviderName = { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 HANDLE on_initialized_event_handle, | 191 HANDLE on_initialized_event_handle, |
191 const base::char16* browser_data_directory) { | 192 const base::char16* browser_data_directory) { |
192 install_static::InitializeFromPrimaryModule(); | 193 install_static::InitializeFromPrimaryModule(); |
193 base::Process process(process_handle); | 194 base::Process process(process_handle); |
194 base::win::ScopedHandle on_initialized_event(on_initialized_event_handle); | 195 base::win::ScopedHandle on_initialized_event(on_initialized_event_handle); |
195 | 196 |
196 // 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. |
197 base::AtExitManager exit_manager; | 198 base::AtExitManager exit_manager; |
198 // Initialize the commandline singleton from the environment. | 199 // Initialize the commandline singleton from the environment. |
199 base::CommandLine::Init(0, nullptr); | 200 base::CommandLine::Init(0, nullptr); |
| 201 const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess(); |
200 | 202 |
| 203 logging::InitChromeLogging(cmd_line, logging::APPEND_TO_OLD_LOG_FILE); |
201 logging::LogEventProvider::Initialize(kChromeWatcherTraceProviderName); | 204 logging::LogEventProvider::Initialize(kChromeWatcherTraceProviderName); |
202 | 205 |
203 // Arrange to be shut down as late as possible, as we want to outlive | 206 // Arrange to be shut down as late as possible, as we want to outlive |
204 // chrome.exe in order to report its exit status. | 207 // chrome.exe in order to report its exit status. |
205 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); | 208 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY); |
206 | 209 |
207 // Make sure the process exits cleanly on unexpected errors. | 210 // Make sure the process exits cleanly on unexpected errors. |
208 base::EnableTerminationOnHeapCorruption(); | 211 base::EnableTerminationOnHeapCorruption(); |
209 base::EnableTerminationOnOutOfMemory(); | 212 base::EnableTerminationOnOutOfMemory(); |
210 base::win::RegisterInvalidParamHandler(); | 213 base::win::RegisterInvalidParamHandler(); |
211 const base::CommandLine& cmd_line = *base::CommandLine::ForCurrentProcess(); | |
212 base::win::SetupCRT(cmd_line); | 214 base::win::SetupCRT(cmd_line); |
213 | 215 |
214 // Run a UI message loop on the main thread. | 216 // Run a UI message loop on the main thread. |
215 base::PlatformThread::SetName("WatcherMainThread"); | 217 base::PlatformThread::SetName("WatcherMainThread"); |
216 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); | 218 base::MessageLoop msg_loop(base::MessageLoop::TYPE_UI); |
217 | 219 |
218 base::RunLoop run_loop; | 220 base::RunLoop run_loop; |
219 BrowserMonitor monitor(registry_path, &run_loop); | 221 BrowserMonitor monitor(registry_path, &run_loop); |
220 if (!monitor.StartWatching(process.Duplicate(), | 222 if (!monitor.StartWatching(process.Duplicate(), |
221 std::move(on_initialized_event))) { | 223 std::move(on_initialized_event))) { |
222 return 1; | 224 return 1; |
223 } | 225 } |
224 run_loop.Run(); | 226 run_loop.Run(); |
225 // TODO(manzagop): hang monitoring using WindowHangMonitor. | 227 // TODO(manzagop): hang monitoring using WindowHangMonitor. |
226 | 228 |
227 // Wind logging down. | 229 // Wind logging down. |
228 logging::LogEventProvider::Uninitialize(); | 230 logging::LogEventProvider::Uninitialize(); |
229 | 231 |
230 return 0; | 232 return 0; |
231 } | 233 } |
232 | 234 |
233 static_assert( | 235 static_assert( |
234 std::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, | 236 std::is_same<decltype(&WatcherMain), ChromeWatcherMainFunction>::value, |
235 "WatcherMain() has wrong type"); | 237 "WatcherMain() has wrong type"); |
OLD | NEW |