| 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/utils.h" | 5 #include "components/update_client/utils.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <cmath> | 11 #include <cmath> |
| 12 #include <cstring> | 12 #include <cstring> |
| 13 #include <map> |
| 13 #include <vector> | 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/callback.h" | 16 #include "base/callback.h" |
| 16 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 17 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
| 18 #include "base/files/memory_mapped_file.h" | 19 #include "base/files/memory_mapped_file.h" |
| 19 #include "base/guid.h" | 20 #include "base/guid.h" |
| 20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_piece.h" | 22 #include "base/strings/string_piece.h" |
| 22 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 24 #include "base/sys_info.h" | 25 #include "base/sys_info.h" |
| 25 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
| 26 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 27 #include "components/crx_file/id_util.h" | 28 #include "components/crx_file/id_util.h" |
| 28 #include "components/update_client/configurator.h" | 29 #include "components/update_client/configurator.h" |
| 29 #include "components/update_client/crx_update_item.h" | 30 #include "components/update_client/crx_update_item.h" |
| 30 #include "components/update_client/update_client.h" | 31 #include "components/update_client/update_client.h" |
| 31 #include "components/update_client/update_client_errors.h" | 32 #include "components/update_client/update_client_errors.h" |
| 32 #include "components/update_client/update_query_params.h" | 33 #include "components/update_client/update_query_params.h" |
| 34 #include "components/update_client/updater_state.h" |
| 33 #include "crypto/secure_hash.h" | 35 #include "crypto/secure_hash.h" |
| 34 #include "crypto/sha2.h" | 36 #include "crypto/sha2.h" |
| 35 #include "net/base/load_flags.h" | 37 #include "net/base/load_flags.h" |
| 36 #include "net/url_request/url_fetcher.h" | 38 #include "net/url_request/url_fetcher.h" |
| 37 #include "net/url_request/url_request_context_getter.h" | 39 #include "net/url_request/url_request_context_getter.h" |
| 38 #include "net/url_request/url_request_status.h" | 40 #include "net/url_request/url_request_status.h" |
| 39 #include "url/gurl.h" | 41 #include "url/gurl.h" |
| 40 | 42 |
| 41 namespace update_client { | 43 namespace update_client { |
| 42 | 44 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 std::string GetServicePack() { | 85 std::string GetServicePack() { |
| 84 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
| 85 return base::win::OSInfo::GetInstance()->service_pack_str(); | 87 return base::win::OSInfo::GetInstance()->service_pack_str(); |
| 86 #else | 88 #else |
| 87 return std::string(); | 89 return std::string(); |
| 88 #endif | 90 #endif |
| 89 } | 91 } |
| 90 | 92 |
| 91 } // namespace | 93 } // namespace |
| 92 | 94 |
| 93 std::string BuildProtocolRequest(const std::string& prod_id, | 95 std::string BuildProtocolRequest( |
| 94 const std::string& browser_version, | 96 const std::string& prod_id, |
| 95 const std::string& channel, | 97 const std::string& browser_version, |
| 96 const std::string& lang, | 98 const std::string& channel, |
| 97 const std::string& os_long_name, | 99 const std::string& lang, |
| 98 const std::string& download_preference, | 100 const std::string& os_long_name, |
| 99 const std::string& request_body, | 101 const std::string& download_preference, |
| 100 const std::string& additional_attributes) { | 102 const std::string& request_body, |
| 103 const std::string& additional_attributes, |
| 104 const std::unique_ptr<UpdaterState::Attributes>& updater_state_attributes) { |
| 101 std::string request( | 105 std::string request( |
| 102 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 106 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 103 "<request protocol=\"3.0\" "); | 107 "<request protocol=\"3.0\" "); |
| 104 | 108 |
| 105 if (!additional_attributes.empty()) | 109 if (!additional_attributes.empty()) |
| 106 base::StringAppendF(&request, "%s ", additional_attributes.c_str()); | 110 base::StringAppendF(&request, "%s ", additional_attributes.c_str()); |
| 107 | 111 |
| 108 // Chrome version and platform information. | 112 // Chrome version and platform information. |
| 109 base::StringAppendF( | 113 base::StringAppendF( |
| 110 &request, | 114 &request, |
| 111 "version=\"%s-%s\" prodversion=\"%s\" " | 115 "version=\"%s-%s\" prodversion=\"%s\" " |
| 112 "requestid=\"{%s}\" lang=\"%s\" updaterchannel=\"%s\" prodchannel=\"%s\" " | 116 "requestid=\"{%s}\" lang=\"%s\" updaterchannel=\"%s\" prodchannel=\"%s\" " |
| 113 "os=\"%s\" arch=\"%s\" nacl_arch=\"%s\"", | 117 "os=\"%s\" arch=\"%s\" nacl_arch=\"%s\"", |
| 114 prod_id.c_str(), // "version" is prefixed by prod_id. | 118 prod_id.c_str(), // "version" is prefixed by prod_id. |
| 115 browser_version.c_str(), | 119 browser_version.c_str(), |
| 116 browser_version.c_str(), // "prodversion" | 120 browser_version.c_str(), // "prodversion" |
| 117 base::GenerateGUID().c_str(), // "requestid" | 121 base::GenerateGUID().c_str(), // "requestid" |
| 118 lang.c_str(), // "lang", | 122 lang.c_str(), // "lang" |
| 119 channel.c_str(), // "updaterchannel" | 123 channel.c_str(), // "updaterchannel" |
| 120 channel.c_str(), // "prodchannel" | 124 channel.c_str(), // "prodchannel" |
| 121 UpdateQueryParams::GetOS(), // "os" | 125 UpdateQueryParams::GetOS(), // "os" |
| 122 UpdateQueryParams::GetArch(), // "arch" | 126 UpdateQueryParams::GetArch(), // "arch" |
| 123 UpdateQueryParams::GetNaclArch()); // "nacl_arch" | 127 UpdateQueryParams::GetNaclArch()); // "nacl_arch" |
| 124 #if defined(OS_WIN) | 128 #if defined(OS_WIN) |
| 125 const bool is_wow64(base::win::OSInfo::GetInstance()->wow64_status() == | 129 const bool is_wow64(base::win::OSInfo::GetInstance()->wow64_status() == |
| 126 base::win::OSInfo::WOW64_ENABLED); | 130 base::win::OSInfo::WOW64_ENABLED); |
| 127 if (is_wow64) | 131 if (is_wow64) |
| 128 base::StringAppendF(&request, " wow64=\"1\""); | 132 base::StringAppendF(&request, " wow64=\"1\""); |
| 129 #endif | 133 #endif |
| 130 if (!download_preference.empty()) | 134 if (!download_preference.empty()) |
| 131 base::StringAppendF(&request, " dlpref=\"%s\"", | 135 base::StringAppendF(&request, " dlpref=\"%s\"", |
| 132 download_preference.c_str()); | 136 download_preference.c_str()); |
| 137 if (updater_state_attributes && |
| 138 updater_state_attributes->count(UpdaterState::kDomainJoined)) { |
| 139 base::StringAppendF( |
| 140 &request, " %s=\"%s\"", // domainjoined |
| 141 UpdaterState::kDomainJoined, |
| 142 (*updater_state_attributes)[UpdaterState::kDomainJoined].c_str()); |
| 143 } |
| 133 base::StringAppendF(&request, ">"); | 144 base::StringAppendF(&request, ">"); |
| 134 | 145 |
| 135 // HW platform information. | 146 // HW platform information. |
| 136 base::StringAppendF(&request, "<hw physmemory=\"%d\"/>", | 147 base::StringAppendF(&request, "<hw physmemory=\"%d\"/>", |
| 137 GetPhysicalMemoryGB()); // "physmem" in GB. | 148 GetPhysicalMemoryGB()); // "physmem" in GB. |
| 138 | 149 |
| 139 // OS version and platform information. | 150 // OS version and platform information. |
| 140 const std::string os_version = GetOSVersion(); | 151 const std::string os_version = GetOSVersion(); |
| 141 const std::string os_sp = GetServicePack(); | 152 const std::string os_sp = GetServicePack(); |
| 142 | |
| 143 base::StringAppendF( | 153 base::StringAppendF( |
| 144 &request, "<os platform=\"%s\" arch=\"%s\"", | 154 &request, "<os platform=\"%s\" arch=\"%s\"", |
| 145 os_long_name.c_str(), // "platform" | 155 os_long_name.c_str(), // "platform" |
| 146 base::SysInfo().OperatingSystemArchitecture().c_str()); // "arch" | 156 base::SysInfo().OperatingSystemArchitecture().c_str()); // "arch" |
| 147 if (!os_version.empty()) | 157 if (!os_version.empty()) |
| 148 base::StringAppendF(&request, " version=\"%s\"", os_version.c_str()); | 158 base::StringAppendF(&request, " version=\"%s\"", os_version.c_str()); |
| 149 if (!os_sp.empty()) | 159 if (!os_sp.empty()) |
| 150 base::StringAppendF(&request, " sp=\"%s\"", os_sp.c_str()); | 160 base::StringAppendF(&request, " sp=\"%s\"", os_sp.c_str()); |
| 151 base::StringAppendF(&request, "/>"); | 161 base::StringAppendF(&request, "/>"); |
| 152 | 162 |
| 163 #if defined(GOOGLE_CHROME_BUILD) |
| 164 // Updater state. |
| 165 if (updater_state_attributes) { |
| 166 base::StringAppendF(&request, "<updater"); |
| 167 for (const auto& attr : *updater_state_attributes) { |
| 168 if (attr.first != UpdaterState::kDomainJoined) { |
| 169 base::StringAppendF(&request, " %s=\"%s\"", attr.first.c_str(), |
| 170 attr.second.c_str()); |
| 171 } |
| 172 } |
| 173 base::StringAppendF(&request, "/>"); |
| 174 } |
| 175 #endif // GOOGLE_CHROME_BUILD |
| 176 |
| 153 // The actual payload of the request. | 177 // The actual payload of the request. |
| 154 base::StringAppendF(&request, "%s</request>", request_body.c_str()); | 178 base::StringAppendF(&request, "%s</request>", request_body.c_str()); |
| 155 | 179 |
| 156 return request; | 180 return request; |
| 157 } | 181 } |
| 158 | 182 |
| 159 std::unique_ptr<net::URLFetcher> SendProtocolRequest( | 183 std::unique_ptr<net::URLFetcher> SendProtocolRequest( |
| 160 const GURL& url, | 184 const GURL& url, |
| 161 const std::string& protocol_request, | 185 const std::string& protocol_request, |
| 162 net::URLFetcherDelegate* url_fetcher_delegate, | 186 net::URLFetcherDelegate* url_fetcher_delegate, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 [](const GURL& url) { return !url.SchemeIsCryptographic(); }), | 335 [](const GURL& url) { return !url.SchemeIsCryptographic(); }), |
| 312 urls->end()); | 336 urls->end()); |
| 313 } | 337 } |
| 314 | 338 |
| 315 CrxInstaller::Result InstallFunctionWrapper(base::Callback<bool()> callback) { | 339 CrxInstaller::Result InstallFunctionWrapper(base::Callback<bool()> callback) { |
| 316 return CrxInstaller::Result(callback.Run() ? InstallError::NONE | 340 return CrxInstaller::Result(callback.Run() ? InstallError::NONE |
| 317 : InstallError::GENERIC_ERROR); | 341 : InstallError::GENERIC_ERROR); |
| 318 } | 342 } |
| 319 | 343 |
| 320 } // namespace update_client | 344 } // namespace update_client |
| OLD | NEW |