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

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: 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
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..7681e03885ee4b270a6a0ad93470d913fdd0de17 100644
--- a/chrome/installer/util/google_update_util.cc
+++ b/chrome/installer/util/google_update_util.cc
@@ -132,25 +132,13 @@ 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(
+bool ParseUntrustedData(
grt (UTC plus 2) 2014/03/03 15:18:26 add doc comment
jackhou1 2014/03/04 00:56:28 Done.
+ 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 ||
- !IsStringPrintable(data_string)) {
- LOG(ERROR) << "Invalid value in " << kEnvVariableUntrustedData;
+ if (!IsStringPrintable(data_string)) {
+ LOG(ERROR) << "Invalid value in untrusted data string.";
return false;
}
-
- VLOG(1) << kEnvVariableUntrustedData << ": " << data_string;
-
std::vector<std::pair<std::string, std::string> > kv_pairs;
if (!base::SplitStringIntoKeyValuePairs(data_string, '=', '&', &kv_pairs)) {
LOG(ERROR) << "Failed to parse untrusted data: " << data_string;
@@ -171,6 +159,27 @@ 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) {
+ DCHECK(untrusted_data);
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ std::string data_string;
+ if (env == NULL || !env->GetVar(kEnvVariableUntrustedData, &data_string))
grt (UTC plus 2) 2014/03/03 15:18:26 i think "!env" is more idomatic for testing that a
jackhou1 2014/03/04 00:56:28 Done.
+ return false;
+
+ if (data_string.length() > kEnvVariableUntrustedDataMaxLength) {
+ LOG(ERROR) << kEnvVariableUntrustedData << " is too long.";
+ return false;
+ }
+
+ VLOG(1) << kEnvVariableUntrustedData << ": " << data_string;
grt (UTC plus 2) 2014/03/03 15:18:26 don't log data_string here since IsStringPrintable
jackhou1 2014/03/04 00:56:28 Done.
+
+ return ParseUntrustedData(data_string, untrusted_data);
+}
+
} // namespace
bool EnsureUserLevelGoogleUpdatePresent() {
@@ -221,4 +230,21 @@ std::string GetUntrustedDataValue(const std::string& key) {
return std::string();
}
+std::string GetUntrustedDataValueFromTag(const std::string& tag,
grt (UTC plus 2) 2014/03/03 15:18:26 should the size of |tag| be restricted in the same
jackhou1 2014/03/04 00:56:28 Done. I'm don't know if there is a specific reaso
+ const std::string& key) {
+ std::map<std::string, std::string> untrusted_data;
+ if (ParseUntrustedData(tag, &untrusted_data)) {
grt (UTC plus 2) 2014/03/03 15:18:26 without the logging calls (see next comment), i be
jackhou1 2014/03/04 00:56:28 Done.
+ std::map<std::string, std::string>::const_iterator data_it(
+ untrusted_data.find(key));
+ if (data_it != untrusted_data.end()) {
+ VLOG(1) << "Key " << key << " is " << data_it->second;
grt (UTC plus 2) 2014/03/03 15:18:26 coding style says "Remove most logging calls befor
jackhou1 2014/03/04 00:56:28 Done.
+ return data_it->second;
+ } else {
+ VLOG(1) << "Key not found: " << key;
+ }
+ }
+
+ return std::string();
+}
+
} // namespace google_update
« chrome/installer/util/google_update_util.h ('K') | « 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