Skip to content

Commit

Permalink
[remoting] Integrate with RemotingFtlMobileAPIKey
Browse files Browse the repository at this point in the history
This CL implements GetRemotingFtlMobileAPIKey on google_apis and hooks
it up with FtlGrpcContext.

Bug: 954594
Change-Id: I8fb55de710f5ba5b0ee83127eada4c2b806ad8e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1583001
Reviewed-by: Joe Downing <joedow@chromium.org>
Reviewed-by: Roger Tawa <rogerta@chromium.org>
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#655360}
  • Loading branch information
ywh233 authored and Commit Bot committed Apr 30, 2019
1 parent 2baf2a1 commit e287631
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
17 changes: 17 additions & 0 deletions google_apis/google_api_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
#define GOOGLE_API_KEY_REMOTING_FTL DUMMY_API_TOKEN
#endif

#if !defined(GOOGLE_API_KEY_REMOTING_FTL_MOBILE)
#define GOOGLE_API_KEY_REMOTING_FTL_MOBILE DUMMY_API_TOKEN
#endif

// These are used as shortcuts for developers and users providing
// OAuth credentials via preprocessor defines or environment
// variables. If set, they will be used to replace any of the client
Expand Down Expand Up @@ -125,6 +129,11 @@ class APIKeyCache {
STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY_REMOTING_FTL), nullptr,
std::string(), environment.get(), command_line);

api_key_remoting_ftl_mobile_ = CalculateKeyValue(
GOOGLE_API_KEY_REMOTING_FTL_MOBILE,
STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY_REMOTING_FTL_MOBILE), nullptr,
std::string(), environment.get(), command_line);

metrics_key_ = CalculateKeyValue(
GOOGLE_METRICS_SIGNING_KEY,
STRINGIZE_NO_EXPANSION(GOOGLE_METRICS_SIGNING_KEY), nullptr,
Expand Down Expand Up @@ -194,6 +203,9 @@ class APIKeyCache {
#endif
std::string api_key_non_stable() const { return api_key_non_stable_; }
std::string api_key_remoting_ftl() const { return api_key_remoting_ftl_; }
std::string api_key_remoting_ftl_mobile() const {
return api_key_remoting_ftl_mobile_;
}

std::string metrics_key() const { return metrics_key_; }

Expand Down Expand Up @@ -292,6 +304,7 @@ class APIKeyCache {
std::string api_key_;
std::string api_key_non_stable_;
std::string api_key_remoting_ftl_;
std::string api_key_remoting_ftl_mobile_;
std::string metrics_key_;
std::string client_ids_[CLIENT_NUM_ITEMS];
std::string client_secrets_[CLIENT_NUM_ITEMS];
Expand All @@ -316,6 +329,10 @@ std::string GetRemotingFtlAPIKey() {
return g_api_key_cache.Get().api_key_remoting_ftl();
}

std::string GetRemotingFtlMobileAPIKey() {
return g_api_key_cache.Get().api_key_remoting_ftl_mobile();
}

#if defined(OS_IOS)
void SetAPIKey(const std::string& api_key) {
g_api_key_cache.Get().set_api_key(api_key);
Expand Down
1 change: 1 addition & 0 deletions google_apis/google_api_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ std::string GetNonStableAPIKey();
// Retrieves the Chrome Remote Desktop FTL API key to be used during the
// signaling process.
std::string GetRemotingFtlAPIKey();
std::string GetRemotingFtlMobileAPIKey();

#if defined(OS_IOS)
// Sets the API key. This should be called as early as possible before this
Expand Down
7 changes: 6 additions & 1 deletion remoting/signaling/ftl_grpc_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ GrpcChannelSharedPtr FtlGrpcContext::CreateChannel() {
// static
std::unique_ptr<grpc::ClientContext> FtlGrpcContext::CreateClientContext() {
auto context = std::make_unique<grpc::ClientContext>();
context->AddMetadata("x-goog-api-key", google_apis::GetRemotingFtlAPIKey());
#if defined(OS_ANDROID) || defined(OS_IOS)
std::string api_key = google_apis::GetRemotingFtlMobileAPIKey();
#else
std::string api_key = google_apis::GetRemotingFtlAPIKey();
#endif
context->AddMetadata("x-goog-api-key", api_key);
return context;
}

Expand Down

0 comments on commit e287631

Please sign in to comment.