Remove BooleanPrefMember usage from Data Reduction Proxy IO classes.
[chromium-blink-merge.git] / components / update_client / update_query_params.cc
blob33bd00e197cf711cede869036974a054c40955fd
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/update_client/update_query_params.h"
7 #include "base/compiler_specific.h"
8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/win/windows_version.h"
11 #include "components/update_client/update_query_params_delegate.h"
13 namespace update_client {
15 namespace {
17 const char kUnknown[] = "unknown";
19 // The request extra information is the OS and architecture, this helps
20 // the server select the right package to be delivered.
21 const char kOs[] =
22 #if defined(OS_MACOSX)
23 "mac";
24 #elif defined(OS_WIN)
25 "win";
26 #elif defined(OS_ANDROID)
27 "android";
28 #elif defined(OS_CHROMEOS)
29 "cros";
30 #elif defined(OS_LINUX)
31 "linux";
32 #elif defined(OS_OPENBSD)
33 "openbsd";
34 #else
35 #error "unknown os"
36 #endif
38 const char kArch[] =
39 #if defined(__amd64__) || defined(_WIN64)
40 "x64";
41 #elif defined(__i386__) || defined(_WIN32)
42 "x86";
43 #elif defined(__arm__)
44 "arm";
45 #elif defined(__aarch64__)
46 "arm64";
47 #elif defined(__mips__)
48 "mipsel";
49 #else
50 #error "unknown arch"
51 #endif
53 const char kChrome[] = "chrome";
55 #if defined(GOOGLE_CHROME_BUILD)
56 const char kChromeCrx[] = "chromecrx";
57 #else
58 const char kChromiumCrx[] = "chromiumcrx";
59 #endif // defined(GOOGLE_CHROME_BUILD)
61 UpdateQueryParamsDelegate* g_delegate = NULL;
63 } // namespace
65 // static
66 std::string UpdateQueryParams::Get(ProdId prod) {
67 return base::StringPrintf(
68 "os=%s&arch=%s&nacl_arch=%s&prod=%s%s", kOs, kArch, GetNaclArch(),
69 GetProdIdString(prod),
70 g_delegate ? g_delegate->GetExtraParams().c_str() : "");
73 // static
74 const char* UpdateQueryParams::GetProdIdString(UpdateQueryParams::ProdId prod) {
75 switch (prod) {
76 case UpdateQueryParams::CHROME:
77 return kChrome;
78 break;
79 case UpdateQueryParams::CRX:
80 #if defined(GOOGLE_CHROME_BUILD)
81 return kChromeCrx;
82 #else
83 return kChromiumCrx;
84 #endif
85 break;
87 return kUnknown;
90 // static
91 const char* UpdateQueryParams::GetOS() {
92 return kOs;
95 // static
96 const char* UpdateQueryParams::GetArch() {
97 return kArch;
100 // static
101 const char* UpdateQueryParams::GetNaclArch() {
102 #if defined(ARCH_CPU_X86_FAMILY)
103 #if defined(ARCH_CPU_X86_64)
104 return "x86-64";
105 #elif defined(OS_WIN)
106 bool x86_64 = (base::win::OSInfo::GetInstance()->wow64_status() ==
107 base::win::OSInfo::WOW64_ENABLED);
108 return x86_64 ? "x86-64" : "x86-32";
109 #else
110 return "x86-32";
111 #endif
112 #elif defined(ARCH_CPU_ARMEL)
113 return "arm";
114 #elif defined(ARCH_CPU_ARM64)
115 return "arm64";
116 #elif defined(ARCH_CPU_MIPSEL)
117 return "mips32";
118 #else
119 // NOTE: when adding new values here, please remember to update the
120 // comment in the .h file about possible return values from this function.
121 #error "You need to add support for your architecture here"
122 #endif
125 // static
126 void UpdateQueryParams::SetDelegate(UpdateQueryParamsDelegate* delegate) {
127 DCHECK(!g_delegate || !delegate || (delegate == g_delegate));
128 g_delegate = delegate;
131 } // namespace update_client