Home | History | Annotate | Download | only in omaha_query_params
      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.
      4 
      5 #include "components/omaha_query_params/omaha_query_params.h"
      6 
      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/omaha_query_params/omaha_query_params_delegate.h"
     12 
     13 namespace omaha_query_params {
     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)
     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
     37 
     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
     52 
     53 const char kChrome[] = "chrome";
     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 OmahaQueryParamsDelegate* g_delegate = NULL;
     62 
     63 }  // namespace
     64 
     65 // static
     66 std::string OmahaQueryParams::Get(ProdId prod) {
     67   return base::StringPrintf(
     68       "os=%s&arch=%s&nacl_arch=%s&prod=%s%s",
     69       kOs,
     70       kArch,
     71       GetNaclArch(),
     72       GetProdIdString(prod),
     73       g_delegate ? g_delegate->GetExtraParams().c_str() : "");
     74 }
     75 
     76 // static
     77 const char* OmahaQueryParams::GetProdIdString(OmahaQueryParams::ProdId prod) {
     78   switch (prod) {
     79     case OmahaQueryParams::CHROME:
     80       return kChrome;
     81       break;
     82     case OmahaQueryParams::CRX:
     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
     94 const char* OmahaQueryParams::GetOS() {
     95   return kOs;
     96 }
     97 
     98 // static
     99 const char* OmahaQueryParams::GetArch() {
    100   return kArch;
    101 }
    102 
    103 // static
    104 const char* OmahaQueryParams::GetNaclArch() {
    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";
    117 #elif defined(ARCH_CPU_ARM64)
    118   return "arm64";
    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 // static
    129 void OmahaQueryParams::SetDelegate(OmahaQueryParamsDelegate* delegate) {
    130   DCHECK(!g_delegate || !delegate);
    131   g_delegate = delegate;
    132 }
    133 
    134 }  // namespace omaha_query_params
    135