summaryrefslogtreecommitdiffstats
path: root/chrome/installer
diff options
context:
space:
mode:
authorjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-11 01:02:26 +0000
committerjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-11 01:02:26 +0000
commite9b84dd40be75e6855e96112718085e05ce53b0b (patch)
tree8322e282168a6c5db8b30f09f9d38112943ff570 /chrome/installer
parent14ba9442cd91d36890d0002762597fc49b3a86df (diff)
downloadchromium_src-e9b84dd40be75e6855e96112718085e05ce53b0b.zip
chromium_src-e9b84dd40be75e6855e96112718085e05ce53b0b.tar.gz
chromium_src-e9b84dd40be75e6855e96112718085e05ce53b0b.tar.bz2
Add google_update::GetUntrustedDataValueFromTag()
This is similar to GetUntrustedDataValue() but allows extracting a value from an arbitrary tag. BUG=341353 Review URL: https://codereview.chromium.org/180243021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256091 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rw-r--r--chrome/installer/util/google_update_util.cc43
-rw-r--r--chrome/installer/util/google_update_util.h7
2 files changed, 37 insertions, 13 deletions
diff --git a/chrome/installer/util/google_update_util.cc b/chrome/installer/util/google_update_util.cc
index 748e3f6..18ea762 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
diff --git a/chrome/installer/util/google_update_util.h b/chrome/installer/util/google_update_util.h
index 30d77e9..8ef2b9a 100644
--- a/chrome/installer/util/google_update_util.h
+++ b/chrome/installer/util/google_update_util.h
@@ -27,6 +27,13 @@ bool UninstallGoogleUpdate(bool system_install);
// contains non-printable characters.
std::string GetUntrustedDataValue(const std::string& key);
+// Returns the value corresponding to |key| in untrusted data passed from
+// |tag|. |tag| should be a printable list of key-value pairs, e.g.
+// "key1=value1&key2=value2". Returns an empty string if |key| is absent or if
+// its value contains non-printable characters.
+std::string GetUntrustedDataValueFromTag(const std::string& tag,
+ const std::string& key);
+
} // namespace google_update
#endif // CHROME_INSTALLER_UTIL_GOOGLE_UPDATE_UTIL_H_