Commit 07833805 authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

[Mac] Put the CPU type into Chrome's “about” string.

There will be different binaries offered for Intel and Arm Macs,
so distinguish them.

This achieves this via a slight refactor, funneling all the places
that show this data through the same function.

Bug: 1106067
Change-Id: Id5f44ab4d7ca3186d09669984abed5b0377224ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2305749
Commit-Queue: Avi Drissman <avi@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791500}
parent f257555b
......@@ -180,6 +180,15 @@ inline bool IsOSLaterThan11_DontCallThis() {
return !IsAtMostOS11();
}
enum class CPUType {
kIntel,
kTranslatedIntel, // Rosetta
kArm,
};
// Returns the type of CPU this is being executed on.
BASE_EXPORT CPUType GetCPUType();
// Retrieve the system's model identifier string from the IOKit registry:
// for example, "MacPro4,1", "MacBookPro6,1". Returns empty string upon
// failure.
......
......@@ -9,6 +9,8 @@
#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/xattr.h>
......@@ -23,6 +25,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/sys_string_conversions.h"
#include "build/build_config.h"
namespace base {
namespace mac {
......@@ -350,6 +353,29 @@ int MacOSVersion() {
} // namespace internal
#if defined(ARCH_CPU_X86_64)
namespace {
// https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment#3616845
bool ProcessIsTranslated() {
int ret = 0;
size_t size = sizeof(ret);
if (sysctlbyname("sysctl.proc_translated", &ret, &size, nullptr, 0) == -1)
return false;
return ret;
}
} // namespace
#endif // ARCH_CPU_X86_64
CPUType GetCPUType() {
#if defined(ARCH_CPU_ARM64)
return CPUType::kArm;
#elif defined(ARCH_CPU_X86_64)
return ProcessIsTranslated() ? CPUType::kTranslatedIntel : CPUType::kIntel;
#else
#error Time for another chip transition?
#endif // ARCH_CPU_*
}
std::string GetModelIdentifier() {
std::string return_string;
ScopedIOObject<io_service_t> platform_expert(
......
......@@ -35,6 +35,7 @@
#include "chrome/browser/policy/schema_registry_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
#include "chrome/browser/ui/webui/version_ui.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/channel_info.h"
#include "chrome/grit/chromium_strings.h"
......@@ -1221,9 +1222,7 @@ std::string PolicyUIHandler::GetPoliciesAsJson() const {
: IDS_VERSION_UI_UNOFFICIAL)
.c_str(),
(channel_name.empty() ? "" : " " + channel_name).c_str(),
l10n_util::GetStringUTF8(sizeof(void*) == 8 ? IDS_VERSION_UI_64BIT
: IDS_VERSION_UI_32BIT)
.c_str(),
l10n_util::GetStringUTF8(VersionUI::VersionProcessorVariation()).c_str(),
cohort_name.c_str());
chrome_metadata.SetKey("version", base::Value(version));
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/ui/webui/management_ui.h"
#include "chrome/browser/ui/webui/settings/about_handler.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_tag_registry.h"
#include "chrome/browser/ui/webui/version_ui.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/pref_names.h"
......@@ -292,9 +293,7 @@ void AboutSection::AddLoadTimeData(content::WebUIDataSource* html_source) {
? IDS_VERSION_UI_OFFICIAL
: IDS_VERSION_UI_UNOFFICIAL),
base::UTF8ToUTF16(chrome::GetChannelName()),
l10n_util::GetStringUTF16(sizeof(void*) == 8
? IDS_VERSION_UI_64BIT
: IDS_VERSION_UI_32BIT)));
l10n_util::GetStringUTF16(VersionUI::VersionProcessorVariation())));
html_source->AddString(
"aboutProductCopyright",
base::i18n::MessageFormatter::FormatWithNumberedArgs(
......
......@@ -15,6 +15,7 @@
#include "chrome/browser/extensions/api/passwords_private/passwords_private_delegate_factory.h"
#include "chrome/browser/password_manager/bulk_leak_check_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/version_ui.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/url_constants.h"
......@@ -486,8 +487,7 @@ base::string16 SafetyCheckHandler::GetStringForUpdates(UpdateStatus status) {
? IDS_VERSION_UI_OFFICIAL
: IDS_VERSION_UI_UNOFFICIAL),
base::UTF8ToUTF16(chrome::GetChannelName()),
l10n_util::GetStringUTF16(sizeof(void*) == 8 ? IDS_VERSION_UI_64BIT
: IDS_VERSION_UI_32BIT));
l10n_util::GetStringUTF16(VersionUI::VersionProcessorVariation()));
}
}
......
......@@ -43,6 +43,10 @@
#include "ui/chromeos/devicetype_utils.h"
#endif
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
#endif
// Components for building event strings.
constexpr char kParent[] = "parent";
constexpr char kUpdates[] = "updates";
......@@ -376,6 +380,27 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_Relaunch) {
}
TEST_F(SafetyCheckHandlerTest, CheckUpdates_Disabled) {
const char* processor_variation = nullptr;
#if defined(OS_MACOSX)
switch (base::mac::GetCPUType()) {
case base::mac::CPUType::kIntel:
processor_variation = " (x86_64)";
break;
case base::mac::CPUType::kTranslatedIntel:
processor_variation = " (x86_64 translated)";
break;
case base::mac::CPUType::kArm:
processor_variation = " (arm64)";
break;
}
#elif defined(ARCH_CPU_64_BITS)
processor_variation = " (64-bit)";
#elif defined(ARCH_CPU_32_BITS)
processor_variation = " (32-bit)";
#else
#error Update for a processor that is neither 32-bit nor 64-bit.
#endif // OS_*
version_updater_->SetReturnedStatus(VersionUpdater::Status::DISABLED);
safety_check_->PerformSafetyCheck();
// TODO(crbug/1072432): Since the UNKNOWN state is not present in JS in M83,
......@@ -389,8 +414,7 @@ TEST_F(SafetyCheckHandlerTest, CheckUpdates_Disabled) {
event, "Version " + version_info::GetVersionNumber() + " (" +
(version_info::IsOfficialBuild() ? "Official Build"
: "Developer Build") +
") " + chrome::GetChannelName() +
(sizeof(void*) == 8 ? " (64-bit)" : " (32-bit)"));
") " + chrome::GetChannelName() + processor_variation);
histogram_tester_.ExpectBucketCount(
"Settings.SafetyCheck.UpdatesResult",
SafetyCheckHandler::UpdateStatus::kUnknown, 1);
......
......@@ -31,6 +31,7 @@
#include "chrome/browser/ui/webui/policy_indicator_localized_strings_provider.h"
#include "chrome/browser/ui/webui/settings/reset_settings_handler.h"
#include "chrome/browser/ui/webui/settings/shared_settings_localized_strings_provider.h"
#include "chrome/browser/ui/webui/version_ui.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_features.h"
......@@ -275,9 +276,7 @@ void AddAboutStrings(content::WebUIDataSource* html_source, Profile* profile) {
? IDS_VERSION_UI_OFFICIAL
: IDS_VERSION_UI_UNOFFICIAL),
base::UTF8ToUTF16(chrome::GetChannelName()),
l10n_util::GetStringUTF16(sizeof(void*) == 8
? IDS_VERSION_UI_64BIT
: IDS_VERSION_UI_32BIT)));
l10n_util::GetStringUTF16(VersionUI::VersionProcessorVariation())));
html_source->AddString(
"aboutProductCopyright",
base::i18n::MessageFormatter::FormatWithNumberedArgs(
......
......@@ -118,15 +118,34 @@ VersionUI::VersionUI(content::WebUI* web_ui)
VersionUI::~VersionUI() {}
// static
int VersionUI::VersionProcessorVariation() {
#if defined(OS_MACOSX)
switch (base::mac::GetCPUType()) {
case base::mac::CPUType::kIntel:
return IDS_VERSION_UI_64BIT_INTEL;
case base::mac::CPUType::kTranslatedIntel:
return IDS_VERSION_UI_64BIT_TRANSLATED_INTEL;
case base::mac::CPUType::kArm:
return IDS_VERSION_UI_64BIT_ARM;
}
#elif defined(ARCH_CPU_64_BITS)
return IDS_VERSION_UI_64BIT;
#elif defined(ARCH_CPU_32_BITS)
return IDS_VERSION_UI_32BIT;
#else
#error Update for a processor that is neither 32-bit nor 64-bit.
#endif
}
// static
void VersionUI::AddVersionDetailStrings(content::WebUIDataSource* html_source) {
html_source->AddLocalizedString(version_ui::kOfficial,
version_info::IsOfficialBuild()
? IDS_VERSION_UI_OFFICIAL
: IDS_VERSION_UI_UNOFFICIAL);
html_source->AddLocalizedString(
version_ui::kVersionBitSize,
sizeof(void*) == 8 ? IDS_VERSION_UI_64BIT : IDS_VERSION_UI_32BIT);
html_source->AddLocalizedString(version_ui::kVersionProcessorVariation,
VersionProcessorVariation());
// Data strings.
html_source->AddString(version_ui::kVersion,
......
......@@ -15,6 +15,9 @@ class VersionUI : public content::WebUIController {
explicit VersionUI(content::WebUI* web_ui);
~VersionUI() override;
// Returns the IDS_* string id for the variation of the processor.
static int VersionProcessorVariation();
// Loads a data source with many named details comprising version info.
// The keys are from version_ui_constants.
static void AddVersionDetailStrings(content::WebUIDataSource* html_source);
......
......@@ -57,7 +57,7 @@ about:version template page
<span>$i18n{version}</span>
(<span>$i18n{official}</span>)
<span>$i18n{version_modifier}</span>
<span>$i18n{version_bitsize}</span>
<span>$i18n{version_processor_variation}</span>
<if expr="is_win">
<span>$i18n{update_cohort_name}</span>
</if>
......
......@@ -82,7 +82,7 @@ const char kUserAgentName[] = "user_agent_name";
const char kVariationsCmdName[] = "variations_cmd_name";
const char kVariationsName[] = "variations_name";
const char kVersion[] = "version";
const char kVersionBitSize[] = "version_bitsize";
const char kVersionModifier[] = "version_modifier";
const char kVersionProcessorVariation[] = "version_processor_variation";
} // namespace version_ui
......@@ -87,8 +87,8 @@ extern const char kUserAgentName[];
extern const char kVariationsCmdName[];
extern const char kVariationsName[];
extern const char kVersion[];
extern const char kVersionBitSize[];
extern const char kVersionModifier[];
extern const char kVersionProcessorVariation[];
} // namespace version_ui
......
......@@ -15,6 +15,17 @@
<message name="IDS_VERSION_UI_64BIT" desc="64-bit on the chrome://version page">
(64-bit)
</message>
<if expr="is_macosx">
<message name="IDS_VERSION_UI_64BIT_INTEL" desc="On the chrome://version page, an indicator that this is an instance of Chromium built for the 64-bit x86 processor. Translation is not needed; this is a technical term.">
(x86_64)
</message>
<message name="IDS_VERSION_UI_64BIT_TRANSLATED_INTEL" desc="On the chrome://version page, an indicator that this is an instance of Chromium built for the 64-bit x86 processor, but being run on an Arm processor. Do not translate 'x86_64' as that is a technical term. The 'translated' in this string refers to the fact that these two processors use different languages, so the sense of 'translated' for this string is as in a language translation.">
(x86_64 translated)
</message>
<message name="IDS_VERSION_UI_64BIT_ARM" desc="On the chrome://version page, an indicator that this is an instance of Chromium built for the 64-bit Arm processor. Translation is not needed; this is a technical term.">
(arm64)
</message>
</if>
<message name="IDS_VERSION_UI_REVISION" desc="label for the revision on the about:version page">
Revision
</message>
......
bdc5de160996684170d70a61c8dca8ffa8478d4c
\ No newline at end of file
97eb908dab59824f6893d0da789bca272aa64d52
\ No newline at end of file
3dc03c0b95e22efc97f56040acdafaf44d83cfea
\ No newline at end of file
......@@ -72,7 +72,7 @@ web::WebUIIOSDataSource* CreateVersionUIDataSource() {
? IDS_VERSION_UI_OFFICIAL
: IDS_VERSION_UI_UNOFFICIAL);
html_source->AddLocalizedString(
version_ui::kVersionBitSize,
version_ui::kVersionProcessorVariation,
sizeof(void*) == 8 ? IDS_VERSION_UI_64BIT : IDS_VERSION_UI_32BIT);
html_source->AddLocalizedString(version_ui::kUserAgentName,
IDS_VERSION_UI_USER_AGENT);
......
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