Commit 5df16e65 authored by Xiaohui Chen's avatar Xiaohui Chen Committed by Commit Bot

Retry auth token when assistant request errors

Bug: 111370621
Test: locally build and fake auth errors with bad tokens.
Change-Id: Id8099ccd67add90fc4b593877bcfce44c2eff654
Reviewed-on: https://chromium-review.googlesource.com/1165857Reviewed-by: default avatarMuyuan Li <muyuanli@chromium.org>
Commit-Queue: Xiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581402}
parent ffb3dcff
......@@ -60,6 +60,7 @@ Service::Service()
main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
power_manager_observer_(this),
voice_interaction_observer_binding_(this),
assistant_interaction_subscriber_binding_(this),
weak_ptr_factory_(this) {
registry_.AddInterface<mojom::AssistantPlatform>(base::BindRepeating(
&Service::BindAssistantPlatformConnection, base::Unretained(this)));
......@@ -172,6 +173,15 @@ void Service::OnVoiceInteractionHotwordEnabled(bool enabled) {
RequestAccessToken();
}
void Service::OnInteractionFinished(
mojom::AssistantInteractionResolution resolution) {
if (resolution == mojom::AssistantInteractionResolution::kError) {
// When communicateion error happens, it could be caused by auth errors.
// Retry with a new auth token to attempt recovery.
RequestAccessToken();
}
}
void Service::BindAssistantSettingsManager(
mojom::AssistantSettingsManagerRequest request) {
DCHECK(assistant_settings_manager_);
......@@ -299,6 +309,14 @@ void Service::CreateAssistantManagerService(bool enable_hotword) {
assistant_manager_service_.get()->GetAssistantSettingsManager();
registry_.AddInterface<mojom::AssistantSettingsManager>(base::BindRepeating(
&Service::BindAssistantSettingsManager, base::Unretained(this)));
// Subscribe to Assistant interaction events.
chromeos::assistant::mojom::AssistantInteractionSubscriberPtr
interaction_subscriber_ptr;
assistant_interaction_subscriber_binding_.Bind(
mojo::MakeRequest(&interaction_subscriber_ptr));
assistant_manager_service_->AddAssistantInteractionSubscriber(
std::move(interaction_subscriber_ptr));
#endif
}
......
......@@ -42,6 +42,7 @@ class AssistantSettingsManager;
class Service : public service_manager::Service,
public chromeos::PowerManagerClient::Observer,
public ash::mojom::SessionActivationObserver,
public mojom::AssistantInteractionSubscriber,
public mojom::AssistantPlatform,
public ash::mojom::VoiceInteractionObserver {
public:
......@@ -93,6 +94,25 @@ class Service : public service_manager::Service,
void OnAssistantFeatureAllowedChanged(
ash::mojom::AssistantAllowedState state) override {}
// chromeos::assistant::mojom::AssistantInteractionSubscriber:
void OnInteractionStarted(bool is_voice_interaction) override{};
void OnInteractionFinished(
mojom::AssistantInteractionResolution resolution) override;
void OnHtmlResponse(const std::string& response) override{};
void OnSuggestionsResponse(
std::vector<mojom::AssistantSuggestionPtr> response) override{};
void OnTextResponse(const std::string& response) override{};
void OnOpenUrlResponse(const GURL& url) 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() override{};
void BindAssistantSettingsManager(
mojom::AssistantSettingsManagerRequest request);
......@@ -152,6 +172,8 @@ class Service : public service_manager::Service,
ash::mojom::VoiceInteractionControllerPtr voice_interaction_controller_;
mojo::Binding<ash::mojom::VoiceInteractionObserver>
voice_interaction_observer_binding_;
mojo::Binding<chromeos::assistant::mojom::AssistantInteractionSubscriber>
assistant_interaction_subscriber_binding_;
base::WeakPtrFactory<Service> weak_ptr_factory_;
......
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