This source file includes following definitions.
- RecordBlacklistSetupEvent
- ReportSuccessfulBlocks
- InitializeChromeElf
- BrowserBlacklistBeaconSetup
#include "base/bind.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/registry.h"
#include "chrome/browser/chrome_elf_init_win.h"
#include "chrome_elf/blacklist/blacklist.h"
#include "chrome_elf/chrome_elf_constants.h"
#include "chrome_elf/dll_hash/dll_hash.h"
#include "content/public/browser/browser_thread.h"
#include "version.h"
namespace {
const char kBrowserBlacklistTrialName[] = "BrowserBlacklist";
const char kBrowserBlacklistTrialEnabledGroupName[] = "Enabled";
const int kBlacklistReportingDelaySec = 600;
enum BlacklistSetupEventType {
BLACKLIST_SETUP_ENABLED = 0,
BLACKLIST_SETUP_RAN_SUCCESSFULLY,
BLACKLIST_SETUP_FAILED,
BLACKLIST_THUNK_SETUP_FAILED,
BLACKLIST_INTERCEPTION_FAILED,
BLACKLIST_SETUP_EVENT_MAX,
};
void RecordBlacklistSetupEvent(BlacklistSetupEventType blacklist_setup_event) {
UMA_HISTOGRAM_ENUMERATION("Blacklist.Setup",
blacklist_setup_event,
BLACKLIST_SETUP_EVENT_MAX);
}
void ReportSuccessfulBlocks() {
int num_blocked_dlls = 0;
blacklist::SuccessfullyBlocked(NULL, &num_blocked_dlls);
if (num_blocked_dlls == 0)
return;
std::vector<const wchar_t*> blocked_dlls(num_blocked_dlls);
blacklist::SuccessfullyBlocked(&blocked_dlls[0], &num_blocked_dlls);
for (size_t i = 0; i < blocked_dlls.size(); ++i) {
std::string dll_name_utf8;
base::WideToUTF8(blocked_dlls[i], wcslen(blocked_dlls[i]), &dll_name_utf8);
int uma_hash = DllNameToHash(dll_name_utf8);
UMA_HISTOGRAM_SPARSE_SLOWLY("Blacklist.Blocked", uma_hash);
}
}
}
void InitializeChromeElf() {
if (base::FieldTrialList::FindFullName(kBrowserBlacklistTrialName) ==
kBrowserBlacklistTrialEnabledGroupName) {
BrowserBlacklistBeaconSetup();
} else {
base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER);
blacklist_registry_key.DeleteKey(blacklist::kRegistryBeaconPath);
}
ReportSuccessfulBlocks();
content::BrowserThread::PostDelayedTask(
content::BrowserThread::UI,
FROM_HERE,
base::Bind(&ReportSuccessfulBlocks),
base::TimeDelta::FromSeconds(kBlacklistReportingDelaySec));
}
void BrowserBlacklistBeaconSetup() {
base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER,
blacklist::kRegistryBeaconPath,
KEY_QUERY_VALUE | KEY_SET_VALUE);
if (!blacklist_registry_key.Valid())
return;
DWORD blacklist_state = blacklist::BLACKLIST_STATE_MAX;
blacklist_registry_key.ReadValueDW(blacklist::kBeaconState, &blacklist_state);
if (blacklist_state == blacklist::BLACKLIST_ENABLED) {
RecordBlacklistSetupEvent(BLACKLIST_SETUP_RAN_SUCCESSFULLY);
} else {
switch (blacklist_state) {
case blacklist::BLACKLIST_SETUP_RUNNING:
RecordBlacklistSetupEvent(BLACKLIST_SETUP_FAILED);
break;
case blacklist::BLACKLIST_THUNK_SETUP:
RecordBlacklistSetupEvent(BLACKLIST_THUNK_SETUP_FAILED);
break;
case blacklist::BLACKLIST_INTERCEPTING:
RecordBlacklistSetupEvent(BLACKLIST_INTERCEPTION_FAILED);
break;
}
if (blacklist_state != blacklist::BLACKLIST_DISABLED) {
blacklist_registry_key.WriteValue(blacklist::kBeaconState,
blacklist::BLACKLIST_DISABLED);
}
}
base::string16 blacklist_version;
blacklist_registry_key.ReadValue(blacklist::kBeaconVersion,
&blacklist_version);
if (blacklist_version != TEXT(CHROME_VERSION_STRING)) {
LONG set_version = blacklist_registry_key.WriteValue(
blacklist::kBeaconVersion,
TEXT(CHROME_VERSION_STRING));
LONG set_state = blacklist_registry_key.WriteValue(
blacklist::kBeaconState,
blacklist::BLACKLIST_ENABLED);
if (set_version == ERROR_SUCCESS && set_state == ERROR_SUCCESS)
RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED);
}
}