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

Side by Side Diff: components/browser_watcher/exit_funnel_win.cc

Issue 792163002: Add ExitFunnel to prepare for instrumenting browser exits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Add some more testing, make a start on pulling the reader to a standalone function. 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "components/browser_watcher/exit_funnel_win.h"
6
7 #include <windows.h>
8
9 #include "base/strings/stringprintf.h"
10 #include "base/time/time.h"
11
12 namespace browser_watcher {
13
14 ExitFunnel::ExitFunnel() {
15 }
16
17 ExitFunnel::~ExitFunnel() {
18 }
19
20 bool ExitFunnel::Init(const base::char16* registry_path,
21 base::ProcessHandle process_handle) {
22 // Concatenate the pid and the creation time of the process to get a
23 // unique key name.
24 base::ProcessId pid = base::GetProcId(process_handle);
25
26 FILETIME creation_time = {};
27 FILETIME dummy = {};
28 if (!::GetProcessTimes(process_handle, &creation_time,
29 &dummy, &dummy, &dummy)) {
30 LOG(ERROR) << "Invalid process handle, can't get process times.";
31 return false;
32 }
33
34 base::string16 key_name = registry_path;
35 base::StringAppendF(&key_name, L"\\%d-%lld", pid,
36 base::Time::FromFileTime(creation_time).ToInternalValue());
37
38 LONG res = key_.Create(HKEY_CURRENT_USER, key_name.c_str(), KEY_SET_VALUE);
39 if (res != ERROR_SUCCESS) {
40 LOG(ERROR) << "Unable to create key " << key_name << " error " << res;
41 return false;
42 }
43
44 return true;
45 }
46
47 bool ExitFunnel::RecordEvent(const base::char16* event_name) {
48 int64 now = base::Time::Now().ToInternalValue();
49
50 LONG res = key_.WriteValue(event_name, &now, sizeof(now), REG_QWORD);
51 if (res != ERROR_SUCCESS) {
52 LOG(ERROR) << "Unable to write value " << event_name << " error " << res;
53 return false;
54 }
55
56 return true;
57 }
58
59 bool ExitFunnel::RecordSingleEvent(const base::char16* registry_path,
60 const base::char16* event_name) {
61 ExitFunnel funnel;
62
63 if (!funnel.Init(registry_path, base::GetCurrentProcessHandle()))
64 return false;
65
66 return funnel.RecordEvent(event_name);
67 }
68
69 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698