Commit bf89f72a authored by Yue Li's avatar Yue Li Committed by Commit Bot

Add entrypoint for Assistant OptIn flow

Bug: b/78191741
Change-Id: I0bd7969e411adbace1f76eea8ba0d0d964312afe
Reviewed-on: https://chromium-review.googlesource.com/1099729
Commit-Queue: Yue Li <updowndota@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568039}
parent 1d697363
......@@ -14,6 +14,7 @@
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/toast/toast_data.h"
#include "ash/system/toast/toast_manager.h"
#include "ash/voice_interaction/voice_interaction_controller.h"
#include "base/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/utf_string_conversions.h"
......@@ -79,6 +80,11 @@ void AssistantController::SetWebContentsManager(
web_contents_manager_ = std::move(web_contents_manager);
}
void AssistantController::SetAssistantSetup(
mojom::AssistantSetupPtr assistant_setup) {
assistant_setup_ = std::move(assistant_setup);
}
void AssistantController::RequestScreenshot(
const gfx::Rect& rect,
RequestScreenshotCallback callback) {
......@@ -164,6 +170,13 @@ void AssistantController::RemoveInteractionModelObserver(
}
void AssistantController::StartInteraction() {
if (!Shell::Get()->voice_interaction_controller()->setup_completed()) {
assistant_setup_->StartAssistantOptInFlow();
return;
}
if (!Shell::Get()->voice_interaction_controller()->settings_enabled())
return;
if (!assistant_) {
ShowToast(kUnboundServiceToastId, IDS_ASH_ASSISTANT_ERROR_GENERIC);
return;
......
......@@ -15,6 +15,7 @@
#include "ash/highlighter/highlighter_controller.h"
#include "ash/public/interfaces/assistant_controller.mojom.h"
#include "ash/public/interfaces/assistant_image_downloader.mojom.h"
#include "ash/public/interfaces/assistant_setup.mojom.h"
#include "ash/public/interfaces/web_contents_manager.mojom.h"
#include "base/macros.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
......@@ -121,12 +122,14 @@ class AssistantController
void OnSpeechLevelUpdated(float speech_level) override;
// mojom::AssistantController:
// TODO(updowndota): Refactor Set() calls to use a factory pattern.
void SetAssistant(
chromeos::assistant::mojom::AssistantPtr assistant) override;
void SetAssistantImageDownloader(
mojom::AssistantImageDownloaderPtr assistant_image_downloader) override;
void SetWebContentsManager(
mojom::WebContentsManagerPtr web_contents_manager) override;
void SetAssistantSetup(mojom::AssistantSetupPtr assistant_setup) override;
void RequestScreenshot(const gfx::Rect& rect,
RequestScreenshotCallback callback) override;
......@@ -157,6 +160,7 @@ class AssistantController
chromeos::assistant::mojom::AssistantPtr assistant_;
mojom::AssistantImageDownloaderPtr assistant_image_downloader_;
mojom::WebContentsManagerPtr web_contents_manager_;
mojom::AssistantSetupPtr assistant_setup_;
std::unique_ptr<AssistantBubbleController> assistant_bubble_controller_;
......
......@@ -20,6 +20,7 @@ mojom("interfaces_internal") {
"ash_message_center_controller.mojom",
"assistant_controller.mojom",
"assistant_image_downloader.mojom",
"assistant_setup.mojom",
"cast_config.mojom",
"client_image_registry.mojom",
"constants.mojom",
......
......@@ -6,6 +6,7 @@ module ash.mojom;
import "ash/public/interfaces/assistant_image_downloader.mojom";
import "ash/public/interfaces/web_contents_manager.mojom";
import "ash/public/interfaces/assistant_setup.mojom";
import "chromeos/services/assistant/public/mojom/assistant.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom";
......@@ -26,6 +27,9 @@ interface AssistantController {
// AssistantClient.
SetWebContentsManager(WebContentsManager web_contents_manager);
// Provides an interface to the |assistant_setup| owned by AssistantClient.
SetAssistantSetup(AssistantSetup assistant_setup);
// Requests screenshot of specified |rect| region and returns the screenshot
// encoded in JPEG format. If |rect| is empty, it returns fullscreen
// screenshot.
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module ash.mojom;
// Interface for a class which is responsible for start Assistant OptIn flow.
interface AssistantSetup {
// Start the assistant setup flow.
StartAssistantOptInFlow();
};
......@@ -3736,6 +3736,8 @@ split_static_library("ui") {
"ash/assistant/assistant_context_util.h",
"ash/assistant/assistant_image_downloader.cc",
"ash/assistant/assistant_image_downloader.h",
"ash/assistant/assistant_setup.cc",
"ash/assistant/assistant_setup.h",
"ash/assistant/platform_audio_input_host.cc",
"ash/assistant/platform_audio_input_host.h",
"ash/assistant/web_contents_manager.cc",
......
......@@ -9,6 +9,7 @@
#include "ash/public/interfaces/voice_interaction_controller.mojom.h"
#include "chrome/browser/chromeos/arc/voice_interaction/voice_interaction_controller_client.h"
#include "chrome/browser/ui/ash/assistant/assistant_image_downloader.h"
#include "chrome/browser/ui/ash/assistant/assistant_setup.h"
#include "chrome/browser/ui/ash/assistant/web_contents_manager.h"
#include "chromeos/services/assistant/public/mojom/constants.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
......@@ -59,8 +60,8 @@ void AssistantClient::MaybeInit(service_manager::Connector* connector) {
assistant_image_downloader_ =
std::make_unique<AssistantImageDownloader>(connector);
web_contents_manager_ = std::make_unique<WebContentsManager>(connector);
assistant_setup_ = std::make_unique<AssistantSetup>(connector);
}
void AssistantClient::OnAssistantStatusChanged(bool running) {
......
......@@ -19,6 +19,7 @@ class Connector;
class AssistantImageDownloader;
class WebContentsManager;
class AssistantSetup;
// Class to handle all assistant in-browser-process functionalities.
class AssistantClient : chromeos::assistant::mojom::Client {
......@@ -46,6 +47,7 @@ class AssistantClient : chromeos::assistant::mojom::Client {
AssistantContext context_;
std::unique_ptr<AssistantImageDownloader> assistant_image_downloader_;
std::unique_ptr<AssistantSetup> assistant_setup_;
std::unique_ptr<WebContentsManager> web_contents_manager_;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/assistant/assistant_setup.h"
#include "ash/public/interfaces/assistant_controller.mojom.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_ui.h"
#include "services/service_manager/public/cpp/connector.h"
AssistantSetup::AssistantSetup(service_manager::Connector* connector)
: binding_(this) {
// Bind to the Assistant controller in ash.
ash::mojom::AssistantControllerPtr assistant_controller;
connector->BindInterface(ash::mojom::kServiceName, &assistant_controller);
ash::mojom::AssistantSetupPtr ptr;
binding_.Bind(mojo::MakeRequest(&ptr));
assistant_controller->SetAssistantSetup(std::move(ptr));
}
AssistantSetup::~AssistantSetup() = default;
void AssistantSetup::StartAssistantOptInFlow() {
if (chromeos::AssistantOptInDialog::IsActive())
return;
chromeos::AssistantOptInDialog::Show();
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_ASSISTANT_ASSISTANT_SETUP_H_
#define CHROME_BROWSER_UI_ASH_ASSISTANT_ASSISTANT_SETUP_H_
#include "ash/public/interfaces/assistant_setup.mojom.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h"
namespace service_manager {
class Connector;
} // namespace service_manager
// AssistantSetup is the class responsible for start Assistant OptIn flow.
class AssistantSetup : public ash::mojom::AssistantSetup {
public:
explicit AssistantSetup(service_manager::Connector* connector);
~AssistantSetup() override;
// ash::mojom::AssistantSetup:
void StartAssistantOptInFlow() override;
private:
mojo::Binding<ash::mojom::AssistantSetup> binding_;
DISALLOW_COPY_AND_ASSIGN(AssistantSetup);
};
#endif // CHROME_BROWSER_UI_ASH_ASSISTANT_ASSISTANT_SETUP_H_
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