[email protected] | f44f0a82 | 2011-06-24 18:39:12 | [diff] [blame] | 1 | // 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 | |||||
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 5 | #include "chrome/common/channel_info.h" |
[email protected] | f44f0a82 | 2011-06-24 18:39:12 | [diff] [blame] | 6 | |
Tom Anderson | b8a8603 | 2019-10-09 20:12:45 | [diff] [blame] | 7 | #include "base/environment.h" |
[email protected] | 81b34900 | 2014-03-04 18:42:58 | [diff] [blame] | 8 | #include "base/strings/string_util.h" |
Nico Weber | 9116a2f1 | 2019-10-07 16:32:12 | [diff] [blame] | 9 | #include "build/branding_buildflags.h" |
[email protected] | 99713a53 | 2013-11-20 05:45:17 | [diff] [blame] | 10 | #include "build/build_config.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 11 | #include "components/version_info/version_info.h" |
[email protected] | 99713a53 | 2013-11-20 05:45:17 | [diff] [blame] | 12 | |
[email protected] | f44f0a82 | 2011-06-24 18:39:12 | [diff] [blame] | 13 | namespace chrome { |
14 | |||||
[email protected] | ba5ab466 | 2014-04-30 14:36:31 | [diff] [blame] | 15 | namespace { |
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 Weber | 7e526ba5 | 2019-10-29 18:40:57 | [diff] [blame] | 20 | version_info::Channel GetChannelImpl(std::string* modifier_out) { |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 21 | version_info::Channel channel = version_info::Channel::UNKNOWN; |
[email protected] | ba5ab466 | 2014-04-30 14:36:31 | [diff] [blame] | 22 | std::string modifier; |
23 | |||||
[email protected] | f44f0a82 | 2011-06-24 18:39:12 | [diff] [blame] | 24 | char* env = getenv("CHROME_VERSION_EXTRA"); |
[email protected] | ba5ab466 | 2014-04-30 14:36:31 | [diff] [blame] | 25 | if (env) |
26 | modifier = env; | ||||
[email protected] | f44f0a82 | 2011-06-24 18:39:12 | [diff] [blame] | 27 | |
Nico Weber | 9116a2f1 | 2019-10-07 16:32:12 | [diff] [blame] | 28 | #if BUILDFLAG(GOOGLE_CHROME_BRANDING) |
[email protected] | f44f0a82 | 2011-06-24 18:39:12 | [diff] [blame] | 29 | // 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") { | ||||
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 33 | channel = version_info::Channel::STABLE; |
[email protected] | f44f0a82 | 2011-06-24 18:39:12 | [diff] [blame] | 34 | modifier = ""; |
[email protected] | ba5ab466 | 2014-04-30 14:36:31 | [diff] [blame] | 35 | } else if (modifier == "dev") { |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 36 | channel = version_info::Channel::DEV; |
[email protected] | ba5ab466 | 2014-04-30 14:36:31 | [diff] [blame] | 37 | } else if (modifier == "beta") { |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 38 | channel = version_info::Channel::BETA; |
[email protected] | f44f0a82 | 2011-06-24 18:39:12 | [diff] [blame] | 39 | } else { |
40 | modifier = "unknown"; | ||||
41 | } | ||||
42 | #endif | ||||
43 | |||||
[email protected] | ba5ab466 | 2014-04-30 14:36:31 | [diff] [blame] | 44 | if (modifier_out) |
45 | modifier_out->swap(modifier); | ||||
46 | |||||
47 | return channel; | ||||
48 | } | ||||
49 | |||||
50 | } // namespace | ||||
51 | |||||
Boris Vidolov | 8657801 | 2018-03-21 16:55:25 | [diff] [blame] | 52 | std::string GetChannelName() { |
[email protected] | ba5ab466 | 2014-04-30 14:36:31 | [diff] [blame] | 53 | std::string modifier; |
Nico Weber | 7e526ba5 | 2019-10-29 18:40:57 | [diff] [blame] | 54 | GetChannelImpl(&modifier); |
[email protected] | f44f0a82 | 2011-06-24 18:39:12 | [diff] [blame] | 55 | return modifier; |
56 | } | ||||
57 | |||||
Steve Kobes | d90e3bcc | 2017-06-27 05:14:12 | [diff] [blame] | 58 | std::string GetChannelSuffixForDataDir() { |
Nico Weber | 7e526ba5 | 2019-10-29 18:40:57 | [diff] [blame] | 59 | 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 Kobes | d90e3bcc | 2017-06-27 05:14:12 | [diff] [blame] | 68 | } |
Steve Kobes | d90e3bcc | 2017-06-27 05:14:12 | [diff] [blame] | 69 | |
Tom Anderson | b8a8603 | 2019-10-09 20:12:45 | [diff] [blame] | 70 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
71 | std::string GetDesktopName(base::Environment* env) { | ||||
72 | #if BUILDFLAG(GOOGLE_CHROME_BRANDING) | ||||
Olivier Tilloy | de982ca | 2020-04-14 17:33:06 | [diff] [blame] | 73 | // 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 Anderson | b8a8603 | 2019-10-09 20:12:45 | [diff] [blame] | 80 | 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 Kleckner | a05b404 | 2018-12-28 21:42:54 | [diff] [blame] | 101 | version_info::Channel GetChannel() { |
Nico Weber | 7e526ba5 | 2019-10-29 18:40:57 | [diff] [blame] | 102 | return GetChannelImpl(nullptr); |
[email protected] | f44f0a82 | 2011-06-24 18:39:12 | [diff] [blame] | 103 | } |
104 | |||||
[email protected] | f44f0a82 | 2011-06-24 18:39:12 | [diff] [blame] | 105 | } // namespace chrome |