diff --git a/android_webview/browser/aw_ip_protection_config_provider.cc b/android_webview/browser/aw_ip_protection_config_provider.cc index 03eccc662a8f8..31f142334a714 100644 --- a/android_webview/browser/aw_ip_protection_config_provider.cc +++ b/android_webview/browser/aw_ip_protection_config_provider.cc @@ -38,17 +38,6 @@ #include "net/third_party/quiche/src/quiche/blind_sign_auth/proto/blind_sign_auth_options.pb.h" #include "net/third_party/quiche/src/quiche/blind_sign_auth/proto/spend_token_data.pb.h" -namespace { -// TODO(crbug.com/40216037): Once `google_apis::GetAPIKey()` handles this -// logic we can remove this helper. -std::string GetAPIKey() { - version_info::Channel channel = version_info::android::GetChannel(); - return channel == version_info::Channel::STABLE - ? google_apis::GetAPIKey() - : google_apis::GetNonStableAPIKey(); -} -} // namespace - namespace android_webview { AwIpProtectionConfigProvider::AwIpProtectionConfigProvider( @@ -71,7 +60,7 @@ void AwIpProtectionConfigProvider::SetUp() { ->GetURLLoaderFactoryForBrowserProcess() .get(), ip_protection::IpProtectionConfigProviderHelper::kWebViewIpBlinding, - GetAPIKey()); + google_apis::GetAPIKey(version_info::android::GetChannel())); } if (!bsa_) { diff --git a/chrome/browser/accessibility/accessibility_labels_service.cc b/chrome/browser/accessibility/accessibility_labels_service.cc index 0501a9d040b0e..7a667ba290b82 100644 --- a/chrome/browser/accessibility/accessibility_labels_service.cc +++ b/chrome/browser/accessibility/accessibility_labels_service.cc @@ -43,14 +43,6 @@ using LanguageInfo = language::UrlLanguageHistogram::LanguageInfo; namespace { -// Returns the Chrome Google API key for the channel of this build. -std::string APIKeyForChannel() { - if (chrome::GetChannel() == version_info::Channel::STABLE) { - return google_apis::GetAPIKey(); - } - return google_apis::GetNonStableAPIKey(); -} - AccessibilityLabelsService::ImageAnnotatorBinder& GetImageAnnotatorBinderOverride() { static base::NoDestructor<AccessibilityLabelsService::ImageAnnotatorBinder> @@ -237,7 +229,8 @@ void AccessibilityLabelsService::BindImageAnnotator( auto* manta_service = manta::MantaServiceFactory::GetForProfile(profile_); CHECK(manta_service); service_ = std::make_unique<image_annotation::ImageAnnotationService>( - std::move(service_receiver), APIKeyForChannel(), + std::move(service_receiver), + google_apis::GetAPIKey(chrome::GetChannel()), profile_->GetURLLoaderFactory(), manta_service->CreateAnchovyProvider(), std::make_unique<ImageAnnotatorClient>(profile_)); diff --git a/chrome/browser/ash/login/oobe_quick_start/second_device_auth_broker.cc b/chrome/browser/ash/login/oobe_quick_start/second_device_auth_broker.cc index ff95357267d78..d9c308e8856de 100644 --- a/chrome/browser/ash/login/oobe_quick_start/second_device_auth_broker.cc +++ b/chrome/browser/ash/login/oobe_quick_start/second_device_auth_broker.cc @@ -531,9 +531,7 @@ void SecondDeviceAuthBroker::FetchChallengeBytes( /*post_data=*/kGetChallengeDataRequest, /*headers=*/std::vector<std::string>(), /*cors_exempt_headers=*/std::vector<std::string>(), - /*annotation_tag=*/kChallengeDataAnnotation, - /*is_stable_channel=*/chrome::GetChannel() == - version_info::Channel::STABLE); + /*annotation_tag=*/kChallengeDataAnnotation, chrome::GetChannel()); metrics_.RecordChallengeBytesRequested(); endpoint_fetcher_->PerformRequest( @@ -592,9 +590,7 @@ void SecondDeviceAuthBroker::FetchAuthCode( CreateStartSessionRequestData(fido_assertion_info, certificate), /*headers=*/std::vector<std::string>(), /*cors_exempt_headers=*/std::vector<std::string>(), - /*annotation_tag=*/kStartSessionAnnotation, - /*is_stable_channel=*/chrome::GetChannel() == - version_info::Channel::STABLE); + /*annotation_tag=*/kStartSessionAnnotation, chrome::GetChannel()); metrics_.RecordGaiaAuthenticationStarted(); endpoint_fetcher_->PerformRequest( diff --git a/chrome/browser/feed/feed_service_factory.cc b/chrome/browser/feed/feed_service_factory.cc index bd737d945a57e..1de7c09dcd89b 100644 --- a/chrome/browser/feed/feed_service_factory.cc +++ b/chrome/browser/feed/feed_service_factory.cc @@ -199,10 +199,7 @@ FeedServiceFactory::BuildServiceInstanceForBrowserContext( IdentityManagerFactory::GetForProfile(profile); std::string api_key; if (google_apis::IsGoogleChromeAPIKeyUsed()) { - bool is_stable_channel = - chrome::GetChannel() == version_info::Channel::STABLE; - api_key = is_stable_channel ? google_apis::GetAPIKey() - : google_apis::GetNonStableAPIKey(); + api_key = google_apis::GetAPIKey(chrome::GetChannel()); } scoped_refptr<base::SequencedTaskRunner> background_task_runner = diff --git a/chrome/browser/ip_protection/ip_protection_config_provider.cc b/chrome/browser/ip_protection/ip_protection_config_provider.cc index 9cf0c7ffd0830..b31cd7df4b94e 100644 --- a/chrome/browser/ip_protection/ip_protection_config_provider.cc +++ b/chrome/browser/ip_protection/ip_protection_config_provider.cc @@ -38,16 +38,6 @@ #include "net/third_party/quiche/src/quiche/blind_sign_auth/proto/blind_sign_auth_options.pb.h" #include "net/third_party/quiche/src/quiche/blind_sign_auth/proto/spend_token_data.pb.h" -namespace { -// TODO(crbug.com/40216037): Once `google_apis::GetAPIKey()` handles this -// logic we can remove this helper. -std::string GetAPIKey() { - return chrome::GetChannel() == version_info::Channel::STABLE - ? google_apis::GetAPIKey() - : google_apis::GetNonStableAPIKey(); -} -} // namespace - IpProtectionConfigProvider::IpProtectionConfigProvider( signin::IdentityManager* identity_manager, privacy_sandbox::TrackingProtectionSettings* tracking_protection_settings, @@ -79,7 +69,7 @@ void IpProtectionConfigProvider::SetUp() { std::make_unique<ip_protection::IpProtectionProxyConfigFetcher>( url_loader_factory_.get(), ip_protection::IpProtectionConfigProviderHelper::kChromeIpBlinding, - GetAPIKey()); + google_apis::GetAPIKey(chrome::GetChannel())); } if (!bsa_) { if (!blind_sign_auth_) { diff --git a/chrome/browser/query_tiles/tile_service_factory.cc b/chrome/browser/query_tiles/tile_service_factory.cc index 3280a8ece9c75..f1a328b72fbb1 100644 --- a/chrome/browser/query_tiles/tile_service_factory.cc +++ b/chrome/browser/query_tiles/tile_service_factory.cc @@ -35,16 +35,6 @@ #endif namespace query_tiles { -namespace { - -std::string GetGoogleAPIKey() { - bool is_stable_channel = - chrome::GetChannel() == version_info::Channel::STABLE; - return is_stable_channel ? google_apis::GetAPIKey() - : google_apis::GetNonStableAPIKey(); -} - -} // namespace // static TileServiceFactory* TileServiceFactory::GetInstance() { @@ -105,11 +95,12 @@ std::unique_ptr<KeyedService> TileServiceFactory::BuildServiceInstanceFor( default_server_url = base::android::ConvertJavaStringToUTF8(env, j_server_url); #endif - return CreateTileService(image_fetcher_service, db_provider, storage_dir, - background_task_scheduler, accept_languanges, - GetCountryCode(), GetGoogleAPIKey(), client_version, - default_server_url, url_loader_factory, - ProfileKey::FromSimpleFactoryKey(key)->GetPrefs()); + return CreateTileService( + image_fetcher_service, db_provider, storage_dir, + background_task_scheduler, accept_languanges, GetCountryCode(), + google_apis::GetAPIKey(chrome::GetChannel()), client_version, + default_server_url, url_loader_factory, + ProfileKey::FromSimpleFactoryKey(key)->GetPrefs()); } } // namespace query_tiles diff --git a/chrome/browser/ui/lens/lens_overlay_query_controller.cc b/chrome/browser/ui/lens/lens_overlay_query_controller.cc index 7dd18738c730f..3eb6f17a72341 100644 --- a/chrome/browser/ui/lens/lens_overlay_query_controller.cc +++ b/chrome/browser/ui/lens/lens_overlay_query_controller.cc @@ -796,9 +796,7 @@ void LensOverlayQueryController::FetchEndpoint( /*post_data=*/request_data_string, /*headers=*/headers, /*cors_exempt_headers=*/cors_exempt_headers, - /*annotation_tag=*/kTrafficAnnotationTag, - /*is_stable_channel=*/chrome::GetChannel() == - version_info::Channel::STABLE); + /*annotation_tag=*/kTrafficAnnotationTag, chrome::GetChannel()); EndpointFetcher* fetcher = endpoint_fetcher.get(); base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(fetcher_created_callback), diff --git a/chrome/browser/ui/webui/ash/emoji/gif_tenor_api_fetcher.cc b/chrome/browser/ui/webui/ash/emoji/gif_tenor_api_fetcher.cc index f21833a993762..e6bf7c63ef55f 100644 --- a/chrome/browser/ui/webui/ash/emoji/gif_tenor_api_fetcher.cc +++ b/chrome/browser/ui/webui/ash/emoji/gif_tenor_api_fetcher.cc @@ -97,9 +97,7 @@ std::unique_ptr<EndpointFetcher> CreateEndpointFetcher( /*post_data=*/"", /*headers=*/std::vector<std::string>(), /*cors_exempt_headers=*/std::vector<std::string>(), - /*annotation_tag=*/annotation_tag, - /*is_stable_channel=*/chrome::GetChannel() == - version_info::Channel::STABLE); + /*annotation_tag=*/annotation_tag, chrome::GetChannel()); } const base::Value::List* FindList( diff --git a/components/autofill/core/browser/crowdsourcing/autofill_crowdsourcing_manager.cc b/components/autofill/core/browser/crowdsourcing/autofill_crowdsourcing_manager.cc index 3c801c9d35f80..501eadeb2e05c 100644 --- a/components/autofill/core/browser/crowdsourcing/autofill_crowdsourcing_manager.cc +++ b/components/autofill/core/browser/crowdsourcing/autofill_crowdsourcing_manager.cc @@ -567,10 +567,7 @@ std::string GetAPIKeyForUrl(version_info::Channel channel) { } // Get the API key from Chrome baked keys. - if (channel == version_info::Channel::STABLE) { - return google_apis::GetAPIKey(); - } - return google_apis::GetNonStableAPIKey(); + return google_apis::GetAPIKey(channel); } std::optional<std::vector<variations::VariationID>>& GetActiveExperiments() { diff --git a/components/endpoint_fetcher/BUILD.gn b/components/endpoint_fetcher/BUILD.gn index 3d8ee18336259..4535ea4809816 100644 --- a/components/endpoint_fetcher/BUILD.gn +++ b/components/endpoint_fetcher/BUILD.gn @@ -15,6 +15,7 @@ source_set("endpoint_fetcher") { "//components/signin/public/identity_manager", "//components/version_info:channel", "//google_apis", + "//google_apis/common", "//net", "//services/data_decoder/public/cpp", "//services/network/public/cpp", diff --git a/components/endpoint_fetcher/endpoint_fetcher.cc b/components/endpoint_fetcher/endpoint_fetcher.cc index 6f34248e85442..c12ecb2dc5e25 100644 --- a/components/endpoint_fetcher/endpoint_fetcher.cc +++ b/components/endpoint_fetcher/endpoint_fetcher.cc @@ -11,6 +11,7 @@ #include "components/signin/public/identity_manager/access_token_info.h" #include "components/signin/public/identity_manager/identity_manager.h" #include "components/version_info/channel.h" +#include "google_apis/common/api_key_request_util.h" #include "google_apis/gaia/gaia_urls.h" #include "google_apis/google_api_keys.h" #include "net/http/http_status_code.h" @@ -60,7 +61,7 @@ EndpointFetcher::EndpointFetcher( const std::vector<std::string>& headers, const std::vector<std::string>& cors_exempt_headers, const net::NetworkTrafficAnnotationTag& annotation_tag, - bool is_stable_channel) + version_info::Channel channel) : auth_type_(CHROME_API_KEY), url_(url), http_method_(http_method), @@ -74,7 +75,7 @@ EndpointFetcher::EndpointFetcher( identity_manager_(nullptr), consent_level_(std::nullopt), sanitize_response_(true), - is_stable_channel_(is_stable_channel) {} + channel_(channel) {} EndpointFetcher::EndpointFetcher( const scoped_refptr<network::SharedURLLoaderFactory>& url_loader_factory, @@ -233,10 +234,7 @@ void EndpointFetcher::PerformRequest( base::StringPrintf("Bearer %s", key)); break; case CHROME_API_KEY: { - std::string api_key = is_stable_channel_ - ? google_apis::GetAPIKey() - : google_apis::GetNonStableAPIKey(); - resource_request->headers.SetHeader("x-goog-api-key", api_key); + google_apis::AddDefaultAPIKeyToRequest(*resource_request, channel_); break; } default: diff --git a/components/endpoint_fetcher/endpoint_fetcher.h b/components/endpoint_fetcher/endpoint_fetcher.h index 8e4c6ad532c2c..a7de99122d949 100644 --- a/components/endpoint_fetcher/endpoint_fetcher.h +++ b/components/endpoint_fetcher/endpoint_fetcher.h @@ -32,6 +32,10 @@ struct AccessTokenInfo; class IdentityManager; } // namespace signin +namespace version_info { +enum class Channel; +} + class GoogleServiceAuthError; class GURL; @@ -91,7 +95,7 @@ class EndpointFetcher { const std::vector<std::string>& headers, const std::vector<std::string>& cors_exempt_headers, const net::NetworkTrafficAnnotationTag& annotation_tag, - bool is_stable_channel); + version_info::Channel channel); // Constructor if no authentication is needed. EndpointFetcher( @@ -181,7 +185,7 @@ class EndpointFetcher { // null if `identity_manager_` is null. const std::optional<signin::ConsentLevel> consent_level_; bool sanitize_response_; - bool is_stable_channel_; + version_info::Channel channel_; // Members set in Fetch std::unique_ptr<const signin::PrimaryAccountAccessTokenFetcher> diff --git a/components/manta/base_provider.cc b/components/manta/base_provider.cc index a9a716124e16f..a32bc35abb8d8 100644 --- a/components/manta/base_provider.cc +++ b/components/manta/base_provider.cc @@ -5,6 +5,7 @@ #include "components/manta/base_provider.h" #include "base/containers/fixed_flat_map.h" +#include "base/version_info/channel.h" #include "components/manta/proto/manta.pb.h" namespace manta { @@ -157,7 +158,7 @@ std::unique_ptr<EndpointFetcher> BaseProvider::CreateEndpointFetcherForDemoMode( /*cors_exempt_headers=*/std::vector<std::string>(), /*annotation_tag=*/annotation_tag, // ChromeOS always uses the stable channel API key - /*is_stable_channel=*/true); + version_info::Channel::STABLE); } } // namespace manta diff --git a/components/password_manager/core/browser/leak_detection/leak_detection_check_factory_impl.cc b/components/password_manager/core/browser/leak_detection/leak_detection_check_factory_impl.cc index 20499d6372030..bd9b5b7e5e022 100644 --- a/components/password_manager/core/browser/leak_detection/leak_detection_check_factory_impl.cc +++ b/components/password_manager/core/browser/leak_detection/leak_detection_check_factory_impl.cc @@ -25,12 +25,7 @@ std::optional<std::string> GetAPIKey(bool signed_in_user, if (signed_in_user) { return std::nullopt; } - - if (channel == version_info::Channel::STABLE) { - return google_apis::GetAPIKey(); - } - - return google_apis::GetNonStableAPIKey(); + return google_apis::GetAPIKey(channel); } } // namespace diff --git a/google_apis/google_api_keys-inc.cc b/google_apis/google_api_keys-inc.cc index 722c60266194e..29956962ceb8c 100644 --- a/google_apis/google_api_keys-inc.cc +++ b/google_apis/google_api_keys-inc.cc @@ -393,18 +393,15 @@ bool HasAPIKeyConfigured() { } std::string GetAPIKey(::version_info::Channel channel) { - return channel == ::version_info::Channel::STABLE ? GetAPIKey() - : GetNonStableAPIKey(); + return channel == ::version_info::Channel::STABLE + ? GetAPIKey() + : g_api_key_cache.Get().api_key_non_stable(); } std::string GetAPIKey() { return g_api_key_cache.Get().api_key(); } -std::string GetNonStableAPIKey() { - return g_api_key_cache.Get().api_key_non_stable(); -} - std::string GetRemotingAPIKey() { return g_api_key_cache.Get().api_key_remoting(); } diff --git a/google_apis/google_api_keys.h b/google_apis/google_api_keys.h index 21fc39a9c1e25..66eda66364299 100644 --- a/google_apis/google_api_keys.h +++ b/google_apis/google_api_keys.h @@ -89,12 +89,6 @@ std::string GetAPIKey(version_info::Channel channel); // distribution channel instead of calling this function directly. COMPONENT_EXPORT(GOOGLE_APIS) std::string GetAPIKey(); -// Non-stable channels may have a different Google API key. -// -// DEPRECATED: Use `GetAPIKey(channel)` to get the right key for your -// distribution channel instead of calling this function directly. -COMPONENT_EXPORT(GOOGLE_APIS) std::string GetNonStableAPIKey(); - // Retrieves the Chrome Remote Desktop API key. COMPONENT_EXPORT(GOOGLE_APIS) std::string GetRemotingAPIKey();