Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Unified Diff: chrome/browser/conflicts/module_info_util_win.cc

Issue 2720513005: Add InspectModule() that returns a populated ModuleInspectionResult struct (Closed)
Patch Set: a Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..2581b5a40152d7c4bb838c2060ec0feadcbda649 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,39 @@ 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)) {
+ 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) {
+ size_t min_length = std::numeric_limits<size_t>::max();
+ const base::string16& lower_string = base::i18n::ToLower(*string);
+ for (const auto& mapping : prefix_mapping) {
+ const base::string16& prefix = base::i18n::ToLower(mapping.first);
chrisha 2017/02/28 18:51:28 Could we just document that we expect StringMappin
Patrick Monette 2017/02/28 23:37:38 Indeed. Done.
+ if (base::StartsWith(lower_string, prefix, base::CompareCase::SENSITIVE)) {
chrisha 2017/02/28 18:51:29 Do we have expectations that the paths in |prefix_
Patrick Monette 2017/02/28 23:37:38 I don't think this function needs to expect paths
+ base::string16 collapsed_string = lower_string;
+ base::ReplaceFirstSubstringAfterOffset(&collapsed_string, 0, prefix,
+ mapping.second);
+ size_t length = collapsed_string.length() - mapping.second.length();
+ if (length < min_length) {
chrisha 2017/02/28 18:51:28 We're only doing the collapsing if it's shorter? W
Patrick Monette 2017/02/28 23:37:38 Chatted offline. Ignored.
+ *string = collapsed_string;
+ min_length = length;
+ }
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698