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> |
| 11 | 11 |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "base/version.h" | 17 #include "base/version.h" |
| 18 #include "libxml/tree.h" | 18 #include "libxml/tree.h" |
| 19 #include "third_party/libxml/chromium/libxml_utils.h" | 19 #include "third_party/libxml/chromium/libxml_utils.h" |
| 20 | 20 |
| 21 namespace update_client { | 21 namespace update_client { |
| 22 | 22 |
| 23 static const char* kExpectedResponseProtocol = "3.0"; | 23 static const char* kExpectedResponseProtocol = "3.0"; |
| 24 const char UpdateResponse::Result::kCohort[] = "cohort"; | 24 const char UpdateResponse::Result::kCohort[] = "cohort"; |
| 25 const char UpdateResponse::Result::kCohortHint[] = "cohorthint"; | 25 const char UpdateResponse::Result::kCohortHint[] = "cohorthint"; |
| 26 const char UpdateResponse::Result::kCohortName[] = "cohortname"; | 26 const char UpdateResponse::Result::kCohortName[] = "cohortname"; |
| 27 | 27 |
| 28 UpdateResponse::UpdateResponse() { | 28 UpdateResponse::UpdateResponse() = default; |
| 29 } | 29 UpdateResponse::~UpdateResponse() = default; |
| 30 UpdateResponse::~UpdateResponse() { | |
| 31 } | |
| 32 | 30 |
| 33 UpdateResponse::Results::Results() : daystart_elapsed_seconds(kNoDaystart) { | 31 UpdateResponse::Results::Results() = default; |
| 34 } | |
| 35 UpdateResponse::Results::Results(const Results& other) = default; | 32 UpdateResponse::Results::Results(const Results& other) = default; |
| 36 UpdateResponse::Results::~Results() { | 33 UpdateResponse::Results::~Results() = default; |
| 37 } | |
| 38 | 34 |
| 39 UpdateResponse::Result::Result() {} | 35 UpdateResponse::Result::Result() = default; |
| 40 UpdateResponse::Result::Result(const Result& other) = default; | 36 UpdateResponse::Result::Result(const Result& other) = default; |
| 41 UpdateResponse::Result::~Result() { | 37 UpdateResponse::Result::~Result() = default; |
| 42 } | |
| 43 | 38 |
| 44 UpdateResponse::Result::Manifest::Manifest() { | 39 UpdateResponse::Result::Manifest::Manifest() = default; |
| 45 } | |
| 46 UpdateResponse::Result::Manifest::Manifest(const Manifest& other) = default; | 40 UpdateResponse::Result::Manifest::Manifest(const Manifest& other) = default; |
| 47 UpdateResponse::Result::Manifest::~Manifest() { | 41 UpdateResponse::Result::Manifest::~Manifest() = default; |
| 48 } | |
| 49 | 42 |
| 50 UpdateResponse::Result::Manifest::Package::Package() : size(0), sizediff(0) { | 43 UpdateResponse::Result::Manifest::Package::Package() = default; |
| 51 } | |
| 52 UpdateResponse::Result::Manifest::Package::Package(const Package& other) = | 44 UpdateResponse::Result::Manifest::Package::Package(const Package& other) = |
| 53 default; | 45 default; |
| 54 UpdateResponse::Result::Manifest::Package::~Package() { | 46 UpdateResponse::Result::Manifest::Package::~Package() = default; |
| 55 } | |
| 56 | 47 |
| 57 void UpdateResponse::ParseError(const char* details, ...) { | 48 void UpdateResponse::ParseError(const char* details, ...) { |
| 58 va_list args; | 49 va_list args; |
| 59 va_start(args, details); | 50 va_start(args, details); |
| 60 | 51 |
| 61 if (!errors_.empty()) { | 52 if (!errors_.empty()) { |
| 62 errors_ += "\r\n"; | 53 errors_ += "\r\n"; |
| 63 } | 54 } |
| 64 | 55 |
| 65 base::StringAppendV(&errors_, details, args); | 56 base::StringAppendV(&errors_, details, args); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 | 238 |
| 248 // Expect at least one url for full update. | 239 // Expect at least one url for full update. |
| 249 if (result->crx_urls.empty()) { | 240 if (result->crx_urls.empty()) { |
| 250 *error = "Missing valid url for full update."; | 241 *error = "Missing valid url for full update."; |
| 251 return false; | 242 return false; |
| 252 } | 243 } |
| 253 | 244 |
| 254 return true; | 245 return true; |
| 255 } | 246 } |
| 256 | 247 |
| 248 // Parses the <actions> tag. It picks up the "run" attribute of the first | |
| 249 // "action" element in "actions". | |
| 250 void ParseActionsTag(xmlNode* updatecheck, UpdateResponse::Result* result) { | |
| 251 std::vector<xmlNode*> actions = GetChildren(updatecheck, "actions"); | |
| 252 if (actions.empty()) | |
| 253 return; | |
| 254 | |
| 255 std::vector<xmlNode*> action = GetChildren(actions.front(), "action"); | |
| 256 if (action.empty()) | |
| 257 return; | |
| 258 | |
| 259 result->action_run = GetAttribute(action.front(), "run"); | |
| 260 } | |
| 261 | |
| 257 // Parses the <updatecheck> tag. | 262 // Parses the <updatecheck> tag. |
| 258 bool ParseUpdateCheckTag(xmlNode* updatecheck, | 263 bool ParseUpdateCheckTag(xmlNode* updatecheck, |
| 259 UpdateResponse::Result* result, | 264 UpdateResponse::Result* result, |
| 260 std::string* error) { | 265 std::string* error) { |
| 261 // Read the |status| attribute. | 266 // Read the |status| attribute. |
| 262 result->status = GetAttribute(updatecheck, "status"); | 267 result->status = GetAttribute(updatecheck, "status"); |
| 263 if (result->status.empty()) { | 268 if (result->status.empty()) { |
| 264 *error = "Missing status on updatecheck node"; | 269 *error = "Missing status on updatecheck node"; |
| 265 return false; | 270 return false; |
| 266 } | 271 } |
| 267 | 272 |
| 268 if (result->status == "noupdate") | 273 if (result->status == "noupdate") { |
| 274 ParseActionsTag(updatecheck, result); | |
| 269 return true; | 275 return true; |
| 276 } | |
| 270 | 277 |
| 271 if (result->status == "ok") { | 278 if (result->status == "ok") { |
| 272 std::vector<xmlNode*> urls = GetChildren(updatecheck, "urls"); | 279 std::vector<xmlNode*> urls = GetChildren(updatecheck, "urls"); |
| 273 if (urls.empty()) { | 280 if (urls.empty()) { |
| 274 *error = "Missing urls on updatecheck."; | 281 *error = "Missing urls on updatecheck."; |
| 275 return false; | 282 return false; |
| 276 } | 283 } |
| 277 | 284 |
| 278 if (!ParseUrlsTag(urls[0], result, error)) { | 285 if (!ParseUrlsTag(urls[0], result, error)) { |
| 279 return false; | 286 return false; |
| 280 } | 287 } |
| 281 | 288 |
| 282 std::vector<xmlNode*> manifests = GetChildren(updatecheck, "manifest"); | 289 std::vector<xmlNode*> manifests = GetChildren(updatecheck, "manifest"); |
| 283 if (manifests.empty()) { | 290 if (manifests.empty()) { |
| 284 *error = "Missing manifest on updatecheck."; | 291 *error = "Missing manifest on updatecheck."; |
| 285 return false; | 292 return false; |
| 286 } | 293 } |
| 287 | 294 |
| 295 ParseActionsTag(updatecheck, result); | |
|
waffles
2017/04/28 17:01:02
Is there harm in moving these out of the ifs? (Alw
Sorin Jianu
2017/04/28 17:03:01
There is no obvious harm but this way the code is
| |
| 288 return ParseManifestTag(manifests[0], result, error); | 296 return ParseManifestTag(manifests[0], result, error); |
| 289 } | 297 } |
| 290 | 298 |
| 291 // Return the |updatecheck| element status as a parsing error. | 299 // Return the |updatecheck| element status as a parsing error. |
| 292 *error = result->status; | 300 *error = result->status; |
| 293 return false; | 301 return false; |
| 294 } | 302 } |
| 295 | 303 |
| 296 // Parses a single <app> tag. | 304 // Parses a single <app> tag. |
| 297 bool ParseAppTag(xmlNode* app, | 305 bool ParseAppTag(xmlNode* app, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 results_.list.push_back(result); | 400 results_.list.push_back(result); |
| 393 } else { | 401 } else { |
| 394 ParseError("%s", error.c_str()); | 402 ParseError("%s", error.c_str()); |
| 395 } | 403 } |
| 396 } | 404 } |
| 397 | 405 |
| 398 return true; | 406 return true; |
| 399 } | 407 } |
| 400 | 408 |
| 401 } // namespace update_client | 409 } // namespace update_client |
| OLD | NEW |