From 01565ee9b8ea8f38a5d8c9366a03be2295a27244 Mon Sep 17 00:00:00 2001 From: Collin Baker Date: Fri, 7 May 2021 23:44:32 +0000 Subject: [PATCH] Show and start tutorials from chrome://internals/user-education/ Wires up the WebUI page to tutorials infrastructure. Currently starting a tutorial will do nothing since FeatureTutorialService is a stub. Bug: 1194751 Change-Id: I32b9df5028195cbe692ae94a1475bcf6cd75da22 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2875644 Commit-Queue: Collin Baker Reviewed-by: Robert Sesek Reviewed-by: Dana Fried Cr-Commit-Position: refs/heads/master@{#880629} --- .../user_education_internals.js | 6 ++--- .../user_education_internals.mojom | 8 ++++-- ...r_education_internals_page_handler_impl.cc | 27 ++++++++++++++++--- ...er_education_internals_page_handler_impl.h | 8 +++++- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/chrome/browser/resources/internals/user_education/user_education_internals.js b/chrome/browser/resources/internals/user_education/user_education_internals.js index a2ffaed3a19550..0ba33a5a9eb0bc 100644 --- a/chrome/browser/resources/internals/user_education/user_education_internals.js +++ b/chrome/browser/resources/internals/user_education/user_education_internals.js @@ -35,9 +35,9 @@ class UserEducationInternalsElement extends PolymerElement { /** @override */ ready() { super.ready(); - // TODO(crbug.com/1194751): fetch tutorial IDs from handler and display - // them. - this.tutorials_ = ['test1', 'test2']; + this.handler_.getTutorials().then(({tutorialIds}) => { + this.tutorials_ = tutorialIds; + }); } /** diff --git a/chrome/browser/ui/webui/internals/user_education/user_education_internals.mojom b/chrome/browser/ui/webui/internals/user_education/user_education_internals.mojom index bbca5549d9c63c..2861192af7bdce 100644 --- a/chrome/browser/ui/webui/internals/user_education/user_education_internals.mojom +++ b/chrome/browser/ui/webui/internals/user_education/user_education_internals.mojom @@ -7,6 +7,10 @@ module mojom.user_education_internals; // Provides access to browser-side user education data (including IPH) for // chrome://internals/user-education interface UserEducationInternalsPageHandler { - // TODO(crbug.com/1194751): add methods for getting list of tutorials - // and starting a tutorial. + // Get the list of all available tutorials. Only needs to be called once + // since the browser-side list is static and does not change. + GetTutorials() => (array tutorial_ids); + + // Start a tutorial listed in the `GetTutorials` result. + StartTutorial(string tutorial_id); }; diff --git a/chrome/browser/ui/webui/internals/user_education/user_education_internals_page_handler_impl.cc b/chrome/browser/ui/webui/internals/user_education/user_education_internals_page_handler_impl.cc index aaf5a2a55fa0eb..2e6fdf7a74514c 100644 --- a/chrome/browser/ui/webui/internals/user_education/user_education_internals_page_handler_impl.cc +++ b/chrome/browser/ui/webui/internals/user_education/user_education_internals_page_handler_impl.cc @@ -4,15 +4,36 @@ #include "chrome/browser/ui/webui/internals/user_education/user_education_internals_page_handler_impl.h" +#include "chrome/browser/ui/user_education/feature_tutorial_service.h" +#include "chrome/browser/ui/user_education/feature_tutorial_service_factory.h" +#include "chrome/browser/ui/user_education/feature_tutorials.h" #include "chrome/grit/dev_ui_browser_resources.h" #include "ui/base/webui/resource_path.h" UserEducationInternalsPageHandlerImpl::UserEducationInternalsPageHandlerImpl( Profile* profile) -/* : profile_(profile) */ { - // TODO(crbug.com/1194751): get reference to tutorial registry (once - // implemented). + : tutorial_service_(FeatureTutorialServiceFactory::GetForProfile(profile)) { } UserEducationInternalsPageHandlerImpl:: ~UserEducationInternalsPageHandlerImpl() = default; + +void UserEducationInternalsPageHandlerImpl::GetTutorials( + GetTutorialsCallback callback) { + std::vector id_pieces = GetAllFeatureTutorialStringIds(); + + std::vector ids; + for (base::StringPiece piece : id_pieces) + ids.emplace_back(piece.data(), piece.size()); + + std::move(callback).Run(std::move(ids)); +} + +void UserEducationInternalsPageHandlerImpl::StartTutorial( + const std::string& tutorial_id) { + base::Optional tutorial = + GetFeatureTutorialFromStringId(tutorial_id); + if (!tutorial) + return; + tutorial_service_->StartTutorial(*tutorial); +} diff --git a/chrome/browser/ui/webui/internals/user_education/user_education_internals_page_handler_impl.h b/chrome/browser/ui/webui/internals/user_education/user_education_internals_page_handler_impl.h index 25740ec1b8569f..dae079d9f76358 100644 --- a/chrome/browser/ui/webui/internals/user_education/user_education_internals_page_handler_impl.h +++ b/chrome/browser/ui/webui/internals/user_education/user_education_internals_page_handler_impl.h @@ -9,6 +9,8 @@ #include "chrome/browser/ui/webui/internals/user_education/user_education_internals.mojom.h" #include "content/public/browser/web_ui_data_source.h" +class FeatureTutorialService; + class UserEducationInternalsPageHandlerImpl : public mojom::user_education_internals:: UserEducationInternalsPageHandler { @@ -21,8 +23,12 @@ class UserEducationInternalsPageHandlerImpl UserEducationInternalsPageHandlerImpl& operator=( const UserEducationInternalsPageHandlerImpl&) = delete; + // mojom::user_education_internals::UserEducationInternalsPageHandler: + void GetTutorials(GetTutorialsCallback callback) override; + void StartTutorial(const std::string& tutorial_id) override; + private: - // Profile* profile_ = nullptr; + FeatureTutorialService* const tutorial_service_; }; #endif // CHROME_BROWSER_UI_WEBUI_INTERNALS_USER_EDUCATION_USER_EDUCATION_INTERNALS_PAGE_HANDLER_IMPL_H_