Commit afd4351b authored by Yue Li's avatar Yue Li Committed by Commit Bot

Fix assistant service intialize logic

Bug: None
Test: Manual Test
Change-Id: Ia0ab2867db8b047049534632d4ffdbc6e618ce56
Reviewed-on: https://chromium-review.googlesource.com/1162508Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Yue Li <updowndota@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580618}
parent dd54970a
...@@ -215,14 +215,14 @@ void Service::Init(mojom::ClientPtr client, ...@@ -215,14 +215,14 @@ void Service::Init(mojom::ClientPtr client,
voice_interaction_controller_->IsHotwordEnabled(base::BindOnce( voice_interaction_controller_->IsHotwordEnabled(base::BindOnce(
&Service::CreateAssistantManagerService, weak_ptr_factory_.GetWeakPtr())); &Service::CreateAssistantManagerService, weak_ptr_factory_.GetWeakPtr()));
voice_interaction_controller_->AddObserver(std::move(ptr)); voice_interaction_controller_->AddObserver(std::move(ptr));
voice_interaction_controller_->IsSettingEnabled(
base::BindOnce(&Service::OnVoiceInteractionSettingsEnabled,
weak_ptr_factory_.GetWeakPtr()));
#else #else
assistant_manager_service_ = assistant_manager_service_ =
std::make_unique<FakeAssistantManagerServiceImpl>(); std::make_unique<FakeAssistantManagerServiceImpl>();
RequestAccessToken();
#endif #endif
voice_interaction_controller_->IsSettingEnabled(
base::BindOnce(&Service::OnVoiceInteractionSettingsEnabled,
weak_ptr_factory_.GetWeakPtr()));
} }
void Service::GetPrimaryAccountInfoCallback( void Service::GetPrimaryAccountInfoCallback(
...@@ -276,14 +276,13 @@ void Service::GetAccessTokenCallback(const base::Optional<std::string>& token, ...@@ -276,14 +276,13 @@ void Service::GetAccessTokenCallback(const base::Optional<std::string>& token,
} }
void Service::CreateAssistantManagerService(bool enable_hotword) { void Service::CreateAssistantManagerService(bool enable_hotword) {
hotword_enabled_ = enable_hotword;
#if BUILDFLAG(ENABLE_CROS_LIBASSISTANT) #if BUILDFLAG(ENABLE_CROS_LIBASSISTANT)
hotword_enabled_ = enable_hotword;
device::mojom::BatteryMonitorPtr battery_monitor; device::mojom::BatteryMonitorPtr battery_monitor;
context()->connector()->BindInterface(device::mojom::kServiceName, context()->connector()->BindInterface(device::mojom::kServiceName,
mojo::MakeRequest(&battery_monitor)); mojo::MakeRequest(&battery_monitor));
assistant_manager_service_ = std::make_unique<AssistantManagerServiceImpl>( assistant_manager_service_ = std::make_unique<AssistantManagerServiceImpl>(
context()->connector(), std::move(battery_monitor), this, enable_hotword); context()->connector(), std::move(battery_monitor), this, enable_hotword);
#endif
// Bind to Assistant controller in ash. // Bind to Assistant controller in ash.
context()->connector()->BindInterface(ash::mojom::kServiceName, context()->connector()->BindInterface(ash::mojom::kServiceName,
...@@ -292,7 +291,6 @@ void Service::CreateAssistantManagerService(bool enable_hotword) { ...@@ -292,7 +291,6 @@ void Service::CreateAssistantManagerService(bool enable_hotword) {
BindAssistantConnection(mojo::MakeRequest(&ptr)); BindAssistantConnection(mojo::MakeRequest(&ptr));
assistant_controller_->SetAssistant(std::move(ptr)); assistant_controller_->SetAssistant(std::move(ptr));
AddAshSessionObserver();
registry_.AddInterface<mojom::Assistant>(base::BindRepeating( registry_.AddInterface<mojom::Assistant>(base::BindRepeating(
&Service::BindAssistantConnection, base::Unretained(this))); &Service::BindAssistantConnection, base::Unretained(this)));
...@@ -300,12 +298,16 @@ void Service::CreateAssistantManagerService(bool enable_hotword) { ...@@ -300,12 +298,16 @@ void Service::CreateAssistantManagerService(bool enable_hotword) {
assistant_manager_service_.get()->GetAssistantSettingsManager(); assistant_manager_service_.get()->GetAssistantSettingsManager();
registry_.AddInterface<mojom::AssistantSettingsManager>(base::BindRepeating( registry_.AddInterface<mojom::AssistantSettingsManager>(base::BindRepeating(
&Service::BindAssistantSettingsManager, base::Unretained(this))); &Service::BindAssistantSettingsManager, base::Unretained(this)));
#endif
} }
void Service::FinalizeAssistantManagerService() { void Service::FinalizeAssistantManagerService() {
DCHECK(assistant_manager_service_->GetState() == DCHECK(assistant_manager_service_->GetState() ==
AssistantManagerService::State::RUNNING); AssistantManagerService::State::RUNNING);
if (!session_observer_binding_)
AddAshSessionObserver();
// Double check settings enabled status to avoid racing issue. // Double check settings enabled status to avoid racing issue.
if (!settings_enabled_) { if (!settings_enabled_) {
assistant_manager_service_->Stop(); assistant_manager_service_->Stop();
......
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