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 Configurator& config, |
Sorin Jianu
2014/07/10 12:27:28
I was suggesting to not take the dependency on Con
tommycli
2014/07/10 16:08:14
Done.
| |
43 const std::string& request_body, | |
44 const std::string& additional_attributes) { | 44 const std::string& additional_attributes) { |
45 const std::string prod_id( | 45 const std::string prod_id( |
46 OmahaQueryParams::GetProdIdString(OmahaQueryParams::CHROME)); | 46 OmahaQueryParams::GetProdIdString(OmahaQueryParams::CHROME)); |
47 const chrome::VersionInfo chrome_version_info; | 47 const std::string app_version(config.ApplicationVersion().GetString()); |
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 | 48 |
52 std::string request( | 49 std::string request( |
53 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 50 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
54 "<request protocol=\"3.0\" "); | 51 "<request protocol=\"3.0\" "); |
55 | 52 |
56 if (!additional_attributes.empty()) | 53 if (!additional_attributes.empty()) |
57 base::StringAppendF(&request, "%s ", additional_attributes.c_str()); | 54 base::StringAppendF(&request, "%s ", additional_attributes.c_str()); |
58 | 55 |
59 // Chrome version and platform information. | 56 // Chrome version and platform information. |
60 base::StringAppendF( | 57 base::StringAppendF( |
61 &request, | 58 &request, |
62 "version=\"%s-%s\" prodversion=\"%s\" " | 59 "version=\"%s-%s\" prodversion=\"%s\" " |
63 "requestid=\"{%s}\" lang=\"%s\" updaterchannel=\"%s\" prodchannel=\"%s\" " | 60 "requestid=\"{%s}\" lang=\"%s\" updaterchannel=\"%s\" prodchannel=\"%s\" " |
64 "os=\"%s\" arch=\"%s\" nacl_arch=\"%s\"", | 61 "os=\"%s\" arch=\"%s\" nacl_arch=\"%s\"", |
65 prod_id.c_str(), | 62 prod_id.c_str(), |
66 chrome_version.c_str(), // "version" | 63 app_version.c_str(), // "version" |
Sorin Jianu
2014/07/10 12:27:28
I suggesting keeping the old naming. "app version"
tommycli
2014/07/10 16:08:14
Done. Changed to browser_version since it's techni
| |
67 chrome_version.c_str(), // "prodversion" | 64 app_version.c_str(), // "prodversion" |
68 base::GenerateGUID().c_str(), // "requestid" | 65 base::GenerateGUID().c_str(), // "requestid" |
69 lang.c_str(), // "lang", | 66 config.GetLang().c_str(), // "lang", |
70 channel.c_str(), // "updaterchannel" | 67 config.GetChannelString().c_str(), // "updaterchannel" |
Sorin Jianu
2014/07/10 12:27:28
we could also keep the local variable "channel", a
tommycli
2014/07/10 16:08:13
Done.
| |
71 channel.c_str(), // "prodchannel" | 68 config.GetChannelString().c_str(), // "prodchannel" |
72 OmahaQueryParams::GetOS(), // "os" | 69 OmahaQueryParams::GetOS(), // "os" |
73 OmahaQueryParams::GetArch(), // "arch" | 70 OmahaQueryParams::GetArch(), // "arch" |
74 OmahaQueryParams::GetNaclArch()); // "nacl_arch" | 71 OmahaQueryParams::GetNaclArch()); // "nacl_arch" |
75 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
76 const bool is_wow64(base::win::OSInfo::GetInstance()->wow64_status() == | 73 const bool is_wow64(base::win::OSInfo::GetInstance()->wow64_status() == |
77 base::win::OSInfo::WOW64_ENABLED); | 74 base::win::OSInfo::WOW64_ENABLED); |
78 if (is_wow64) | 75 if (is_wow64) |
79 base::StringAppendF(&request, " wow64=\"1\""); | 76 base::StringAppendF(&request, " wow64=\"1\""); |
80 #endif | 77 #endif |
81 base::StringAppendF(&request, ">"); | 78 base::StringAppendF(&request, ">"); |
82 | 79 |
83 // HW platform information. | 80 // HW platform information. |
84 base::StringAppendF(&request, | 81 base::StringAppendF(&request, |
85 "<hw physmemory=\"%d\"/>", | 82 "<hw physmemory=\"%d\"/>", |
86 GetPhysicalMemoryGB()); // "physmem" in GB. | 83 GetPhysicalMemoryGB()); // "physmem" in GB. |
87 | 84 |
88 // OS version and platform information. | 85 // OS version and platform information. |
89 base::StringAppendF( | 86 base::StringAppendF( |
90 &request, | 87 &request, |
91 "<os platform=\"%s\" version=\"%s\" arch=\"%s\"/>", | 88 "<os platform=\"%s\" version=\"%s\" arch=\"%s\"/>", |
92 chrome::VersionInfo().OSType().c_str(), // "platform" | 89 config.GetOSLongName().c_str(), // "platform" |
93 base::SysInfo().OperatingSystemVersion().c_str(), // "version" | 90 base::SysInfo().OperatingSystemVersion().c_str(), // "version" |
94 base::SysInfo().OperatingSystemArchitecture().c_str()); // "arch" | 91 base::SysInfo().OperatingSystemArchitecture().c_str()); // "arch" |
95 | 92 |
96 // The actual payload of the request. | 93 // The actual payload of the request. |
97 base::StringAppendF(&request, "%s</request>", request_body.c_str()); | 94 base::StringAppendF(&request, "%s</request>", request_body.c_str()); |
98 | 95 |
99 return request; | 96 return request; |
100 } | 97 } |
101 | 98 |
102 net::URLFetcher* SendProtocolRequest( | 99 net::URLFetcher* SendProtocolRequest( |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 DCHECK(extensions::Extension::IdIsValid(id)); | 182 DCHECK(extensions::Extension::IdIsValid(id)); |
186 return id; | 183 return id; |
187 } | 184 } |
188 | 185 |
189 std::string GetCrxComponentID(const CrxComponent& component) { | 186 std::string GetCrxComponentID(const CrxComponent& component) { |
190 return HexStringToID(StringToLowerASCII( | 187 return HexStringToID(StringToLowerASCII( |
191 base::HexEncode(&component.pk_hash[0], component.pk_hash.size() / 2))); | 188 base::HexEncode(&component.pk_hash[0], component.pk_hash.size() / 2))); |
192 } | 189 } |
193 | 190 |
194 } // namespace component_updater | 191 } // namespace component_updater |
OLD | NEW |