[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 | |||||
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame^] | 5 | #include "components/omaha_query_params/omaha_query_params.h" |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 6 | |
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 7 | #include "base/compiler_specific.h" |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame^] | 8 | #include "base/logging.h" |
[email protected] | 3c8a6b0 | 2013-06-11 00:49:49 | [diff] [blame] | 9 | #include "base/strings/stringprintf.h" |
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 10 | #include "base/win/windows_version.h" |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame^] | 11 | #include "components/omaha_query_params/omaha_query_params_delegate.h" |
12 | |||||
13 | namespace omaha_query_params { | ||||
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 14 | |
15 | namespace { | ||||
16 | |||||
17 | const 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. | ||||
21 | const char kOs[] = | ||||
22 | #if defined(OS_MACOSX) | ||||
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 23 | "mac"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 24 | #elif defined(OS_WIN) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 25 | "win"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 26 | #elif defined(OS_ANDROID) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 27 | "android"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 28 | #elif defined(OS_CHROMEOS) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 29 | "cros"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 30 | #elif defined(OS_LINUX) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 31 | "linux"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 32 | #elif defined(OS_OPENBSD) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 33 | "openbsd"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 34 | #else |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 35 | #error "unknown os" |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 36 | #endif |
37 | |||||
38 | const char kArch[] = | ||||
39 | #if defined(__amd64__) || defined(_WIN64) | ||||
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 40 | "x64"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 41 | #elif defined(__i386__) || defined(_WIN32) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 42 | "x86"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 43 | #elif defined(__arm__) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 44 | "arm"; |
[email protected] | e199278 | 2014-03-31 22:10:30 | [diff] [blame] | 45 | #elif defined(__aarch64__) |
[email protected] | 884ccf1a | 2014-02-20 21:52:48 | [diff] [blame] | 46 | "arm64"; |
[email protected] | 19a02a3 | 2013-04-23 05:26:06 | [diff] [blame] | 47 | #elif defined(__mips__) |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 48 | "mipsel"; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 49 | #else |
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 50 | #error "unknown arch" |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 51 | #endif |
52 | |||||
53 | const char kChrome[] = "chrome"; | ||||
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 54 | |
[email protected] | 9afc14e2 | 2013-09-25 22:34:14 | [diff] [blame] | 55 | #if defined(GOOGLE_CHROME_BUILD) |
56 | const char kChromeCrx[] = "chromecrx"; | ||||
57 | #else | ||||
58 | const char kChromiumCrx[] = "chromiumcrx"; | ||||
59 | #endif // defined(GOOGLE_CHROME_BUILD) | ||||
60 | |||||
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame^] | 61 | OmahaQueryParamsDelegate* g_delegate = NULL; |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 62 | |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame^] | 63 | } // namespace |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 64 | |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 65 | // static |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 66 | std::string OmahaQueryParams::Get(ProdId prod) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 67 | return base::StringPrintf( |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame^] | 68 | "os=%s&arch=%s&nacl_arch=%s&prod=%s%s", |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 69 | kOs, |
70 | kArch, | ||||
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 71 | GetNaclArch(), |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 72 | GetProdIdString(prod), |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame^] | 73 | g_delegate ? g_delegate->GetExtraParams().c_str() : ""); |
[email protected] | faae55a | 2013-03-11 10:19:02 | [diff] [blame] | 74 | } |
75 | |||||
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 76 | // static |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame^] | 77 | const char* OmahaQueryParams::GetProdIdString(OmahaQueryParams::ProdId prod) { |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 78 | switch (prod) { |
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame^] | 79 | case OmahaQueryParams::CHROME: |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 80 | return kChrome; |
81 | break; | ||||
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame^] | 82 | case OmahaQueryParams::CRX: |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 83 | #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] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 94 | const char* OmahaQueryParams::GetOS() { |
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 95 | return kOs; |
96 | } | ||||
97 | |||||
98 | // static | ||||
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 99 | const char* OmahaQueryParams::GetArch() { |
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 100 | return kArch; |
101 | } | ||||
102 | |||||
103 | // static | ||||
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 104 | const char* OmahaQueryParams::GetNaclArch() { |
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 105 | #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] | 884ccf1a | 2014-02-20 21:52:48 | [diff] [blame] | 117 | #elif defined(ARCH_CPU_ARM64) |
118 | return "arm64"; | ||||
[email protected] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 119 | #elif defined(ARCH_CPU_MIPSEL) |
120 | return "mips32"; | ||||
121 | #else | ||||
[email protected] | ec4a678 | 2014-02-14 20:00:04 | [diff] [blame] | 122 | // 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] | 4c0a0dc | 2013-03-26 09:12:23 | [diff] [blame] | 124 | #error "You need to add support for your architecture here" |
125 | #endif | ||||
126 | } | ||||
127 | |||||
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame^] | 128 | // static |
129 | void OmahaQueryParams::SetDelegate(OmahaQueryParamsDelegate* delegate) { | ||||
130 | DCHECK(!g_delegate || !delegate); | ||||
131 | g_delegate = delegate; | ||||
[email protected] | c25082b | 2013-09-10 23:46:24 | [diff] [blame] | 132 | } |
133 | |||||
[email protected] | 8f4b69e | 2014-06-26 00:01:31 | [diff] [blame^] | 134 | } // namespace omaha_query_params |