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
3 // found in the LICENSE file.
7 #include "base/at_exit.h"
8 #include "base/command_line.h"
9 #include "base/logging_win.h"
10 #include "base/template_util.h"
11 #include "components/browser_watcher/exit_code_watcher_win.h"
12 #include "components/browser_watcher/watcher_main_api_win.h"
16 // Use the same log facility as Chrome for convenience.
17 // {7FE69228-633E-4f06-80C1-527FEA23E3A7}
18 const GUID kChromeWatcherTraceProviderName
= {
19 0x7fe69228, 0x633e, 0x4f06,
20 { 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } };
24 // The main entry point to the watcher, declared as extern "C" to avoid name
26 extern "C" int WatcherMain(const base::char16
* registry_path
) {
27 // The exit manager is in charge of calling the dtors of singletons.
28 base::AtExitManager exit_manager
;
29 // Initialize the commandline singleton from the environment.
30 base::CommandLine::Init(0, NULL
);
32 logging::LogEventProvider::Initialize(kChromeWatcherTraceProviderName
);
34 // Arrange to be shut down as late as possible, as we want to outlive
35 // chrome.exe in order to report its exit status.
36 // TODO(siggi): Does this (windowless) process need to register a console
37 // handler too, in order to get notice of logoff events?
38 ::SetProcessShutdownParameters(0x100, SHUTDOWN_NORETRY
);
40 browser_watcher::ExitCodeWatcher
exit_code_watcher(registry_path
);
42 // Attempt to wait on our parent process, and record its exit status.
43 if (exit_code_watcher
.ParseArguments(
44 *base::CommandLine::ForCurrentProcess())) {
45 // Wait on the process.
46 exit_code_watcher
.WaitForExit();
51 logging::LogEventProvider::Uninitialize();
56 static_assert(base::is_same
<decltype(&WatcherMain
),
57 browser_watcher::WatcherMainFunction
>::value
,
58 "WatcherMain() has wrong type");