Commit a666b374 authored by Avi Drissman's avatar Avi Drissman Committed by Chromium LUCI CQ

Cache Mac channel information

Soon, with TargetChannel, an instance of Chrome on the disk
might be upgraded to an instance of Chrome of a different
channel. Cache the channel information on startup, so that
even if it's changed, the channel information of the current
running instance is available.

This relands aa20f9b8 with
a fix.

Fixed: 1163159
Change-Id: If1e3da89ff70da765782dd4dbdf0505da67c4e3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2620839Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842079}
parent 5976b8e3
...@@ -578,6 +578,10 @@ void ChromeMainDelegate::PostEarlyInitialization(bool is_running_tests) { ...@@ -578,6 +578,10 @@ void ChromeMainDelegate::PostEarlyInitialization(bool is_running_tests) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
UmaSessionStats::OnStartup(); UmaSessionStats::OnStartup();
#endif #endif
#if defined(OS_MAC)
chrome::CacheChannelInfo();
#endif
} }
bool ChromeMainDelegate::ShouldCreateFeatureList() { bool ChromeMainDelegate::ShouldCreateFeatureList() {
......
...@@ -42,6 +42,12 @@ std::string GetChannelName(); ...@@ -42,6 +42,12 @@ std::string GetChannelName();
version_info::Channel GetChannel(); version_info::Channel GetChannel();
#if defined(OS_MAC) #if defined(OS_MAC)
// Because the channel information on the Mac is baked into the Info.plist file,
// and that file may change during an update, this function must be called
// early in startup to cache the channel info so that the correct channel info
// can be returned later.
void CacheChannelInfo();
// Maps the name of the channel to version_info::Channel, always returning // Maps the name of the channel to version_info::Channel, always returning
// Channel::UNKNOWN for unbranded builds. For branded builds defaults to // Channel::UNKNOWN for unbranded builds. For branded builds defaults to
// Channel::STABLE, if channel is empty, else matches the name and returns // Channel::STABLE, if channel is empty, else matches the name and returns
......
...@@ -7,14 +7,19 @@ ...@@ -7,14 +7,19 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include "base/mac/bundle_locations.h" #include "base/mac/bundle_locations.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "build/branding_buildflags.h" #include "build/branding_buildflags.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
namespace chrome { namespace chrome {
std::string GetChannelName() { namespace {
std::string ChannelName() {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
static const base::NoDestructor<std::string> channel([] {
// Use the main Chrome application bundle and not the framework bundle. // Use the main Chrome application bundle and not the framework bundle.
// Keystone keys don't live in the framework. // Keystone keys don't live in the framework.
NSBundle* bundle = base::mac::OuterBundle(); NSBundle* bundle = base::mac::OuterBundle();
...@@ -42,34 +47,23 @@ std::string GetChannelName() { ...@@ -42,34 +47,23 @@ std::string GetChannelName() {
channel = [channel substringFromIndex:[@"universal-" length]]; channel = [channel substringFromIndex:[@"universal-" length]];
if ([channel isEqual:@"beta"] || [channel isEqual:@"dev"] || if ([channel isEqual:@"beta"] || [channel isEqual:@"dev"] ||
[channel isEqual:@"canary"]) { [channel isEqual:@"canary"]) {
// do nothing. // Do nothing.
} else { } else {
channel = @"unknown"; channel = @"unknown";
} }
} }
return base::SysNSStringToUTF8(channel); return base::SysNSStringToUTF8(channel);
}());
return *channel;
#else #else
return std::string(); return std::string();
#endif #endif
} }
version_info::Channel GetChannelByName(const std::string& channel) { bool SideBySideCapable() {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
if (channel.empty())
return version_info::Channel::STABLE;
if (channel == "beta")
return version_info::Channel::BETA;
if (channel == "dev")
return version_info::Channel::DEV;
if (channel == "canary")
return version_info::Channel::CANARY;
#endif
return version_info::Channel::UNKNOWN;
}
bool IsSideBySideCapable() {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) #if BUILDFLAG(GOOGLE_CHROME_BRANDING)
static const base::NoDestructor<bool> capable([] {
// Use the main Chrome application bundle and not the framework bundle. // Use the main Chrome application bundle and not the framework bundle.
// Keystone keys don't live in the framework. // Keystone keys don't live in the framework.
NSBundle* bundle = base::mac::OuterBundle(); NSBundle* bundle = base::mac::OuterBundle();
...@@ -89,14 +83,45 @@ bool IsSideBySideCapable() { ...@@ -89,14 +83,45 @@ bool IsSideBySideCapable() {
// If there is a CrProductDirName key, then the user data dir of this // If there is a CrProductDirName key, then the user data dir of this
// beta/dev/canary Chrome is separate, and it can run side-by-side to the // beta/dev/canary Chrome is separate, and it can run side-by-side to the
// stable Chrome. // stable Chrome.
return [bundle objectForInfoDictionaryKey:@"CrProductDirName"]; return [bundle objectForInfoDictionaryKey:@"CrProductDirName"] != nil;
}());
return *capable;
#else #else
return true; return true;
#endif #endif
} }
} // namespace
void CacheChannelInfo() {
ignore_result(ChannelName());
ignore_result(SideBySideCapable());
}
std::string GetChannelName() {
return ChannelName();
}
version_info::Channel GetChannelByName(const std::string& channel) {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
if (channel.empty())
return version_info::Channel::STABLE;
if (channel == "beta")
return version_info::Channel::BETA;
if (channel == "dev")
return version_info::Channel::DEV;
if (channel == "canary")
return version_info::Channel::CANARY;
#endif
return version_info::Channel::UNKNOWN;
}
bool IsSideBySideCapable() {
return SideBySideCapable();
}
version_info::Channel GetChannel() { version_info::Channel GetChannel() {
return GetChannelByName(GetChannelName()); return GetChannelByName(ChannelName());
} }
} // namespace chrome } // namespace chrome
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment