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

Add more suggestion details.

Now using a mojom struct containing:
- text
- icon URL (optional)
- action URL (optional)

Icon URL will be used to fetch an icon for a suggestion chip view.

Action URL, when specified, dictates a different action to be taken
on suggestion tap/click.

Handling of icon/action URLs will come in follow up CL.

Bug: b:78236856
Change-Id: I04c489285250ccb395cfe54c465a696c8539f619
Reviewed-on: https://chromium-review.googlesource.com/1050906
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557753}
parent 27c69f8b
......@@ -140,7 +140,7 @@ void AssistantController::OnInteractionStarted() {
}
void AssistantController::OnInteractionFinished(
chromeos::assistant::mojom::AssistantInteractionResolution resolution) {}
AssistantInteractionResolution resolution) {}
void AssistantController::OnInteractionDismissed() {
assistant_interaction_model_.SetInteractionState(InteractionState::kInactive);
......@@ -206,8 +206,8 @@ void AssistantController::OnSuggestionChipPressed(const std::string& text) {
}
void AssistantController::OnSuggestionsResponse(
const std::vector<std::string>& response) {
assistant_interaction_model_.AddSuggestions(response);
std::vector<AssistantSuggestionPtr> response) {
assistant_interaction_model_.AddSuggestions(std::move(response));
}
void AssistantController::OnTextResponse(const std::string& response) {
......
......@@ -33,6 +33,11 @@ class AssistantController
public AssistantInteractionModelObserver,
public HighlighterController::Observer {
public:
using AssistantSuggestionPtr =
chromeos::assistant::mojom::AssistantSuggestionPtr;
using AssistantInteractionResolution =
chromeos::assistant::mojom::AssistantInteractionResolution;
AssistantController();
~AssistantController() override;
......@@ -88,10 +93,10 @@ class AssistantController
// chromeos::assistant::mojom::AssistantEventSubscriber:
void OnInteractionStarted() override;
void OnInteractionFinished(
chromeos::assistant::mojom::AssistantInteractionResolution resolution)
override;
AssistantInteractionResolution resolution) override;
void OnHtmlResponse(const std::string& response) override;
void OnSuggestionsResponse(const std::vector<std::string>& response) override;
void OnSuggestionsResponse(
std::vector<AssistantSuggestionPtr> response) override;
void OnTextResponse(const std::string& response) override;
void OnOpenUrlResponse(const GURL& url) override;
void OnSpeechRecognitionStarted() override;
......
......@@ -80,10 +80,15 @@ void AssistantInteractionModel::ClearQuery() {
}
void AssistantInteractionModel::AddSuggestions(
const std::vector<std::string>& suggestions) {
suggestions_list_.insert(suggestions_list_.end(), suggestions.begin(),
suggestions.end());
NotifySuggestionsAdded(suggestions);
std::vector<AssistantSuggestionPtr> suggestions) {
std::vector<AssistantSuggestion*> ptrs;
for (AssistantSuggestionPtr& suggestion : suggestions) {
suggestions_list_.push_back(std::move(suggestion));
ptrs.push_back(suggestions_list_.back().get());
}
NotifySuggestionsAdded(ptrs);
}
void AssistantInteractionModel::ClearSuggestions() {
......@@ -128,7 +133,7 @@ void AssistantInteractionModel::NotifyQueryCleared() {
}
void AssistantInteractionModel::NotifySuggestionsAdded(
const std::vector<std::string>& suggestions) {
const std::vector<AssistantSuggestion*> suggestions) {
for (AssistantInteractionModelObserver& observer : observers_)
observer.OnSuggestionsAdded(suggestions);
}
......
......@@ -11,6 +11,7 @@
#include "base/macros.h"
#include "base/observer_list.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
namespace ash {
......@@ -65,6 +66,10 @@ struct Query {
// recognition, as well as renderable AssistantUiElements and suggestions.
class AssistantInteractionModel {
public:
using AssistantSuggestion = chromeos::assistant::mojom::AssistantSuggestion;
using AssistantSuggestionPtr =
chromeos::assistant::mojom::AssistantSuggestionPtr;
AssistantInteractionModel();
~AssistantInteractionModel();
......@@ -111,7 +116,7 @@ class AssistantInteractionModel {
// Adds the specified |suggestions| that should be rendered for the
// interaction.
void AddSuggestions(const std::vector<std::string>& suggestions);
void AddSuggestions(std::vector<AssistantSuggestionPtr> suggestions);
// Clears all suggestions for the interaction.
void ClearSuggestions();
......@@ -124,14 +129,15 @@ class AssistantInteractionModel {
void NotifyUiElementsCleared();
void NotifyQueryChanged();
void NotifyQueryCleared();
void NotifySuggestionsAdded(const std::vector<std::string>& suggestions);
void NotifySuggestionsAdded(
const std::vector<AssistantSuggestion*> suggestions);
void NotifySuggestionsCleared();
InteractionState interaction_state_ = InteractionState::kInactive;
InputModality input_modality_;
MicState mic_state_ = MicState::kClosed;
Query query_;
std::vector<std::string> suggestions_list_;
std::vector<AssistantSuggestionPtr> suggestions_list_;
std::vector<std::unique_ptr<AssistantUiElement>> ui_element_list_;
base::ObserverList<AssistantInteractionModelObserver> observers_;
......
......@@ -10,6 +10,14 @@
#include "base/macros.h"
namespace chromeos {
namespace assistant {
namespace mojom {
class AssistantSuggestion;
} // namespace mojom
} // namespace assistant
} // namespace chromeos
namespace ash {
class AssistantUiElement;
......@@ -22,6 +30,8 @@ struct Query;
// interaction.
class AssistantInteractionModelObserver {
public:
using AssistantSuggestion = chromeos::assistant::mojom::AssistantSuggestion;
// Invoked when the interaction state is changed.
virtual void OnInteractionStateChanged(InteractionState interaction_state) {}
......@@ -45,8 +55,8 @@ class AssistantInteractionModelObserver {
// Invoked when the specified |suggestions| are added to the associated
// interaction.
virtual void OnSuggestionsAdded(const std::vector<std::string>& suggestions) {
}
virtual void OnSuggestionsAdded(
const std::vector<AssistantSuggestion*>& suggestions) {}
// Invoked when all suggestions associated with the interaction are cleared.
virtual void OnSuggestionsCleared() {}
......
......@@ -283,6 +283,8 @@ class UiElementContainer : public views::View {
class SuggestionsContainer : public views::View {
public:
using AssistantSuggestion = chromeos::assistant::mojom::AssistantSuggestion;
explicit SuggestionsContainer(app_list::SuggestionChipListener* listener)
: suggestion_chip_listener_(listener) {}
......@@ -330,10 +332,10 @@ class SuggestionsContainer : public views::View {
}
}
void AddSuggestions(const std::vector<std::string>& suggestions) {
for (const std::string& suggestion : suggestions) {
void AddSuggestions(const std::vector<AssistantSuggestion*>& suggestions) {
for (const AssistantSuggestion* suggestion : suggestions) {
AddChildView(new app_list::SuggestionChipView(
base::UTF8ToUTF16(suggestion), suggestion_chip_listener_));
base::UTF8ToUTF16(suggestion->text), suggestion_chip_listener_));
}
PreferredSizeChanged();
}
......@@ -547,7 +549,7 @@ void AssistantBubbleView::OnQueryCleared() {
}
void AssistantBubbleView::OnSuggestionsAdded(
const std::vector<std::string>& suggestions) {
const std::vector<AssistantSuggestion*>& suggestions) {
suggestions_container_->AddSuggestions(suggestions);
suggestions_container_->SetVisible(true);
}
......
......@@ -37,6 +37,8 @@ class AssistantBubbleView : public views::View,
public AssistantInteractionModelObserver,
public app_list::SuggestionChipListener {
public:
using AssistantSuggestion = chromeos::assistant::mojom::AssistantSuggestion;
explicit AssistantBubbleView(AssistantController* assistant_controller);
~AssistantBubbleView() override;
......@@ -52,7 +54,8 @@ class AssistantBubbleView : public views::View,
void OnUiElementsCleared() override;
void OnQueryChanged(const Query& query) override;
void OnQueryCleared() override;
void OnSuggestionsAdded(const std::vector<std::string>& suggestions) override;
void OnSuggestionsAdded(
const std::vector<AssistantSuggestion*>& suggestions) override;
void OnSuggestionsCleared() override;
// app_list::SuggestionChipListener:
......
......@@ -169,12 +169,22 @@ void AssistantManagerServiceImpl::OnShowHtml(const std::string& html) {
}
void AssistantManagerServiceImpl::OnShowSuggestions(
const std::vector<std::string>& suggestions) {
const std::vector<action::Suggestion>& suggestions) {
// Convert to mojom struct for IPC.
std::vector<mojom::AssistantSuggestionPtr> ptrs;
for (const action::Suggestion& suggestion : suggestions) {
mojom::AssistantSuggestionPtr ptr = mojom::AssistantSuggestion::New();
ptr->text = suggestion.text;
ptr->icon_url = GURL(suggestion.icon_url);
ptr->action_url = GURL(suggestion.action_url);
ptrs.push_back(std::move(ptr));
}
main_thread_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&AssistantManagerServiceImpl::OnShowSuggestionsOnMainThread,
weak_factory_.GetWeakPtr(), suggestions));
weak_factory_.GetWeakPtr(), std::move(ptrs)));
}
void AssistantManagerServiceImpl::OnShowText(const std::string& text) {
......@@ -350,9 +360,10 @@ void AssistantManagerServiceImpl::OnShowHtmlOnMainThread(
}
void AssistantManagerServiceImpl::OnShowSuggestionsOnMainThread(
const std::vector<std::string>& suggestions) {
subscribers_.ForAllPtrs(
[&suggestions](auto* ptr) { ptr->OnSuggestionsResponse(suggestions); });
const std::vector<mojom::AssistantSuggestionPtr>& suggestions) {
subscribers_.ForAllPtrs([&suggestions](auto* ptr) {
ptr->OnSuggestionsResponse(mojo::Clone(suggestions));
});
}
void AssistantManagerServiceImpl::OnShowTextOnMainThread(
......
......@@ -67,7 +67,8 @@ class AssistantManagerServiceImpl
// AssistantActionObserver overrides:
void OnShowHtml(const std::string& html) override;
void OnShowSuggestions(const std::vector<std::string>& suggestions) override;
void OnShowSuggestions(
const std::vector<action::Suggestion>& suggestions) override;
void OnShowText(const std::string& text) override;
void OnOpenUrl(const std::string& url) override;
......@@ -109,7 +110,7 @@ class AssistantManagerServiceImpl
assistant_client::ConversationStateListener::Resolution resolution);
void OnShowHtmlOnMainThread(const std::string& html);
void OnShowSuggestionsOnMainThread(
const std::vector<std::string>& suggestions);
const std::vector<mojom::AssistantSuggestionPtr>& suggestions);
void OnShowTextOnMainThread(const std::string& text);
void OnOpenUrlOnMainThread(const std::string& url);
void OnRecognitionStateChangedOnMainThread(
......
......@@ -39,7 +39,7 @@ interface AssistantEventSubscriber {
OnHtmlResponse(string response);
// Assistant got suggestions response from server.
OnSuggestionsResponse(array<string> response);
OnSuggestionsResponse(array<AssistantSuggestion> response);
// Assistant got text response from server.
OnTextResponse(string response);
......@@ -108,3 +108,14 @@ enum AssistantInteractionResolution {
// Assistant interaction completed due to multi-device hotword loss.
kMultiDeviceHotwordLoss,
};
// Models an Assistant suggestion.
struct AssistantSuggestion {
// Display text. e.g. "Cancel".
string text;
// Optional URL for icon. e.g. "https://www.gstatic.com/icon.png".
url.mojom.Url icon_url;
// Optional URL for action. e.g.
// "https://www.google.com/search?query=action".
url.mojom.Url action_url;
};
\ No newline at end of file
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