Commit f4e4fa6c authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Integrate third-party metrics in ModuleDatabase

Those metrics already exist in EnumerateModulesModel.

Bug: 690173
Change-Id: I14757cde09e365c8d994782350fdffc07813586a
Reviewed-on: https://chromium-review.googlesource.com/592633Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#490824}
parent f0abac54
......@@ -7,12 +7,38 @@
#include <vector>
#include "base/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "chrome/browser/conflicts/module_database_win.h"
#include "chrome/browser/conflicts/module_info_win.h"
namespace {
// Returns true if the module is signed by Google.
bool IsGoogleModule(const ModuleInfoData& module_data) {
static const wchar_t kGoogle[] = L"Google Inc";
return module_data.inspection_result->certificate_info.subject == kGoogle;
}
// Returns true if the signer name begins with "Microsoft ". Signatures are
// typically "Microsoft Corporation" or "Microsoft Windows", but others may
// exist.
bool IsMicrosoftModule(const ModuleInfoData& module_data) {
static const wchar_t kMicrosoft[] = L"Microsoft ";
return base::StartsWith(
module_data.inspection_result->certificate_info.subject, kMicrosoft,
base::CompareCase::SENSITIVE);
}
// Returns true if |module_data| is a third party module.
bool IsThirdPartyModule(const ModuleInfoData& module_data) {
return !IsGoogleModule(module_data) && !IsMicrosoftModule(module_data);
}
} // namespace
ThirdPartyMetricsRecorder::ThirdPartyMetricsRecorder(
ModuleDatabase* module_database) {
// base::Unretained() is safe here because ThirdPartyMetricsRecorder owns
......@@ -28,31 +54,58 @@ ThirdPartyMetricsRecorder::~ThirdPartyMetricsRecorder() = default;
void ThirdPartyMetricsRecorder::OnNewModuleFound(
const ModuleInfoKey& module_key,
const ModuleInfoData& module_data) {
if (!IsThirdPartyModule(module_data))
return;
const CertificateInfo& certificate_info =
module_data.inspection_result->certificate_info;
module_count_++;
if (certificate_info.type != CertificateType::NO_CERTIFICATE) {
++signed_module_count_;
if (certificate_info.type == CertificateType::CERTIFICATE_IN_CATALOG)
++catalog_module_count_;
if (IsMicrosoftModule(module_data)) {
++microsoft_module_count_;
} else if (IsGoogleModule(module_data)) {
// No need to count these explicitly.
} else {
// Count modules that are neither signed by Google nor Microsoft.
// These are considered "third party" modules.
if (module_data.module_types & ModuleInfoData::kTypeLoadedModule) {
++loaded_third_party_module_count_;
} else {
++not_loaded_third_party_module_count_;
}
}
}
// The uninstallable metric is only recorded for third party metrics.
if (IsThirdPartyModule(module_data)) {
std::vector<base::string16> program_names;
bool uninstallable = installed_programs_.GetInstalledProgramNames(
module_key.module_path, &program_names);
UMA_HISTOGRAM_BOOLEAN("ThirdPartyModules.Uninstallable", uninstallable);
}
}
bool ThirdPartyMetricsRecorder::IsThirdPartyModule(
const ModuleInfoData& module_data) {
static const wchar_t kMicrosoft[] = L"Microsoft ";
static const wchar_t kGoogle[] = L"Google Inc";
const base::string16& certificate_subject =
module_data.inspection_result->certificate_info.subject;
// Check if the signer name begins with "Microsoft ". Signatures are
// typically "Microsoft Corporation" or "Microsoft Windows", but others
// may exist.
if (base::StartsWith(certificate_subject, kMicrosoft,
base::CompareCase::SENSITIVE))
return false;
void ThirdPartyMetricsRecorder::OnModuleDatabaseIdle() {
if (metrics_emitted_)
return;
metrics_emitted_ = true;
return certificate_subject != kGoogle;
// Report back some metrics regarding third party modules and certificates.
base::UmaHistogramCustomCounts("ThirdPartyModules.Modules.Loaded",
loaded_third_party_module_count_, 1, 500, 50);
base::UmaHistogramCustomCounts("ThirdPartyModules.Modules.NotLoaded",
not_loaded_third_party_module_count_, 1, 500,
50);
base::UmaHistogramCustomCounts("ThirdPartyModules.Modules.Signed",
signed_module_count_, 1, 500, 50);
base::UmaHistogramCustomCounts("ThirdPartyModules.Modules.Signed.Microsoft",
microsoft_module_count_, 1, 500, 50);
base::UmaHistogramCustomCounts("ThirdPartyModules.Modules.Signed.Catalog",
catalog_module_count_, 1, 500, 50);
base::UmaHistogramCustomCounts("ThirdPartyModules.Modules.Total",
module_count_, 1, 500, 50);
}
void ThirdPartyMetricsRecorder::OnInstalledProgramsInitialized(
......
......@@ -22,16 +22,24 @@ class ThirdPartyMetricsRecorder : public ModuleDatabaseObserver {
// ModuleDatabaseObserver:
void OnNewModuleFound(const ModuleInfoKey& module_key,
const ModuleInfoData& module_data) override;
void OnModuleDatabaseIdle() override;
private:
void OnInstalledProgramsInitialized(ModuleDatabase* module_database);
// Returns true if |module_data| is a third party module. Third party modules
// are defined as not being signed by Google or Microsoft.
bool IsThirdPartyModule(const ModuleInfoData& module_data);
InstalledPrograms installed_programs_;
// Flag used to avoid sending module counts multiple times.
bool metrics_emitted_ = false;
// Counters for different types of modules.
size_t module_count_ = 0;
size_t signed_module_count_ = 0;
size_t catalog_module_count_ = 0;
size_t microsoft_module_count_ = 0;
size_t loaded_third_party_module_count_ = 0;
size_t not_loaded_third_party_module_count_ = 0;
DISALLOW_COPY_AND_ASSIGN(ThirdPartyMetricsRecorder);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment