Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3983)

Unified Diff: chrome/chrome_watcher/chrome_watcher_main.cc

Issue 811603003: Add a console control handler chrome_watcher.dll. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@base_process
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/chrome_watcher/chrome_watcher_main.cc
diff --git a/chrome/chrome_watcher/chrome_watcher_main.cc b/chrome/chrome_watcher/chrome_watcher_main.cc
index 6d35d0c9f4463f54b90aa678119dcb81eb72c299..60ceaca20e4d20a6790fcf5e93faef3cee302205 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,8 +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, false) {}
+
+ base::WaitableEvent handler_done;
+ base::ProcessHandle process;
+ const base::char16* registry_path;
+};
+HandlerData *handler_data = NULL;
+
+static BOOL CALLBACK ConsoleCtrlHandler(DWORD ctl_type) {
+ if (handler_data && ctl_type == CTRL_LOGOFF_EVENT) {
+ // Record the watcher logoff event in the browser's exit funnel.
+ browser_watcher::ExitFunnel funnel;
+ funnel.Init(handler_data->registry_path, handler_data->process);
+ funnel.RecordEvent(L"WatcherLogoff");
+
+ // Release the main function.
+ 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
// mangling.
extern "C" int WatcherMain(const base::char16* registry_path) {
@@ -44,6 +71,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;
+ handler_data = &data;
+ ::SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
+
// Wait on the process.
exit_code_watcher.WaitForExit();
@@ -51,6 +86,17 @@ extern "C" int WatcherMain(const base::char16* registry_path) {
funnel.Init(registry_path, exit_code_watcher.process().Handle());
funnel.RecordEvent(L"BrowserExit");
+ // Wait for a max of 30 seconds to see whether we get notified of logoff.
+ data.handler_done.TimedWait(base::TimeDelta::FromSeconds(30));
erikwright (departed) 2014/12/18 21:45:07 This wait is problematic. During an uninstall it c
Sigurður Ásgeirsson 2014/12/18 21:50:33 This is a good point. While this isn't intended as
+
+ // 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);
+ handler_data = NULL;
+
ret = 0;
}
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698