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 <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
21 #include "components/update_client/configurator.h" | 21 #include "components/update_client/configurator.h" |
22 #include "components/update_client/crx_update_item.h" | 22 #include "components/update_client/crx_update_item.h" |
23 #include "components/update_client/persisted_data.h" | 23 #include "components/update_client/persisted_data.h" |
24 #include "components/update_client/request_sender.h" | 24 #include "components/update_client/request_sender.h" |
| 25 #include "components/update_client/update_client.h" |
25 #include "components/update_client/utils.h" | 26 #include "components/update_client/utils.h" |
26 #include "url/gurl.h" | 27 #include "url/gurl.h" |
27 | 28 |
28 namespace update_client { | 29 namespace update_client { |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 // Returns a sanitized version of the brand or an empty string otherwise. | 33 // Returns a sanitized version of the brand or an empty string otherwise. |
33 std::string SanitizeBrand(const std::string& brand) { | 34 std::string SanitizeBrand(const std::string& brand) { |
34 return IsValidBrand(brand) ? brand : std::string(""); | 35 return IsValidBrand(brand) ? brand : std::string(""); |
35 } | 36 } |
36 | 37 |
37 // Returns a sanitized version of the |ap| or an empty string otherwise. | 38 // Filters invalid attributes from |installer_attributes|. |
38 std::string SanitizeAp(const std::string& ap) { | 39 update_client::InstallerAttributes SanitizeInstallerAttributes( |
39 return IsValidAp(ap) ? ap : std::string(); | 40 const update_client::InstallerAttributes& installer_attributes) { |
| 41 update_client::InstallerAttributes sanitized_attrs; |
| 42 for (const auto& attr : installer_attributes) { |
| 43 if (IsValidInstallerAttribute(attr)) |
| 44 sanitized_attrs.insert(attr); |
| 45 } |
| 46 return sanitized_attrs; |
40 } | 47 } |
41 | 48 |
42 // Returns true if at least one item requires network encryption. | 49 // Returns true if at least one item requires network encryption. |
43 bool IsEncryptionRequired(const std::vector<CrxUpdateItem*>& items) { | 50 bool IsEncryptionRequired(const std::vector<CrxUpdateItem*>& items) { |
44 for (const auto& item : items) { | 51 for (const auto& item : items) { |
45 if (item->component.requires_network_encryption) | 52 if (item->component.requires_network_encryption) |
46 return true; | 53 return true; |
47 } | 54 } |
48 return false; | 55 return false; |
49 } | 56 } |
(...skipping 13 matching lines...) Expand all Loading... |
63 // </packages> | 70 // </packages> |
64 // </app> | 71 // </app> |
65 std::string BuildUpdateCheckRequest(const Configurator& config, | 72 std::string BuildUpdateCheckRequest(const Configurator& config, |
66 const std::vector<CrxUpdateItem*>& items, | 73 const std::vector<CrxUpdateItem*>& items, |
67 PersistedData* metadata, | 74 PersistedData* metadata, |
68 const std::string& additional_attributes) { | 75 const std::string& additional_attributes) { |
69 const std::string brand(SanitizeBrand(config.GetBrand())); | 76 const std::string brand(SanitizeBrand(config.GetBrand())); |
70 std::string app_elements; | 77 std::string app_elements; |
71 for (size_t i = 0; i != items.size(); ++i) { | 78 for (size_t i = 0; i != items.size(); ++i) { |
72 const CrxUpdateItem* item = items[i]; | 79 const CrxUpdateItem* item = items[i]; |
73 const std::string ap(SanitizeAp(item->component.ap)); | 80 const update_client::InstallerAttributes installer_attributes( |
| 81 SanitizeInstallerAttributes(item->component.installer_attributes)); |
74 std::string app("<app "); | 82 std::string app("<app "); |
75 base::StringAppendF(&app, "appid=\"%s\" version=\"%s\"", item->id.c_str(), | 83 base::StringAppendF(&app, "appid=\"%s\" version=\"%s\"", item->id.c_str(), |
76 item->component.version.GetString().c_str()); | 84 item->component.version.GetString().c_str()); |
77 if (!brand.empty()) | 85 if (!brand.empty()) |
78 base::StringAppendF(&app, " brand=\"%s\"", brand.c_str()); | 86 base::StringAppendF(&app, " brand=\"%s\"", brand.c_str()); |
79 if (item->on_demand) | 87 if (item->on_demand) |
80 base::StringAppendF(&app, " installsource=\"ondemand\""); | 88 base::StringAppendF(&app, " installsource=\"ondemand\""); |
81 if (!ap.empty()) | 89 |
82 base::StringAppendF(&app, " ap=\"%s\"", ap.c_str()); | 90 for (const auto& attr : installer_attributes) |
| 91 base::StringAppendF(&app, " %s=\"%s\"", attr.first.c_str(), |
| 92 attr.second.c_str()); |
| 93 |
83 base::StringAppendF(&app, ">"); | 94 base::StringAppendF(&app, ">"); |
84 base::StringAppendF(&app, "<updatecheck />"); | 95 base::StringAppendF(&app, "<updatecheck />"); |
85 base::StringAppendF(&app, "<ping rd=\"%d\" ping_freshness=\"%s\" />", | 96 base::StringAppendF(&app, "<ping rd=\"%d\" ping_freshness=\"%s\" />", |
86 metadata->GetDateLastRollCall(item->id), | 97 metadata->GetDateLastRollCall(item->id), |
87 metadata->GetPingFreshness(item->id).c_str()); | 98 metadata->GetPingFreshness(item->id).c_str()); |
88 if (!item->component.fingerprint.empty()) { | 99 if (!item->component.fingerprint.empty()) { |
89 base::StringAppendF(&app, | 100 base::StringAppendF(&app, |
90 "<packages>" | 101 "<packages>" |
91 "<package fp=\"%s\"/>" | 102 "<package fp=\"%s\"/>" |
92 "</packages>", | 103 "</packages>", |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } // namespace | 212 } // namespace |
202 | 213 |
203 std::unique_ptr<UpdateChecker> UpdateChecker::Create( | 214 std::unique_ptr<UpdateChecker> UpdateChecker::Create( |
204 const scoped_refptr<Configurator>& config, | 215 const scoped_refptr<Configurator>& config, |
205 PersistedData* persistent) { | 216 PersistedData* persistent) { |
206 return std::unique_ptr<UpdateChecker>( | 217 return std::unique_ptr<UpdateChecker>( |
207 new UpdateCheckerImpl(config, persistent)); | 218 new UpdateCheckerImpl(config, persistent)); |
208 } | 219 } |
209 | 220 |
210 } // namespace update_client | 221 } // namespace update_client |
OLD | NEW |