[google_apis] Allow overriding use_official_google_api_keys
Previously, is_chrome_branded would override a false value. Fix that and update the C++ logic to be compatible. Retains the existing behavior for iOS only due to iOS issue https://crbug.com/1171510, which caused the previous attempt, https://crrev.com/c/2657805, to be reverted. Bug: 1294915, 1183709 Change-Id: I68d8babe6461a91117396488b2a27772c9952f80 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3756721 Reviewed-by: Sylvain Defresne <sdefresne@chromium.org> Commit-Queue: David Dorwin <ddorwin@chromium.org> Cr-Commit-Position: refs/heads/main@{#1041234}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
6a96ad6216
commit
0ae6b65b32
google_apis
@ -17,14 +17,13 @@ declare_args() {
|
||||
# Set the variable to false to not use the internal file, even for
|
||||
# Chrome-branded builds or when it exists in your checkout.
|
||||
#
|
||||
# Leave it unset or set to "" to have the variable
|
||||
# implicitly set to true if you have
|
||||
# src/google_apis/internal/google_chrome_api_keys.h in your
|
||||
# checkout, and implicitly set to false if not.
|
||||
#
|
||||
# Note that Chrome-branded builds always behave as if the variable
|
||||
# was explicitly set to true, i.e. they always use official keys,
|
||||
# and will fail to build if the internal file is missing.
|
||||
# Leave it set to "" to have the variable implicitly set to true for
|
||||
# Chrome-branded builds or if
|
||||
# //src/google_apis/internal/google_chrome_api_keys.h is present and false
|
||||
# otherwise.
|
||||
# This does not apply to iOS builds, which use different mechanisms and always
|
||||
# evaluate to use_official_google_api_keys=false.
|
||||
# See https://crbug.com/1183709.
|
||||
use_official_google_api_keys = ""
|
||||
|
||||
# Set these to bake the specified API keys and OAuth client
|
||||
@ -36,9 +35,8 @@ declare_args() {
|
||||
# require server-side APIs may fail to work if no keys are
|
||||
# provided.
|
||||
#
|
||||
# Note that when building a Chrome-branded build or if
|
||||
# `use_official_google_api_keys` has been set to `true` (explicitly or
|
||||
# implicitly), these values will be ignored and the official
|
||||
# Note that if `use_official_google_api_keys` has been set to true
|
||||
# (explicitly or implicitly), these values will be ignored and the official
|
||||
# keys will be used instead.
|
||||
google_api_key = ""
|
||||
|
||||
@ -50,21 +48,42 @@ declare_args() {
|
||||
}
|
||||
|
||||
if (use_official_google_api_keys == "") {
|
||||
# Default behavior, check if the key file exists.
|
||||
check_internal_result =
|
||||
exec_script("build/check_internal.py",
|
||||
[ rebase_path("internal/google_chrome_api_keys.h",
|
||||
root_build_dir) ],
|
||||
"value")
|
||||
use_official_google_api_keys = check_internal_result == 1
|
||||
# No override set. Determine the default behavior.
|
||||
if (is_chrome_branded) {
|
||||
# Chrome-branded builds default to behaving as if
|
||||
#`use_official_google_api_keys` was explicitly set to true and will fail to
|
||||
# build if the file is missing.
|
||||
use_official_google_api_keys = true
|
||||
|
||||
# TODO(crbug.com/1294931): Remove this override when fixing the issue.
|
||||
if (is_fuchsia) {
|
||||
use_official_google_api_keys = false
|
||||
}
|
||||
} else {
|
||||
# Check if the key file exists.
|
||||
check_internal_result =
|
||||
exec_script("build/check_internal.py",
|
||||
[ rebase_path("internal/google_chrome_api_keys.h",
|
||||
root_build_dir) ],
|
||||
"value")
|
||||
use_official_google_api_keys = check_internal_result == 1
|
||||
}
|
||||
}
|
||||
|
||||
# Official API keys should always be used for Chrome-branded builds except on
|
||||
# iOS (see https://crbug.com/1183709) and Fuchsia (see the description of
|
||||
# https://crbug.com/1171510 for background).
|
||||
assert(
|
||||
use_official_google_api_keys || !is_chrome_branded || is_ios || is_fuchsia)
|
||||
|
||||
# This arg should always be false on iOS. See https://crbug.com/1183709.
|
||||
assert(!use_official_google_api_keys || !is_ios)
|
||||
|
||||
config("key_defines") {
|
||||
defines = []
|
||||
|
||||
# TODO(crbug.com/1294915): Refactor so use_official_google_api_keys can be
|
||||
# used for Fuchsia.
|
||||
if (!is_fuchsia && (is_chrome_branded || use_official_google_api_keys)) {
|
||||
# On iOS, Chrome branding controls this define. See https://crbug.com/1183709.
|
||||
if (use_official_google_api_keys || (is_ios && is_chrome_branded)) {
|
||||
defines += [ "USE_OFFICIAL_GOOGLE_API_KEYS=1" ]
|
||||
}
|
||||
if (google_api_key != "") {
|
||||
@ -143,7 +162,8 @@ template("google_apis_tmpl") {
|
||||
"//services/network/public/cpp",
|
||||
]
|
||||
|
||||
if (is_chrome_branded || use_official_google_api_keys) {
|
||||
# On iOS, Chrome branding controls this deps. See https://crbug.com/1183709.
|
||||
if (use_official_google_api_keys || (is_ios && is_chrome_branded)) {
|
||||
deps += [ "internal:generate_metrics_key_header" ]
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,8 @@ class APIKeyCache {
|
||||
}
|
||||
|
||||
std::string api_key() const { return api_key_; }
|
||||
#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_FUCHSIA)
|
||||
#if BUILDFLAG(IS_IOS) || \
|
||||
(BUILDFLAG(IS_FUCHSIA) && !defined(USE_OFFICIAL_GOOGLE_API_KEYS))
|
||||
void set_api_key(const std::string& api_key) { api_key_ = api_key; }
|
||||
#endif
|
||||
std::string api_key_non_stable() const { return api_key_non_stable_; }
|
||||
@ -301,7 +302,10 @@ class APIKeyCache {
|
||||
}
|
||||
|
||||
if (key_value == DUMMY_API_TOKEN) {
|
||||
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && !BUILDFLAG(IS_FUCHSIA)
|
||||
// iOS does not use USE_OFFICIAL_GOOGLE_API_KEYS. See https://crbug.com/1183709.
|
||||
// TODO(Tcrbug.com/1183709): The GN logic is inconsistent with this.
|
||||
#if defined(USE_OFFICIAL_GOOGLE_API_KEYS) || \
|
||||
(BUILDFLAG(IS_IOS) && BUILDFLAG(GOOGLE_CHROME_BRANDING))
|
||||
// No key should be unset in an official build except the
|
||||
// GOOGLE_DEFAULT_* keys. The default keys don't trigger this
|
||||
// check as their "unset" value is not DUMMY_API_TOKEN.
|
||||
@ -369,7 +373,8 @@ std::string GetFresnelAPIKey() {
|
||||
return g_api_key_cache.Get().api_key_fresnel();
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_FUCHSIA)
|
||||
#if BUILDFLAG(IS_IOS) || \
|
||||
(BUILDFLAG(IS_FUCHSIA) && !defined(USE_OFFICIAL_GOOGLE_API_KEYS))
|
||||
void SetAPIKey(const std::string& api_key) {
|
||||
g_api_key_cache.Get().set_api_key(api_key);
|
||||
}
|
||||
|
@ -89,7 +89,8 @@ std::string GetReadAloudAPIKey();
|
||||
// Retrieves the Fresnel API Key.
|
||||
std::string GetFresnelAPIKey();
|
||||
|
||||
#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_FUCHSIA)
|
||||
#if BUILDFLAG(IS_IOS) || \
|
||||
(BUILDFLAG(IS_FUCHSIA) && !defined(USE_OFFICIAL_GOOGLE_API_KEYS))
|
||||
// Sets the API key. This should be called as early as possible before this
|
||||
// API key is even accessed. It must be called before GetAPIKey.
|
||||
// TODO(https://crbug.com/1166007): Enforce this is called before GetAPIKey.
|
||||
|
Reference in New Issue
Block a user