summaryrefslogtreecommitdiffstats
path: root/chrome/chrome_watcher
diff options
context:
space:
mode:
authorsiggi <siggi@chromium.org>2014-12-19 07:20:51 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-19 15:22:15 +0000
commitd497a1a3857023c55ae421f11208d38e78795b58 (patch)
tree2e3480aab9ab3e4a5c862a06d6895af4f11dbf00 /chrome/chrome_watcher
parent3c2ea8eaf679e8db1cbcc85fc57ec18e0a43ea30 (diff)
downloadchromium_src-d497a1a3857023c55ae421f11208d38e78795b58.zip
chromium_src-d497a1a3857023c55ae421f11208d38e78795b58.tar.gz
chromium_src-d497a1a3857023c55ae421f11208d38e78795b58.tar.bz2
Add a console control handler chrome_watcher.dll.
This will hopefully allow conclusively answering whether the problem is at ExitWindows-time. R=erikwright@chromium.org, mpearson@chromium.org BUG=412384 Review URL: https://codereview.chromium.org/811603003 Cr-Commit-Position: refs/heads/master@{#309201}
Diffstat (limited to 'chrome/chrome_watcher')
-rw-r--r--chrome/chrome_watcher/chrome_watcher_main.cc55
1 files changed, 54 insertions, 1 deletions
diff --git a/chrome/chrome_watcher/chrome_watcher_main.cc b/chrome/chrome_watcher/chrome_watcher_main.cc
index 6d35d0c..0eb644c 100644
--- a/chrome/chrome_watcher/chrome_watcher_main.cc
+++ b/chrome/chrome_watcher/chrome_watcher_main.cc
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/logging_win.h"
#include "base/process/process.h"
+#include "base/synchronization/waitable_event.h"
#include "base/template_util.h"
#include "components/browser_watcher/exit_code_watcher_win.h"
#include "components/browser_watcher/exit_funnel_win.h"
@@ -21,6 +22,34 @@ const GUID kChromeWatcherTraceProviderName = {
0x7fe69228, 0x633e, 0x4f06,
{ 0x80, 0xc1, 0x52, 0x7f, 0xea, 0x23, 0xe3, 0xa7 } };
+// The data shared from the main function to the console handler.
+struct HandlerData {
+ HandlerData() : handler_done(true /* manual_reset */,
+ false /* initially_signaled */) {
+ }
+
+ base::WaitableEvent handler_done;
+ base::ProcessHandle process;
+ const base::char16* registry_path;
+};
+
+HandlerData *g_handler_data = nullptr;
+
+BOOL CALLBACK ConsoleCtrlHandler(DWORD ctl_type) {
+ if (g_handler_data && ctl_type == CTRL_LOGOFF_EVENT) {
+ // Record the watcher logoff event in the browser's exit funnel.
+ browser_watcher::ExitFunnel funnel;
+ funnel.Init(g_handler_data->registry_path, g_handler_data->process);
+ funnel.RecordEvent(L"WatcherLogoff");
+
+ // Release the main function.
+ g_handler_data->handler_done.Signal();
+ }
+
+ // Fall through to the next handler in turn.
+ return FALSE;
+}
+
} // namespace
// The main entry point to the watcher, declared as extern "C" to avoid name
@@ -29,7 +58,7 @@ extern "C" int WatcherMain(const base::char16* registry_path) {
// The exit manager is in charge of calling the dtors of singletons.
base::AtExitManager exit_manager;
// Initialize the commandline singleton from the environment.
- base::CommandLine::Init(0, NULL);
+ base::CommandLine::Init(0, nullptr);
logging::LogEventProvider::Initialize(kChromeWatcherTraceProviderName);
@@ -44,6 +73,14 @@ extern "C" int WatcherMain(const base::char16* registry_path) {
// Attempt to wait on our parent process, and record its exit status.
if (exit_code_watcher.ParseArguments(
*base::CommandLine::ForCurrentProcess())) {
+ // Set up a console control handler, and provide it the data it needs
+ // to record into the browser's exit funnel.
+ HandlerData data;
+ data.process = exit_code_watcher.process().Handle();
+ data.registry_path = registry_path;
+ g_handler_data = &data;
+ ::SetConsoleCtrlHandler(&ConsoleCtrlHandler, TRUE /* Add */);
+
// Wait on the process.
exit_code_watcher.WaitForExit();
@@ -51,6 +88,22 @@ extern "C" int WatcherMain(const base::char16* registry_path) {
funnel.Init(registry_path, exit_code_watcher.process().Handle());
funnel.RecordEvent(L"BrowserExit");
+ // Chrome/content exit codes are currently in the range of 0-28.
+ // Anything outside this range is strange, so watch harder.
+ int exit_code = exit_code_watcher.exit_code();
+ if (exit_code < 0 || exit_code > 28) {
+ // Wait for a max of 30 seconds to see whether we get notified of logoff.
+ data.handler_done.TimedWait(base::TimeDelta::FromSeconds(30));
+ }
+
+ // Remove the console control handler.
+ // There is a potential race here, where the handler might be executing
+ // already as we fall through here. Hopefully SetConsoleCtrlHandler is
+ // synchronizing against handler execution, for there's no other way to
+ // close the race. Thankfully we'll just get snuffed out, as this is logoff.
+ ::SetConsoleCtrlHandler(&ConsoleCtrlHandler, FALSE /* Add */);
+ g_handler_data = nullptr;
+
ret = 0;
}