Chromium Code Reviews| Index: chrome/browser/install_verification/win/install_verification.cc |
| diff --git a/chrome/browser/install_verification/win/install_verification.cc b/chrome/browser/install_verification/win/install_verification.cc |
| index 82c1d8180b301e33ea854812ed53a37ea03c234b..4de7bd623666317818093dd79903b584d7256bbc 100644 |
| --- a/chrome/browser/install_verification/win/install_verification.cc |
| +++ b/chrome/browser/install_verification/win/install_verification.cc |
| @@ -5,15 +5,21 @@ |
| #include "chrome/browser/install_verification/win/install_verification.h" |
| #include <stddef.h> |
| +#include <windows.h> |
| #include <set> |
| #include <vector> |
| +#include "base/files/file_path.h" |
| #include "base/metrics/sparse_histogram.h" |
| +#include "base/process/process.h" |
| +#include "base/process/process_handle.h" |
| +#include "base/strings/string_util.h" |
| #include "chrome/browser/install_verification/win/loaded_module_verification.h" |
| #include "chrome/browser/install_verification/win/module_ids.h" |
| #include "chrome/browser/install_verification/win/module_info.h" |
| #include "chrome/browser/install_verification/win/module_verification_common.h" |
| +#include "components/variations/metrics_util.h" |
| namespace { |
| @@ -21,9 +27,51 @@ void ReportModuleMatch(size_t module_id) { |
| UMA_HISTOGRAM_SPARSE_SLOWLY("InstallVerifier.ModuleMatch", module_id); |
| } |
| +base::FilePath GetExeFilePathForProcess(const base::Process& process) { |
| + wchar_t exe_name[MAX_PATH]; |
| + DWORD exe_name_len = arraysize(exe_name); |
| + // Note: requesting the Win32 path format. |
| + if (::QueryFullProcessImageName(process.Handle(), 0, exe_name, |
| + &exe_name_len) == 0) { |
| + DPLOG(ERROR) << "Failed to get executable name for process"; |
| + return base::FilePath(); |
| + } |
| + |
| + // QueryFullProcessImageName's documentation does not specify behavior when |
| + // the buffer is too small, but we know that GetModuleFileNameEx succeeds and |
| + // truncates the returned name in such a case. Given that paths of arbitrary |
| + // length may exist, the conservative approach is to reject names when |
| + // the returned length is that of the buffer. |
| + if (exe_name_len > 0 && exe_name_len < arraysize(exe_name)) |
| + return base::FilePath(exe_name); |
| + |
| + return base::FilePath(); |
| +} |
| + |
| +void ReportParentProcessName() { |
| + base::ProcessId ppid = |
| + base::GetParentProcessId(base::GetCurrentProcessHandle()); |
| + |
| + base::Process process( |
| + base::Process::OpenWithAccess(ppid, PROCESS_QUERY_LIMITED_INFORMATION)); |
| + |
| + uint32_t hash = 0U; |
| + |
| + if (process.IsValid()) { |
| + base::FilePath path(GetExeFilePathForProcess(process)); |
| + |
| + 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.
|
| + hash = |
| + 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.
|
| + } |
| + |
| + UMA_HISTOGRAM_SPARSE_SLOWLY("Windows.ParentProcessNameHash", hash); |
| +} |
| + |
| } // namespace |
| void VerifyInstallation() { |
| + ReportParentProcessName(); |
| ModuleIDs module_ids; |
| LoadModuleIDs(&module_ids); |
| std::set<ModuleInfo> loaded_modules; |