123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- // Copyright (c) 2011 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "chrome/common/channel_info.h"
- #include <stdlib.h>
- #include <string>
- #include "base/environment.h"
- #include "base/notreached.h"
- #include "base/strings/string_piece.h"
- #include "base/strings/string_util.h"
- #include "build/branding_buildflags.h"
- #include "build/build_config.h"
- #include "build/chromeos_buildflags.h"
- #include "components/version_info/version_info.h"
- namespace chrome {
- namespace {
- struct ChannelState {
- version_info::Channel channel;
- bool is_extended_stable;
- };
- // Returns the channel state for the browser based on branding and the
- // CHROME_VERSION_EXTRA environment variable. In unbranded (Chromium) builds,
- // this function unconditionally returns `channel` = UNKNOWN and
- // `is_extended_stable` = false. In branded (Google Chrome) builds, this
- // function returns `channel` = UNKNOWN and `is_extended_stable` = false for any
- // unexpected $CHROME_VERSION_EXTRA value.
- ChannelState GetChannelImpl() {
- #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
- const char* const env = getenv("CHROME_VERSION_EXTRA");
- const base::StringPiece env_str =
- env ? base::StringPiece(env) : base::StringPiece();
- // Ordered by decreasing expected population size.
- if (env_str == "stable")
- return {version_info::Channel::STABLE, /*is_extended_stable=*/false};
- if (env_str == "extended")
- return {version_info::Channel::STABLE, /*is_extended_stable=*/true};
- if (env_str == "beta")
- return {version_info::Channel::BETA, /*is_extended_stable=*/false};
- if (env_str == "unstable") // linux version of "dev"
- return {version_info::Channel::DEV, /*is_extended_stable=*/false};
- #endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
- return {version_info::Channel::UNKNOWN, /*is_extended_stable=*/false};
- }
- } // namespace
- std::string GetChannelName(WithExtendedStable with_extended_stable) {
- #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
- const auto channel_state = GetChannelImpl();
- switch (channel_state.channel) {
- case version_info::Channel::UNKNOWN:
- return "unknown";
- case version_info::Channel::CANARY:
- NOTREACHED();
- return "unknown";
- case version_info::Channel::DEV:
- return "dev";
- case version_info::Channel::BETA:
- return "beta";
- case version_info::Channel::STABLE:
- if (with_extended_stable && channel_state.is_extended_stable)
- return "extended";
- return std::string();
- }
- #else // BUILDFLAG(GOOGLE_CHROME_BRANDING)
- const char* const env = getenv("CHROME_VERSION_EXTRA");
- return env ? std::string(base::StringPiece(env)) : std::string();
- #endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
- }
- std::string GetChannelSuffixForDataDir() {
- switch (GetChannel()) {
- case version_info::Channel::BETA:
- return "-beta";
- case version_info::Channel::DEV:
- return "-unstable";
- default:
- // Stable, extended stable, and unknown (e.g. in unbranded builds) don't
- // get a suffix.
- return std::string();
- }
- }
- // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
- // of lacros-chrome is complete.
- #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
- std::string GetDesktopName(base::Environment* env) {
- #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
- // Google Chrome packaged as a snap is a special case: the application name
- // is always "google-chrome", regardless of the channel (channels are built
- // in to snapd, switching between them or doing parallel installs does not
- // require distinct application names).
- std::string snap_name;
- if (env->GetVar("SNAP_NAME", &snap_name) && snap_name == "google-chrome")
- return "google-chrome.desktop";
- version_info::Channel product_channel(GetChannel());
- switch (product_channel) {
- case version_info::Channel::DEV:
- return "google-chrome-unstable.desktop";
- case version_info::Channel::BETA:
- return "google-chrome-beta.desktop";
- default:
- // Extended stable is not differentiated from regular stable.
- return "google-chrome.desktop";
- }
- #else // BUILDFLAG(CHROMIUM_BRANDING)
- // Allow $CHROME_DESKTOP to override the built-in value, so that development
- // versions can set themselves as the default without interfering with
- // non-official, packaged versions using the built-in value.
- std::string name;
- if (env->GetVar("CHROME_DESKTOP", &name) && !name.empty())
- return name;
- return "chromium-browser.desktop";
- #endif
- }
- #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
- version_info::Channel GetChannel() {
- return GetChannelImpl().channel;
- }
- bool IsExtendedStableChannel() {
- return GetChannelImpl().is_extended_stable;
- }
- } // namespace chrome
|