Index: components/browser_watcher/exit_funnel_win.cc |
diff --git a/components/browser_watcher/exit_funnel_win.cc b/components/browser_watcher/exit_funnel_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6457b89fcb85d29141bf43d929ab3ec83d985c87 |
--- /dev/null |
+++ b/components/browser_watcher/exit_funnel_win.cc |
@@ -0,0 +1,71 @@ |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/browser_watcher/exit_funnel_win.h" |
+ |
+#include <windows.h> |
+ |
+#include "base/strings/string16.h" |
erikwright (departed)
2014/12/11 15:00:46
dup from header
Sigurður Ásgeirsson
2014/12/12 16:21:40
Done.
|
+#include "base/strings/stringprintf.h" |
+#include "base/time/time.h" |
+#include "base/win/registry.h" |
erikwright (departed)
2014/12/11 15:00:46
dup from header
Sigurður Ásgeirsson
2014/12/12 16:21:40
Done.
|
+ |
+namespace browser_watcher { |
+ |
+ExitFunnel::ExitFunnel() { |
+} |
+ |
+ExitFunnel::~ExitFunnel() { |
+} |
+ |
+bool ExitFunnel::Init(const base::char16* registry_path, |
+ base::ProcessHandle process_handle) { |
+ // Concatenate the pid and the creation time of the process to get a |
+ // unique key name. |
+ base::ProcessId pid = base::GetProcId(process_handle); |
+ |
+ FILETIME creation_time = {}; |
+ FILETIME dummy = {}; |
+ if (!::GetProcessTimes(process_handle, &creation_time, |
+ &dummy, &dummy, &dummy)) { |
+ LOG(ERROR) << "Invalid process handle, can't get process times."; |
+ return false; |
+ } |
+ |
+ base::string16 key_name = registry_path; |
+ base::StringAppendF(&key_name, L"\\%d-%lld", pid, |
erikwright (departed)
2014/12/11 15:00:46
Personally I find this harder to read than:
base:
Sigurður Ásgeirsson
2014/12/12 16:21:40
Acknowledged.
|
+ base::Time::FromFileTime(creation_time).ToInternalValue()); |
+ |
+ LONG res = key_.Create(HKEY_CURRENT_USER, key_name.c_str(), KEY_SET_VALUE); |
+ if (res != ERROR_SUCCESS) { |
+ LOG(ERROR) << "Unable to create key " << key_name << " error " << res; |
+ return false; |
+ } |
+ |
+ return true; |
+} |
+ |
+bool ExitFunnel::RecordEvent(const base::char16* event_name) { |
+ int64 now = base::Time::Now().ToInternalValue(); |
+ |
+ LONG res = key_.WriteValue(event_name, &now, sizeof(now), REG_QWORD); |
+ if (res != ERROR_SUCCESS) { |
+ LOG(ERROR) << "Unable to write value " << event_name << " error " << res; |
+ return false; |
+ } |
+ |
+ return true; |
+} |
+ |
+bool ExitFunnel::RecordSingleEvent(const base::char16* registry_path, |
+ const base::char16* event_name) { |
+ ExitFunnel funnel; |
+ |
+ if (!funnel.Init(registry_path, base::GetCurrentProcessHandle())) |
+ return false; |
+ |
+ return funnel.RecordEvent(event_name); |
+} |
+ |
+} // namespace browser_watcher |