Commit 4cd7ee2d authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

Plumb through the API key for devtools surveys

Devtools is adding functionality to do in-product surveys via a
non-public API. This CL adds the ability for the chrome-internal
repository to set an API key that gets piped through to devtools.

The API key is added to google_api_keys in the same way that other API
keys are handled, meaning it can be locally overridden, although there
is not much point to actually doing this because the API itself is not
public.

This CL adds a new method 'getSurveyAPIKey' to the InspectorFrontendHost
API which the devtools frontend uses to communicate with chrome.

The corresponding frontend CL is http://crrev.com/c/2361683/

Doc: https://docs.google.com/document/d/1wMRb1hI2zJ1mzOSJjjF46C2hToGksQf2AxurorxaiTg/edit#heading=h.jc7x7daf69yo

Bug: 1112738
Change-Id: Ic3d9d436556f06b8ff8fb3593e4ed40d68ed3507
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2362182Reviewed-by: default avatarSimon Zünd <szuend@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807027}
parent 7237d134
...@@ -233,5 +233,7 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend( ...@@ -233,5 +233,7 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(
&Delegate::SetOpenNewWindowForPopups, delegate); &Delegate::SetOpenNewWindowForPopups, delegate);
d->RegisterHandler("registerExtensionsAPI", &Delegate::RegisterExtensionsAPI, d->RegisterHandler("registerExtensionsAPI", &Delegate::RegisterExtensionsAPI,
delegate); delegate);
d->RegisterHandlerWithCallback("getSurveyAPIKey", &Delegate::GetSurveyAPIKey,
delegate);
return d; return d;
} }
...@@ -104,6 +104,7 @@ class DevToolsEmbedderMessageDispatcher { ...@@ -104,6 +104,7 @@ class DevToolsEmbedderMessageDispatcher {
virtual void SetOpenNewWindowForPopups(bool value) = 0; virtual void SetOpenNewWindowForPopups(bool value) = 0;
virtual void RegisterExtensionsAPI(const std::string& origin, virtual void RegisterExtensionsAPI(const std::string& origin,
const std::string& script) = 0; const std::string& script) = 0;
virtual void GetSurveyAPIKey(const DispatchCallback& callback) = 0;
}; };
using DispatchCallback = Delegate::DispatchCallback; using DispatchCallback = Delegate::DispatchCallback;
......
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/common/permissions/permissions_data.h" #include "extensions/common/permissions/permissions_data.h"
#include "google_apis/google_api_keys.h"
#include "ipc/ipc_channel.h" #include "ipc/ipc_channel.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
...@@ -1530,6 +1531,12 @@ void DevToolsUIBindings::RegisterExtensionsAPI(const std::string& origin, ...@@ -1530,6 +1531,12 @@ void DevToolsUIBindings::RegisterExtensionsAPI(const std::string& origin,
extensions_api_[origin + "/"] = script; extensions_api_[origin + "/"] = script;
} }
void DevToolsUIBindings::GetSurveyAPIKey(const DispatchCallback& callback) {
base::DictionaryValue response;
response.SetString("apiKey", google_apis::GetDevtoolsSurveysAPIKey());
callback.Run(&response);
}
void DevToolsUIBindings::SetDelegate(Delegate* delegate) { void DevToolsUIBindings::SetDelegate(Delegate* delegate) {
delegate_.reset(delegate); delegate_.reset(delegate);
} }
......
...@@ -171,6 +171,7 @@ class DevToolsUIBindings : public DevToolsEmbedderMessageDispatcher::Delegate, ...@@ -171,6 +171,7 @@ class DevToolsUIBindings : public DevToolsEmbedderMessageDispatcher::Delegate,
void SetOpenNewWindowForPopups(bool value) override; void SetOpenNewWindowForPopups(bool value) override;
void RegisterExtensionsAPI(const std::string& origin, void RegisterExtensionsAPI(const std::string& origin,
const std::string& script) override; const std::string& script) override;
void GetSurveyAPIKey(const DispatchCallback& callback) override;
void EnableRemoteDeviceCounter(bool enable); void EnableRemoteDeviceCounter(bool enable);
......
...@@ -95,6 +95,12 @@ ...@@ -95,6 +95,12 @@
#define GOOGLE_API_KEY_SODA DUMMY_API_TOKEN #define GOOGLE_API_KEY_SODA DUMMY_API_TOKEN
#endif #endif
// API key for the DevTools frontend to use for surveys. Note there is no
// public API to replace this functionality.
#if !defined(GOOGLE_API_KEY_DEVTOOLS_SURVEYS)
#define GOOGLE_API_KEY_DEVTOOLS_SURVEYS DUMMY_API_TOKEN
#endif
// These are used as shortcuts for developers and users providing // These are used as shortcuts for developers and users providing
// OAuth credentials via preprocessor defines or environment // OAuth credentials via preprocessor defines or environment
// variables. If set, they will be used to replace any of the client // variables. If set, they will be used to replace any of the client
...@@ -147,6 +153,11 @@ class APIKeyCache { ...@@ -147,6 +153,11 @@ class APIKeyCache {
GOOGLE_API_KEY_SODA, STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY_SODA), GOOGLE_API_KEY_SODA, STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY_SODA),
nullptr, std::string(), environment.get(), command_line, gaia_config); nullptr, std::string(), environment.get(), command_line, gaia_config);
api_key_devtools_surveys_ = CalculateKeyValue(
GOOGLE_API_KEY_DEVTOOLS_SURVEYS,
STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY_DEVTOOLS_SURVEYS), nullptr,
std::string(), environment.get(), command_line, gaia_config);
metrics_key_ = CalculateKeyValue( metrics_key_ = CalculateKeyValue(
GOOGLE_METRICS_SIGNING_KEY, GOOGLE_METRICS_SIGNING_KEY,
STRINGIZE_NO_EXPANSION(GOOGLE_METRICS_SIGNING_KEY), nullptr, STRINGIZE_NO_EXPANSION(GOOGLE_METRICS_SIGNING_KEY), nullptr,
...@@ -213,6 +224,9 @@ class APIKeyCache { ...@@ -213,6 +224,9 @@ class APIKeyCache {
std::string api_key_remoting() const { return api_key_remoting_; } std::string api_key_remoting() const { return api_key_remoting_; }
std::string api_key_sharing() const { return api_key_sharing_; } std::string api_key_sharing() const { return api_key_sharing_; }
std::string api_key_soda() const { return api_key_soda_; } std::string api_key_soda() const { return api_key_soda_; }
std::string api_key_devtools_surveys() const {
return api_key_devtools_surveys_;
}
std::string metrics_key() const { return metrics_key_; } std::string metrics_key() const { return metrics_key_; }
...@@ -324,6 +338,7 @@ class APIKeyCache { ...@@ -324,6 +338,7 @@ class APIKeyCache {
std::string api_key_remoting_; std::string api_key_remoting_;
std::string api_key_sharing_; std::string api_key_sharing_;
std::string api_key_soda_; std::string api_key_soda_;
std::string api_key_devtools_surveys_;
std::string metrics_key_; std::string metrics_key_;
std::string client_ids_[CLIENT_NUM_ITEMS]; std::string client_ids_[CLIENT_NUM_ITEMS];
std::string client_secrets_[CLIENT_NUM_ITEMS]; std::string client_secrets_[CLIENT_NUM_ITEMS];
...@@ -356,6 +371,10 @@ std::string GetSodaAPIKey() { ...@@ -356,6 +371,10 @@ std::string GetSodaAPIKey() {
return g_api_key_cache.Get().api_key_soda(); return g_api_key_cache.Get().api_key_soda();
} }
std::string GetDevtoolsSurveysAPIKey() {
return g_api_key_cache.Get().api_key_devtools_surveys();
}
#if defined(OS_IOS) #if defined(OS_IOS)
void SetAPIKey(const std::string& api_key) { void SetAPIKey(const std::string& api_key) {
g_api_key_cache.Get().set_api_key(api_key); g_api_key_cache.Get().set_api_key(api_key);
......
...@@ -83,6 +83,10 @@ std::string GetSharingAPIKey(); ...@@ -83,6 +83,10 @@ std::string GetSharingAPIKey();
// Retrieves the Speech On-Device API (SODA) API Key. // Retrieves the Speech On-Device API (SODA) API Key.
std::string GetSodaAPIKey(); std::string GetSodaAPIKey();
// Retrieves the DevTools Survey API Key. Note there is no public API to replace
// this functionality.
std::string GetDevtoolsSurveysAPIKey();
#if defined(OS_IOS) #if defined(OS_IOS)
// Sets the API key. This should be called as early as possible before this // Sets the API key. This should be called as early as possible before this
// API key is even accessed. // API key is even accessed.
......
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