OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/component_updater/component_updater_utils.h" | 5 #include "chrome/browser/component_updater/component_updater_utils.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.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/sys_info.h" | 16 #include "base/sys_info.h" |
17 #include "base/win/windows_version.h" | 17 #include "chrome/browser/component_updater/component_updater_configurator.h" |
18 #include "chrome/browser/component_updater/crx_update_item.h" | 18 #include "chrome/browser/component_updater/crx_update_item.h" |
19 #include "chrome/browser/omaha_query_params/chrome_omaha_query_params_delegate.h
" | |
20 #include "chrome/common/chrome_version_info.h" | |
21 #include "components/omaha_query_params/omaha_query_params.h" | |
22 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
23 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
24 #include "net/url_request/url_fetcher.h" | 21 #include "net/url_request/url_fetcher.h" |
25 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
26 #include "net/url_request/url_request_status.h" | 23 #include "net/url_request/url_request_status.h" |
27 | 24 |
28 using omaha_query_params::OmahaQueryParams; | |
29 | |
30 namespace component_updater { | 25 namespace component_updater { |
31 | 26 |
32 namespace { | 27 namespace { |
33 | 28 |
34 // Returns the amount of physical memory in GB, rounded to the nearest GB. | 29 // Returns the amount of physical memory in GB, rounded to the nearest GB. |
35 int GetPhysicalMemoryGB() { | 30 int GetPhysicalMemoryGB() { |
36 const double kOneGB = 1024 * 1024 * 1024; | 31 const double kOneGB = 1024 * 1024 * 1024; |
37 const int64 phys_mem = base::SysInfo::AmountOfPhysicalMemory(); | 32 const int64 phys_mem = base::SysInfo::AmountOfPhysicalMemory(); |
38 return static_cast<int>(std::floor(0.5 + phys_mem / kOneGB)); | 33 return static_cast<int>(std::floor(0.5 + phys_mem / kOneGB)); |
39 } | 34 } |
40 | 35 |
41 } // namespace | 36 } // namespace |
42 | 37 |
43 std::string BuildProtocolRequest(const std::string& request_body, | 38 std::string BuildProtocolRequest(const Configurator& config, |
| 39 const std::string& request_body, |
44 const std::string& additional_attributes) { | 40 const std::string& additional_attributes) { |
45 const std::string prod_id( | |
46 OmahaQueryParams::GetProdIdString(OmahaQueryParams::CHROME)); | |
47 const chrome::VersionInfo chrome_version_info; | |
48 const std::string chrome_version(chrome_version_info.Version()); | |
49 const std::string channel(ChromeOmahaQueryParamsDelegate::GetChannelString()); | |
50 const std::string lang(ChromeOmahaQueryParamsDelegate::GetLang()); | |
51 | |
52 std::string request( | 41 std::string request( |
53 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 42 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
54 "<request protocol=\"3.0\" "); | 43 "<request protocol=\"3.0\" "); |
55 | 44 |
56 if (!additional_attributes.empty()) | 45 if (!additional_attributes.empty()) |
57 base::StringAppendF(&request, "%s ", additional_attributes.c_str()); | 46 base::StringAppendF(&request, "%s ", additional_attributes.c_str()); |
58 | 47 |
59 // Chrome version and platform information. | 48 base::StringAppendF(&request, "requestid=\\\"{%s}\\\" ", |
60 base::StringAppendF( | 49 base::GenerateGUID().c_str()); // "requestid" |
61 &request, | 50 |
62 "version=\"%s-%s\" prodversion=\"%s\" " | 51 if (!config.PlatformRequestParams().empty()) { |
63 "requestid=\"{%s}\" lang=\"%s\" updaterchannel=\"%s\" prodchannel=\"%s\" " | 52 base::StringAppendF(&request, "%s ", |
64 "os=\"%s\" arch=\"%s\" nacl_arch=\"%s\"", | 53 config.PlatformRequestParams().c_str()); |
65 prod_id.c_str(), | 54 } |
66 chrome_version.c_str(), // "version" | 55 |
67 chrome_version.c_str(), // "prodversion" | |
68 base::GenerateGUID().c_str(), // "requestid" | |
69 lang.c_str(), // "lang", | |
70 channel.c_str(), // "updaterchannel" | |
71 channel.c_str(), // "prodchannel" | |
72 OmahaQueryParams::GetOS(), // "os" | |
73 OmahaQueryParams::GetArch(), // "arch" | |
74 OmahaQueryParams::GetNaclArch()); // "nacl_arch" | |
75 #if defined(OS_WIN) | |
76 const bool is_wow64(base::win::OSInfo::GetInstance()->wow64_status() == | |
77 base::win::OSInfo::WOW64_ENABLED); | |
78 if (is_wow64) | |
79 base::StringAppendF(&request, " wow64=\"1\""); | |
80 #endif | |
81 base::StringAppendF(&request, ">"); | 56 base::StringAppendF(&request, ">"); |
82 | 57 |
83 // HW platform information. | 58 // HW platform information. |
84 base::StringAppendF(&request, | 59 base::StringAppendF(&request, |
85 "<hw physmemory=\"%d\"/>", | 60 "<hw physmemory=\"%d\"/>", |
86 GetPhysicalMemoryGB()); // "physmem" in GB. | 61 GetPhysicalMemoryGB()); // "physmem" in GB. |
87 | 62 |
88 // OS version and platform information. | 63 // OS version and platform information. |
89 base::StringAppendF( | 64 base::StringAppendF(&request, "%s", config.RequestOSTag().c_str()); |
90 &request, | |
91 "<os platform=\"%s\" version=\"%s\" arch=\"%s\"/>", | |
92 chrome::VersionInfo().OSType().c_str(), // "platform" | |
93 base::SysInfo().OperatingSystemVersion().c_str(), // "version" | |
94 base::SysInfo().OperatingSystemArchitecture().c_str()); // "arch" | |
95 | 65 |
96 // The actual payload of the request. | 66 // The actual payload of the request. |
97 base::StringAppendF(&request, "%s</request>", request_body.c_str()); | 67 base::StringAppendF(&request, "%s</request>", request_body.c_str()); |
98 | 68 |
99 return request; | 69 return request; |
100 } | 70 } |
101 | 71 |
102 net::URLFetcher* SendProtocolRequest( | 72 net::URLFetcher* SendProtocolRequest( |
103 const GURL& url, | 73 const GURL& url, |
104 const std::string& protocol_request, | 74 const std::string& protocol_request, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 DCHECK(extensions::Extension::IdIsValid(id)); | 155 DCHECK(extensions::Extension::IdIsValid(id)); |
186 return id; | 156 return id; |
187 } | 157 } |
188 | 158 |
189 std::string GetCrxComponentID(const CrxComponent& component) { | 159 std::string GetCrxComponentID(const CrxComponent& component) { |
190 return HexStringToID(StringToLowerASCII( | 160 return HexStringToID(StringToLowerASCII( |
191 base::HexEncode(&component.pk_hash[0], component.pk_hash.size() / 2))); | 161 base::HexEncode(&component.pk_hash[0], component.pk_hash.size() / 2))); |
192 } | 162 } |
193 | 163 |
194 } // namespace component_updater | 164 } // namespace component_updater |
OLD | NEW |