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 14 matching lines...) Expand all Loading... | |
| 25 } | 25 } |
| 26 UpdateResponse::~UpdateResponse() { | 26 UpdateResponse::~UpdateResponse() { |
| 27 } | 27 } |
| 28 | 28 |
| 29 UpdateResponse::Results::Results() : daystart_elapsed_seconds(kNoDaystart) { | 29 UpdateResponse::Results::Results() : daystart_elapsed_seconds(kNoDaystart) { |
| 30 } | 30 } |
| 31 UpdateResponse::Results::Results(const Results& other) = default; | 31 UpdateResponse::Results::Results(const Results& other) = default; |
| 32 UpdateResponse::Results::~Results() { | 32 UpdateResponse::Results::~Results() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 UpdateResponse::Result::Result() { | 35 UpdateResponse::Result::Result() {} |
| 36 UpdateResponse::Result::Result(const Result& other) | |
| 37 : crx_urls(other.crx_urls), | |
| 38 crx_diffurls(other.crx_diffurls), | |
| 39 manifest(other.manifest), | |
| 40 cohort(new std::string(*other.cohort)), | |
| 41 cohort_hint(new std::string(*other.cohort_hint)), | |
| 42 cohort_name(new std::string(*other.cohort_name)) {} | |
| 43 UpdateResponse::Result& UpdateResponse::Result::operator=(const Result& other) { | |
|
Sorin Jianu
2016/08/22 19:59:34
oh, no.
waffles
2016/08/22 23:40:32
Yeah. :(
Tried another approach using a map.
| |
| 44 crx_urls = other.crx_urls; | |
| 45 crx_diffurls = other.crx_diffurls; | |
| 46 manifest = other.manifest; | |
| 47 cohort = std::unique_ptr<std::string>(new std::string(*other.cohort)); | |
| 48 cohort_name = | |
| 49 std::unique_ptr<std::string>(new std::string(*other.cohort_name)); | |
| 50 cohort_hint = | |
| 51 std::unique_ptr<std::string>(new std::string(*other.cohort_hint)); | |
| 52 return *this; | |
| 36 } | 53 } |
| 37 UpdateResponse::Result::Result(const Result& other) = default; | |
| 38 UpdateResponse::Result::~Result() { | 54 UpdateResponse::Result::~Result() { |
| 39 } | 55 } |
| 40 | 56 |
| 41 UpdateResponse::Result::Manifest::Manifest() { | 57 UpdateResponse::Result::Manifest::Manifest() { |
| 42 } | 58 } |
| 43 UpdateResponse::Result::Manifest::Manifest(const Manifest& other) = default; | 59 UpdateResponse::Result::Manifest::Manifest(const Manifest& other) = default; |
| 44 UpdateResponse::Result::Manifest::~Manifest() { | 60 UpdateResponse::Result::Manifest::~Manifest() { |
| 45 } | 61 } |
| 46 | 62 |
| 47 UpdateResponse::Result::Manifest::Package::Package() : size(0), sizediff(0) { | 63 UpdateResponse::Result::Manifest::Package::Package() : size(0), sizediff(0) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 for (xmlAttr* attr = node->properties; attr != NULL; attr = attr->next) { | 102 for (xmlAttr* attr = node->properties; attr != NULL; attr = attr->next) { |
| 87 if (!xmlStrcmp(attr->name, name) && attr->children && | 103 if (!xmlStrcmp(attr->name, name) && attr->children && |
| 88 attr->children->content) { | 104 attr->children->content) { |
| 89 return std::string( | 105 return std::string( |
| 90 reinterpret_cast<const char*>(attr->children->content)); | 106 reinterpret_cast<const char*>(attr->children->content)); |
| 91 } | 107 } |
| 92 } | 108 } |
| 93 return std::string(); | 109 return std::string(); |
| 94 } | 110 } |
| 95 | 111 |
| 112 // Returns the value of a named attribute, or nullptr . | |
| 113 static std::unique_ptr<std::string> GetAttributePtr( | |
| 114 xmlNode* node, | |
| 115 const char* attribute_name) { | |
| 116 const xmlChar* name = reinterpret_cast<const xmlChar*>(attribute_name); | |
| 117 for (xmlAttr* attr = node->properties; attr != NULL; attr = attr->next) { | |
| 118 if (!xmlStrcmp(attr->name, name) && attr->children && | |
| 119 attr->children->content) { | |
| 120 return std::unique_ptr<std::string>(new std::string( | |
| 121 reinterpret_cast<const char*>(attr->children->content))); | |
| 122 } | |
| 123 } | |
| 124 return nullptr; | |
| 125 } | |
| 126 | |
| 96 // This is used for the xml parser to report errors. This assumes the context | 127 // This is used for the xml parser to report errors. This assumes the context |
| 97 // is a pointer to a std::string where the error message should be appended. | 128 // is a pointer to a std::string where the error message should be appended. |
| 98 static void XmlErrorFunc(void* context, const char* message, ...) { | 129 static void XmlErrorFunc(void* context, const char* message, ...) { |
| 99 va_list args; | 130 va_list args; |
| 100 va_start(args, message); | 131 va_start(args, message); |
| 101 std::string* error = static_cast<std::string*>(context); | 132 std::string* error = static_cast<std::string*>(context); |
| 102 base::StringAppendV(error, message, args); | 133 base::StringAppendV(error, message, args); |
| 103 va_end(args); | 134 va_end(args); |
| 104 } | 135 } |
| 105 | 136 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 return false; | 292 return false; |
| 262 } | 293 } |
| 263 | 294 |
| 264 return ParseManifestTag(manifests[0], result, error); | 295 return ParseManifestTag(manifests[0], result, error); |
| 265 } | 296 } |
| 266 | 297 |
| 267 // Parses a single <app> tag. | 298 // Parses a single <app> tag. |
| 268 bool ParseAppTag(xmlNode* app, | 299 bool ParseAppTag(xmlNode* app, |
| 269 UpdateResponse::Result* result, | 300 UpdateResponse::Result* result, |
| 270 std::string* error) { | 301 std::string* error) { |
| 302 // Read cohort information. | |
| 303 result->cohort = GetAttributePtr(app, "cohort"); | |
| 304 result->cohort_hint = GetAttributePtr(app, "cohorthint"); | |
| 305 result->cohort_name = GetAttributePtr(app, "cohortname"); | |
| 306 | |
| 271 // Read the crx id. | 307 // Read the crx id. |
| 272 result->extension_id = GetAttribute(app, "appid"); | 308 result->extension_id = GetAttribute(app, "appid"); |
| 273 if (result->extension_id.empty()) { | 309 if (result->extension_id.empty()) { |
| 274 *error = "Missing appid on app node"; | 310 *error = "Missing appid on app node"; |
| 275 return false; | 311 return false; |
| 276 } | 312 } |
| 277 | 313 |
| 278 // Get the <updatecheck> tag. | 314 // Get the <updatecheck> tag. |
| 279 std::vector<xmlNode*> updates = GetChildren(app, "updatecheck"); | 315 std::vector<xmlNode*> updates = GetChildren(app, "updatecheck"); |
| 280 if (updates.empty()) { | 316 if (updates.empty()) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 results_.list.push_back(result); | 388 results_.list.push_back(result); |
| 353 } else { | 389 } else { |
| 354 ParseError("%s", error.c_str()); | 390 ParseError("%s", error.c_str()); |
| 355 } | 391 } |
| 356 } | 392 } |
| 357 | 393 |
| 358 return true; | 394 return true; |
| 359 } | 395 } |
| 360 | 396 |
| 361 } // namespace update_client | 397 } // namespace update_client |
| OLD | NEW |