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

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

Powered by Google App Engine
This is Rietveld 408576698