blob: 88b20489b1b5ef06224502e365f3e8e825fa1a1f [file] [log] [blame]
[email protected]f44f0a822011-06-24 18:39:121// Copyright (c) 2011 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
sdefresne9fb67692015-08-03 18:48:225#include "chrome/common/channel_info.h"
[email protected]f44f0a822011-06-24 18:39:126
Tom Andersonb8a86032019-10-09 20:12:457#include "base/environment.h"
[email protected]81b349002014-03-04 18:42:588#include "base/strings/string_util.h"
Nico Weber9116a2f12019-10-07 16:32:129#include "build/branding_buildflags.h"
[email protected]99713a532013-11-20 05:45:1710#include "build/build_config.h"
sdefresne9fb67692015-08-03 18:48:2211#include "components/version_info/version_info.h"
[email protected]99713a532013-11-20 05:45:1712
[email protected]f44f0a822011-06-24 18:39:1213namespace chrome {
14
[email protected]ba5ab4662014-04-30 14:36:3115namespace {
16
17// Helper function to return both the channel enum and modifier string.
18// Implements both together to prevent their behavior from diverging, which has
19// happened multiple times in the past.
Nico Weber7e526ba52019-10-29 18:40:5720version_info::Channel GetChannelImpl(std::string* modifier_out) {
sdefresne6e883e42015-07-30 08:05:5421 version_info::Channel channel = version_info::Channel::UNKNOWN;
[email protected]ba5ab4662014-04-30 14:36:3122 std::string modifier;
23
[email protected]f44f0a822011-06-24 18:39:1224 char* env = getenv("CHROME_VERSION_EXTRA");
[email protected]ba5ab4662014-04-30 14:36:3125 if (env)
26 modifier = env;
[email protected]f44f0a822011-06-24 18:39:1227
Nico Weber9116a2f12019-10-07 16:32:1228#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
[email protected]f44f0a822011-06-24 18:39:1229 // Only ever return "", "unknown", "dev" or "beta" in a branded build.
30 if (modifier == "unstable") // linux version of "dev"
31 modifier = "dev";
32 if (modifier == "stable") {
sdefresne6e883e42015-07-30 08:05:5433 channel = version_info::Channel::STABLE;
[email protected]f44f0a822011-06-24 18:39:1234 modifier = "";
[email protected]ba5ab4662014-04-30 14:36:3135 } else if (modifier == "dev") {
sdefresne6e883e42015-07-30 08:05:5436 channel = version_info::Channel::DEV;
[email protected]ba5ab4662014-04-30 14:36:3137 } else if (modifier == "beta") {
sdefresne6e883e42015-07-30 08:05:5438 channel = version_info::Channel::BETA;
[email protected]f44f0a822011-06-24 18:39:1239 } else {
40 modifier = "unknown";
41 }
42#endif
43
[email protected]ba5ab4662014-04-30 14:36:3144 if (modifier_out)
45 modifier_out->swap(modifier);
46
47 return channel;
48}
49
50} // namespace
51
Boris Vidolov86578012018-03-21 16:55:2552std::string GetChannelName() {
[email protected]ba5ab4662014-04-30 14:36:3153 std::string modifier;
Nico Weber7e526ba52019-10-29 18:40:5754 GetChannelImpl(&modifier);
[email protected]f44f0a822011-06-24 18:39:1255 return modifier;
56}
57
Steve Kobesd90e3bcc2017-06-27 05:14:1258std::string GetChannelSuffixForDataDir() {
Nico Weber7e526ba52019-10-29 18:40:5759 switch (GetChannel()) {
60 case version_info::Channel::BETA:
61 return "-beta";
62 case version_info::Channel::DEV:
63 return "-unstable";
64 default:
65 // Stable and unknown (e.g. in unbranded builds) don't get a suffix.
66 return std::string();
67 }
Steve Kobesd90e3bcc2017-06-27 05:14:1268}
Steve Kobesd90e3bcc2017-06-27 05:14:1269
Tom Andersonb8a86032019-10-09 20:12:4570#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
71std::string GetDesktopName(base::Environment* env) {
72#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
Olivier Tilloyde982ca2020-04-14 17:33:0673 // Google Chrome packaged as a snap is a special case: the application name
74 // is always "google-chrome", regardless of the channel (channels are built
75 // in to snapd, switching between them or doing parallel installs does not
76 // require distinct application names).
77 std::string snap_name;
78 if (env->GetVar("SNAP_NAME", &snap_name) && snap_name == "google-chrome")
79 return "google-chrome.desktop";
Tom Andersonb8a86032019-10-09 20:12:4580 version_info::Channel product_channel(GetChannel());
81 switch (product_channel) {
82 case version_info::Channel::DEV:
83 return "google-chrome-unstable.desktop";
84 case version_info::Channel::BETA:
85 return "google-chrome-beta.desktop";
86 default:
87 return "google-chrome.desktop";
88 }
89#else // BUILDFLAG(CHROMIUM_BRANDING)
90 // Allow $CHROME_DESKTOP to override the built-in value, so that development
91 // versions can set themselves as the default without interfering with
92 // non-official, packaged versions using the built-in value.
93 std::string name;
94 if (env->GetVar("CHROME_DESKTOP", &name) && !name.empty())
95 return name;
96 return "chromium-browser.desktop";
97#endif
98}
99#endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
100
Reid Klecknera05b4042018-12-28 21:42:54101version_info::Channel GetChannel() {
Nico Weber7e526ba52019-10-29 18:40:57102 return GetChannelImpl(nullptr);
[email protected]f44f0a822011-06-24 18:39:12103}
104
[email protected]f44f0a822011-06-24 18:39:12105} // namespace chrome