Home | History | Annotate | Download | only in omaha_query_params
      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 
     50 const char kStable[] = "stable";
     51 const char kBeta[] = "beta";
     52 const char kDev[] = "dev";
     53 const char kCanary[] = "canary";
     54 
     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 
     61 }  // namespace
     62 
     63 namespace chrome {
     64 
     65 // static
     66 std::string OmahaQueryParams::Get(ProdId prod) {
     67   return base::StringPrintf(
     68       "os=%s&arch=%s&nacl_arch=%s&prod=%s&prodchannel=%s&prodversion=%s",
     69       kOs,
     70       kArch,
     71       getNaclArch(),
     72       GetProdIdString(prod),
     73       GetChannelString(),
     74       chrome::VersionInfo().Version().c_str());
     75 }
     76 
     77 // static
     78 const char* OmahaQueryParams::GetProdIdString(
     79     chrome::OmahaQueryParams::ProdId prod) {
     80   switch (prod) {
     81     case chrome::OmahaQueryParams::CHROME:
     82       return kChrome;
     83       break;
     84     case chrome::OmahaQueryParams::CRX:
     85 #if defined(GOOGLE_CHROME_BUILD)
     86       return kChromeCrx;
     87 #else
     88       return kChromiumCrx;
     89 #endif
     90       break;
     91   }
     92   return kUnknown;
     93 }
     94 
     95 // static
     96 const char* OmahaQueryParams::getOS() {
     97   return kOs;
     98 }
     99 
    100 // static
    101 const char* OmahaQueryParams::getArch() {
    102   return kArch;
    103 }
    104 
    105 // static
    106 const char* OmahaQueryParams::getNaclArch() {
    107 #if defined(ARCH_CPU_X86_FAMILY)
    108 #if defined(ARCH_CPU_X86_64)
    109   return "x86-64";
    110 #elif defined(OS_WIN)
    111   bool x86_64 = (base::win::OSInfo::GetInstance()->wow64_status() ==
    112                  base::win::OSInfo::WOW64_ENABLED);
    113   return x86_64 ? "x86-64" : "x86-32";
    114 #else
    115   return "x86-32";
    116 #endif
    117 #elif defined(ARCH_CPU_ARMEL)
    118   return "arm";
    119 #elif defined(ARCH_CPU_MIPSEL)
    120   return "mips32";
    121 #else
    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.
    124 #error "You need to add support for your architecture here"
    125 #endif
    126 }
    127 
    128 const char* OmahaQueryParams::GetChannelString() {
    129   switch (chrome::VersionInfo::GetChannel()) {
    130     case chrome::VersionInfo::CHANNEL_STABLE:
    131       return kStable;
    132       break;
    133     case chrome::VersionInfo::CHANNEL_BETA:
    134       return kBeta;
    135       break;
    136     case chrome::VersionInfo::CHANNEL_DEV:
    137       return kDev;
    138       break;
    139     case chrome::VersionInfo::CHANNEL_CANARY:
    140       return kCanary;
    141       break;
    142     case chrome::VersionInfo::CHANNEL_UNKNOWN:
    143       return kUnknown;
    144       break;
    145   }
    146   return kUnknown;
    147 }
    148 
    149 }  // namespace chrome
    150