David Black | 6b4b1ad2 | 2018-08-21 02:45:08 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/assistant/assistant_cache_controller.h" |
| 6 | |
| 7 | #include <vector> |
| 8 | |
David Black | d08c051 | 2018-08-21 17:18:26 | [diff] [blame^] | 9 | #include "ash/assistant/util/deep_link_util.h" |
David Black | 6b4b1ad2 | 2018-08-21 02:45:08 | [diff] [blame] | 10 | #include "ash/shell.h" |
| 11 | #include "ash/strings/grit/ash_strings.h" |
| 12 | #include "ash/voice_interaction/voice_interaction_controller.h" |
| 13 | #include "chromeos/services/assistant/public/mojom/assistant.mojom.h" |
| 14 | #include "ui/base/l10n/l10n_util.h" |
| 15 | |
| 16 | namespace ash { |
| 17 | |
| 18 | AssistantCacheController::AssistantCacheController() |
| 19 | : voice_interaction_binding_(this) { |
| 20 | UpdateConversationStarters(); |
| 21 | |
| 22 | // Bind to observe changes to screen context preference. |
| 23 | mojom::VoiceInteractionObserverPtr ptr; |
| 24 | voice_interaction_binding_.Bind(mojo::MakeRequest(&ptr)); |
| 25 | Shell::Get()->voice_interaction_controller()->AddObserver(std::move(ptr)); |
| 26 | } |
| 27 | |
| 28 | AssistantCacheController::~AssistantCacheController() = default; |
| 29 | |
| 30 | void AssistantCacheController::AddModelObserver( |
| 31 | AssistantCacheModelObserver* observer) { |
| 32 | model_.AddObserver(observer); |
| 33 | } |
| 34 | |
| 35 | void AssistantCacheController::RemoveModelObserver( |
| 36 | AssistantCacheModelObserver* observer) { |
| 37 | model_.RemoveObserver(observer); |
| 38 | } |
| 39 | |
| 40 | void AssistantCacheController::OnVoiceInteractionContextEnabled(bool enabled) { |
| 41 | UpdateConversationStarters(); |
| 42 | } |
| 43 | |
| 44 | // TODO(dmblack): The conversation starter cache should receive its contents |
| 45 | // from the server. Hard-coding for the time being. |
| 46 | void AssistantCacheController::UpdateConversationStarters() { |
| 47 | using namespace chromeos::assistant::mojom; |
| 48 | |
| 49 | std::vector<AssistantSuggestionPtr> conversation_starters; |
| 50 | |
David Black | d08c051 | 2018-08-21 17:18:26 | [diff] [blame^] | 51 | auto AddConversationStarter = [&conversation_starters]( |
| 52 | int message_id, GURL action_url = GURL()) { |
David Black | 6b4b1ad2 | 2018-08-21 02:45:08 | [diff] [blame] | 53 | AssistantSuggestionPtr starter = AssistantSuggestion::New(); |
| 54 | starter->text = l10n_util::GetStringUTF8(message_id); |
David Black | d08c051 | 2018-08-21 17:18:26 | [diff] [blame^] | 55 | starter->action_url = action_url; |
David Black | 6b4b1ad2 | 2018-08-21 02:45:08 | [diff] [blame] | 56 | conversation_starters.push_back(std::move(starter)); |
| 57 | }; |
| 58 | |
| 59 | AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_WHAT_CAN_YOU_DO); |
| 60 | |
David Black | d08c051 | 2018-08-21 17:18:26 | [diff] [blame^] | 61 | if (Shell::Get()->voice_interaction_controller()->context_enabled()) { |
| 62 | AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_WHATS_ON_MY_SCREEN, |
| 63 | assistant::util::CreateWhatsOnMyScreenDeepLink()); |
| 64 | } |
David Black | 6b4b1ad2 | 2018-08-21 02:45:08 | [diff] [blame] | 65 | |
| 66 | AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_WHATS_ON_MY_CALENDAR); |
| 67 | |
| 68 | // TODO(dmblack): Shuffle these chips and limit our total chip count to four. |
| 69 | AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_PLAY_MUSIC); |
| 70 | AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_SEND_AN_EMAIL); |
| 71 | AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_WHATS_THE_WEATHER); |
| 72 | AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_IM_BORED); |
| 73 | AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_OPEN_FILES); |
David Black | d08c051 | 2018-08-21 17:18:26 | [diff] [blame^] | 74 | AddConversationStarter(IDS_ASH_ASSISTANT_CHIP_SET_A_REMINDER); |
David Black | 6b4b1ad2 | 2018-08-21 02:45:08 | [diff] [blame] | 75 | |
| 76 | model_.SetConversationStarters(std::move(conversation_starters)); |
| 77 | } |
| 78 | |
| 79 | } // namespace ash |