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

Unified Diff: components/update_client/update_response.cc

Issue 2252093002: Add support for Omaha cohorts to the component updater. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Through #13 Created 4 years, 4 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: components/update_client/update_response.cc
diff --git a/components/update_client/update_response.cc b/components/update_client/update_response.cc
index e89a774ae7a77627b0800cf8b6218642c96de385..0667b90f1970f3a0bf98b99b3041558860aba288 100644
--- a/components/update_client/update_response.cc
+++ b/components/update_client/update_response.cc
@@ -20,6 +20,9 @@
namespace update_client {
static const char* kExpectedResponseProtocol = "3.0";
+const char* UpdateResponse::Result::kCohort = "cohort";
+const char* UpdateResponse::Result::kCohortHint = "cohorthint";
+const char* UpdateResponse::Result::kCohortName = "cohortname";
UpdateResponse::UpdateResponse() {
}
@@ -32,8 +35,7 @@ UpdateResponse::Results::Results(const Results& other) = default;
UpdateResponse::Results::~Results() {
}
-UpdateResponse::Result::Result() {
-}
+UpdateResponse::Result::Result() {}
UpdateResponse::Result::Result(const Result& other) = default;
UpdateResponse::Result::~Result() {
}
@@ -93,6 +95,21 @@ static std::string GetAttribute(xmlNode* node, const char* attribute_name) {
return std::string();
}
+// Returns the value of a named attribute, or nullptr .
+static std::unique_ptr<std::string> GetAttributePtr(
+ xmlNode* node,
+ const char* attribute_name) {
+ const xmlChar* name = reinterpret_cast<const xmlChar*>(attribute_name);
+ for (xmlAttr* attr = node->properties; attr != NULL; attr = attr->next) {
+ if (!xmlStrcmp(attr->name, name) && attr->children &&
+ attr->children->content) {
+ return std::unique_ptr<std::string>(new std::string(
Sorin Jianu 2016/08/23 00:20:03 Can we use MakeUnique or WrapUniquento make this s
waffles 2016/08/23 00:36:18 Done.
+ reinterpret_cast<const char*>(attr->children->content)));
+ }
+ }
+ return nullptr;
+}
+
// This is used for the xml parser to report errors. This assumes the context
// is a pointer to a std::string where the error message should be appended.
static void XmlErrorFunc(void* context, const char* message, ...) {
@@ -268,6 +285,17 @@ bool ParseUpdateCheckTag(xmlNode* updatecheck,
bool ParseAppTag(xmlNode* app,
UpdateResponse::Result* result,
std::string* error) {
+ // Read cohort information.
+ auto cohort = GetAttributePtr(app, "cohort");
+ static const char* attrs[] = {UpdateResponse::Result::kCohort,
+ UpdateResponse::Result::kCohortHint,
+ UpdateResponse::Result::kCohortName};
+ for (const auto& attr : attrs) {
+ auto value = GetAttributePtr(app, attr);
+ if (value)
+ result->cohort_attrs.insert({attr, *value});
+ }
+
// Read the crx id.
result->extension_id = GetAttribute(app, "appid");
if (result->extension_id.empty()) {

Powered by Google App Engine
This is Rietveld 408576698