Commit 3cf47826 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

Add new devtools survey APIs

We are no longer passing the API key to the frontend to perform the
survey so this CL deletes getAPIKey which is not used.

The devtools frontend now triggers the existing Chrome HaTS impl to run
the survey.

CanShowSurvey will be used to determine whether we show the survey link
in the devtools frontend, and then ShowSurvey will be used when the
link is clicked.

Bug: 1112738
Change-Id: Ia456e419c2678cfe6c90976d82af8d37f1ac435f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2509570
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823551}
parent e25847a9
......@@ -233,7 +233,8 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(
&Delegate::SetOpenNewWindowForPopups, delegate);
d->RegisterHandler("registerExtensionsAPI", &Delegate::RegisterExtensionsAPI,
delegate);
d->RegisterHandlerWithCallback("getSurveyAPIKey", &Delegate::GetSurveyAPIKey,
d->RegisterHandlerWithCallback("showSurvey", &Delegate::ShowSurvey, delegate);
d->RegisterHandlerWithCallback("canShowSurvey", &Delegate::CanShowSurvey,
delegate);
return d;
}
......@@ -104,7 +104,10 @@ class DevToolsEmbedderMessageDispatcher {
virtual void SetOpenNewWindowForPopups(bool value) = 0;
virtual void RegisterExtensionsAPI(const std::string& origin,
const std::string& script) = 0;
virtual void GetSurveyAPIKey(const DispatchCallback& callback) = 0;
virtual void ShowSurvey(const DispatchCallback& callback,
const std::string& trigger) = 0;
virtual void CanShowSurvey(const DispatchCallback& callback,
const std::string& trigger) = 0;
};
using DispatchCallback = Delegate::DispatchCallback;
......
......@@ -40,6 +40,8 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/hats/hats_service.h"
#include "chrome/browser/ui/hats/hats_service_factory.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/chrome_manifest_url_handlers.h"
......@@ -1524,9 +1526,33 @@ void DevToolsUIBindings::RegisterExtensionsAPI(const std::string& origin,
extensions_api_[origin + "/"] = script;
}
void DevToolsUIBindings::GetSurveyAPIKey(const DispatchCallback& callback) {
namespace {
void ShowSurveyCallback(const DevToolsUIBindings::DispatchCallback& callback,
bool survey_shown) {
base::DictionaryValue response;
response.SetBoolean("surveyShown", survey_shown);
callback.Run(&response);
}
} // namespace
void DevToolsUIBindings::ShowSurvey(const DispatchCallback& callback,
const std::string& trigger) {
HatsService* hats_service =
HatsServiceFactory::GetForProfile(profile_->GetOriginalProfile(), true);
hats_service->LaunchSurvey(
trigger, base::BindOnce(ShowSurveyCallback, callback, true),
base::BindOnce(ShowSurveyCallback, callback, false));
}
void DevToolsUIBindings::CanShowSurvey(const DispatchCallback& callback,
const std::string& trigger) {
HatsService* hats_service =
HatsServiceFactory::GetForProfile(profile_->GetOriginalProfile(), true);
bool can_show = hats_service->CanShowSurvey(trigger);
base::DictionaryValue response;
response.SetString("apiKey", google_apis::GetDevtoolsSurveysAPIKey());
response.SetBoolean("canShowSurvey", can_show);
callback.Run(&response);
}
......
......@@ -171,7 +171,10 @@ class DevToolsUIBindings : public DevToolsEmbedderMessageDispatcher::Delegate,
void SetOpenNewWindowForPopups(bool value) override;
void RegisterExtensionsAPI(const std::string& origin,
const std::string& script) override;
void GetSurveyAPIKey(const DispatchCallback& callback) override;
void ShowSurvey(const DispatchCallback& callback,
const std::string& trigger) override;
void CanShowSurvey(const DispatchCallback& callback,
const std::string& trigger) override;
void EnableRemoteDeviceCounter(bool enable);
......
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