Chromium Code Reviews| Index: chrome/browser/conflicts/module_info_util_win.cc |
| diff --git a/chrome/browser/conflicts/module_info_util_win.cc b/chrome/browser/conflicts/module_info_util_win.cc |
| index 01b30b2e78ecea0562ea6d53c11013e92e4a7e44..2e9251f56aadcc17fd78125c8093100c0f6ac21d 100644 |
| --- a/chrome/browser/conflicts/module_info_util_win.cc |
| +++ b/chrome/browser/conflicts/module_info_util_win.cc |
| @@ -13,10 +13,15 @@ |
| // This must be after wincrypt and wintrust. |
| #include <mscat.h> |
| +#include <limits> |
| #include <memory> |
| -#include <vector> |
| +#include <string> |
| +#include "base/environment.h" |
| +#include "base/i18n/case_conversion.h" |
| #include "base/scoped_generic.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "base/win/scoped_handle.h" |
| namespace { |
| @@ -238,3 +243,43 @@ void GetCertificateInfo(const base::FilePath& filename, |
| certificate_info->path = filename; |
| certificate_info->subject = subject; |
| } |
| + |
| +StringMapping GetEnvironmentVariablesMapping( |
| + const std::vector<base::string16>& environment_variables) { |
| + std::unique_ptr<base::Environment> environment(base::Environment::Create()); |
| + |
| + StringMapping string_mapping; |
| + for (const base::string16& variable : environment_variables) { |
| + std::string value; |
| + if (environment->GetVar(base::UTF16ToASCII(variable).c_str(), &value)) { |
| + value = base::TrimString(value, "\\", base::TRIM_TRAILING).as_string(); |
| + string_mapping.push_back( |
| + std::make_pair(base::i18n::ToLower(base::UTF8ToUTF16(value)), |
| + L"%" + base::i18n::ToLower(variable) + L"%")); |
| + } |
| + } |
| + |
| + return string_mapping; |
| +} |
| + |
| +void CollapseMatchingPrefixInString(const StringMapping& prefix_mapping, |
| + base::string16* string) { |
| + const base::string16 string_copy = *string; |
| + DCHECK_EQ(base::i18n::ToLower(string_copy), string_copy); |
| + |
| + size_t min_length = std::numeric_limits<size_t>::max(); |
| + for (const auto& mapping : prefix_mapping) { |
| + DCHECK_EQ(base::i18n::ToLower(mapping.first), mapping.first); |
| + if (base::StartsWith(string_copy, mapping.first, |
| + base::CompareCase::SENSITIVE)) { |
| + base::string16 collapsed_string = string_copy; |
| + base::ReplaceFirstSubstringAfterOffset(&collapsed_string, 0, |
| + mapping.first, mapping.second); |
| + size_t length = collapsed_string.length() - mapping.second.length(); |
|
chrisha
2017/03/01 15:45:42
Shouldn't we have logic to ensure the next charact
Patrick Monette
2017/03/02 20:27:07
Done.
|
| + if (length < min_length) { |
| + *string = collapsed_string; |
| + min_length = length; |
| + } |
| + } |
| + } |
| +} |