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

Side by Side 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, 3 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 unified diff | Download patch
OLDNEW
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>
11 11
12 #include "base/memory/ptr_util.h"
12 #include "base/stl_util.h" 13 #include "base/stl_util.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/version.h" 17 #include "base/version.h"
17 #include "libxml/tree.h" 18 #include "libxml/tree.h"
18 #include "third_party/libxml/chromium/libxml_utils.h" 19 #include "third_party/libxml/chromium/libxml_utils.h"
19 20
20 namespace update_client { 21 namespace update_client {
21 22
22 static const char* kExpectedResponseProtocol = "3.0"; 23 static const char* kExpectedResponseProtocol = "3.0";
24 const char UpdateResponse::Result::kCohort[] = "cohort";
25 const char UpdateResponse::Result::kCohortHint[] = "cohorthint";
26 const char UpdateResponse::Result::kCohortName[] = "cohortname";
23 27
24 UpdateResponse::UpdateResponse() { 28 UpdateResponse::UpdateResponse() {
25 } 29 }
26 UpdateResponse::~UpdateResponse() { 30 UpdateResponse::~UpdateResponse() {
27 } 31 }
28 32
29 UpdateResponse::Results::Results() : daystart_elapsed_seconds(kNoDaystart) { 33 UpdateResponse::Results::Results() : daystart_elapsed_seconds(kNoDaystart) {
30 } 34 }
31 UpdateResponse::Results::Results(const Results& other) = default; 35 UpdateResponse::Results::Results(const Results& other) = default;
32 UpdateResponse::Results::~Results() { 36 UpdateResponse::Results::~Results() {
33 } 37 }
34 38
35 UpdateResponse::Result::Result() { 39 UpdateResponse::Result::Result() {}
36 }
37 UpdateResponse::Result::Result(const Result& other) = default; 40 UpdateResponse::Result::Result(const Result& other) = default;
38 UpdateResponse::Result::~Result() { 41 UpdateResponse::Result::~Result() {
39 } 42 }
40 43
41 UpdateResponse::Result::Manifest::Manifest() { 44 UpdateResponse::Result::Manifest::Manifest() {
42 } 45 }
43 UpdateResponse::Result::Manifest::Manifest(const Manifest& other) = default; 46 UpdateResponse::Result::Manifest::Manifest(const Manifest& other) = default;
44 UpdateResponse::Result::Manifest::~Manifest() { 47 UpdateResponse::Result::Manifest::~Manifest() {
45 } 48 }
46 49
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 for (xmlAttr* attr = node->properties; attr != NULL; attr = attr->next) { 89 for (xmlAttr* attr = node->properties; attr != NULL; attr = attr->next) {
87 if (!xmlStrcmp(attr->name, name) && attr->children && 90 if (!xmlStrcmp(attr->name, name) && attr->children &&
88 attr->children->content) { 91 attr->children->content) {
89 return std::string( 92 return std::string(
90 reinterpret_cast<const char*>(attr->children->content)); 93 reinterpret_cast<const char*>(attr->children->content));
91 } 94 }
92 } 95 }
93 return std::string(); 96 return std::string();
94 } 97 }
95 98
99 // Returns the value of a named attribute, or nullptr .
100 static std::unique_ptr<std::string> GetAttributePtr(
101 xmlNode* node,
102 const char* attribute_name) {
103 const xmlChar* name = reinterpret_cast<const xmlChar*>(attribute_name);
104 for (xmlAttr* attr = node->properties; attr != NULL; attr = attr->next) {
105 if (!xmlStrcmp(attr->name, name) && attr->children &&
106 attr->children->content) {
107 return base::MakeUnique<std::string>(
108 reinterpret_cast<const char*>(attr->children->content));
109 }
110 }
111 return nullptr;
112 }
113
96 // This is used for the xml parser to report errors. This assumes the context 114 // 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. 115 // is a pointer to a std::string where the error message should be appended.
98 static void XmlErrorFunc(void* context, const char* message, ...) { 116 static void XmlErrorFunc(void* context, const char* message, ...) {
99 va_list args; 117 va_list args;
100 va_start(args, message); 118 va_start(args, message);
101 std::string* error = static_cast<std::string*>(context); 119 std::string* error = static_cast<std::string*>(context);
102 base::StringAppendV(error, message, args); 120 base::StringAppendV(error, message, args);
103 va_end(args); 121 va_end(args);
104 } 122 }
105 123
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 return false; 279 return false;
262 } 280 }
263 281
264 return ParseManifestTag(manifests[0], result, error); 282 return ParseManifestTag(manifests[0], result, error);
265 } 283 }
266 284
267 // Parses a single <app> tag. 285 // Parses a single <app> tag.
268 bool ParseAppTag(xmlNode* app, 286 bool ParseAppTag(xmlNode* app,
269 UpdateResponse::Result* result, 287 UpdateResponse::Result* result,
270 std::string* error) { 288 std::string* error) {
289 // Read cohort information.
290 auto cohort = GetAttributePtr(app, "cohort");
291 static const char* attrs[] = {UpdateResponse::Result::kCohort,
292 UpdateResponse::Result::kCohortHint,
293 UpdateResponse::Result::kCohortName};
294 for (const auto& attr : attrs) {
295 auto value = GetAttributePtr(app, attr);
296 if (value)
297 result->cohort_attrs.insert({attr, *value});
298 }
299
271 // Read the crx id. 300 // Read the crx id.
272 result->extension_id = GetAttribute(app, "appid"); 301 result->extension_id = GetAttribute(app, "appid");
273 if (result->extension_id.empty()) { 302 if (result->extension_id.empty()) {
274 *error = "Missing appid on app node"; 303 *error = "Missing appid on app node";
275 return false; 304 return false;
276 } 305 }
277 306
278 // Get the <updatecheck> tag. 307 // Get the <updatecheck> tag.
279 std::vector<xmlNode*> updates = GetChildren(app, "updatecheck"); 308 std::vector<xmlNode*> updates = GetChildren(app, "updatecheck");
280 if (updates.empty()) { 309 if (updates.empty()) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 results_.list.push_back(result); 381 results_.list.push_back(result);
353 } else { 382 } else {
354 ParseError("%s", error.c_str()); 383 ParseError("%s", error.c_str());
355 } 384 }
356 } 385 }
357 386
358 return true; 387 return true;
359 } 388 }
360 389
361 } // namespace update_client 390 } // namespace update_client
OLDNEW
« 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