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/version.h" |
17 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
18 #include "chrome/browser/component_updater/component_updater_service.h" | 19 #include "chrome/browser/component_updater/component_updater_service.h" |
19 #include "chrome/browser/component_updater/crx_update_item.h" | 20 #include "chrome/browser/component_updater/crx_update_item.h" |
20 #include "chrome/browser/omaha_query_params/omaha_query_params.h" | 21 #include "chrome/browser/omaha_query_params/omaha_query_params.h" |
21 #include "chrome/common/chrome_version_info.h" | |
22 #include "extensions/common/extension.h" | 22 #include "extensions/common/extension.h" |
23 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
24 #include "net/url_request/url_fetcher.h" | 24 #include "net/url_request/url_fetcher.h" |
25 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
26 #include "net/url_request/url_request_status.h" | 26 #include "net/url_request/url_request_status.h" |
27 | 27 |
28 namespace component_updater { | 28 namespace component_updater { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 // Returns the amount of physical memory in GB, rounded to the nearest GB. | 32 // Returns the amount of physical memory in GB, rounded to the nearest GB. |
33 int GetPhysicalMemoryGB() { | 33 int GetPhysicalMemoryGB() { |
34 const double kOneGB = 1024 * 1024 * 1024; | 34 const double kOneGB = 1024 * 1024 * 1024; |
35 const int64 phys_mem = base::SysInfo::AmountOfPhysicalMemory(); | 35 const int64 phys_mem = base::SysInfo::AmountOfPhysicalMemory(); |
36 return static_cast<int>(std::floor(0.5 + phys_mem / kOneGB)); | 36 return static_cast<int>(std::floor(0.5 + phys_mem / kOneGB)); |
37 } | 37 } |
38 | 38 |
39 } // namespace | 39 } // namespace |
40 | 40 |
41 std::string BuildProtocolRequest(const std::string& request_body, | 41 std::string BuildProtocolRequest(const std::string& chrome_version, |
| 42 const std::string& platform_name, |
| 43 const std::string& request_body, |
42 const std::string& additional_attributes) { | 44 const std::string& additional_attributes) { |
43 const std::string prod_id(chrome::OmahaQueryParams::GetProdIdString( | 45 const std::string prod_id(chrome::OmahaQueryParams::GetProdIdString( |
44 chrome::OmahaQueryParams::CHROME)); | 46 chrome::OmahaQueryParams::CHROME)); |
45 const chrome::VersionInfo chrome_version_info; | |
46 const std::string chrome_version(chrome_version_info.Version()); | |
47 | 47 |
48 std::string request( | 48 std::string request( |
49 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 49 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
50 "<request protocol=\"3.0\" "); | 50 "<request protocol=\"3.0\" "); |
51 | 51 |
52 if (!additional_attributes.empty()) | 52 if (!additional_attributes.empty()) |
53 base::StringAppendF(&request, "%s ", additional_attributes.c_str()); | 53 base::StringAppendF(&request, "%s ", additional_attributes.c_str()); |
54 | 54 |
55 // Chrome version and platform information. | 55 // Chrome version and platform information. |
56 base::StringAppendF( | 56 base::StringAppendF( |
(...skipping 21 matching lines...) Expand all Loading... |
78 | 78 |
79 // HW platform information. | 79 // HW platform information. |
80 base::StringAppendF(&request, | 80 base::StringAppendF(&request, |
81 "<hw physmemory=\"%d\"/>", | 81 "<hw physmemory=\"%d\"/>", |
82 GetPhysicalMemoryGB()); // "physmem" in GB. | 82 GetPhysicalMemoryGB()); // "physmem" in GB. |
83 | 83 |
84 // OS version and platform information. | 84 // OS version and platform information. |
85 base::StringAppendF( | 85 base::StringAppendF( |
86 &request, | 86 &request, |
87 "<os platform=\"%s\" version=\"%s\" arch=\"%s\"/>", | 87 "<os platform=\"%s\" version=\"%s\" arch=\"%s\"/>", |
88 chrome::VersionInfo().OSType().c_str(), // "platform" | 88 platform_name.c_str(), // "platform" |
89 base::SysInfo().OperatingSystemVersion().c_str(), // "version" | 89 base::SysInfo().OperatingSystemVersion().c_str(), // "version" |
90 base::SysInfo().OperatingSystemArchitecture().c_str()); // "arch" | 90 base::SysInfo().OperatingSystemArchitecture().c_str()); // "arch" |
91 | 91 |
92 // The actual payload of the request. | 92 // The actual payload of the request. |
93 base::StringAppendF(&request, "%s</request>", request_body.c_str()); | 93 base::StringAppendF(&request, "%s</request>", request_body.c_str()); |
94 | 94 |
95 return request; | 95 return request; |
96 } | 96 } |
97 | 97 |
98 net::URLFetcher* SendProtocolRequest( | 98 net::URLFetcher* SendProtocolRequest( |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 DCHECK(extensions::Extension::IdIsValid(id)); | 181 DCHECK(extensions::Extension::IdIsValid(id)); |
182 return id; | 182 return id; |
183 } | 183 } |
184 | 184 |
185 std::string GetCrxComponentID(const CrxComponent& component) { | 185 std::string GetCrxComponentID(const CrxComponent& component) { |
186 return HexStringToID(StringToLowerASCII( | 186 return HexStringToID(StringToLowerASCII( |
187 base::HexEncode(&component.pk_hash[0], component.pk_hash.size() / 2))); | 187 base::HexEncode(&component.pk_hash[0], component.pk_hash.size() / 2))); |
188 } | 188 } |
189 | 189 |
190 } // namespace component_updater | 190 } // namespace component_updater |
OLD | NEW |