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

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: Fix unit test 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
« no previous file with comments | « components/update_client/update_response.h ('k') | components/update_client/update_response_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..eccbd10fc1cb3b4fbd64db45cb7ef21479b51822 100644
--- a/components/update_client/update_response.cc
+++ b/components/update_client/update_response.cc
@@ -9,6 +9,7 @@
#include <algorithm>
#include <memory>
+#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
@@ -20,6 +21,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 +36,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 +96,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 base::MakeUnique<std::string>(
+ 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 +286,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()) {
« no previous file with comments | « components/update_client/update_response.h ('k') | components/update_client/update_response_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698