Commit 10d16dc9 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Put the basename of unsigned modules into crash keys

The crash keys are named "unsigned-modules-*" where * is a number from
0 to 9.

This will allow us to assess which accessibility software doesn't sign
all of their modules.

Bug: 846953
Change-Id: Iea0aabc1694972120c7ef48327c0b982092ed179
Reviewed-on: https://chromium-review.googlesource.com/1148990
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578727}
parent 8c2846e5
......@@ -4,15 +4,17 @@
#include "chrome/browser/conflicts/third_party_metrics_recorder_win.h"
#include <vector>
#include <algorithm>
#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_piece.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/conflicts/module_info_util_win.h"
#include "chrome/browser/conflicts/module_info_win.h"
#include "components/crash/core/common/crash_key.h"
namespace {
......@@ -24,7 +26,9 @@ bool IsGoogleModule(base::StringPiece16 subject) {
} // namespace
ThirdPartyMetricsRecorder::ThirdPartyMetricsRecorder() = default;
ThirdPartyMetricsRecorder::ThirdPartyMetricsRecorder() {
current_value_.reserve(kCrashKeySize);
}
ThirdPartyMetricsRecorder::~ThirdPartyMetricsRecorder() = default;
......@@ -55,6 +59,10 @@ void ThirdPartyMetricsRecorder::OnNewModuleFound(
++not_loaded_third_party_module_count_;
}
}
} else {
// Put unsigned modules into the crash keys.
if (module_data.module_properties & ModuleInfoData::kPropertyLoadedModule)
AddUnsignedModuleToCrashkeys(module_data.inspection_result->basename);
}
}
......@@ -78,3 +86,43 @@ void ThirdPartyMetricsRecorder::OnModuleDatabaseIdle() {
base::UmaHistogramCustomCounts("ThirdPartyModules.Modules.Total",
module_count_, 1, 500, 50);
}
void ThirdPartyMetricsRecorder::AddUnsignedModuleToCrashkeys(
const base::string16& module_basename) {
using UnsignedModulesKey = crash_reporter::CrashKeyString<kCrashKeySize>;
static UnsignedModulesKey unsigned_modules_keys[] = {
{"unsigned-modules-1", UnsignedModulesKey::Tag::kArray},
{"unsigned-modules-2", UnsignedModulesKey::Tag::kArray},
{"unsigned-modules-3", UnsignedModulesKey::Tag::kArray},
{"unsigned-modules-4", UnsignedModulesKey::Tag::kArray},
{"unsigned-modules-5", UnsignedModulesKey::Tag::kArray},
};
if (current_key_index_ >= base::size(unsigned_modules_keys))
return;
std::string module = base::UTF16ToUTF8(module_basename);
// Truncate the basename if it doesn't fit in one crash key.
size_t module_length = std::min(module.length(), kCrashKeySize);
// Check if the module fits in the current string or if a new string is
// needed.
size_t length_remaining = kCrashKeySize;
if (!current_value_.empty())
length_remaining -= current_value_.length() + 1;
if (module_length > length_remaining) {
current_value_.clear();
if (++current_key_index_ >= base::size(unsigned_modules_keys))
return;
}
// Append the module to the current string. Separate with a comma if needed.
if (!current_value_.empty())
current_value_.append(",");
current_value_.append(module, 0, module_length);
unsigned_modules_keys[current_key_index_].Set(current_value_);
}
......@@ -5,7 +5,10 @@
#ifndef CHROME_BROWSER_CONFLICTS_THIRD_PARTY_METRICS_RECORDER_WIN_H_
#define CHROME_BROWSER_CONFLICTS_THIRD_PARTY_METRICS_RECORDER_WIN_H_
#include <string>
#include "base/macros.h"
#include "base/strings/string16.h"
#include "chrome/browser/conflicts/module_database_observer_win.h"
struct ModuleInfoData;
......@@ -23,6 +26,22 @@ class ThirdPartyMetricsRecorder : public ModuleDatabaseObserver {
void OnModuleDatabaseIdle() override;
private:
// The size of the unsigned modules crash keys.
static constexpr size_t kCrashKeySize = 256;
// A helper function that writes the unsigned modules name to a series of
// crash keys. The crash keys are leaked so that they can be picked up by the
// crash reporter. Creating another instance of ThirdPartyMetricsRecorder
// will start overwriting the current values in the crash keys. This is not
// a problem in practice because this class is leaked.
void AddUnsignedModuleToCrashkeys(const base::string16& module_basename);
// The index of the crash key that is currently being updated.
int current_key_index_ = 0;
// The value of the crash key that is currently being updated.
std::string current_value_;
// Flag used to avoid sending module counts multiple times.
bool metrics_emitted_ = false;
......
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