blob: f2d298ddc571cae8c3b6e6ff5a2f1f8118807137 [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]4c0a0dc2013-03-26 09:12:237#include "base/compiler_specific.h"
[email protected]8f4b69e2014-06-26 00:01:318#include "base/logging.h"
[email protected]3c8a6b02013-06-11 00:49:499#include "base/strings/stringprintf.h"
[email protected]4c0a0dc2013-03-26 09:12:2310#include "base/win/windows_version.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"
[email protected]8f4b69e2014-06-26 00:01:3113
sorin39eab2f2015-01-06 01:09:0814namespace update_client {
[email protected]faae55a2013-03-11 10:19:0215
16namespace {
17
18const char kUnknown[] = "unknown";
19
20// The request extra information is the OS and architecture, this helps
21// the server select the right package to be delivered.
22const char kOs[] =
23#if defined(OS_MACOSX)
[email protected]ec4a6782014-02-14 20:00:0424 "mac";
[email protected]faae55a2013-03-11 10:19:0225#elif defined(OS_WIN)
[email protected]ec4a6782014-02-14 20:00:0426 "win";
[email protected]faae55a2013-03-11 10:19:0227#elif defined(OS_ANDROID)
[email protected]ec4a6782014-02-14 20:00:0428 "android";
[email protected]faae55a2013-03-11 10:19:0229#elif defined(OS_CHROMEOS)
[email protected]ec4a6782014-02-14 20:00:0430 "cros";
[email protected]faae55a2013-03-11 10:19:0231#elif defined(OS_LINUX)
[email protected]ec4a6782014-02-14 20:00:0432 "linux";
[email protected]faae55a2013-03-11 10:19:0233#elif defined(OS_OPENBSD)
[email protected]ec4a6782014-02-14 20:00:0434 "openbsd";
[email protected]faae55a2013-03-11 10:19:0235#else
[email protected]ec4a6782014-02-14 20:00:0436#error "unknown os"
[email protected]faae55a2013-03-11 10:19:0237#endif
38
39const char kArch[] =
40#if defined(__amd64__) || defined(_WIN64)
[email protected]ec4a6782014-02-14 20:00:0441 "x64";
[email protected]faae55a2013-03-11 10:19:0242#elif defined(__i386__) || defined(_WIN32)
[email protected]ec4a6782014-02-14 20:00:0443 "x86";
[email protected]faae55a2013-03-11 10:19:0244#elif defined(__arm__)
[email protected]ec4a6782014-02-14 20:00:0445 "arm";
[email protected]e1992782014-03-31 22:10:3046#elif defined(__aarch64__)
[email protected]884ccf1a2014-02-20 21:52:4847 "arm64";
[email protected]19a02a32013-04-23 05:26:0648#elif defined(__mips__)
[email protected]ec4a6782014-02-14 20:00:0449 "mipsel";
[email protected]faae55a2013-03-11 10:19:0250#else
[email protected]ec4a6782014-02-14 20:00:0451#error "unknown arch"
[email protected]faae55a2013-03-11 10:19:0252#endif
53
54const char kChrome[] = "chrome";
[email protected]faae55a2013-03-11 10:19:0255
[email protected]9afc14e22013-09-25 22:34:1456#if defined(GOOGLE_CHROME_BUILD)
57const char kChromeCrx[] = "chromecrx";
58#else
59const char kChromiumCrx[] = "chromiumcrx";
60#endif // defined(GOOGLE_CHROME_BUILD)
61
sorin39eab2f2015-01-06 01:09:0862UpdateQueryParamsDelegate* g_delegate = NULL;
[email protected]faae55a2013-03-11 10:19:0263
[email protected]8f4b69e2014-06-26 00:01:3164} // namespace
[email protected]faae55a2013-03-11 10:19:0265
[email protected]e3e696d32013-06-21 20:41:3666// static
sorin39eab2f2015-01-06 01:09:0867std::string UpdateQueryParams::Get(ProdId prod) {
[email protected]7d3cbc92013-03-18 22:33:0468 return base::StringPrintf(
sorin39eab2f2015-01-06 01:09:0869 "os=%s&arch=%s&nacl_arch=%s&prod=%s%s", kOs, kArch, GetNaclArch(),
[email protected]7d3cbc92013-03-18 22:33:0470 GetProdIdString(prod),
[email protected]8f4b69e2014-06-26 00:01:3171 g_delegate ? g_delegate->GetExtraParams().c_str() : "");
[email protected]faae55a2013-03-11 10:19:0272}
73
[email protected]4c0a0dc2013-03-26 09:12:2374// static
sorin39eab2f2015-01-06 01:09:0875const char* UpdateQueryParams::GetProdIdString(UpdateQueryParams::ProdId prod) {
[email protected]e3e696d32013-06-21 20:41:3676 switch (prod) {
sorin39eab2f2015-01-06 01:09:0877 case UpdateQueryParams::CHROME:
[email protected]e3e696d32013-06-21 20:41:3678 return kChrome;
79 break;
sorin39eab2f2015-01-06 01:09:0880 case UpdateQueryParams::CRX:
[email protected]e3e696d32013-06-21 20:41:3681#if defined(GOOGLE_CHROME_BUILD)
82 return kChromeCrx;
83#else
84 return kChromiumCrx;
85#endif
86 break;
87 }
88 return kUnknown;
89}
90
91// static
sorin39eab2f2015-01-06 01:09:0892const char* UpdateQueryParams::GetOS() {
[email protected]4c0a0dc2013-03-26 09:12:2393 return kOs;
94}
95
96// static
sorin39eab2f2015-01-06 01:09:0897const char* UpdateQueryParams::GetArch() {
[email protected]4c0a0dc2013-03-26 09:12:2398 return kArch;
99}
100
101// static
sorin39eab2f2015-01-06 01:09:08102const char* UpdateQueryParams::GetNaclArch() {
[email protected]4c0a0dc2013-03-26 09:12:23103#if defined(ARCH_CPU_X86_FAMILY)
104#if defined(ARCH_CPU_X86_64)
105 return "x86-64";
106#elif defined(OS_WIN)
107 bool x86_64 = (base::win::OSInfo::GetInstance()->wow64_status() ==
108 base::win::OSInfo::WOW64_ENABLED);
109 return x86_64 ? "x86-64" : "x86-32";
110#else
111 return "x86-32";
112#endif
113#elif defined(ARCH_CPU_ARMEL)
114 return "arm";
[email protected]884ccf1a2014-02-20 21:52:48115#elif defined(ARCH_CPU_ARM64)
116 return "arm64";
[email protected]4c0a0dc2013-03-26 09:12:23117#elif defined(ARCH_CPU_MIPSEL)
118 return "mips32";
119#else
[email protected]ec4a6782014-02-14 20:00:04120// NOTE: when adding new values here, please remember to update the
121// comment in the .h file about possible return values from this function.
[email protected]4c0a0dc2013-03-26 09:12:23122#error "You need to add support for your architecture here"
123#endif
124}
125
[email protected]8f4b69e2014-06-26 00:01:31126// static
sorin39eab2f2015-01-06 01:09:08127void UpdateQueryParams::SetDelegate(UpdateQueryParamsDelegate* delegate) {
droger0a8d9a62015-03-06 20:39:20128 DCHECK(!g_delegate || !delegate || (delegate == g_delegate));
[email protected]8f4b69e2014-06-26 00:01:31129 g_delegate = delegate;
[email protected]c25082b2013-09-10 23:46:24130}
131
sorin39eab2f2015-01-06 01:09:08132} // namespace update_client