blob: 56aea40c92ae28f6f2e968fc728f5615955502b6 [file] [log] [blame]
[email protected]ec4a6782014-02-14 20:00:041// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]faae55a2013-03-11 10:19:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
sorin39eab2f2015-01-06 01:09:085#include "components/update_client/update_query_params.h"
[email protected]faae55a2013-03-11 10:19:026
[email protected]8f4b69e2014-06-26 00:01:317#include "base/logging.h"
[email protected]3c8a6b02013-06-11 00:49:498#include "base/strings/stringprintf.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:039#include "base/system/sys_info.h"
Nico Weber356b3042019-08-23 15:30:4110#include "build/branding_buildflags.h"
avi5dd91f82015-12-25 22:30:4611#include "build/build_config.h"
sorin39eab2f2015-01-06 01:09:0812#include "components/update_client/update_query_params_delegate.h"
mxnguyenb76476192017-04-03 17:54:1413#include "components/version_info/version_info.h"
[email protected]8f4b69e2014-06-26 00:01:3114
wychen7b07e7b2017-01-10 17:48:2915#if defined(OS_WIN)
16#include "base/win/windows_version.h"
17#endif
18
sorin39eab2f2015-01-06 01:09:0819namespace update_client {
[email protected]faae55a2013-03-11 10:19:0220
21namespace {
22
23const 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.
27const char kOs[] =
28#if defined(OS_MACOSX)
[email protected]ec4a6782014-02-14 20:00:0429 "mac";
[email protected]faae55a2013-03-11 10:19:0230#elif defined(OS_WIN)
[email protected]ec4a6782014-02-14 20:00:0431 "win";
[email protected]faae55a2013-03-11 10:19:0232#elif defined(OS_ANDROID)
[email protected]ec4a6782014-02-14 20:00:0433 "android";
[email protected]faae55a2013-03-11 10:19:0234#elif defined(OS_CHROMEOS)
[email protected]ec4a6782014-02-14 20:00:0435 "cros";
[email protected]faae55a2013-03-11 10:19:0236#elif defined(OS_LINUX)
[email protected]ec4a6782014-02-14 20:00:0437 "linux";
Scott Graham5ef0d852017-08-14 19:39:5538#elif defined(OS_FUCHSIA)
39 "fuchsia";
[email protected]faae55a2013-03-11 10:19:0240#elif defined(OS_OPENBSD)
[email protected]ec4a6782014-02-14 20:00:0441 "openbsd";
[email protected]faae55a2013-03-11 10:19:0242#else
[email protected]ec4a6782014-02-14 20:00:0443#error "unknown os"
[email protected]faae55a2013-03-11 10:19:0244#endif
45
46const char kArch[] =
47#if defined(__amd64__) || defined(_WIN64)
[email protected]ec4a6782014-02-14 20:00:0448 "x64";
[email protected]faae55a2013-03-11 10:19:0249#elif defined(__i386__) || defined(_WIN32)
[email protected]ec4a6782014-02-14 20:00:0450 "x86";
[email protected]faae55a2013-03-11 10:19:0251#elif defined(__arm__)
[email protected]ec4a6782014-02-14 20:00:0452 "arm";
[email protected]e1992782014-03-31 22:10:3053#elif defined(__aarch64__)
[email protected]884ccf1a2014-02-20 21:52:4854 "arm64";
Gordana.Cmiljanovica43ce602016-04-27 09:17:0555#elif defined(__mips__) && (__mips == 64)
56 "mips64el";
[email protected]19a02a32013-04-23 05:26:0657#elif defined(__mips__)
[email protected]ec4a6782014-02-14 20:00:0458 "mipsel";
Shawn Anastasio0daeebc2019-03-20 22:31:4159#elif defined(__powerpc64__)
60 "ppc64";
[email protected]faae55a2013-03-11 10:19:0261#else
[email protected]ec4a6782014-02-14 20:00:0462#error "unknown arch"
[email protected]faae55a2013-03-11 10:19:0263#endif
64
65const char kChrome[] = "chrome";
[email protected]faae55a2013-03-11 10:19:0266
Nico Weber356b3042019-08-23 15:30:4167#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
68const char kCrx[] = "chromecrx";
[email protected]9afc14e22013-09-25 22:34:1469#else
Nico Weber356b3042019-08-23 15:30:4170const char kCrx[] = "chromiumcrx";
71#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
[email protected]9afc14e22013-09-25 22:34:1472
Ivan Kotenkov75b1c3a2017-10-24 14:47:2473UpdateQueryParamsDelegate* g_delegate = nullptr;
[email protected]faae55a2013-03-11 10:19:0274
[email protected]8f4b69e2014-06-26 00:01:3175} // namespace
[email protected]faae55a2013-03-11 10:19:0276
[email protected]e3e696d32013-06-21 20:41:3677// static
sorin39eab2f2015-01-06 01:09:0878std::string UpdateQueryParams::Get(ProdId prod) {
[email protected]7d3cbc92013-03-18 22:33:0479 return base::StringPrintf(
Joshua Pawlickiafaa2922019-09-03 18:50:2380 "os=%s&arch=%s&os_arch=%s&nacl_arch=%s&prod=%s%s&acceptformat=crx3", kOs,
81 kArch, base::SysInfo().OperatingSystemArchitecture().c_str(),
wafflesd4d30032017-05-25 02:12:2782 GetNaclArch(), GetProdIdString(prod),
[email protected]8f4b69e2014-06-26 00:01:3183 g_delegate ? g_delegate->GetExtraParams().c_str() : "");
[email protected]faae55a2013-03-11 10:19:0284}
85
[email protected]4c0a0dc2013-03-26 09:12:2386// static
sorin39eab2f2015-01-06 01:09:0887const char* UpdateQueryParams::GetProdIdString(UpdateQueryParams::ProdId prod) {
[email protected]e3e696d32013-06-21 20:41:3688 switch (prod) {
sorin39eab2f2015-01-06 01:09:0889 case UpdateQueryParams::CHROME:
[email protected]e3e696d32013-06-21 20:41:3690 return kChrome;
91 break;
sorin39eab2f2015-01-06 01:09:0892 case UpdateQueryParams::CRX:
Nico Weber356b3042019-08-23 15:30:4193 return kCrx;
[email protected]e3e696d32013-06-21 20:41:3694 break;
95 }
96 return kUnknown;
97}
98
99// static
sorin39eab2f2015-01-06 01:09:08100const char* UpdateQueryParams::GetOS() {
[email protected]4c0a0dc2013-03-26 09:12:23101 return kOs;
102}
103
104// static
sorin39eab2f2015-01-06 01:09:08105const char* UpdateQueryParams::GetArch() {
[email protected]4c0a0dc2013-03-26 09:12:23106 return kArch;
107}
108
109// static
sorin39eab2f2015-01-06 01:09:08110const char* UpdateQueryParams::GetNaclArch() {
[email protected]4c0a0dc2013-03-26 09:12:23111#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]884ccf1a2014-02-20 21:52:48123#elif defined(ARCH_CPU_ARM64)
124 return "arm64";
[email protected]4c0a0dc2013-03-26 09:12:23125#elif defined(ARCH_CPU_MIPSEL)
126 return "mips32";
Gordana.Cmiljanovica43ce602016-04-27 09:17:05127#elif defined(ARCH_CPU_MIPS64EL)
128 return "mips64";
Shawn Anastasio0daeebc2019-03-20 22:31:41129#elif defined(ARCH_CPU_PPC64)
130 return "ppc64";
[email protected]4c0a0dc2013-03-26 09:12:23131#else
[email protected]ec4a6782014-02-14 20:00:04132// 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]4c0a0dc2013-03-26 09:12:23134#error "You need to add support for your architecture here"
135#endif
136}
137
[email protected]8f4b69e2014-06-26 00:01:31138// static
mxnguyenb76476192017-04-03 17:54:14139std::string UpdateQueryParams::GetProdVersion() {
140 return version_info::GetVersionNumber();
141}
142
143// static
sorin39eab2f2015-01-06 01:09:08144void UpdateQueryParams::SetDelegate(UpdateQueryParamsDelegate* delegate) {
droger0a8d9a62015-03-06 20:39:20145 DCHECK(!g_delegate || !delegate || (delegate == g_delegate));
[email protected]8f4b69e2014-06-26 00:01:31146 g_delegate = delegate;
[email protected]c25082b2013-09-10 23:46:24147}
148
sorin39eab2f2015-01-06 01:09:08149} // namespace update_client