Commit ee6f32b5 authored by David Black's avatar David Black Committed by Commit Bot

Handles opt in button press.

Handles press of opt in to trigger onboarding flow.

There didn't seem to be a great place to put this so I broke out an
AssistantSetupController. Potentially this might be a good place to
cache settings state on the Ash side in the future when we clean up
VoiceInteractionController.

Note that the AssistantOptInView is still hidden programmatically.
A follow up CL will show this view when appropriate.

See bug for demo.

Bug: b:111315696
Change-Id: I6438abc780d2d5e5753dd22c34c477b7364324e4
Reviewed-on: https://chromium-review.googlesource.com/1166259
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581891}
parent 484447e0
......@@ -68,6 +68,7 @@ component("ash") {
"assistant/assistant_interaction_controller.h",
"assistant/assistant_notification_controller.h",
"assistant/assistant_screen_context_controller.h",
"assistant/assistant_setup_controller.h",
"assistant/assistant_ui_controller.h",
"assistant/model/assistant_interaction_model.h",
"assistant/model/assistant_interaction_model_observer.h",
......@@ -734,6 +735,7 @@ component("ash") {
"assistant/assistant_interaction_controller.cc",
"assistant/assistant_notification_controller.cc",
"assistant/assistant_screen_context_controller.cc",
"assistant/assistant_setup_controller.cc",
"assistant/assistant_ui_controller.cc",
"assistant/model/assistant_interaction_model.cc",
"assistant/model/assistant_query.cc",
......
......@@ -8,6 +8,7 @@
#include "ash/assistant/assistant_interaction_controller.h"
#include "ash/assistant/assistant_notification_controller.h"
#include "ash/assistant/assistant_screen_context_controller.h"
#include "ash/assistant/assistant_setup_controller.h"
#include "ash/assistant/assistant_ui_controller.h"
#include "ash/assistant/util/deep_link_util.h"
#include "ash/new_window_controller.h"
......@@ -28,6 +29,8 @@ AssistantController::AssistantController()
std::make_unique<AssistantNotificationController>(this)),
assistant_screen_context_controller_(
std::make_unique<AssistantScreenContextController>(this)),
assistant_setup_controller_(
std::make_unique<AssistantSetupController>(this)),
assistant_ui_controller_(std::make_unique<AssistantUiController>(this)),
voice_interaction_binding_(this),
weak_factory_(this) {
......@@ -81,9 +84,12 @@ void AssistantController::SetAssistantImageDownloader(
assistant_image_downloader_ = std::move(assistant_image_downloader);
}
// TODO(dmblack): Call SetAssistantSetup directly on AssistantSetupController
// instead of going through AssistantController.
void AssistantController::SetAssistantSetup(
mojom::AssistantSetupPtr assistant_setup) {
assistant_setup_ = std::move(assistant_setup);
assistant_setup_controller_->SetAssistantSetup(assistant_setup_.get());
}
void AssistantController::SetWebContentsManager(
......@@ -168,23 +174,9 @@ void AssistantController::OnDeepLinkReceived(
// UI and behavior for Assistant.
Shell::Get()->new_window_controller()->OpenFeedbackPage();
break;
case DeepLinkType::kOnboarding:
if (GetDeepLinkParamAsBool(params, DeepLinkParam::kRelaunch)) {
assistant_setup_->StartAssistantOptInFlow(base::BindOnce(
[](AssistantUiController* ui_controller, bool completed) {
if (completed)
ui_controller->ShowUi(AssistantSource::kSetup);
},
// |assistant_setup_| and |assistant_ui_controller_| are both owned
// by this class, so a raw pointer is safe here.
assistant_ui_controller_.get()));
} else {
assistant_setup_->StartAssistantOptInFlow(base::DoNothing());
}
assistant_ui_controller_->HideUi(AssistantSource::kSetup);
break;
case DeepLinkType::kUnsupported:
case DeepLinkType::kExplore:
case DeepLinkType::kOnboarding:
case DeepLinkType::kQuery:
case DeepLinkType::kReminders:
case DeepLinkType::kSettings:
......
......@@ -35,6 +35,7 @@ namespace ash {
class AssistantInteractionController;
class AssistantNotificationController;
class AssistantScreenContextController;
class AssistantSetupController;
class AssistantUiController;
class ASH_EXPORT AssistantController
......@@ -129,6 +130,11 @@ class ASH_EXPORT AssistantController
return assistant_screen_context_controller_.get();
}
AssistantSetupController* setup_controller() {
DCHECK(assistant_setup_controller_);
return assistant_setup_controller_.get();
}
AssistantUiController* ui_controller() {
DCHECK(assistant_ui_controller_);
return assistant_ui_controller_.get();
......@@ -182,6 +188,8 @@ class ASH_EXPORT AssistantController
std::unique_ptr<AssistantScreenContextController>
assistant_screen_context_controller_;
std::unique_ptr<AssistantSetupController> assistant_setup_controller_;
std::unique_ptr<AssistantUiController> assistant_ui_controller_;
mojo::Binding<mojom::VoiceInteractionObserver> voice_interaction_binding_;
......
// 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 "ash/assistant/assistant_setup_controller.h"
#include "ash/assistant/assistant_controller.h"
#include "ash/assistant/assistant_ui_controller.h"
#include "ash/assistant/util/deep_link_util.h"
namespace ash {
AssistantSetupController::AssistantSetupController(
AssistantController* assistant_controller)
: assistant_controller_(assistant_controller) {
assistant_controller_->AddObserver(this);
}
AssistantSetupController::~AssistantSetupController() {
assistant_controller_->RemoveObserver(this);
}
void AssistantSetupController::SetAssistantSetup(
mojom::AssistantSetup* assistant_setup) {
assistant_setup_ = assistant_setup;
}
void AssistantSetupController::OnDeepLinkReceived(
assistant::util::DeepLinkType type,
const std::map<std::string, std::string>& params) {
using namespace assistant::util;
if (type != DeepLinkType::kOnboarding)
return;
base::Optional<bool> relaunch =
GetDeepLinkParamAsBool(params, DeepLinkParam::kRelaunch);
StartOnboarding(relaunch.value_or(false));
}
void AssistantSetupController::OnOptInButtonPressed() {
StartOnboarding(/*relaunch=*/true);
}
void AssistantSetupController::StartOnboarding(bool relaunch) {
if (!assistant_setup_)
return;
if (relaunch) {
assistant_setup_->StartAssistantOptInFlow(base::BindOnce(
[](AssistantController* assistant_controller, bool completed) {
if (completed) {
assistant_controller->ui_controller()->ShowUi(
AssistantSource::kSetup);
}
},
// AssistantController owns |assistant_setup_| so a raw pointer is safe.
assistant_controller_));
} else {
assistant_setup_->StartAssistantOptInFlow(base::DoNothing());
}
// Assistant UI should be hidden while the user onboards.
assistant_controller_->ui_controller()->HideUi(AssistantSource::kSetup);
}
} // namespace ash
// 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 ASH_ASSISTANT_ASSISTANT_SETUP_CONTROLLER_H_
#define ASH_ASSISTANT_ASSISTANT_SETUP_CONTROLLER_H_
#include <map>
#include <string>
#include "ash/assistant/assistant_controller_observer.h"
#include "ash/assistant/ui/main_stage/assistant_opt_in_view.h"
#include "ash/public/interfaces/assistant_setup.mojom.h"
#include "base/macros.h"
namespace ash {
class AssistantController;
class AssistantSetupController : public AssistantControllerObserver,
public AssistantOptInDelegate {
public:
explicit AssistantSetupController(AssistantController* assistant_controller);
~AssistantSetupController() override;
// Sets the controller's internal |assistant_setup_| reference.
void SetAssistantSetup(mojom::AssistantSetup* assistant_setup);
// AssistantControllerObserver:
void OnDeepLinkReceived(
assistant::util::DeepLinkType type,
const std::map<std::string, std::string>& params) override;
// AssistantOptInDelegate:
void OnOptInButtonPressed() override;
private:
void StartOnboarding(bool relaunch);
AssistantController* const assistant_controller_; // Owned by Shell.
mojom::AssistantSetup* assistant_setup_ =
nullptr; // Owned by AssistantController.
DISALLOW_COPY_AND_ASSIGN(AssistantSetupController);
};
} // namespace ash
#endif // ASH_ASSISTANT_ASSISTANT_SETUP_CONTROLLER_H_
......@@ -7,6 +7,7 @@
#include <memory>
#include "ash/assistant/assistant_controller.h"
#include "ash/assistant/assistant_setup_controller.h"
#include "ash/assistant/ui/main_stage/assistant_opt_in_view.h"
#include "ash/assistant/ui/main_stage/suggestion_container_view.h"
#include "ui/views/layout/fill_layout.h"
......@@ -55,6 +56,7 @@ void AssistantFooterView::InitLayout() {
// Opt in view.
opt_in_view_ = new AssistantOptInView();
opt_in_view_->SetVisible(false);
opt_in_view_->set_delegate(assistant_controller_->setup_controller());
AddChildView(opt_in_view_);
}
......
......@@ -70,7 +70,7 @@ class AssistantOptInContainer : public views::View {
// AssistantOptInView ----------------------------------------------------------
AssistantOptInView::AssistantOptInView() {
AssistantOptInView::AssistantOptInView() : views::Button(/*listener=*/this) {
InitLayout();
}
......@@ -140,4 +140,10 @@ void AssistantOptInView::InitLayout() {
container->AddChildView(label_);
}
void AssistantOptInView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (delegate_)
delegate_->OnOptInButtonPressed();
}
} // namespace ash
......@@ -6,7 +6,7 @@
#define ASH_ASSISTANT_UI_MAIN_STAGE_ASSISTANT_OPT_IN_VIEW_H_
#include "base/macros.h"
#include "ui/views/view.h"
#include "ui/views/controls/button/button.h"
namespace views {
class StyledLabel;
......@@ -14,20 +14,40 @@ class StyledLabel;
namespace ash {
class AssistantOptInView : public views::View {
// AssistantOptInDelegate ------------------------------------------------------
class AssistantOptInDelegate {
public:
// Invoked when the Assistant opt in button is pressed.
virtual void OnOptInButtonPressed() = 0;
protected:
virtual ~AssistantOptInDelegate() = default;
};
// AssistantOptInView ----------------------------------------------------------
class AssistantOptInView : public views::Button, public views::ButtonListener {
public:
AssistantOptInView();
~AssistantOptInView() override;
// views::View:
// views::Button:
void ChildPreferredSizeChanged(views::View* child) override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
void set_delegate(AssistantOptInDelegate* delegate) { delegate_ = delegate; }
private:
void InitLayout();
views::StyledLabel* label_; // Owned by view hierarchy.
AssistantOptInDelegate* delegate_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(AssistantOptInView);
};
......
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