File: update_query_params.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (160 lines) | stat: -rw-r--r-- 4,021 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/update_client/update_query_params.h"

#include "base/check.h"
#include "base/strings/stringprintf.h"
#include "base/system/sys_info.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "components/update_client/update_query_params_delegate.h"
#include "components/version_info/version_info.h"

#if BUILDFLAG(IS_WIN)
#include "base/win/windows_version.h"
#endif

namespace update_client {

namespace {

const char kUnknown[] = "unknown";

// The request extra information is the OS and architecture, this helps
// the server select the right package to be delivered.
const char kOs[] =
#if BUILDFLAG(IS_APPLE)
    "mac";
#elif BUILDFLAG(IS_WIN)
    "win";
#elif BUILDFLAG(IS_ANDROID)
    "android";
#elif BUILDFLAG(IS_CHROMEOS)
    "cros";
#elif BUILDFLAG(IS_LINUX)
    "linux";
#elif BUILDFLAG(IS_FUCHSIA)
    "fuchsia";
#elif BUILDFLAG(IS_OPENBSD)
    "openbsd";
#else
#error "unknown os"
#endif

const char kArch[] =
#if defined(ARCH_CPU_X86_64)
    "x64";
#elif defined(ARCH_CPU_X86)
    "x86";
#elif defined(ARCH_CPU_ARMEL)
    "arm";
#elif defined(ARCH_CPU_ARM64)
    "arm64";
#elif defined(ARCH_CPU_MIPS64EL)
    "mips64el";
#elif defined(ARCH_CPU_MIPSEL)
    "mipsel";
#elif defined(__powerpc64__)
    "ppc64";
#elif defined(ARCH_CPU_LOONGARCH32)
        "loongarch32";
#elif defined(ARCH_CPU_LOONGARCH64)
        "loongarch64";
#elif defined(ARCH_CPU_RISCV64)
        "riscv64";
#else
#error "unknown arch"
#endif

#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
const char kChrome[] = "chrome";
const char kCrx[] = "chromecrx";
const char kWebView[] = "googleandroidwebview";
#else
const char kChrome[] = "chromium";
const char kCrx[] = "chromiumcrx";
const char kWebView[] = "androidwebview";
#endif  // BUILDFLAG(GOOGLE_CHROME_BRANDING)

UpdateQueryParamsDelegate* g_delegate = nullptr;

}  // namespace

// static
std::string UpdateQueryParams::Get(ProdId prod) {
  return base::StringPrintf(
      "os=%s&arch=%s&os_arch=%s&nacl_arch=%s&prod=%s%s&acceptformat=crx3,puff",
      kOs, kArch, base::SysInfo().OperatingSystemArchitecture().c_str(),
      GetNaclArch(), GetProdIdString(prod),
      g_delegate ? g_delegate->GetExtraParams().c_str() : "");
}

// static
const char* UpdateQueryParams::GetProdIdString(UpdateQueryParams::ProdId prod) {
  switch (prod) {
    case UpdateQueryParams::CHROME:
      return kChrome;
    case UpdateQueryParams::CRX:
      return kCrx;
    case UpdateQueryParams::WEBVIEW:
      return kWebView;
  }
  return kUnknown;
}

// static
const char* UpdateQueryParams::GetOS() {
  return kOs;
}

// static
const char* UpdateQueryParams::GetArch() {
  return kArch;
}

// static
const char* UpdateQueryParams::GetNaclArch() {
#if defined(ARCH_CPU_X86_FAMILY)
#if defined(ARCH_CPU_X86_64)
  return "x86-64";
#elif BUILDFLAG(IS_WIN)
  bool x86_64 = base::win::OSInfo::GetInstance()->IsWowX86OnAMD64();
  return x86_64 ? "x86-64" : "x86-32";
#else
  return "x86-32";
#endif
#elif defined(ARCH_CPU_ARM_FAMILY)
  return "arm";
#elif defined(ARCH_CPU_MIPSEL)
  return "mips32";
#elif defined(ARCH_CPU_MIPS64EL)
  return "mips64";
#elif defined(ARCH_CPU_PPC64)
  return "ppc64";
#elif defined(ARCH_CPU_LOONGARCH32)
  return "loongarch32";
#elif defined(ARCH_CPU_LOONGARCH64)
  return "loongarch64";
#elif defined(ARCH_CPU_RISCV64)
  return "riscv64";
#else
  // NOTE: when adding new values here, please remember to update the
  // comment in the .h file about possible return values from this function.
#error "You need to add support for your architecture here"
#endif
}

// static
std::string UpdateQueryParams::GetProdVersion() {
  return std::string(version_info::GetVersionNumber());
}

// static
void UpdateQueryParams::SetDelegate(UpdateQueryParamsDelegate* delegate) {
  CHECK(!g_delegate || !delegate || (delegate == g_delegate));
  g_delegate = delegate;
}

}  // namespace update_client