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

Side by Side Diff: chrome/browser/install_verification/win/install_verification.cc

Issue 2055613002: Report hash of Chrome's parent process name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix windbg hash. add some more processes. Created 4 years, 6 months 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/install_verification/win/install_verification.h" 5 #include "chrome/browser/install_verification/win/install_verification.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <windows.h>
8 9
9 #include <set> 10 #include <set>
10 #include <vector> 11 #include <vector>
11 12
13 #include "base/files/file_path.h"
12 #include "base/metrics/sparse_histogram.h" 14 #include "base/metrics/sparse_histogram.h"
15 #include "base/process/process.h"
16 #include "base/process/process_handle.h"
17 #include "base/strings/string_util.h"
13 #include "chrome/browser/install_verification/win/loaded_module_verification.h" 18 #include "chrome/browser/install_verification/win/loaded_module_verification.h"
14 #include "chrome/browser/install_verification/win/module_ids.h" 19 #include "chrome/browser/install_verification/win/module_ids.h"
15 #include "chrome/browser/install_verification/win/module_info.h" 20 #include "chrome/browser/install_verification/win/module_info.h"
16 #include "chrome/browser/install_verification/win/module_verification_common.h" 21 #include "chrome/browser/install_verification/win/module_verification_common.h"
22 #include "components/variations/metrics_util.h"
17 23
18 namespace { 24 namespace {
19 25
20 void ReportModuleMatch(size_t module_id) { 26 void ReportModuleMatch(size_t module_id) {
21 UMA_HISTOGRAM_SPARSE_SLOWLY("InstallVerifier.ModuleMatch", module_id); 27 UMA_HISTOGRAM_SPARSE_SLOWLY("InstallVerifier.ModuleMatch", module_id);
22 } 28 }
23 29
30 base::FilePath GetExeFilePathForProcess(const base::Process& process) {
31 wchar_t exe_name[MAX_PATH];
32 DWORD exe_name_len = arraysize(exe_name);
33 // Note: requesting the Win32 path format.
34 if (::QueryFullProcessImageName(process.Handle(), 0, exe_name,
35 &exe_name_len) == 0) {
36 DPLOG(ERROR) << "Failed to get executable name for process";
37 return base::FilePath();
38 }
39
40 // QueryFullProcessImageName's documentation does not specify behavior when
41 // the buffer is too small, but we know that GetModuleFileNameEx succeeds and
42 // truncates the returned name in such a case. Given that paths of arbitrary
43 // length may exist, the conservative approach is to reject names when
44 // the returned length is that of the buffer.
45 if (exe_name_len > 0 && exe_name_len < arraysize(exe_name))
46 return base::FilePath(exe_name);
47
48 return base::FilePath();
49 }
50
51 void ReportParentProcessName() {
52 base::ProcessId ppid =
53 base::GetParentProcessId(base::GetCurrentProcessHandle());
54
55 base::Process process(
56 base::Process::OpenWithAccess(ppid, PROCESS_QUERY_LIMITED_INFORMATION));
57
58 uint32_t hash = 0U;
59
60 if (process.IsValid()) {
61 base::FilePath path(GetExeFilePathForProcess(process));
62
63 if (!path.empty())
robertshield 2016/06/09 03:29:59 nit: I thought we needed {} if the statement below
Will Harris 2016/06/09 03:35:47 git cl format never adds braces even when they are
Will Harris 2016/06/09 16:22:51 Done.
64 hash =
65 metrics::HashName(base::ToLowerASCII(path.BaseName().AsUTF8Unsafe()));
Alexei Svitkine (slow) 2016/06/09 15:04:26 Nit: AsUTF8Unsafe() stands out and makes the reade
Will Harris 2016/06/09 16:22:51 Done.
66 }
67
68 UMA_HISTOGRAM_SPARSE_SLOWLY("Windows.ParentProcessNameHash", hash);
69 }
70
24 } // namespace 71 } // namespace
25 72
26 void VerifyInstallation() { 73 void VerifyInstallation() {
74 ReportParentProcessName();
27 ModuleIDs module_ids; 75 ModuleIDs module_ids;
28 LoadModuleIDs(&module_ids); 76 LoadModuleIDs(&module_ids);
29 std::set<ModuleInfo> loaded_modules; 77 std::set<ModuleInfo> loaded_modules;
30 if (GetLoadedModules(&loaded_modules)) { 78 if (GetLoadedModules(&loaded_modules)) {
31 VerifyLoadedModules(loaded_modules, module_ids, &ReportModuleMatch); 79 VerifyLoadedModules(loaded_modules, module_ids, &ReportModuleMatch);
32 } 80 }
33 } 81 }
OLDNEW
« 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