Commit 6b4b1ad2 authored by David Black's avatar David Black Committed by Commit Bot

Adds conversation starters.

Conversation starters are suggestions that show when Assistant UI is
launched. They transcend Assistant sessions in that they are pre-cached
and held in memory until needed.

To accomplish this, this CL:
- Adds AssistantCacheController/AssistantCacheModel(Observer)
- Adds support for conversation starters to SuggestionContainerView.

Still TODO:
- Limit to four conversation starters.
- Conversation starters should be centered horizontally.
- Conversation starters should be cached from the server.

In the future, we can also use this new cache for engagement cards
and other growth initiatives.

See bug for mock/demo.

Bug: b:111694337
Change-Id: Ic280d7e39a5b61c9400448f883fce147a889d908
Reviewed-on: https://chromium-review.googlesource.com/1179365Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#584605}
parent 15958335
...@@ -67,6 +67,7 @@ component("ash") { ...@@ -67,6 +67,7 @@ component("ash") {
"app_list/app_list_presenter_delegate_impl.h", "app_list/app_list_presenter_delegate_impl.h",
"ash_export.h", "ash_export.h",
"ash_service.h", "ash_service.h",
"assistant/assistant_cache_controller.h",
"assistant/assistant_controller.h", "assistant/assistant_controller.h",
"assistant/assistant_controller_observer.h", "assistant/assistant_controller_observer.h",
"assistant/assistant_interaction_controller.h", "assistant/assistant_interaction_controller.h",
...@@ -74,6 +75,8 @@ component("ash") { ...@@ -74,6 +75,8 @@ component("ash") {
"assistant/assistant_screen_context_controller.h", "assistant/assistant_screen_context_controller.h",
"assistant/assistant_setup_controller.h", "assistant/assistant_setup_controller.h",
"assistant/assistant_ui_controller.h", "assistant/assistant_ui_controller.h",
"assistant/model/assistant_cache_model.h",
"assistant/model/assistant_cache_model_observer.h",
"assistant/model/assistant_interaction_model.h", "assistant/model/assistant_interaction_model.h",
"assistant/model/assistant_interaction_model_observer.h", "assistant/model/assistant_interaction_model_observer.h",
"assistant/model/assistant_query.h", "assistant/model/assistant_query.h",
...@@ -733,12 +736,14 @@ component("ash") { ...@@ -733,12 +736,14 @@ component("ash") {
"app_list/app_list_controller_impl.cc", "app_list/app_list_controller_impl.cc",
"app_list/app_list_presenter_delegate_impl.cc", "app_list/app_list_presenter_delegate_impl.cc",
"ash_service.cc", "ash_service.cc",
"assistant/assistant_cache_controller.cc",
"assistant/assistant_controller.cc", "assistant/assistant_controller.cc",
"assistant/assistant_interaction_controller.cc", "assistant/assistant_interaction_controller.cc",
"assistant/assistant_notification_controller.cc", "assistant/assistant_notification_controller.cc",
"assistant/assistant_screen_context_controller.cc", "assistant/assistant_screen_context_controller.cc",
"assistant/assistant_setup_controller.cc", "assistant/assistant_setup_controller.cc",
"assistant/assistant_ui_controller.cc", "assistant/assistant_ui_controller.cc",
"assistant/model/assistant_cache_model.cc",
"assistant/model/assistant_interaction_model.cc", "assistant/model/assistant_interaction_model.cc",
"assistant/model/assistant_query.cc", "assistant/model/assistant_query.cc",
"assistant/model/assistant_response.cc", "assistant/model/assistant_response.cc",
......
// 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_cache_controller.h"
#include <vector>
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/voice_interaction/voice_interaction_controller.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "ui/base/l10n/l10n_util.h"
namespace ash {
AssistantCacheController::AssistantCacheController()
: voice_interaction_binding_(this) {
UpdateConversationStarters();
// Bind to observe changes to screen context preference.
mojom::VoiceInteractionObserverPtr ptr;
voice_interaction_binding_.Bind(mojo::MakeRequest(&ptr));
Shell::Get()->voice_interaction_controller()->AddObserver(std::move(ptr));
}
AssistantCacheController::~AssistantCacheController() = default;
void AssistantCacheController::AddModelObserver(
AssistantCacheModelObserver* observer) {
model_.AddObserver(observer);
}
void AssistantCacheController::RemoveModelObserver(
AssistantCacheModelObserver* observer) {
model_.RemoveObserver(observer);
}
void AssistantCacheController::OnVoiceInteractionContextEnabled(bool enabled) {
UpdateConversationStarters();
}
// TODO(dmblack): The conversation starter cache should receive its contents
// from the server. Hard-coding for the time being.
void AssistantCacheController::UpdateConversationStarters() {
using namespace chromeos::assistant::mojom;
std::vector<AssistantSuggestionPtr> conversation_starters;
auto AddConversationStarter = [&conversation_starters](int message_id) {
AssistantSuggestionPtr starter = AssistantSuggestion::New();
starter->text = l10n_util::GetStringUTF8(message_id);
conversation_starters.push_back(std::move(starter));
};
AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_WHAT_CAN_YOU_DO);
// TODO(dmblack): Add a deep link for this chip to start a screen context
// query to receive back contextual cards.
if (Shell::Get()->voice_interaction_controller()->context_enabled())
AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_WHATS_ON_MY_SCREEN);
AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_WHATS_ON_MY_CALENDAR);
// TODO(dmblack): Shuffle these chips and limit our total chip count to four.
AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_PLAY_MUSIC);
AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_SEND_AN_EMAIL);
AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_WHATS_THE_WEATHER);
AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_IM_BORED);
AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_OPEN_FILES);
model_.SetConversationStarters(std::move(conversation_starters));
}
} // 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_CACHE_CONTROLLER_H_
#define ASH_ASSISTANT_ASSISTANT_CACHE_CONTROLLER_H_
#include "ash/assistant/model/assistant_cache_model.h"
#include "ash/public/interfaces/voice_interaction_controller.mojom.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h"
namespace ash {
class AssistantCacheModelObserver;
class AssistantCacheController : public mojom::VoiceInteractionObserver {
public:
AssistantCacheController();
~AssistantCacheController() override;
// Returns a reference to the underlying model.
const AssistantCacheModel* model() const { return &model_; }
// Adds/removes the specified cache model |observer|.
void AddModelObserver(AssistantCacheModelObserver* observer);
void RemoveModelObserver(AssistantCacheModelObserver* observer);
private:
// mojom::VoiceInteractionObserver:
void OnVoiceInteractionStatusChanged(
mojom::VoiceInteractionState state) override {}
void OnVoiceInteractionSettingsEnabled(bool enabled) override {}
void OnVoiceInteractionContextEnabled(bool enabled) override;
void OnVoiceInteractionHotwordEnabled(bool enabled) override {}
void OnVoiceInteractionSetupCompleted(bool completed) override {}
void OnAssistantFeatureAllowedChanged(
mojom::AssistantAllowedState state) override {}
void UpdateConversationStarters();
mojo::Binding<mojom::VoiceInteractionObserver> voice_interaction_binding_;
AssistantCacheModel model_;
DISALLOW_COPY_AND_ASSIGN(AssistantCacheController);
};
} // namespace ash
#endif // ASH_ASSISTANT_ASSISTANT_CACHE_CONTROLLER_H_
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ash/assistant/assistant_controller.h" #include "ash/assistant/assistant_controller.h"
#include "ash/assistant/assistant_cache_controller.h"
#include "ash/assistant/assistant_controller_observer.h" #include "ash/assistant/assistant_controller_observer.h"
#include "ash/assistant/assistant_interaction_controller.h" #include "ash/assistant/assistant_interaction_controller.h"
#include "ash/assistant/assistant_notification_controller.h" #include "ash/assistant/assistant_notification_controller.h"
...@@ -23,6 +24,7 @@ namespace ash { ...@@ -23,6 +24,7 @@ namespace ash {
AssistantController::AssistantController() AssistantController::AssistantController()
: assistant_volume_control_binding_(this), : assistant_volume_control_binding_(this),
assistant_cache_controller_(std::make_unique<AssistantCacheController>()),
assistant_interaction_controller_( assistant_interaction_controller_(
std::make_unique<AssistantInteractionController>(this)), std::make_unique<AssistantInteractionController>(this)),
assistant_notification_controller_( assistant_notification_controller_(
......
...@@ -32,6 +32,7 @@ class UnguessableToken; ...@@ -32,6 +32,7 @@ class UnguessableToken;
namespace ash { namespace ash {
class AssistantCacheController;
class AssistantInteractionController; class AssistantInteractionController;
class AssistantNotificationController; class AssistantNotificationController;
class AssistantScreenContextController; class AssistantScreenContextController;
...@@ -125,6 +126,11 @@ class ASH_EXPORT AssistantController ...@@ -125,6 +126,11 @@ class ASH_EXPORT AssistantController
// Called before dtor to deregister services and avoid life cycle issues. // Called before dtor to deregister services and avoid life cycle issues.
void ShutDown(); void ShutDown();
AssistantCacheController* cache_controller() {
DCHECK(assistant_cache_controller_);
return assistant_cache_controller_.get();
}
AssistantInteractionController* interaction_controller() { AssistantInteractionController* interaction_controller() {
DCHECK(assistant_interaction_controller_); DCHECK(assistant_interaction_controller_);
return assistant_interaction_controller_.get(); return assistant_interaction_controller_.get();
...@@ -189,6 +195,8 @@ class ASH_EXPORT AssistantController ...@@ -189,6 +195,8 @@ class ASH_EXPORT AssistantController
mojom::WebContentsManagerPtr web_contents_manager_; mojom::WebContentsManagerPtr web_contents_manager_;
std::unique_ptr<AssistantCacheController> assistant_cache_controller_;
std::unique_ptr<AssistantInteractionController> std::unique_ptr<AssistantInteractionController>
assistant_interaction_controller_; assistant_interaction_controller_;
......
...@@ -234,10 +234,8 @@ void AssistantInteractionController::OnHtmlResponse( ...@@ -234,10 +234,8 @@ void AssistantInteractionController::OnHtmlResponse(
std::make_unique<AssistantCardElement>(response)); std::make_unique<AssistantCardElement>(response));
} }
void AssistantInteractionController::OnSuggestionChipPressed(int id) { void AssistantInteractionController::OnSuggestionChipPressed(
const AssistantSuggestion* suggestion = const AssistantSuggestion* suggestion) {
assistant_interaction_model_.response()->GetSuggestionById(id);
// If the suggestion contains a non-empty action url, we will handle the // If the suggestion contains a non-empty action url, we will handle the
// suggestion chip pressed event by launching the action url in the browser. // suggestion chip pressed event by launching the action url in the browser.
if (!suggestion->action_url.is_empty()) { if (!suggestion->action_url.is_empty()) {
......
...@@ -94,7 +94,7 @@ class AssistantInteractionController ...@@ -94,7 +94,7 @@ class AssistantInteractionController
void OnDialogPlateContentsCommitted(const std::string& text) override; void OnDialogPlateContentsCommitted(const std::string& text) override;
// Invoked on suggestion chip pressed event. // Invoked on suggestion chip pressed event.
void OnSuggestionChipPressed(int id); void OnSuggestionChipPressed(const AssistantSuggestion* suggestion);
private: private:
void StartTextInteraction(const std::string text); void StartTextInteraction(const std::string text);
......
// 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/model/assistant_cache_model.h"
#include "ash/assistant/model/assistant_cache_model_observer.h"
namespace ash {
AssistantCacheModel::AssistantCacheModel() = default;
AssistantCacheModel::~AssistantCacheModel() = default;
void AssistantCacheModel::AddObserver(AssistantCacheModelObserver* observer) {
observers_.AddObserver(observer);
}
void AssistantCacheModel::RemoveObserver(
AssistantCacheModelObserver* observer) {
observers_.RemoveObserver(observer);
}
void AssistantCacheModel::SetConversationStarters(
std::vector<AssistantSuggestionPtr> conversation_starters) {
conversation_starters_.clear();
conversation_starters_.swap(conversation_starters);
NotifyConversationStartersChanged();
}
const chromeos::assistant::mojom::AssistantSuggestion*
AssistantCacheModel::GetConversationStarterById(int id) const {
// We consider the index of a conversation starter within our backing vector
// to be its unique id.
DCHECK_GE(id, 0);
DCHECK_LT(id, static_cast<int>(conversation_starters_.size()));
return conversation_starters_.at(id).get();
}
std::map<int, const chromeos::assistant::mojom::AssistantSuggestion*>
AssistantCacheModel::GetConversationStarters() const {
std::map<int, const AssistantSuggestion*> conversation_starters;
// We use index within our backing vector to represent unique id.
int id = 0;
for (const AssistantSuggestionPtr& starter : conversation_starters_)
conversation_starters[id++] = starter.get();
return conversation_starters;
};
void AssistantCacheModel::NotifyConversationStartersChanged() {
const std::map<int, const AssistantSuggestion*> conversation_starters =
GetConversationStarters();
for (AssistantCacheModelObserver& observer : observers_)
observer.OnConversationStartersChanged(conversation_starters);
}
} // 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_MODEL_ASSISTANT_CACHE_MODEL_H_
#define ASH_ASSISTANT_MODEL_ASSISTANT_CACHE_MODEL_H_
#include <map>
#include <vector>
#include "base/macros.h"
#include "base/observer_list.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
namespace ash {
class AssistantCacheModelObserver;
class AssistantCacheModel {
public:
using AssistantSuggestion = chromeos::assistant::mojom::AssistantSuggestion;
using AssistantSuggestionPtr =
chromeos::assistant::mojom::AssistantSuggestionPtr;
AssistantCacheModel();
~AssistantCacheModel();
// Adds/removes the specified cache model |observer|.
void AddObserver(AssistantCacheModelObserver* observer);
void RemoveObserver(AssistantCacheModelObserver* observer);
// Sets the cache of conversation starters.
void SetConversationStarters(
std::vector<AssistantSuggestionPtr> conversation_starters);
// Returns the conversation starter uniquely identified by |id|.
const AssistantSuggestion* GetConversationStarterById(int id) const;
// Returns all cached conversation starters, mapped to a unique id.
std::map<int, const AssistantSuggestion*> GetConversationStarters() const;
private:
void NotifyConversationStartersChanged();
std::vector<AssistantSuggestionPtr> conversation_starters_;
base::ObserverList<AssistantCacheModelObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(AssistantCacheModel);
};
} // namespace ash
#endif // ASH_ASSISTANT_MODEL_ASSISTANT_CACHE_MODEL_H_
// 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_MODEL_ASSISTANT_CACHE_MODEL_OBSERVER_H_
#define ASH_ASSISTANT_MODEL_ASSISTANT_CACHE_MODEL_OBSERVER_H_
#include <map>
#include "base/macros.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
namespace ash {
// An observer which receives notification of changes to the Assistant cache.
class AssistantCacheModelObserver {
public:
using AssistantSuggestion = chromeos::assistant::mojom::AssistantSuggestion;
// Invoked when the cache of conversation starters has changed.
virtual void OnConversationStartersChanged(
const std::map<int, const AssistantSuggestion*>& conversation_starters) {}
protected:
virtual ~AssistantCacheModelObserver() = default;
};
} // namespace ash
#endif // ASH_ASSISTANT_MODEL_ASSISTANT_CACHE_MODEL_OBSERVER_H_
...@@ -37,8 +37,7 @@ class AssistantResponse { ...@@ -37,8 +37,7 @@ class AssistantResponse {
// interaction. // interaction.
void AddSuggestions(std::vector<AssistantSuggestionPtr> suggestions); void AddSuggestions(std::vector<AssistantSuggestionPtr> suggestions);
// Returns the suggestion uniquely identified by |id|, or |nullptr| if no // Returns the suggestion uniquely identified by |id|.
// matching suggestion exists.
const AssistantSuggestion* GetSuggestionById(int id) const; const AssistantSuggestion* GetSuggestionById(int id) const;
// Returns all suggestions belongs to the response, mapped to a unique id. // Returns all suggestions belongs to the response, mapped to a unique id.
......
...@@ -6,8 +6,10 @@ ...@@ -6,8 +6,10 @@
#include <memory> #include <memory>
#include "ash/assistant/assistant_cache_controller.h"
#include "ash/assistant/assistant_controller.h" #include "ash/assistant/assistant_controller.h"
#include "ash/assistant/assistant_interaction_controller.h" #include "ash/assistant/assistant_interaction_controller.h"
#include "ash/assistant/assistant_ui_controller.h"
#include "ash/assistant/model/assistant_response.h" #include "ash/assistant/model/assistant_response.h"
#include "ash/assistant/ui/assistant_ui_constants.h" #include "ash/assistant/ui/assistant_ui_constants.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -32,11 +34,15 @@ SuggestionContainerView::SuggestionContainerView( ...@@ -32,11 +34,15 @@ SuggestionContainerView::SuggestionContainerView(
// The Assistant controller indirectly owns the view hierarchy to which // The Assistant controller indirectly owns the view hierarchy to which
// SuggestionContainerView belongs so is guaranteed to outlive it. // SuggestionContainerView belongs so is guaranteed to outlive it.
assistant_controller_->cache_controller()->AddModelObserver(this);
assistant_controller_->interaction_controller()->AddModelObserver(this); assistant_controller_->interaction_controller()->AddModelObserver(this);
assistant_controller_->ui_controller()->AddModelObserver(this);
} }
SuggestionContainerView::~SuggestionContainerView() { SuggestionContainerView::~SuggestionContainerView() {
assistant_controller_->ui_controller()->RemoveModelObserver(this);
assistant_controller_->interaction_controller()->RemoveModelObserver(this); assistant_controller_->interaction_controller()->RemoveModelObserver(this);
assistant_controller_->cache_controller()->RemoveModelObserver(this);
} }
gfx::Size SuggestionContainerView::CalculatePreferredSize() const { gfx::Size SuggestionContainerView::CalculatePreferredSize() const {
...@@ -63,13 +69,33 @@ void SuggestionContainerView::InitLayout() { ...@@ -63,13 +69,33 @@ void SuggestionContainerView::InitLayout() {
views::BoxLayout::CrossAxisAlignment::CROSS_AXIS_ALIGNMENT_END); views::BoxLayout::CrossAxisAlignment::CROSS_AXIS_ALIGNMENT_END);
} }
void SuggestionContainerView::OnConversationStartersChanged(
const std::map<int, const AssistantSuggestion*>& conversation_starters) {
// TODO(dmblack): If UI is visible, we may want to animate this transition.
OnSuggestionsCleared();
OnSuggestionsChanged(conversation_starters);
}
void SuggestionContainerView::OnResponseChanged( void SuggestionContainerView::OnResponseChanged(
const AssistantResponse& response) { const AssistantResponse& response) {
OnResponseCleared(); has_received_response_ = true;
OnSuggestionsCleared();
OnSuggestionsChanged(response.GetSuggestions());
}
void SuggestionContainerView::OnResponseCleared() {
// Note that we don't reset |has_received_response_| here because that refers
// to whether we've received a response during the current Assistant UI
// session, not whether we are currently displaying a response.
OnSuggestionsCleared();
}
void SuggestionContainerView::OnSuggestionsChanged(
const std::map<int, const AssistantSuggestion*>& suggestions) {
using AssistantSuggestion = chromeos::assistant::mojom::AssistantSuggestion; using AssistantSuggestion = chromeos::assistant::mojom::AssistantSuggestion;
for (const std::pair<int, const AssistantSuggestion*>& suggestion : for (const std::pair<int, const AssistantSuggestion*>& suggestion :
response.GetSuggestions()) { suggestions) {
// We will use the same identifier by which the Assistant interaction model // We will use the same identifier by which the Assistant interaction model
// uniquely identifies a suggestion to uniquely identify its corresponding // uniquely identifies a suggestion to uniquely identify its corresponding
// suggestion chip view. // suggestion chip view.
...@@ -108,7 +134,7 @@ void SuggestionContainerView::OnResponseChanged( ...@@ -108,7 +134,7 @@ void SuggestionContainerView::OnResponseChanged(
} }
} }
void SuggestionContainerView::OnResponseCleared() { void SuggestionContainerView::OnSuggestionsCleared() {
// Abort any download requests in progress. // Abort any download requests in progress.
download_request_weak_factory_.InvalidateWeakPtrs(); download_request_weak_factory_.InvalidateWeakPtrs();
...@@ -126,8 +152,38 @@ void SuggestionContainerView::OnSuggestionChipIconDownloaded( ...@@ -126,8 +152,38 @@ void SuggestionContainerView::OnSuggestionChipIconDownloaded(
void SuggestionContainerView::ButtonPressed(views::Button* sender, void SuggestionContainerView::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
const AssistantSuggestion* suggestion = nullptr;
// If we haven't yet received a query response, the suggestion chip that was
// pressed was a conversation starter.
if (!has_received_response_) {
suggestion = assistant_controller_->cache_controller()
->model()
->GetConversationStarterById(sender->id());
} else {
// Otherwise, the suggestion chip belonged to the interaction response.
suggestion = assistant_controller_->interaction_controller()
->model()
->response()
->GetSuggestionById(sender->id());
}
// TODO(dmblack): Use a delegate pattern here similar to CaptionBar.
assistant_controller_->interaction_controller()->OnSuggestionChipPressed( assistant_controller_->interaction_controller()->OnSuggestionChipPressed(
static_cast<app_list::SuggestionChipView*>(sender)->id()); suggestion);
}
void SuggestionContainerView::OnUiVisibilityChanged(bool visible,
AssistantSource source) {
if (visible) {
// Show conversation starters at the beginning of an Assistant session.
OnConversationStartersChanged(assistant_controller_->cache_controller()
->model()
->GetConversationStarters());
} else {
// Reset view state.
has_received_response_ = false;
}
} }
} // namespace ash } // namespace ash
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
#include <map> #include <map>
#include "ash/app_list/views/suggestion_chip_view.h" #include "ash/app_list/views/suggestion_chip_view.h"
#include "ash/assistant/model/assistant_cache_model_observer.h"
#include "ash/assistant/model/assistant_interaction_model_observer.h" #include "ash/assistant/model/assistant_interaction_model_observer.h"
#include "ash/assistant/model/assistant_ui_model_observer.h"
#include "ash/assistant/ui/assistant_scroll_view.h" #include "ash/assistant/ui/assistant_scroll_view.h"
#include "base/macros.h" #include "base/macros.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h" #include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
...@@ -22,10 +24,14 @@ class AssistantController; ...@@ -22,10 +24,14 @@ class AssistantController;
// laying out SuggestionChipViews in response to Assistant interaction model // laying out SuggestionChipViews in response to Assistant interaction model
// suggestion events. // suggestion events.
class SuggestionContainerView : public AssistantScrollView, class SuggestionContainerView : public AssistantScrollView,
public AssistantCacheModelObserver,
public AssistantInteractionModelObserver, public AssistantInteractionModelObserver,
public AssistantUiModelObserver,
public views::ButtonListener { public views::ButtonListener {
public: public:
using AssistantSuggestion = chromeos::assistant::mojom::AssistantSuggestion; using AssistantSuggestion = chromeos::assistant::mojom::AssistantSuggestion;
using AssistantSuggestionPtr =
chromeos::assistant::mojom::AssistantSuggestionPtr;
explicit SuggestionContainerView(AssistantController* assistant_controller); explicit SuggestionContainerView(AssistantController* assistant_controller);
~SuggestionContainerView() override; ~SuggestionContainerView() override;
...@@ -35,16 +41,28 @@ class SuggestionContainerView : public AssistantScrollView, ...@@ -35,16 +41,28 @@ class SuggestionContainerView : public AssistantScrollView,
int GetHeightForWidth(int width) const override; int GetHeightForWidth(int width) const override;
void OnContentsPreferredSizeChanged(views::View* content_view) override; void OnContentsPreferredSizeChanged(views::View* content_view) override;
// AssistantCacheModelObserver:
void OnConversationStartersChanged(
const std::map<int, const AssistantSuggestion*>& conversation_starters)
override;
// AssistantInteractionModelObserver: // AssistantInteractionModelObserver:
void OnResponseChanged(const AssistantResponse& response) override; void OnResponseChanged(const AssistantResponse& response) override;
void OnResponseCleared() override; void OnResponseCleared() override;
// AssistantUiModelObserver:
void OnUiVisibilityChanged(bool visible, AssistantSource source) override;
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private: private:
void InitLayout(); void InitLayout();
void OnSuggestionsChanged(
const std::map<int, const AssistantSuggestion*>& suggestions);
void OnSuggestionsCleared();
// Invoked on suggestion chip icon downloaded event. // Invoked on suggestion chip icon downloaded event.
void OnSuggestionChipIconDownloaded(int id, const gfx::ImageSkia& icon); void OnSuggestionChipIconDownloaded(int id, const gfx::ImageSkia& icon);
...@@ -55,6 +73,10 @@ class SuggestionContainerView : public AssistantScrollView, ...@@ -55,6 +73,10 @@ class SuggestionContainerView : public AssistantScrollView,
// identifies the view's underlying suggestion. // identifies the view's underlying suggestion.
std::map<int, app_list::SuggestionChipView*> suggestion_chip_views_; std::map<int, app_list::SuggestionChipView*> suggestion_chip_views_;
// True if we have received a query response during this Assistant UI session,
// false otherwise.
bool has_received_response_ = false;
// Weak pointer factory used for image downloading requests. // Weak pointer factory used for image downloading requests.
base::WeakPtrFactory<SuggestionContainerView> download_request_weak_factory_; base::WeakPtrFactory<SuggestionContainerView> download_request_weak_factory_;
......
...@@ -44,6 +44,8 @@ class ASH_EXPORT VoiceInteractionController ...@@ -44,6 +44,8 @@ class ASH_EXPORT VoiceInteractionController
bool setup_completed() const { return setup_completed_; } bool setup_completed() const { return setup_completed_; }
bool context_enabled() const { return context_enabled_; }
mojom::AssistantAllowedState allowed_state() const { return allowed_state_; } mojom::AssistantAllowedState allowed_state() const { return allowed_state_; }
bool notification_enabled() const { return notification_enabled_; } bool notification_enabled() const { return notification_enabled_; }
......
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