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

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: Remove stray files. 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/string16.h"
erikwright (departed) 2014/12/11 15:00:46 dup from header
Sigurður Ásgeirsson 2014/12/12 16:21:40 Done.
10 #include "base/strings/stringprintf.h"
11 #include "base/time/time.h"
12 #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.
13
14 namespace browser_watcher {
15
16 ExitFunnel::ExitFunnel() {
17 }
18
19 ExitFunnel::~ExitFunnel() {
20 }
21
22 bool ExitFunnel::Init(const base::char16* registry_path,
23 base::ProcessHandle process_handle) {
24 // Concatenate the pid and the creation time of the process to get a
25 // unique key name.
26 base::ProcessId pid = base::GetProcId(process_handle);
27
28 FILETIME creation_time = {};
29 FILETIME dummy = {};
30 if (!::GetProcessTimes(process_handle, &creation_time,
31 &dummy, &dummy, &dummy)) {
32 LOG(ERROR) << "Invalid process handle, can't get process times.";
33 return false;
34 }
35
36 base::string16 key_name = registry_path;
37 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.
38 base::Time::FromFileTime(creation_time).ToInternalValue());
39
40 LONG res = key_.Create(HKEY_CURRENT_USER, key_name.c_str(), KEY_SET_VALUE);
41 if (res != ERROR_SUCCESS) {
42 LOG(ERROR) << "Unable to create key " << key_name << " error " << res;
43 return false;
44 }
45
46 return true;
47 }
48
49 bool ExitFunnel::RecordEvent(const base::char16* event_name) {
50 int64 now = base::Time::Now().ToInternalValue();
51
52 LONG res = key_.WriteValue(event_name, &now, sizeof(now), REG_QWORD);
53 if (res != ERROR_SUCCESS) {
54 LOG(ERROR) << "Unable to write value " << event_name << " error " << res;
55 return false;
56 }
57
58 return true;
59 }
60
61 bool ExitFunnel::RecordSingleEvent(const base::char16* registry_path,
62 const base::char16* event_name) {
63 ExitFunnel funnel;
64
65 if (!funnel.Init(registry_path, base::GetCurrentProcessHandle()))
66 return false;
67
68 return funnel.RecordEvent(event_name);
69 }
70
71 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698