1 // Copyright (c) 2012 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. 4 5 #include "chrome/common/omaha_query_params/omaha_query_params.h" 6 7 #include "base/compiler_specific.h" 8 #include "base/strings/stringprintf.h" 9 #include "base/win/windows_version.h" 10 #include "chrome/common/chrome_version_info.h" 11 12 namespace { 13 14 const char kUnknown[] = "unknown"; 15 16 // The request extra information is the OS and architecture, this helps 17 // the server select the right package to be delivered. 18 const char kOs[] = 19 #if defined(OS_MACOSX) 20 "mac"; 21 #elif defined(OS_WIN) 22 "win"; 23 #elif defined(OS_ANDROID) 24 "android"; 25 #elif defined(OS_CHROMEOS) 26 "cros"; 27 #elif defined(OS_LINUX) 28 "linux"; 29 #elif defined(OS_OPENBSD) 30 "openbsd"; 31 #else 32 #error "unknown os" 33 #endif 34 35 const char kArch[] = 36 #if defined(__amd64__) || defined(_WIN64) 37 "x64"; 38 #elif defined(__i386__) || defined(_WIN32) 39 "x86"; 40 #elif defined(__arm__) 41 "arm"; 42 #elif defined(__mips__) 43 "mipsel"; 44 #else 45 #error "unknown arch" 46 #endif 47 48 const char kChrome[] = "chrome"; 49 const char kChromeCrx[] = "chromecrx"; 50 const char kChromiumCrx[] = "chromiumcrx"; 51 52 const char kStable[] = "stable"; 53 const char kBeta[] = "beta"; 54 const char kDev[] = "dev"; 55 const char kCanary[] = "canary"; 56 57 const char* GetChannelString() { 58 switch (chrome::VersionInfo::GetChannel()) { 59 case chrome::VersionInfo::CHANNEL_STABLE: 60 return kStable; 61 break; 62 case chrome::VersionInfo::CHANNEL_BETA: 63 return kBeta; 64 break; 65 case chrome::VersionInfo::CHANNEL_DEV: 66 return kDev; 67 break; 68 case chrome::VersionInfo::CHANNEL_CANARY: 69 return kCanary; 70 break; 71 case chrome::VersionInfo::CHANNEL_UNKNOWN: 72 return kUnknown; 73 break; 74 } 75 return kUnknown; 76 } 77 78 } // namespace 79 80 namespace chrome { 81 82 // static 83 std::string OmahaQueryParams::Get(ProdId prod) { 84 return base::StringPrintf( 85 "os=%s&arch=%s&nacl_arch=%s&prod=%s&prodchannel=%s&prodversion=%s", 86 kOs, 87 kArch, 88 getNaclArch(), 89 GetProdIdString(prod), 90 GetChannelString(), 91 chrome::VersionInfo().Version().c_str()); 92 } 93 94 // static 95 const char* OmahaQueryParams::GetProdIdString( 96 chrome::OmahaQueryParams::ProdId prod) { 97 switch (prod) { 98 case chrome::OmahaQueryParams::CHROME: 99 return kChrome; 100 break; 101 case chrome::OmahaQueryParams::CRX: 102 #if defined(GOOGLE_CHROME_BUILD) 103 return kChromeCrx; 104 #else 105 return kChromiumCrx; 106 #endif 107 break; 108 } 109 return kUnknown; 110 } 111 112 // static 113 const char* OmahaQueryParams::getOS() { 114 return kOs; 115 } 116 117 // static 118 const char* OmahaQueryParams::getArch() { 119 return kArch; 120 } 121 122 // static 123 const char* OmahaQueryParams::getNaclArch() { 124 #if defined(ARCH_CPU_X86_FAMILY) 125 #if defined(ARCH_CPU_X86_64) 126 return "x86-64"; 127 #elif defined(OS_WIN) 128 bool x86_64 = (base::win::OSInfo::GetInstance()->wow64_status() == 129 base::win::OSInfo::WOW64_ENABLED); 130 return x86_64 ? "x86-64" : "x86-32"; 131 #else 132 return "x86-32"; 133 #endif 134 #elif defined(ARCH_CPU_ARMEL) 135 return "arm"; 136 #elif defined(ARCH_CPU_MIPSEL) 137 return "mips32"; 138 #else 139 // NOTE: when adding new values here, please remember to update the 140 // comment in the .h file about possible return values from this function. 141 #error "You need to add support for your architecture here" 142 #endif 143 } 144 145 } // namespace chrome 146