[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 5 | #include "components/update_client/update_query_params.h" |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 6 | |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame] | 7 | #include "base/logging.h" |
[email protected] | 3c8a6b0 | 2013-06-11 00:49:49 | [diff] [blame] | 8 | #include "base/strings/stringprintf.h" |
Sebastien Marchand | 75a7cdf | 2018-11-13 23:47:03 | [diff] [blame] | 9 | #include "base/system/sys_info.h" |
Nico Weber | 356b304 | 2019-08-23 15:30:41 | [diff] [blame] | 10 | #include "build/branding_buildflags.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 11 | #include "build/build_config.h" |
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 12 | #include "components/update_client/update_query_params_delegate.h" |
mxnguyen | b7647619 | 2017-04-03 17:54:14 | [diff] [blame] | 13 | #include "components/version_info/version_info.h" |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame] | 14 | |
wychen | 7b07e7b | 2017-01-10 17:48:29 | [diff] [blame] | 15 | #if defined(OS_WIN) |
16 | #include "base/win/windows_version.h" | ||||
17 | #endif | ||||
18 | |||||
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 19 | namespace update_client { |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 20 | |
21 | namespace { | ||||
22 | |||||
23 | const char kUnknown[] = "unknown"; | ||||
24 | |||||
25 | // The request extra information is the OS and architecture, this helps | ||||
26 | // the server select the right package to be delivered. | ||||
27 | const char kOs[] = | ||||
28 | #if defined(OS_MACOSX) | ||||
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 29 | "mac"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 30 | #elif defined(OS_WIN) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 31 | "win"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 32 | #elif defined(OS_ANDROID) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 33 | "android"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 34 | #elif defined(OS_CHROMEOS) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 35 | "cros"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 36 | #elif defined(OS_LINUX) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 37 | "linux"; |
Scott Graham | 5ef0d85 | 2017-08-14 19:39:55 | [diff] [blame] | 38 | #elif defined(OS_FUCHSIA) |
39 | "fuchsia"; | ||||
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 40 | #elif defined(OS_OPENBSD) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 41 | "openbsd"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 42 | #else |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 43 | #error "unknown os" |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 44 | #endif |
45 | |||||
46 | const char kArch[] = | ||||
47 | #if defined(__amd64__) || defined(_WIN64) | ||||
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 48 | "x64"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 49 | #elif defined(__i386__) || defined(_WIN32) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 50 | "x86"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 51 | #elif defined(__arm__) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 52 | "arm"; |
[email protected] | e199278 | 2014-03-31 22:10:30 | [diff] [blame] | 53 | #elif defined(__aarch64__) |
[email protected] | 884ccf1a | 2014-02-20 21:52:48 | [diff] [blame] | 54 | "arm64"; |
Gordana.Cmiljanovic | a43ce60 | 2016-04-27 09:17:05 | [diff] [blame] | 55 | #elif defined(__mips__) && (__mips == 64) |
56 | "mips64el"; | ||||
[email protected] | 19a02a3 | 2013-04-23 05:26:06 | [diff] [blame] | 57 | #elif defined(__mips__) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 58 | "mipsel"; |
Shawn Anastasio | 0daeebc | 2019-03-20 22:31:41 | [diff] [blame] | 59 | #elif defined(__powerpc64__) |
60 | "ppc64"; | ||||
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 61 | #else |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 62 | #error "unknown arch" |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 63 | #endif |
64 | |||||
65 | const char kChrome[] = "chrome"; | ||||
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 66 | |
Nico Weber | 356b304 | 2019-08-23 15:30:41 | [diff] [blame] | 67 | #if BUILDFLAG(GOOGLE_CHROME_BRANDING) |
68 | const char kCrx[] = "chromecrx"; | ||||
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 69 | #else |
Nico Weber | 356b304 | 2019-08-23 15:30:41 | [diff] [blame] | 70 | const char kCrx[] = "chromiumcrx"; |
71 | #endif // BUILDFLAG(GOOGLE_CHROME_BRANDING) | ||||
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 72 | |
Ivan Kotenkov | 75b1c3a | 2017-10-24 14:47:24 | [diff] [blame] | 73 | UpdateQueryParamsDelegate* g_delegate = nullptr; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 74 | |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame] | 75 | } // namespace |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 76 | |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 77 | // static |
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 78 | std::string UpdateQueryParams::Get(ProdId prod) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 79 | return base::StringPrintf( |
Joshua Pawlicki | afaa292 | 2019-09-03 18:50:23 | [diff] [blame] | 80 | "os=%s&arch=%s&os_arch=%s&nacl_arch=%s&prod=%s%s&acceptformat=crx3", kOs, |
81 | kArch, base::SysInfo().OperatingSystemArchitecture().c_str(), | ||||
waffles | d4d3003 | 2017-05-25 02:12:27 | [diff] [blame] | 82 | GetNaclArch(), GetProdIdString(prod), |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame] | 83 | g_delegate ? g_delegate->GetExtraParams().c_str() : ""); |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 84 | } |
85 | |||||
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 86 | // static |
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 87 | const char* UpdateQueryParams::GetProdIdString(UpdateQueryParams::ProdId prod) { |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 88 | switch (prod) { |
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 89 | case UpdateQueryParams::CHROME: |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 90 | return kChrome; |
91 | break; | ||||
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 92 | case UpdateQueryParams::CRX: |
Nico Weber | 356b304 | 2019-08-23 15:30:41 | [diff] [blame] | 93 | return kCrx; |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 94 | break; |
95 | } | ||||
96 | return kUnknown; | ||||
97 | } | ||||
98 | |||||
99 | // static | ||||
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 100 | const char* UpdateQueryParams::GetOS() { |
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 101 | return kOs; |
102 | } | ||||
103 | |||||
104 | // static | ||||
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 105 | const char* UpdateQueryParams::GetArch() { |
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 106 | return kArch; |
107 | } | ||||
108 | |||||
109 | // static | ||||
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 110 | const char* UpdateQueryParams::GetNaclArch() { |
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 111 | #if defined(ARCH_CPU_X86_FAMILY) |
112 | #if defined(ARCH_CPU_X86_64) | ||||
113 | return "x86-64"; | ||||
114 | #elif defined(OS_WIN) | ||||
115 | bool x86_64 = (base::win::OSInfo::GetInstance()->wow64_status() == | ||||
116 | base::win::OSInfo::WOW64_ENABLED); | ||||
117 | return x86_64 ? "x86-64" : "x86-32"; | ||||
118 | #else | ||||
119 | return "x86-32"; | ||||
120 | #endif | ||||
121 | #elif defined(ARCH_CPU_ARMEL) | ||||
122 | return "arm"; | ||||
[email protected] | 884ccf1a | 2014-02-20 21:52:48 | [diff] [blame] | 123 | #elif defined(ARCH_CPU_ARM64) |
124 | return "arm64"; | ||||
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 125 | #elif defined(ARCH_CPU_MIPSEL) |
126 | return "mips32"; | ||||
Gordana.Cmiljanovic | a43ce60 | 2016-04-27 09:17:05 | [diff] [blame] | 127 | #elif defined(ARCH_CPU_MIPS64EL) |
128 | return "mips64"; | ||||
Shawn Anastasio | 0daeebc | 2019-03-20 22:31:41 | [diff] [blame] | 129 | #elif defined(ARCH_CPU_PPC64) |
130 | return "ppc64"; | ||||
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 131 | #else |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 132 | // NOTE: when adding new values here, please remember to update the |
133 | // comment in the .h file about possible return values from this function. | ||||
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 134 | #error "You need to add support for your architecture here" |
135 | #endif | ||||
136 | } | ||||
137 | |||||
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame] | 138 | // static |
mxnguyen | b7647619 | 2017-04-03 17:54:14 | [diff] [blame] | 139 | std::string UpdateQueryParams::GetProdVersion() { |
140 | return version_info::GetVersionNumber(); | ||||
141 | } | ||||
142 | |||||
143 | // static | ||||
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 144 | void UpdateQueryParams::SetDelegate(UpdateQueryParamsDelegate* delegate) { |
droger | 0a8d9a6 | 2015-03-06 20:39:20 | [diff] [blame] | 145 | DCHECK(!g_delegate || !delegate || (delegate == g_delegate)); |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame] | 146 | g_delegate = delegate; |
[email protected] | c25082b | 2013-09-10 23:46:24 | [diff] [blame] | 147 | } |
148 | |||||
sorin | 39eab2f | 2015-01-06 01:09:08 | [diff] [blame] | 149 | } // namespace update_client |