Consistent interface to add the Google API key to a request
As part of crrev/c/5734315 I notice there is a lot of inconsistency and duplication in how we set API keys on requests: * Some places set a URL parameter, some set the HTTP header (both are valid per https://cloud.google.com/apis/docs/system-parameters) * The header name is hard-coded in many places * Call sites don't all handle the different stable/non-stable channel keys This CL adds an API to improve on the issues above. Bug: 355544759 Change-Id: Iea4616bcbdcb10ba7d9e2dcd8ffefddd2df813be Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5730337 Auto-Submit: James Lee <ljjlee@google.com> Reviewed-by: Alex Ilin <alexilin@chromium.org> Reviewed-by: Nohemi Fernandez <fernandex@chromium.org> Commit-Queue: James Lee <ljjlee@google.com> Cr-Commit-Position: refs/heads/main@{#1334202}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
0a77734fe4
commit
feb1c36478
@ -14,6 +14,10 @@
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "google_apis/buildflags.h"
|
||||
|
||||
namespace version_info {
|
||||
enum class Channel;
|
||||
}
|
||||
|
||||
// These functions enable you to retrieve keys to use for Google APIs
|
||||
// such as Translate and Safe Browsing.
|
||||
//
|
||||
@ -72,9 +76,23 @@ COMPONENT_EXPORT(GOOGLE_APIS) bool HasAPIKeyConfigured();
|
||||
//
|
||||
// Note that the key should be escaped for the context you use it in,
|
||||
// e.g. URL-escaped if you use it in a URL.
|
||||
//
|
||||
// If you want to attach the key to a network request, consider using
|
||||
// `AddDefaultAPIKeyToRequest()` rather than calling this method and manually
|
||||
// adding the key.
|
||||
COMPONENT_EXPORT(GOOGLE_APIS)
|
||||
std::string GetAPIKey(version_info::Channel channel);
|
||||
|
||||
// Retrieves the API key, for the stable channel.
|
||||
//
|
||||
// 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 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.
|
||||
|
Reference in New Issue
Block a user