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

Unified Diff: chrome/installer/util/google_update_util.cc

Issue 180243021: Add google_update::GetUntrustedDataValueFromTag() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 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
« no previous file with comments | « chrome/installer/util/google_update_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/installer/util/google_update_util.cc
diff --git a/chrome/installer/util/google_update_util.cc b/chrome/installer/util/google_update_util.cc
index 748e3f6c2fe07824bf7ec6711f8c225b143aff0d..18ea762e8f97147f26c7c9fd5b2bd23f4cd0b1ba 100644
--- a/chrome/installer/util/google_update_util.cc
+++ b/chrome/installer/util/google_update_util.cc
@@ -34,7 +34,7 @@ namespace {
const int kGoogleUpdateTimeoutMs = 20 * 1000;
const char kEnvVariableUntrustedData[] = "GoogleUpdateUntrustedData";
-const int kEnvVariableUntrustedDataMaxLength = 4096;
+const int kUntrustedDataMaxLength = 4096;
// Returns true if Google Update is present at the given level.
bool IsGoogleUpdatePresent(bool system_install) {
@@ -132,24 +132,19 @@ bool IsUntrustedDataKeyValid(const std::string& key) {
== key.end();
}
-// Reads and parses untrusted data passed from Google Update as key-value
-// pairs, then overwrites |untrusted_data_map| with the result.
-// Returns true if data are successfully read.
-bool GetGoogleUpdateUntrustedData(
+// Parses |data_string| as key-value pairs and overwrites |untrusted_data| with
+// the result. Returns true if the data could be parsed.
+bool ParseUntrustedData(
+ const std::string& data_string,
std::map<std::string, std::string>* untrusted_data) {
DCHECK(untrusted_data);
- scoped_ptr<base::Environment> env(base::Environment::Create());
- std::string data_string;
- if (env == NULL || !env->GetVar(kEnvVariableUntrustedData, &data_string))
- return false;
-
- if (data_string.length() > kEnvVariableUntrustedDataMaxLength ||
+ if (data_string.length() > kUntrustedDataMaxLength ||
!IsStringPrintable(data_string)) {
- LOG(ERROR) << "Invalid value in " << kEnvVariableUntrustedData;
+ LOG(ERROR) << "Invalid value in untrusted data string.";
return false;
}
- VLOG(1) << kEnvVariableUntrustedData << ": " << data_string;
+ VLOG(1) << "Untrusted data string: " << data_string;
std::vector<std::pair<std::string, std::string> > kv_pairs;
if (!base::SplitStringIntoKeyValuePairs(data_string, '=', '&', &kv_pairs)) {
@@ -171,6 +166,19 @@ bool GetGoogleUpdateUntrustedData(
return true;
}
+// Reads and parses untrusted data passed from Google Update as key-value
+// pairs, then overwrites |untrusted_data_map| with the result.
+// Returns true if data are successfully read.
+bool GetGoogleUpdateUntrustedData(
+ std::map<std::string, std::string>* untrusted_data) {
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ std::string data_string;
+ if (!env || !env->GetVar(kEnvVariableUntrustedData, &data_string))
+ return false;
+
+ return ParseUntrustedData(data_string, untrusted_data);
+}
+
} // namespace
bool EnsureUserLevelGoogleUpdatePresent() {
@@ -221,4 +229,13 @@ std::string GetUntrustedDataValue(const std::string& key) {
return std::string();
}
+std::string GetUntrustedDataValueFromTag(const std::string& tag,
+ const std::string& key) {
+ std::map<std::string, std::string> untrusted_data;
+ if (ParseUntrustedData(tag, &untrusted_data))
+ return untrusted_data[key];
+
+ return std::string();
+}
+
} // namespace google_update
« no previous file with comments | « chrome/installer/util/google_update_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698