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_checker.h" | 5 #include "components/update_client/update_checker.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 namespace update_client { | 27 namespace update_client { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 // Returns a sanitized version of the brand or an empty string otherwise. | 31 // Returns a sanitized version of the brand or an empty string otherwise. |
32 std::string SanitizeBrand(const std::string& brand) { | 32 std::string SanitizeBrand(const std::string& brand) { |
33 return IsValidBrand(brand) ? brand : std::string(""); | 33 return IsValidBrand(brand) ? brand : std::string(""); |
34 } | 34 } |
35 | 35 |
| 36 // Returns a sanitized version of the |ap| or an empty string otherwise. |
| 37 std::string SanitizeAp(const std::string& ap) { |
| 38 return IsValidAp(ap) ? ap : std::string(); |
| 39 } |
| 40 |
36 // Returns true if at least one item requires network encryption. | 41 // Returns true if at least one item requires network encryption. |
37 bool IsEncryptionRequired(const std::vector<CrxUpdateItem*>& items) { | 42 bool IsEncryptionRequired(const std::vector<CrxUpdateItem*>& items) { |
38 for (const auto& item : items) { | 43 for (const auto& item : items) { |
39 if (item->component.requires_network_encryption) | 44 if (item->component.requires_network_encryption) |
40 return true; | 45 return true; |
41 } | 46 } |
42 return false; | 47 return false; |
43 } | 48 } |
44 | 49 |
45 // Builds an update check request for |components|. |additional_attributes| is | 50 // Builds an update check request for |components|. |additional_attributes| is |
(...skipping 10 matching lines...) Expand all Loading... |
56 // <package fp="abcd" /> | 61 // <package fp="abcd" /> |
57 // </packages> | 62 // </packages> |
58 // </app> | 63 // </app> |
59 std::string BuildUpdateCheckRequest(const Configurator& config, | 64 std::string BuildUpdateCheckRequest(const Configurator& config, |
60 const std::vector<CrxUpdateItem*>& items, | 65 const std::vector<CrxUpdateItem*>& items, |
61 const std::string& additional_attributes) { | 66 const std::string& additional_attributes) { |
62 const std::string brand(SanitizeBrand(config.GetBrand())); | 67 const std::string brand(SanitizeBrand(config.GetBrand())); |
63 std::string app_elements; | 68 std::string app_elements; |
64 for (size_t i = 0; i != items.size(); ++i) { | 69 for (size_t i = 0; i != items.size(); ++i) { |
65 const CrxUpdateItem* item = items[i]; | 70 const CrxUpdateItem* item = items[i]; |
| 71 const std::string ap(SanitizeAp(item->component.ap)); |
66 std::string app("<app "); | 72 std::string app("<app "); |
67 base::StringAppendF(&app, "appid=\"%s\" version=\"%s\"", item->id.c_str(), | 73 base::StringAppendF(&app, "appid=\"%s\" version=\"%s\"", item->id.c_str(), |
68 item->component.version.GetString().c_str()); | 74 item->component.version.GetString().c_str()); |
69 if (!brand.empty()) | 75 if (!brand.empty()) |
70 base::StringAppendF(&app, " brand=\"%s\"", brand.c_str()); | 76 base::StringAppendF(&app, " brand=\"%s\"", brand.c_str()); |
71 if (item->on_demand) | 77 if (item->on_demand) |
72 base::StringAppendF(&app, " installsource=\"ondemand\""); | 78 base::StringAppendF(&app, " installsource=\"ondemand\""); |
| 79 if (!ap.empty()) |
| 80 base::StringAppendF(&app, " ap=\"%s\"", ap.c_str()); |
73 base::StringAppendF(&app, ">"); | 81 base::StringAppendF(&app, ">"); |
74 base::StringAppendF(&app, "<updatecheck />"); | 82 base::StringAppendF(&app, "<updatecheck />"); |
75 if (!item->component.fingerprint.empty()) { | 83 if (!item->component.fingerprint.empty()) { |
76 base::StringAppendF(&app, | 84 base::StringAppendF(&app, |
77 "<packages>" | 85 "<packages>" |
78 "<package fp=\"%s\"/>" | 86 "<package fp=\"%s\"/>" |
79 "</packages>", | 87 "</packages>", |
80 item->component.fingerprint.c_str()); | 88 item->component.fingerprint.c_str()); |
81 } | 89 } |
82 base::StringAppendF(&app, "</app>"); | 90 base::StringAppendF(&app, "</app>"); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 179 } |
172 | 180 |
173 } // namespace | 181 } // namespace |
174 | 182 |
175 scoped_ptr<UpdateChecker> UpdateChecker::Create( | 183 scoped_ptr<UpdateChecker> UpdateChecker::Create( |
176 const scoped_refptr<Configurator>& config) { | 184 const scoped_refptr<Configurator>& config) { |
177 return scoped_ptr<UpdateChecker>(new UpdateCheckerImpl(config)); | 185 return scoped_ptr<UpdateChecker>(new UpdateCheckerImpl(config)); |
178 } | 186 } |
179 | 187 |
180 } // namespace update_client | 188 } // namespace update_client |
OLD | NEW |