Chromium Code Reviews| 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()) { |