Removed IOMetrics
[chromium-blink-merge.git] / chrome / chrome_watcher / chrome_watcher_main.cc
blob84706a0ee5f73c995a39a4073ba5091997241743
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.
5 #include <windows.h>
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"
14 namespace {
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 } };
22 } // namespace
24 // The main entry point to the watcher, declared as extern "C" to avoid name
25 // mangling.
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);
41 int ret = 1;
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();
47 ret = 0;
50 // Wind logging down.
51 logging::LogEventProvider::Uninitialize();
53 return ret;
56 static_assert(base::is_same<decltype(&WatcherMain),
57 browser_watcher::WatcherMainFunction>::value,
58 "WatcherMain() has wrong type");