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