This source file includes following definitions.
- ModuleSort
- ConvertToLongPath
- GenerateHash
- NormalizeModule
- Match
- callback_thread_id_
- ScanNow
- ScanImpl
- EnumerateLoadedModules
- EnumerateShellExtensions
- ReadShellExtensions
- EnumerateWinsockModules
- PopulateModuleInformation
- AddToListWithoutDuplicating
- PreparePathMappings
- CollapsePath
- MatchAgainstBlacklist
- ReportBack
- GetSubjectNameFromDigitalSignature
- GetInstance
- RecordLearnMoreStat
- ShouldShowConflictWarning
- AcknowledgeConflictNotification
- ScanNow
- GetModuleList
- GetFirstNotableConflict
- modules_to_notify_about_
- MaybePostScanningTask
- DoneScanning
- ConstructHelpCenterUrl
#include "chrome/browser/enumerate_modules_model_win.h"
#include <Tlhelp32.h>
#include <wintrust.h>
#include <algorithm>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/file_version_info_win.h"
#include "base/files/file_path.h"
#include "base/i18n/case_conversion.h"
#include "base/metrics/histogram.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "base/version.h"
#include "base/win/registry.h"
#include "base/win/scoped_handle.h"
#include "base/win/windows_version.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/net/service_providers_win.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/notification_service.h"
#include "crypto/sha2.h"
#include "grit/generated_resources.h"
#include "grit/google_chrome_strings.h"
#include "ui/base/l10n/l10n_util.h"
using content::BrowserThread;
static const int kModuleCheckDelayMs = 45 * 1000;
static const wchar_t kRegPath[] =
L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved";
static const ModuleEnumerator::RecommendedAction kUninstallLink =
static_cast<ModuleEnumerator::RecommendedAction>(
ModuleEnumerator::UNINSTALL | ModuleEnumerator::SEE_LINK);
static const ModuleEnumerator::RecommendedAction kInvestigatingLink =
static_cast<ModuleEnumerator::RecommendedAction>(
ModuleEnumerator::INVESTIGATING | ModuleEnumerator::SEE_LINK);
static bool ModuleSort(const ModuleEnumerator::Module& a,
const ModuleEnumerator::Module& b) {
if (a.status != b.status)
return a.status > b.status;
if (a.location == b.location)
return a.name < b.name;
return a.location < b.location;
}
namespace {
base::Lock* lock = NULL;
struct FindModule {
public:
explicit FindModule(const ModuleEnumerator::Module& x)
: module(x) {}
bool operator()(const ModuleEnumerator::Module& module_in) const {
return (module.location == module_in.location) &&
(module.name == module_in.name);
}
const ModuleEnumerator::Module& module;
};
bool ConvertToLongPath(const base::string16& short_path,
base::string16* long_path) {
wchar_t long_path_buf[MAX_PATH];
DWORD return_value = GetLongPathName(short_path.c_str(), long_path_buf,
MAX_PATH);
if (return_value != 0 && return_value < MAX_PATH) {
*long_path = long_path_buf;
return true;
}
return false;
}
}
const ModuleEnumerator::BlacklistEntry ModuleEnumerator::kModuleBlacklist[] = {
{ "7ba9402f", "c9132d48", "", "", "", ALL, kInvestigatingLink },
{ "26134911", "59145acf", "", "", "", ALL, kUninstallLink },
{ "f5d8f549", "23d01d5b", "", "", "", ALL, kUninstallLink },
{ "c60ca062", "23d01d5b", "", "", "", ALL, kUninstallLink },
{ "2ea5422a", "6b3a1b00", "a7db0e0c", "", "8.0", XP,
static_cast<RecommendedAction>(UPDATE | SEE_LINK | NOTIFY_USER) },
{ "2ea5422a", "d8686924", "a7db0e0c", "", "8.0", XP,
static_cast<RecommendedAction>(UPDATE | SEE_LINK | NOTIFY_USER) },
{ "6bb57633", "23d01d5b", "", "", "", ALL, kInvestigatingLink },
{ "0396e037.dll", "", "", "", "", ALL, kUninstallLink },
{ "5ce0037c", "59145acf", "", "", "", ALL, kUninstallLink },
{ "e579a039", "23d01d5b", "", "", "", ALL, kUninstallLink },
{ "7add320b", "470a3da3", "", "", "", ALL, kUninstallLink },
{ "7add320b", "7a3c8be3", "", "", "", ALL, kUninstallLink },
{ "1c4df325", "59145acf", "", "", "", ALL, kUninstallLink },
{ "6d01f4a1", "7935e9c2", "", "", "", ALL, kUninstallLink },
{ "4cb4f2e3", "88e4a3b1", "", "", "", ALL, kUninstallLink },
{ "5d10b363", "", "", "", "", ALL, kUninstallLink },
{ "303825ed", "23d01d5b", "", "", "", ALL, INVESTIGATING },
{ "b8dce5c3", "23d01d5b", "", "", "6.03", ALL,
static_cast<RecommendedAction>(UPDATE | DISABLE) },
{ "8f42f22e", "23d01d5b", "", "", "4.0", ALL,
static_cast<RecommendedAction>(UPDATE | DISABLE) },
{ "7ffbdce9", "bc5673f2", "", "", "", ALL,
static_cast<RecommendedAction>(UPDATE | DISABLE | SEE_LINK) },
{ "f9555eea", "e3548061", "", "", "", ALL, kUninstallLink },
{ "ead2768e", "4e61ce60", "", "", "", ALL, INVESTIGATING },
{ "d0893e38", "23d01d5b", "", "", "", ALL, kUninstallLink },
{ "d0893e38", "59145acf", "", "", "", ALL, kUninstallLink },
{ "3e837222", "23d01d5b", "", "", "", ALL, kUninstallLink },
{ "3e837222", "59145acf", "", "", "", ALL, kUninstallLink },
{ "5523579e", "23d01d5b", "", "", "", ALL, INVESTIGATING },
{ "9830bff6", "23d01d5b", "", "", "", ALL, kUninstallLink },
{ "b86ce04d", "59145acf", "", "", "", ALL, kUninstallLink },
{ "f2c8790d", "", "", "", "", ALL, kInvestigatingLink },
{ "37f907e2", "3ad0ff23", "", "", "", ALL, INVESTIGATING },
{ "7405c0c8", "23d01d5b", "", "", "", ALL, kUninstallLink },
{ "0953ed09", "f0d5eeda", "", "", "", ALL, kUninstallLink },
{ "f4f3391e", "119d20f7", "", "", "", ALL, kUninstallLink },
{ "7edcd250", "0733dc3e", "", "", "", ALL, INVESTIGATING },
{ "a1ed94a7", "ea9d6b36", "", "", "", ALL, kUninstallLink },
{ "802aefef", "06120e13", "", "", "3.5.1008.40", ALL, UPDATE },
{ "0b52d2ae", "a4cc88b1", "", "", "", ALL, kUninstallLink },
{ "1936d5cc", "223c44be", "", "", "", ALL, kUninstallLink },
{ "f6915a31", "4e61ce60", "", "", "", ALL, INVESTIGATING },
{ "005965ea", "bc5673f2", "", "", "", ALL, INVESTIGATING },
{ "46c16aa8", "6b3a1b00", "a7db0e0c", "", "8.0", XP,
static_cast<RecommendedAction>(UPDATE | SEE_LINK | NOTIFY_USER) },
{ "46c16aa8", "d8686924", "a7db0e0c", "", "8.0", XP,
static_cast<RecommendedAction>(UPDATE | SEE_LINK | NOTIFY_USER) },
{ "24555d74", "", "", "", "", ALL, kUninstallLink },
{ "61112d7b", "25fb120f", "", "", "", ALL, kInvestigatingLink },
{ "0355549b", "23d01d5b", "", "", "", ALL, kUninstallLink },
{ "02e44508", "23d01d5b", "", "", "", ALL, kUninstallLink },
{ "c4a784d5", "23d01d5b", "", "", "", ALL, kUninstallLink },
{ "2e4eb93d", "23d01d5b", "", "", "", ALL, INVESTIGATING },
{ "bba2037d", "9ab68585", "", "", "", ALL, kUninstallLink },
{ "c70b697d", "4e61ce60", "", "", "", ALL, INVESTIGATING },
{ "38ad9963", "23d01d5b", "", "", "", ALL, kUninstallLink },
{ "e967210d", "23d01d5b", "", "", "", ALL, kUninstallLink },
};
static void GenerateHash(const std::string& input, std::string* output) {
if (input.empty()) {
*output = "";
return;
}
uint8 hash[4];
crypto::SHA256HashString(input, hash, sizeof(hash));
*output = StringToLowerASCII(base::HexEncode(hash, sizeof(hash)));
}
void ModuleEnumerator::NormalizeModule(Module* module) {
base::string16 path = module->location;
if (!ConvertToLongPath(path, &module->location))
module->location = path;
module->location = base::i18n::ToLower(module->location);
size_t last_slash = module->location.find_last_of(L"\\");
if (last_slash != base::string16::npos) {
module->name = module->location.substr(last_slash + 1);
module->location = module->location.substr(0, last_slash + 1);
} else {
module->name = module->location;
module->location.clear();
}
size_t first_space = module->version.find_first_of(L" ");
if (first_space != base::string16::npos)
module->version = module->version.substr(0, first_space);
module->normalized = true;
}
ModuleEnumerator::ModuleStatus ModuleEnumerator::Match(
const ModuleEnumerator::Module& module,
const ModuleEnumerator::BlacklistEntry& blacklisted) {
DCHECK(module.normalized);
DCHECK(strlen(blacklisted.filename) > 0);
DCHECK(!strstr(blacklisted.version_from, " "));
DCHECK(!strstr(blacklisted.version_to, " "));
base::win::Version version = base::win::GetVersion();
switch (version) {
case base::win::VERSION_XP:
if (!(blacklisted.os & XP)) return NOT_MATCHED;
break;
default:
break;
}
std::string filename_hash, location_hash;
GenerateHash(base::WideToUTF8(module.name), &filename_hash);
GenerateHash(base::WideToUTF8(module.location), &location_hash);
if (filename_hash == blacklisted.filename &&
(std::string(blacklisted.location).empty() ||
location_hash == blacklisted.location)) {
Version module_version(base::UTF16ToASCII(module.version));
Version version_min(blacklisted.version_from);
Version version_max(blacklisted.version_to);
bool version_ok = !version_min.IsValid() && !version_max.IsValid();
if (!version_ok) {
bool too_low = version_min.IsValid() &&
(!module_version.IsValid() ||
module_version.CompareTo(version_min) < 0);
bool too_high = version_max.IsValid() &&
(!module_version.IsValid() ||
module_version.CompareTo(version_max) >= 0);
version_ok = !too_low && !too_high;
}
if (version_ok) {
std::string desc_or_signer(blacklisted.desc_or_signer);
std::string signer_hash, description_hash;
GenerateHash(base::WideToUTF8(module.digital_signer), &signer_hash);
GenerateHash(base::WideToUTF8(module.description), &description_hash);
if (signer_hash == desc_or_signer)
return CONFIRMED_BAD;
if (description_hash == desc_or_signer &&
!location_hash.empty() && location_hash == blacklisted.location)
return CONFIRMED_BAD;
return SUSPECTED_BAD;
}
}
return NOT_MATCHED;
}
ModuleEnumerator::ModuleEnumerator(EnumerateModulesModel* observer)
: enumerated_modules_(NULL),
observer_(observer),
limited_mode_(false),
callback_thread_id_(BrowserThread::ID_COUNT) {
}
ModuleEnumerator::~ModuleEnumerator() {
}
void ModuleEnumerator::ScanNow(ModulesVector* list, bool limited_mode) {
enumerated_modules_ = list;
limited_mode_ = limited_mode;
if (!limited_mode_) {
CHECK(BrowserThread::GetCurrentThreadIdentifier(&callback_thread_id_));
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
base::Bind(&ModuleEnumerator::ScanImpl, this));
} else {
ScanImpl();
}
}
void ModuleEnumerator::ScanImpl() {
base::TimeTicks start_time = base::TimeTicks::Now();
enumerated_modules_->clear();
PreparePathMappings();
base::TimeTicks checkpoint = base::TimeTicks::Now();
EnumerateLoadedModules();
base::TimeTicks checkpoint2 = base::TimeTicks::Now();
UMA_HISTOGRAM_TIMES("Conflicts.EnumerateLoadedModules",
checkpoint2 - checkpoint);
checkpoint = checkpoint2;
EnumerateShellExtensions();
checkpoint2 = base::TimeTicks::Now();
UMA_HISTOGRAM_TIMES("Conflicts.EnumerateShellExtensions",
checkpoint2 - checkpoint);
checkpoint = checkpoint2;
EnumerateWinsockModules();
checkpoint2 = base::TimeTicks::Now();
UMA_HISTOGRAM_TIMES("Conflicts.EnumerateWinsockModules",
checkpoint2 - checkpoint);
MatchAgainstBlacklist();
std::sort(enumerated_modules_->begin(),
enumerated_modules_->end(), ModuleSort);
if (!limited_mode_) {
BrowserThread::PostTask(callback_thread_id_, FROM_HERE,
base::Bind(&ModuleEnumerator::ReportBack, this));
} else {
ReportBack();
}
UMA_HISTOGRAM_TIMES("Conflicts.EnumerationTotalTime",
base::TimeTicks::Now() - start_time);
}
void ModuleEnumerator::EnumerateLoadedModules() {
base::win::ScopedHandle snap(::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,
::GetCurrentProcessId()));
if (!snap.Get())
return;
MODULEENTRY32 module = { sizeof(module) };
if (!::Module32First(snap.Get(), &module))
return;
do {
if (_wcsicmp(chrome::kBrowserProcessExecutableName, module.szModule) == 0)
continue;
Module entry;
entry.type = LOADED_MODULE;
entry.location = module.szExePath;
PopulateModuleInformation(&entry);
NormalizeModule(&entry);
CollapsePath(&entry);
enumerated_modules_->push_back(entry);
} while (::Module32Next(snap.Get(), &module));
}
void ModuleEnumerator::EnumerateShellExtensions() {
ReadShellExtensions(HKEY_LOCAL_MACHINE);
ReadShellExtensions(HKEY_CURRENT_USER);
}
void ModuleEnumerator::ReadShellExtensions(HKEY parent) {
base::win::RegistryValueIterator registration(parent, kRegPath);
while (registration.Valid()) {
std::wstring key(std::wstring(L"CLSID\\") + registration.Name() +
L"\\InProcServer32");
base::win::RegKey clsid;
if (clsid.Open(HKEY_CLASSES_ROOT, key.c_str(), KEY_READ) != ERROR_SUCCESS) {
++registration;
continue;
}
base::string16 dll;
if (clsid.ReadValue(L"", &dll) != ERROR_SUCCESS) {
++registration;
continue;
}
clsid.Close();
Module entry;
entry.type = SHELL_EXTENSION;
entry.location = dll;
PopulateModuleInformation(&entry);
NormalizeModule(&entry);
CollapsePath(&entry);
AddToListWithoutDuplicating(entry);
++registration;
}
}
void ModuleEnumerator::EnumerateWinsockModules() {
WinsockLayeredServiceProviderList layered_providers;
GetWinsockLayeredServiceProviders(&layered_providers);
for (size_t i = 0; i < layered_providers.size(); ++i) {
Module entry;
entry.type = WINSOCK_MODULE_REGISTRATION;
entry.status = NOT_MATCHED;
entry.normalized = false;
entry.location = layered_providers[i].path;
entry.description = layered_providers[i].name;
entry.recommended_action = NONE;
entry.duplicate_count = 0;
wchar_t expanded[MAX_PATH];
DWORD size = ExpandEnvironmentStrings(
entry.location.c_str(), expanded, MAX_PATH);
if (size != 0 && size <= MAX_PATH) {
entry.digital_signer =
GetSubjectNameFromDigitalSignature(base::FilePath(expanded));
}
entry.version = base::IntToString16(layered_providers[i].version);
NormalizeModule(&entry);
AddToListWithoutDuplicating(entry);
}
}
void ModuleEnumerator::PopulateModuleInformation(Module* module) {
module->status = NOT_MATCHED;
module->duplicate_count = 0;
module->normalized = false;
module->digital_signer =
GetSubjectNameFromDigitalSignature(base::FilePath(module->location));
module->recommended_action = NONE;
scoped_ptr<FileVersionInfo> version_info(
FileVersionInfo::CreateFileVersionInfo(base::FilePath(module->location)));
if (version_info.get()) {
FileVersionInfoWin* version_info_win =
static_cast<FileVersionInfoWin*>(version_info.get());
VS_FIXEDFILEINFO* fixed_file_info = version_info_win->fixed_file_info();
if (fixed_file_info) {
module->description = version_info_win->file_description();
module->version = version_info_win->file_version();
module->product_name = version_info_win->product_name();
}
}
}
void ModuleEnumerator::AddToListWithoutDuplicating(const Module& module) {
DCHECK(module.normalized);
ModulesVector::iterator iter;
iter = std::find_if(enumerated_modules_->begin(),
enumerated_modules_->end(),
FindModule(module));
if (iter != enumerated_modules_->end()) {
iter->duplicate_count++;
iter->type = static_cast<ModuleType>(iter->type | module.type);
} else {
enumerated_modules_->push_back(module);
}
}
void ModuleEnumerator::PreparePathMappings() {
path_mapping_.clear();
scoped_ptr<base::Environment> environment(base::Environment::Create());
std::vector<base::string16> env_vars;
env_vars.push_back(L"LOCALAPPDATA");
env_vars.push_back(L"ProgramFiles");
env_vars.push_back(L"ProgramData");
env_vars.push_back(L"USERPROFILE");
env_vars.push_back(L"SystemRoot");
env_vars.push_back(L"TEMP");
env_vars.push_back(L"TMP");
env_vars.push_back(L"CommonProgramFiles");
for (std::vector<base::string16>::const_iterator variable = env_vars.begin();
variable != env_vars.end(); ++variable) {
std::string path;
if (environment->GetVar(base::UTF16ToASCII(*variable).c_str(), &path)) {
path_mapping_.push_back(
std::make_pair(base::i18n::ToLower(base::UTF8ToUTF16(path)) + L"\\",
L"%" + base::i18n::ToLower(*variable) + L"%"));
}
}
}
void ModuleEnumerator::CollapsePath(Module* entry) {
size_t min_length = MAXINT;
base::string16 location = entry->location;
for (PathMapping::const_iterator mapping = path_mapping_.begin();
mapping != path_mapping_.end(); ++mapping) {
base::string16 prefix = mapping->first;
if (StartsWith(location, prefix, false)) {
base::string16 new_location = mapping->second +
location.substr(prefix.length() - 1);
size_t length = new_location.length() - mapping->second.length();
if (length < min_length) {
entry->location = new_location;
min_length = length;
}
}
}
}
void ModuleEnumerator::MatchAgainstBlacklist() {
for (size_t m = 0; m < enumerated_modules_->size(); ++m) {
Module* module = &(*enumerated_modules_)[m];
module->status = GOOD;
for (size_t i = 0; i < arraysize(kModuleBlacklist); ++i) {
#if !defined(NDEBUG)
std::string hashes(kModuleBlacklist[i].filename);
std::string hash1, hash2, hash3;
GenerateHash(kModuleBlacklist[i].filename, &hash1);
hashes += " - " + hash1;
GenerateHash(kModuleBlacklist[i].location, &hash2);
hashes += " - " + hash2;
GenerateHash(kModuleBlacklist[i].desc_or_signer, &hash3);
hashes += " - " + hash3;
#endif
ModuleStatus status = Match(*module, kModuleBlacklist[i]);
if (status != NOT_MATCHED) {
module->status = status;
module->recommended_action = kModuleBlacklist[i].help_tip;
break;
}
}
if (module->status == NOT_MATCHED || module->status == GOOD) {
if (StartsWith(module->location, L"%temp%", false) ||
StartsWith(module->location, L"%tmp%", false)) {
module->status = SUSPECTED_BAD;
}
}
}
}
void ModuleEnumerator::ReportBack() {
if (!limited_mode_)
DCHECK(BrowserThread::CurrentlyOn(callback_thread_id_));
observer_->DoneScanning();
}
base::string16 ModuleEnumerator::GetSubjectNameFromDigitalSignature(
const base::FilePath& filename) {
HCERTSTORE store = NULL;
HCRYPTMSG message = NULL;
bool result = !!CryptQueryObject(CERT_QUERY_OBJECT_FILE,
filename.value().c_str(),
CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED,
CERT_QUERY_FORMAT_FLAG_BINARY,
0,
NULL,
NULL,
NULL,
&store,
&message,
NULL);
if (!result)
return base::string16();
DWORD signer_info_size = 0;
result = !!CryptMsgGetParam(message,
CMSG_SIGNER_INFO_PARAM,
0,
NULL,
&signer_info_size);
if (!result)
return base::string16();
scoped_ptr<BYTE[]> signer_info_buffer(new BYTE[signer_info_size]);
CMSG_SIGNER_INFO* signer_info =
reinterpret_cast<CMSG_SIGNER_INFO*>(signer_info_buffer.get());
result = !!CryptMsgGetParam(message,
CMSG_SIGNER_INFO_PARAM,
0,
signer_info,
&signer_info_size);
if (!result)
return base::string16();
CERT_INFO CertInfo = {0};
PCCERT_CONTEXT cert_context = NULL;
CertInfo.Issuer = signer_info->Issuer;
CertInfo.SerialNumber = signer_info->SerialNumber;
cert_context = CertFindCertificateInStore(
store,
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
0,
CERT_FIND_SUBJECT_CERT,
&CertInfo,
NULL);
if (!cert_context)
return base::string16();
DWORD subject_name_size = 0;
if (!(subject_name_size = CertGetNameString(cert_context,
CERT_NAME_SIMPLE_DISPLAY_TYPE,
0,
NULL,
NULL,
0))) {
return base::string16();
}
base::string16 subject_name;
subject_name.resize(subject_name_size);
if (!(CertGetNameString(cert_context,
CERT_NAME_SIMPLE_DISPLAY_TYPE,
0,
NULL,
const_cast<LPWSTR>(subject_name.c_str()),
subject_name_size))) {
return base::string16();
}
return subject_name;
}
EnumerateModulesModel* EnumerateModulesModel::GetInstance() {
return Singleton<EnumerateModulesModel>::get();
}
void EnumerateModulesModel::RecordLearnMoreStat(bool from_menu) {
UMA_HISTOGRAM_ENUMERATION("ConflictingModule.UserSelection",
from_menu ? ACTION_MENU_LEARN_MORE : ACTION_BUBBLE_LEARN_MORE,
ACTION_BOUNDARY);
}
bool EnumerateModulesModel::ShouldShowConflictWarning() const {
if (conflict_notification_acknowledged_)
return false;
return confirmed_bad_modules_detected_ > 0;
}
void EnumerateModulesModel::AcknowledgeConflictNotification() {
if (!conflict_notification_acknowledged_) {
conflict_notification_acknowledged_ = true;
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE,
content::Source<EnumerateModulesModel>(this),
content::NotificationService::NoDetails());
}
}
void EnumerateModulesModel::ScanNow() {
if (scanning_)
return;
lock->Acquire();
scanning_ = true;
if (!module_enumerator_)
module_enumerator_ = new ModuleEnumerator(this);
module_enumerator_->ScanNow(&enumerated_modules_, limited_mode_);
}
base::ListValue* EnumerateModulesModel::GetModuleList() const {
if (scanning_)
return NULL;
lock->Acquire();
if (enumerated_modules_.empty()) {
lock->Release();
return NULL;
}
base::ListValue* list = new base::ListValue();
for (ModuleEnumerator::ModulesVector::const_iterator module =
enumerated_modules_.begin();
module != enumerated_modules_.end(); ++module) {
base::DictionaryValue* data = new base::DictionaryValue();
data->SetInteger("type", module->type);
base::string16 type_string;
if ((module->type & ModuleEnumerator::LOADED_MODULE) == 0) {
if (module->type & ModuleEnumerator::SHELL_EXTENSION)
type_string = base::ASCIIToWide("Shell Extension");
if (module->type & ModuleEnumerator::WINSOCK_MODULE_REGISTRATION) {
if (!type_string.empty())
type_string += base::ASCIIToWide(", ");
type_string += base::ASCIIToWide("Winsock");
}
DCHECK(!type_string.empty());
if (!limited_mode_) {
type_string += base::ASCIIToWide(" -- ");
type_string += l10n_util::GetStringUTF16(IDS_CONFLICTS_NOT_LOADED_YET);
}
}
data->SetString("type_description", type_string);
data->SetInteger("status", module->status);
data->SetString("location", module->location);
data->SetString("name", module->name);
data->SetString("product_name", module->product_name);
data->SetString("description", module->description);
data->SetString("version", module->version);
data->SetString("digital_signer", module->digital_signer);
if (!limited_mode_) {
base::string16 actions;
base::string16 separator = base::ASCIIToWide(" ") +
l10n_util::GetStringUTF16(
IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_SEPARATOR) +
base::ASCIIToWide(" ");
if (module->recommended_action & ModuleEnumerator::NONE) {
actions = l10n_util::GetStringUTF16(
IDS_CONFLICTS_CHECK_INVESTIGATING);
}
if (module->recommended_action & ModuleEnumerator::UNINSTALL) {
if (!actions.empty())
actions += separator;
actions = l10n_util::GetStringUTF16(
IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_UNINSTALL);
}
if (module->recommended_action & ModuleEnumerator::UPDATE) {
if (!actions.empty())
actions += separator;
actions += l10n_util::GetStringUTF16(
IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_UPDATE);
}
if (module->recommended_action & ModuleEnumerator::DISABLE) {
if (!actions.empty())
actions += separator;
actions += l10n_util::GetStringUTF16(
IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_DISABLE);
}
base::string16 possible_resolution =
actions.empty() ? base::ASCIIToWide("")
: l10n_util::GetStringUTF16(
IDS_CONFLICTS_CHECK_POSSIBLE_ACTIONS) +
base::ASCIIToWide(" ") +
actions;
data->SetString("possibleResolution", possible_resolution);
data->SetString("help_url",
ConstructHelpCenterUrl(*module).spec().c_str());
}
list->Append(data);
}
lock->Release();
return list;
}
GURL EnumerateModulesModel::GetFirstNotableConflict() {
lock->Acquire();
GURL url;
if (enumerated_modules_.empty()) {
lock->Release();
return GURL();
}
for (ModuleEnumerator::ModulesVector::const_iterator module =
enumerated_modules_.begin();
module != enumerated_modules_.end(); ++module) {
if (!(module->recommended_action & ModuleEnumerator::NOTIFY_USER))
continue;
url = ConstructHelpCenterUrl(*module);
DCHECK(url.is_valid());
break;
}
lock->Release();
return url;
}
EnumerateModulesModel::EnumerateModulesModel()
: limited_mode_(false),
scanning_(false),
conflict_notification_acknowledged_(false),
confirmed_bad_modules_detected_(0),
suspected_bad_modules_detected_(0),
modules_to_notify_about_(0) {
lock = new base::Lock();
}
EnumerateModulesModel::~EnumerateModulesModel() {
delete lock;
}
void EnumerateModulesModel::MaybePostScanningTask() {
static bool done = false;
if (!done) {
done = true;
const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
if (cmd_line.HasSwitch(switches::kConflictingModulesCheck) ||
base::win::GetVersion() == base::win::VERSION_XP) {
check_modules_timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(kModuleCheckDelayMs),
this, &EnumerateModulesModel::ScanNow);
}
}
}
void EnumerateModulesModel::DoneScanning() {
confirmed_bad_modules_detected_ = 0;
suspected_bad_modules_detected_ = 0;
modules_to_notify_about_ = 0;
for (ModuleEnumerator::ModulesVector::const_iterator module =
enumerated_modules_.begin();
module != enumerated_modules_.end(); ++module) {
if (module->status == ModuleEnumerator::CONFIRMED_BAD) {
++confirmed_bad_modules_detected_;
if (module->recommended_action & ModuleEnumerator::NOTIFY_USER)
++modules_to_notify_about_;
} else if (module->status == ModuleEnumerator::SUSPECTED_BAD) {
++suspected_bad_modules_detected_;
if (module->recommended_action & ModuleEnumerator::NOTIFY_USER)
++modules_to_notify_about_;
}
}
scanning_ = false;
lock->Release();
UMA_HISTOGRAM_COUNTS_100("Conflicts.SuspectedBadModules",
suspected_bad_modules_detected_);
UMA_HISTOGRAM_COUNTS_100("Conflicts.ConfirmedBadModules",
confirmed_bad_modules_detected_);
if (limited_mode_)
return;
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_MODULE_LIST_ENUMERATED,
content::Source<EnumerateModulesModel>(this),
content::NotificationService::NoDetails());
const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
if (!cmd_line.HasSwitch(switches::kConflictingModulesCheck))
return;
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE,
content::Source<EnumerateModulesModel>(this),
content::NotificationService::NoDetails());
}
GURL EnumerateModulesModel::ConstructHelpCenterUrl(
const ModuleEnumerator::Module& module) const {
if (!(module.recommended_action & ModuleEnumerator::SEE_LINK) &&
!(module.recommended_action & ModuleEnumerator::NOTIFY_USER))
return GURL();
std::string filename, location, description, signer;
GenerateHash(base::WideToUTF8(module.name), &filename);
GenerateHash(base::WideToUTF8(module.location), &location);
GenerateHash(base::WideToUTF8(module.description), &description);
GenerateHash(base::WideToUTF8(module.digital_signer), &signer);
base::string16 url =
l10n_util::GetStringFUTF16(IDS_HELP_CENTER_VIEW_CONFLICTS,
base::ASCIIToUTF16(filename), base::ASCIIToUTF16(location),
base::ASCIIToUTF16(description), base::ASCIIToUTF16(signer));
return GURL(base::UTF16ToUTF8(url));
}