chrome_version_info_posix.cc revision 0529e5d033099cbfc42635f6f6183833b09dff6e
1324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// Use of this source code is governed by a BSD-style license that can be
3324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// found in the LICENSE file.
4324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
5324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#include "chrome/common/chrome_version_info.h"
6324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
7324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#include "base/strings/string_util.h"
8324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#include "build/build_config.h"
9324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
10324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruvernamespace chrome {
11324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
12324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// static
13324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverstd::string VersionInfo::GetVersionStringModifier() {
14324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  char* env = getenv("CHROME_VERSION_EXTRA");
15324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  if (!env)
16324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    return std::string();
17324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  std::string modifier(env);
18324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
19324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#if defined(GOOGLE_CHROME_BUILD)
20324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  // Only ever return "", "unknown", "dev" or "beta" in a branded build.
21324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  if (modifier == "unstable")  // linux version of "dev"
22324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    modifier = "dev";
23324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  if (modifier == "stable") {
24324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    modifier = "";
25324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  } else if ((modifier == "dev") || (modifier == "beta")) {
26324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    // do nothing.
27324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  } else {
28324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    modifier = "unknown";
29324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  }
30324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#endif
31324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
32324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  return modifier;
33324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver}
34324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
35324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// static
36324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverVersionInfo::Channel VersionInfo::GetChannel() {
37324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#if defined(GOOGLE_CHROME_BUILD)
38324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  std::string channel = GetVersionStringModifier();
39324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  // There might be suffixes after channel name (e.g. "aura"), so match just
40324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  // the beginning of version string modifier.
41324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  if (channel.empty()) {
42324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    return CHANNEL_STABLE;
43324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  } else if (StartsWithASCII(channel, "beta ", true)) {
44324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    return CHANNEL_BETA;
45324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  } else if (StartsWithASCII(channel, "dev ", true)) {
46324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    return CHANNEL_DEV;
47324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  } else if (StartsWithASCII(channel, "canary ", true)) {
48324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver    return CHANNEL_CANARY;
49324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  }
50324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver#endif
51324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
52324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver  return CHANNEL_UNKNOWN;
53324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver}
54324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver
55324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver}  // namespace chrome
56324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver