| 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 #include "base/guid.h" | 6 #include "base/guid.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
| 9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
| 10 #include "chrome/common/chrome_version_info.h" | 10 #include "chrome/common/chrome_version_info.h" |
| 11 #include "chrome/common/omaha_query_params/omaha_query_params.h" | 11 #include "chrome/common/omaha_query_params/omaha_query_params.h" |
| 12 #include "net/base/load_flags.h" | 12 #include "net/base/load_flags.h" |
| 13 #include "net/url_request/url_fetcher.h" | 13 #include "net/url_request/url_fetcher.h" |
| 14 #include "net/url_request/url_request_context_getter.h" | 14 #include "net/url_request/url_request_context_getter.h" |
| 15 #include "net/url_request/url_request_status.h" | 15 #include "net/url_request/url_request_status.h" |
| 16 | 16 |
| 17 namespace component_updater { | 17 namespace component_updater { |
| 18 | 18 |
| 19 std::string BuildProtocolRequest(const std::string& request_body) { | 19 std::string BuildProtocolRequest(const std::string& request_body, |
| 20 const char request_format[] = | 20 const std::string& additional_attributes) { |
| 21 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | |
| 22 "<request protocol=\"3.0\" version=\"%s-%s\" prodversion=\"%s\" " | |
| 23 "requestid=\"{%s}\" updaterchannel=\"%s\" arch=\"%s\" nacl_arch=\"%s\">" | |
| 24 "<os platform=\"%s\" version=\"%s\" arch=\"%s\"/>" | |
| 25 "%s" | |
| 26 "</request>"; | |
| 27 | |
| 28 const std::string prod_id(chrome::OmahaQueryParams::GetProdIdString( | 21 const std::string prod_id(chrome::OmahaQueryParams::GetProdIdString( |
| 29 chrome::OmahaQueryParams::CHROME)); | 22 chrome::OmahaQueryParams::CHROME)); |
| 30 const std::string chrome_version(chrome::VersionInfo().Version().c_str()); | 23 const std::string chrome_version(chrome::VersionInfo().Version().c_str()); |
| 31 | 24 |
| 32 const std::string request(base::StringPrintf(request_format, | 25 std::string request( |
| 33 // Chrome version and platform information. | 26 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 27 "<request protocol=\"3.0\" "); |
| 28 |
| 29 if (!additional_attributes.empty()) |
| 30 base::StringAppendF(&request, "%s ", additional_attributes.c_str()); |
| 31 |
| 32 // Chrome version and platform information. |
| 33 base::StringAppendF( |
| 34 &request, |
| 35 "version=\"%s-%s\" prodversion=\"%s\" " |
| 36 "requestid=\"{%s}\" updaterchannel=\"%s\" arch=\"%s\" nacl_arch=\"%s\"", |
| 34 prod_id.c_str(), chrome_version.c_str(), // "version" | 37 prod_id.c_str(), chrome_version.c_str(), // "version" |
| 35 chrome_version.c_str(), // "prodversion" | 38 chrome_version.c_str(), // "prodversion" |
| 36 base::GenerateGUID().c_str(), // "requestid" | 39 base::GenerateGUID().c_str(), // "requestid" |
| 37 chrome::OmahaQueryParams::GetChannelString(), // "updaterchannel" | 40 chrome::OmahaQueryParams::GetChannelString(), // "updaterchannel" |
| 38 chrome::OmahaQueryParams::getArch(), // "arch" | 41 chrome::OmahaQueryParams::getArch(), // "arch" |
| 39 chrome::OmahaQueryParams::getNaclArch(), // "nacl_arch" | 42 chrome::OmahaQueryParams::getNaclArch()); // "nacl_arch" |
| 43 #if defined(OS_WIN) |
| 44 const bool is_wow64( |
| 45 base::win::OSInfo::GetInstance()->wow64_status() == |
| 46 base::win::OSInfo::WOW64_ENABLED); |
| 47 if (is_wow64) |
| 48 base::StringAppendF(&request, " wow64=\"1\""); |
| 49 #endif |
| 50 base::StringAppendF(&request, ">"); |
| 40 | 51 |
| 41 // OS version and platform information. | 52 // OS version and platform information. |
| 53 base::StringAppendF( |
| 54 &request, |
| 55 "<os platform=\"%s\" version=\"%s\" arch=\"%s\"/>", |
| 42 chrome::VersionInfo().OSType().c_str(), // "platform" | 56 chrome::VersionInfo().OSType().c_str(), // "platform" |
| 43 base::SysInfo().OperatingSystemVersion().c_str(), // "version" | 57 base::SysInfo().OperatingSystemVersion().c_str(), // "version" |
| 44 base::SysInfo().OperatingSystemArchitecture().c_str(), // "arch" | 58 base::SysInfo().OperatingSystemArchitecture().c_str()); // "arch" |
| 45 | 59 |
| 46 request_body.c_str())); // The actual payload of the request. | 60 // The actual payload of the request. |
| 61 base::StringAppendF(&request, "%s</request>", request_body.c_str()); |
| 47 | 62 |
| 48 return request; | 63 return request; |
| 49 } | 64 } |
| 50 | 65 |
| 51 net::URLFetcher* SendProtocolRequest( | 66 net::URLFetcher* SendProtocolRequest( |
| 52 const GURL& url, | 67 const GURL& url, |
| 53 const std::string& protocol_request, | 68 const std::string& protocol_request, |
| 54 net::URLFetcherDelegate* url_fetcher_delegate, | 69 net::URLFetcherDelegate* url_fetcher_delegate, |
| 55 net::URLRequestContextGetter* url_request_context_getter) { | 70 net::URLRequestContextGetter* url_request_context_getter) { |
| 56 net::URLFetcher* url_fetcher( | 71 net::URLFetcher* url_fetcher( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 117 } |
| 103 } | 118 } |
| 104 | 119 |
| 105 | 120 |
| 106 bool IsHttpServerError(int status_code) { | 121 bool IsHttpServerError(int status_code) { |
| 107 return 500 <= status_code && status_code < 600; | 122 return 500 <= status_code && status_code < 600; |
| 108 } | 123 } |
| 109 | 124 |
| 110 } // namespace component_updater | 125 } // namespace component_updater |
| 111 | 126 |
| OLD | NEW |