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