blob: b04116dbc45513fd6eec45aa13018525376218ef [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
[email protected]8f4b69e2014-06-26 00:01:315#include "components/omaha_query_params/omaha_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"
[email protected]8f4b69e2014-06-26 00:01:3111#include "components/omaha_query_params/omaha_query_params_delegate.h"
12
13namespace omaha_query_params {
[email protected]faae55a2013-03-11 10:19:0214
15namespace {
16
17const char kUnknown[] = "unknown";
18
19// The request extra information is the OS and architecture, this helps
20// the server select the right package to be delivered.
21const char kOs[] =
22#if defined(OS_MACOSX)
[email protected]ec4a6782014-02-14 20:00:0423 "mac";
[email protected]faae55a2013-03-11 10:19:0224#elif defined(OS_WIN)
[email protected]ec4a6782014-02-14 20:00:0425 "win";
[email protected]faae55a2013-03-11 10:19:0226#elif defined(OS_ANDROID)
[email protected]ec4a6782014-02-14 20:00:0427 "android";
[email protected]faae55a2013-03-11 10:19:0228#elif defined(OS_CHROMEOS)
[email protected]ec4a6782014-02-14 20:00:0429 "cros";
[email protected]faae55a2013-03-11 10:19:0230#elif defined(OS_LINUX)
[email protected]ec4a6782014-02-14 20:00:0431 "linux";
[email protected]faae55a2013-03-11 10:19:0232#elif defined(OS_OPENBSD)
[email protected]ec4a6782014-02-14 20:00:0433 "openbsd";
[email protected]faae55a2013-03-11 10:19:0234#else
[email protected]ec4a6782014-02-14 20:00:0435#error "unknown os"
[email protected]faae55a2013-03-11 10:19:0236#endif
37
38const char kArch[] =
39#if defined(__amd64__) || defined(_WIN64)
[email protected]ec4a6782014-02-14 20:00:0440 "x64";
[email protected]faae55a2013-03-11 10:19:0241#elif defined(__i386__) || defined(_WIN32)
[email protected]ec4a6782014-02-14 20:00:0442 "x86";
[email protected]faae55a2013-03-11 10:19:0243#elif defined(__arm__)
[email protected]ec4a6782014-02-14 20:00:0444 "arm";
[email protected]e1992782014-03-31 22:10:3045#elif defined(__aarch64__)
[email protected]884ccf1a2014-02-20 21:52:4846 "arm64";
[email protected]19a02a32013-04-23 05:26:0647#elif defined(__mips__)
[email protected]ec4a6782014-02-14 20:00:0448 "mipsel";
[email protected]faae55a2013-03-11 10:19:0249#else
[email protected]ec4a6782014-02-14 20:00:0450#error "unknown arch"
[email protected]faae55a2013-03-11 10:19:0251#endif
52
53const char kChrome[] = "chrome";
[email protected]faae55a2013-03-11 10:19:0254
[email protected]9afc14e22013-09-25 22:34:1455#if defined(GOOGLE_CHROME_BUILD)
56const char kChromeCrx[] = "chromecrx";
57#else
58const char kChromiumCrx[] = "chromiumcrx";
59#endif // defined(GOOGLE_CHROME_BUILD)
60
[email protected]8f4b69e2014-06-26 00:01:3161OmahaQueryParamsDelegate* g_delegate = NULL;
[email protected]faae55a2013-03-11 10:19:0262
[email protected]8f4b69e2014-06-26 00:01:3163} // namespace
[email protected]faae55a2013-03-11 10:19:0264
[email protected]e3e696d32013-06-21 20:41:3665// static
[email protected]faae55a2013-03-11 10:19:0266std::string OmahaQueryParams::Get(ProdId prod) {
[email protected]7d3cbc92013-03-18 22:33:0467 return base::StringPrintf(
[email protected]8f4b69e2014-06-26 00:01:3168 "os=%s&arch=%s&nacl_arch=%s&prod=%s%s",
[email protected]7d3cbc92013-03-18 22:33:0469 kOs,
70 kArch,
[email protected]ec4a6782014-02-14 20:00:0471 GetNaclArch(),
[email protected]7d3cbc92013-03-18 22:33:0472 GetProdIdString(prod),
[email protected]8f4b69e2014-06-26 00:01:3173 g_delegate ? g_delegate->GetExtraParams().c_str() : "");
[email protected]faae55a2013-03-11 10:19:0274}
75
[email protected]4c0a0dc2013-03-26 09:12:2376// static
[email protected]8f4b69e2014-06-26 00:01:3177const char* OmahaQueryParams::GetProdIdString(OmahaQueryParams::ProdId prod) {
[email protected]e3e696d32013-06-21 20:41:3678 switch (prod) {
[email protected]8f4b69e2014-06-26 00:01:3179 case OmahaQueryParams::CHROME:
[email protected]e3e696d32013-06-21 20:41:3680 return kChrome;
81 break;
[email protected]8f4b69e2014-06-26 00:01:3182 case OmahaQueryParams::CRX:
[email protected]e3e696d32013-06-21 20:41:3683#if defined(GOOGLE_CHROME_BUILD)
84 return kChromeCrx;
85#else
86 return kChromiumCrx;
87#endif
88 break;
89 }
90 return kUnknown;
91}
92
93// static
[email protected]ec4a6782014-02-14 20:00:0494const char* OmahaQueryParams::GetOS() {
[email protected]4c0a0dc2013-03-26 09:12:2395 return kOs;
96}
97
98// static
[email protected]ec4a6782014-02-14 20:00:0499const char* OmahaQueryParams::GetArch() {
[email protected]4c0a0dc2013-03-26 09:12:23100 return kArch;
101}
102
103// static
[email protected]ec4a6782014-02-14 20:00:04104const char* OmahaQueryParams::GetNaclArch() {
[email protected]4c0a0dc2013-03-26 09:12:23105#if defined(ARCH_CPU_X86_FAMILY)
106#if defined(ARCH_CPU_X86_64)
107 return "x86-64";
108#elif defined(OS_WIN)
109 bool x86_64 = (base::win::OSInfo::GetInstance()->wow64_status() ==
110 base::win::OSInfo::WOW64_ENABLED);
111 return x86_64 ? "x86-64" : "x86-32";
112#else
113 return "x86-32";
114#endif
115#elif defined(ARCH_CPU_ARMEL)
116 return "arm";
[email protected]884ccf1a2014-02-20 21:52:48117#elif defined(ARCH_CPU_ARM64)
118 return "arm64";
[email protected]4c0a0dc2013-03-26 09:12:23119#elif defined(ARCH_CPU_MIPSEL)
120 return "mips32";
121#else
[email protected]ec4a6782014-02-14 20:00:04122// NOTE: when adding new values here, please remember to update the
123// comment in the .h file about possible return values from this function.
[email protected]4c0a0dc2013-03-26 09:12:23124#error "You need to add support for your architecture here"
125#endif
126}
127
[email protected]8f4b69e2014-06-26 00:01:31128// static
129void OmahaQueryParams::SetDelegate(OmahaQueryParamsDelegate* delegate) {
130 DCHECK(!g_delegate || !delegate);
131 g_delegate = delegate;
[email protected]c25082b2013-09-10 23:46:24132}
133
[email protected]8f4b69e2014-06-26 00:01:31134} // namespace omaha_query_params