Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/update_client/update_response.h" | 5 #include "components/update_client/update_response.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 std::vector<xmlNode*> result; | 73 std::vector<xmlNode*> result; |
| 74 for (xmlNode* child = root->children; child != NULL; child = child->next) { | 74 for (xmlNode* child = root->children; child != NULL; child = child->next) { |
| 75 if (!TagNameEquals(child, name)) { | 75 if (!TagNameEquals(child, name)) { |
| 76 continue; | 76 continue; |
| 77 } | 77 } |
| 78 result.push_back(child); | 78 result.push_back(child); |
| 79 } | 79 } |
| 80 return result; | 80 return result; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Returns whether the attribute is present. | |
| 84 static bool HasAttribute(xmlNode* node, const char* attribute_name) { | |
| 85 const xmlChar* name = reinterpret_cast<const xmlChar*>(attribute_name); | |
| 86 for (xmlAttr* attr = node->properties; attr != NULL; attr = attr->next) { | |
| 87 if (!xmlStrcmp(attr->name, name) && attr->children && | |
| 88 attr->children->content) { | |
| 89 return true; | |
| 90 } | |
| 91 } | |
| 92 return false; | |
| 93 } | |
| 94 | |
| 83 // Returns the value of a named attribute, or the empty string. | 95 // Returns the value of a named attribute, or the empty string. |
| 84 static std::string GetAttribute(xmlNode* node, const char* attribute_name) { | 96 static std::string GetAttribute(xmlNode* node, const char* attribute_name) { |
| 85 const xmlChar* name = reinterpret_cast<const xmlChar*>(attribute_name); | 97 const xmlChar* name = reinterpret_cast<const xmlChar*>(attribute_name); |
| 86 for (xmlAttr* attr = node->properties; attr != NULL; attr = attr->next) { | 98 for (xmlAttr* attr = node->properties; attr != NULL; attr = attr->next) { |
| 87 if (!xmlStrcmp(attr->name, name) && attr->children && | 99 if (!xmlStrcmp(attr->name, name) && attr->children && |
| 88 attr->children->content) { | 100 attr->children->content) { |
| 89 return std::string( | 101 return std::string( |
| 90 reinterpret_cast<const char*>(attr->children->content)); | 102 reinterpret_cast<const char*>(attr->children->content)); |
| 91 } | 103 } |
| 92 } | 104 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 return false; | 273 return false; |
| 262 } | 274 } |
| 263 | 275 |
| 264 return ParseManifestTag(manifests[0], result, error); | 276 return ParseManifestTag(manifests[0], result, error); |
| 265 } | 277 } |
| 266 | 278 |
| 267 // Parses a single <app> tag. | 279 // Parses a single <app> tag. |
| 268 bool ParseAppTag(xmlNode* app, | 280 bool ParseAppTag(xmlNode* app, |
| 269 UpdateResponse::Result* result, | 281 UpdateResponse::Result* result, |
| 270 std::string* error) { | 282 std::string* error) { |
| 283 // Read cohort information. | |
| 284 result->set_cohort = HasAttribute(app, "cohort"); | |
| 285 result->cohort = GetAttribute(app, "cohort"); | |
|
Sorin Jianu
2016/08/18 21:15:15
Would it make sense to dynamically allocate the co
waffles
2016/08/18 22:29:23
According to the spec, if the server serializes an
| |
| 286 result->set_cohort_hint = HasAttribute(app, "cohorthint"); | |
| 287 result->cohort_hint = GetAttribute(app, "cohorthint"); | |
| 288 result->set_cohort_name = HasAttribute(app, "cohortname"); | |
| 289 result->cohort_name = GetAttribute(app, "cohortname"); | |
| 290 | |
| 271 // Read the crx id. | 291 // Read the crx id. |
| 272 result->extension_id = GetAttribute(app, "appid"); | 292 result->extension_id = GetAttribute(app, "appid"); |
| 273 if (result->extension_id.empty()) { | 293 if (result->extension_id.empty()) { |
| 274 *error = "Missing appid on app node"; | 294 *error = "Missing appid on app node"; |
| 275 return false; | 295 return false; |
| 276 } | 296 } |
| 277 | 297 |
| 278 // Get the <updatecheck> tag. | 298 // Get the <updatecheck> tag. |
| 279 std::vector<xmlNode*> updates = GetChildren(app, "updatecheck"); | 299 std::vector<xmlNode*> updates = GetChildren(app, "updatecheck"); |
| 280 if (updates.empty()) { | 300 if (updates.empty()) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 results_.list.push_back(result); | 372 results_.list.push_back(result); |
| 353 } else { | 373 } else { |
| 354 ParseError("%s", error.c_str()); | 374 ParseError("%s", error.c_str()); |
| 355 } | 375 } |
| 356 } | 376 } |
| 357 | 377 |
| 358 return true; | 378 return true; |
| 359 } | 379 } |
| 360 | 380 |
| 361 } // namespace update_client | 381 } // namespace update_client |
| OLD | NEW |