forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathassistant_interaction_controller_impl.h
170 lines (141 loc) · 6.88 KB
/
assistant_interaction_controller_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// 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_INTERACTION_CONTROLLER_IMPL_H_
#define ASH_ASSISTANT_ASSISTANT_INTERACTION_CONTROLLER_IMPL_H_
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "ash/assistant/model/assistant_interaction_model.h"
#include "ash/assistant/model/assistant_interaction_model_observer.h"
#include "ash/assistant/model/assistant_ui_model_observer.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/highlighter/highlighter_controller.h"
#include "ash/public/cpp/assistant/controller/assistant_controller.h"
#include "ash/public/cpp/assistant/controller/assistant_controller_observer.h"
#include "ash/public/cpp/assistant/controller/assistant_interaction_controller.h"
#include "ash/public/cpp/tablet_mode_observer.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "chromeos/services/assistant/public/cpp/assistant_service.h"
#include "mojo/public/cpp/bindings/receiver.h"
class PrefRegistrySimple;
namespace ash {
class AssistantControllerImpl;
enum class AssistantButtonId;
class AssistantInteractionControllerImpl
: public AssistantInteractionController,
public chromeos::assistant::AssistantInteractionSubscriber,
public AssistantControllerObserver,
public AssistantInteractionModelObserver,
public AssistantUiModelObserver,
public AssistantViewDelegateObserver,
public TabletModeObserver,
public HighlighterController::Observer {
public:
using AssistantInteractionMetadata =
chromeos::assistant::AssistantInteractionMetadata;
using AssistantInteractionResolution =
chromeos::assistant::AssistantInteractionResolution;
using AssistantInteractionType =
chromeos::assistant::AssistantInteractionType;
using AssistantQuerySource = chromeos::assistant::AssistantQuerySource;
using AssistantSuggestion = chromeos::assistant::AssistantSuggestion;
using AssistantSuggestionType = chromeos::assistant::AssistantSuggestionType;
explicit AssistantInteractionControllerImpl(
AssistantControllerImpl* assistant_controller);
~AssistantInteractionControllerImpl() override;
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
// Provides a pointer to the |assistant| owned by AssistantService.
void SetAssistant(chromeos::assistant::Assistant* assistant);
// AssistantInteractionController:
const AssistantInteractionModel* GetModel() const override;
base::TimeDelta GetTimeDeltaSinceLastInteraction() const override;
bool HasHadInteraction() const override;
void StartTextInteraction(const std::string& text,
bool allow_tts,
AssistantQuerySource query_source) override;
// AssistantControllerObserver:
void OnAssistantControllerConstructed() override;
void OnAssistantControllerDestroying() override;
void OnDeepLinkReceived(
assistant::util::DeepLinkType type,
const std::map<std::string, std::string>& params) override;
// AssistantInteractionModelObserver:
void OnInteractionStateChanged(InteractionState interaction_state) override;
void OnInputModalityChanged(InputModality input_modality) override;
void OnMicStateChanged(MicState mic_state) override;
void OnCommittedQueryChanged(const AssistantQuery& assistant_query) override;
// AssistantUiModelObserver:
void OnUiVisibilityChanged(
AssistantVisibility new_visibility,
AssistantVisibility old_visibility,
absl::optional<AssistantEntryPoint> entry_point,
absl::optional<AssistantExitPoint> exit_point) override;
// HighlighterController::Observer:
void OnHighlighterSelectionRecognized(const gfx::Rect& rect) override;
// chromeos::assistant::AssistantInteractionSubscriber:
void OnInteractionStarted(
const AssistantInteractionMetadata& metadata) override;
void OnInteractionFinished(
AssistantInteractionResolution resolution) override;
void OnHtmlResponse(const std::string& response,
const std::string& fallback) override;
void OnSuggestionsResponse(
const std::vector<AssistantSuggestion>& response) override;
void OnTextResponse(const std::string& response) override;
void OnOpenUrlResponse(const GURL& url, bool in_background) override;
void OnOpenAppResponse(
const chromeos::assistant::AndroidAppInfo& app_info) override;
void OnSpeechRecognitionStarted() override;
void OnSpeechRecognitionIntermediateResult(
const std::string& high_confidence_text,
const std::string& low_confidence_text) override;
void OnSpeechRecognitionEndOfUtterance() override;
void OnSpeechRecognitionFinalResult(const std::string& final_result) override;
void OnSpeechLevelUpdated(float speech_level) override;
void OnTtsStarted(bool due_to_error) override;
void OnWaitStarted() override;
// AssistantViewDelegateObserver:
void OnDialogPlateButtonPressed(AssistantButtonId id) override;
void OnDialogPlateContentsCommitted(const std::string& text) override;
void OnSuggestionPressed(
const base::UnguessableToken& suggestion_id) override;
// TabletModeObserver:
void OnTabletModeStarted() override;
void OnTabletModeEnded() override;
private:
void OnTabletModeChanged();
bool HasActiveInteraction() const;
void OnUiVisible(AssistantEntryPoint entry_point);
void StartScreenContextInteraction(bool include_assistant_structure,
const gfx::Rect& region,
AssistantQuerySource query_source);
void StartVoiceInteraction();
void StopActiveInteraction(bool cancel_conversation);
InputModality GetDefaultInputModality() const;
AssistantResponse* GetResponseForActiveInteraction();
AssistantVisibility GetVisibility() const;
bool IsVisible() const;
AssistantControllerImpl* const assistant_controller_; // Owned by Shell.
AssistantInteractionModel model_;
bool has_had_interaction_ = false;
// Owned by AssistantService.
chromeos::assistant::Assistant* assistant_ = nullptr;
base::ScopedObservation<AssistantController, AssistantControllerObserver>
assistant_controller_observation_{this};
base::ScopedObservation<HighlighterController,
HighlighterController::Observer>
highlighter_controller_observation_{this};
base::ScopedObservation<TabletModeController, TabletModeObserver>
tablet_mode_controller_observation_{this};
base::WeakPtrFactory<AssistantInteractionControllerImpl>
screen_context_request_factory_{this};
base::WeakPtrFactory<AssistantInteractionControllerImpl> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(AssistantInteractionControllerImpl);
};
} // namespace ash
#endif // ASH_ASSISTANT_ASSISTANT_INTERACTION_CONTROLLER_IMPL_H_