Commit bbbc8589 authored by Jeroen Dhollander's avatar Jeroen Dhollander Committed by Chromium LUCI CQ

Move FuchsiaApiDelegate to Libassistant Mojom service

Bug: b/177328928
Test: compiled and deployed
Change-Id: I56b03581f2299812e8114d09f76bd56c44fdcf51
Cq-Include-Trybots: luci.chrome.try:linux-chromeos-chrome
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2617516Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Jeroen Dhollander <jeroendh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844830}
parent 42de3208
...@@ -71,10 +71,6 @@ component("lib") { ...@@ -71,10 +71,6 @@ component("lib") {
"assistant_manager_service_impl.h", "assistant_manager_service_impl.h",
"assistant_settings_impl.cc", "assistant_settings_impl.cc",
"assistant_settings_impl.h", "assistant_settings_impl.h",
"chromium_api_delegate.cc",
"chromium_api_delegate.h",
"chromium_http_connection.cc",
"chromium_http_connection.h",
"libassistant_service_host_impl.cc", "libassistant_service_host_impl.cc",
"libassistant_service_host_impl.h", "libassistant_service_host_impl.h",
"media_session/assistant_media_session.cc", "media_session/assistant_media_session.cc",
...@@ -132,7 +128,6 @@ component("lib") { ...@@ -132,7 +128,6 @@ component("lib") {
"//chromeos/services/libassistant", "//chromeos/services/libassistant",
"//chromeos/services/network_config/public/mojom", "//chromeos/services/network_config/public/mojom",
"//chromeos/strings", "//chromeos/strings",
"//libassistant/shared/internal_api:fuchsia_api_helper",
"//libassistant/shared/internal_api/c:api_wrappers_entrypoint", "//libassistant/shared/internal_api/c:api_wrappers_entrypoint",
"//libassistant/shared/public", "//libassistant/shared/public",
"//libassistant/shared/public:export", "//libassistant/shared/public:export",
......
...@@ -178,7 +178,6 @@ AssistantManagerServiceImpl::AssistantManagerServiceImpl( ...@@ -178,7 +178,6 @@ AssistantManagerServiceImpl::AssistantManagerServiceImpl(
this, this,
features::IsAppSupportEnabled(), features::IsAppSupportEnabled(),
features::IsWaitSchedulingEnabled())), features::IsWaitSchedulingEnabled())),
chromium_api_delegate_(std::move(pending_url_loader_factory)),
assistant_settings_( assistant_settings_(
std::make_unique<AssistantSettingsImpl>(context, this)), std::make_unique<AssistantSettingsImpl>(context, this)),
assistant_proxy_(std::make_unique<AssistantProxy>()), assistant_proxy_(std::make_unique<AssistantProxy>()),
...@@ -207,7 +206,8 @@ AssistantManagerServiceImpl::AssistantManagerServiceImpl( ...@@ -207,7 +206,8 @@ AssistantManagerServiceImpl::AssistantManagerServiceImpl(
// |libassistant_service_host| which requires |platform_api_| in its // |libassistant_service_host| which requires |platform_api_| in its
// constructor. // constructor.
// To solve this chicken-and-egg problem, we need a separe Initialize() call. // To solve this chicken-and-egg problem, we need a separe Initialize() call.
assistant_proxy_->Initialize(libassistant_service_host_.get()); assistant_proxy_->Initialize(libassistant_service_host_.get(),
std::move(pending_url_loader_factory));
audio_input_host_ = delegate_->CreateAudioInputHost(); audio_input_host_ = delegate_->CreateAudioInputHost();
...@@ -1025,7 +1025,7 @@ void AssistantManagerServiceImpl::InitAssistant( ...@@ -1025,7 +1025,7 @@ void AssistantManagerServiceImpl::InitAssistant(
DCHECK(!IsServiceStarted()); DCHECK(!IsServiceStarted());
service_controller().Start( service_controller().Start(
action_module_.get(), &chromium_api_delegate_, action_module_.get(),
/*assistant_manager_delegate=*/this, /*assistant_manager_delegate=*/this,
/*conversation_state_listener=*/this, /*conversation_state_listener=*/this,
/*device_state_listener=*/this, /*device_state_listener=*/this,
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "chromeos/assistant/internal/internal_util.h" #include "chromeos/assistant/internal/internal_util.h"
#include "chromeos/services/assistant/assistant_manager_service.h" #include "chromeos/services/assistant/assistant_manager_service.h"
#include "chromeos/services/assistant/assistant_settings_impl.h" #include "chromeos/services/assistant/assistant_settings_impl.h"
#include "chromeos/services/assistant/chromium_api_delegate.h"
#include "chromeos/services/assistant/proxy/assistant_proxy.h" #include "chromeos/services/assistant/proxy/assistant_proxy.h"
#include "chromeos/services/assistant/proxy/conversation_controller_proxy.h" #include "chromeos/services/assistant/proxy/conversation_controller_proxy.h"
#include "chromeos/services/assistant/proxy/libassistant_service_host.h" #include "chromeos/services/assistant/proxy/libassistant_service_host.h"
...@@ -321,7 +320,6 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) AssistantManagerServiceImpl ...@@ -321,7 +320,6 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) AssistantManagerServiceImpl
std::unique_ptr<AssistantMediaSession> media_session_; std::unique_ptr<AssistantMediaSession> media_session_;
std::unique_ptr<CrosPlatformApi> platform_api_; std::unique_ptr<CrosPlatformApi> platform_api_;
std::unique_ptr<action::CrosActionModule> action_module_; std::unique_ptr<action::CrosActionModule> action_module_;
ChromiumApiDelegate chromium_api_delegate_;
std::unique_ptr<AssistantSettingsImpl> assistant_settings_; std::unique_ptr<AssistantSettingsImpl> assistant_settings_;
std::unique_ptr<AssistantProxy> assistant_proxy_; std::unique_ptr<AssistantProxy> assistant_proxy_;
......
...@@ -28,6 +28,6 @@ source_set("proxy") { ...@@ -28,6 +28,6 @@ source_set("proxy") {
"//chromeos/services/assistant/public/cpp", "//chromeos/services/assistant/public/cpp",
"//chromeos/services/assistant/public/cpp/migration", "//chromeos/services/assistant/public/cpp/migration",
"//chromeos/services/libassistant", "//chromeos/services/libassistant",
"//libassistant/shared/internal_api:fuchsia_api_helper", "//services/network/public/cpp",
] ]
} }
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chromeos/services/assistant/proxy/libassistant_service_host.h" #include "chromeos/services/assistant/proxy/libassistant_service_host.h"
#include "chromeos/services/assistant/proxy/service_controller_proxy.h" #include "chromeos/services/assistant/proxy/service_controller_proxy.h"
#include "chromeos/services/libassistant/libassistant_service.h" #include "chromeos/services/libassistant/libassistant_service.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace chromeos { namespace chromeos {
namespace assistant { namespace assistant {
...@@ -24,12 +25,15 @@ AssistantProxy::~AssistantProxy() { ...@@ -24,12 +25,15 @@ AssistantProxy::~AssistantProxy() {
StopLibassistantService(); StopLibassistantService();
} }
void AssistantProxy::Initialize(LibassistantServiceHost* host) { void AssistantProxy::Initialize(
LibassistantServiceHost* host,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory) {
DCHECK(host); DCHECK(host);
libassistant_service_host_ = host; libassistant_service_host_ = host;
LaunchLibassistantService(); LaunchLibassistantService();
BindControllers(host); BindControllers(host, std::move(pending_url_loader_factory));
} }
void AssistantProxy::LaunchLibassistantService() { void AssistantProxy::LaunchLibassistantService() {
...@@ -70,7 +74,10 @@ void AssistantProxy::StopLibassistantServiceOnBackgroundThread() { ...@@ -70,7 +74,10 @@ void AssistantProxy::StopLibassistantServiceOnBackgroundThread() {
libassistant_service_host_->Stop(); libassistant_service_host_->Stop();
} }
void AssistantProxy::BindControllers(LibassistantServiceHost* host) { void AssistantProxy::BindControllers(
LibassistantServiceHost* host,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory) {
mojo::PendingRemote<AudioInputControllerMojom> mojo::PendingRemote<AudioInputControllerMojom>
pending_audio_input_controller_remote; pending_audio_input_controller_remote;
mojo::PendingRemote<AudioStreamFactoryDelegateMojom> mojo::PendingRemote<AudioStreamFactoryDelegateMojom>
...@@ -91,7 +98,8 @@ void AssistantProxy::BindControllers(LibassistantServiceHost* host) { ...@@ -91,7 +98,8 @@ void AssistantProxy::BindControllers(LibassistantServiceHost* host) {
pending_service_controller_remote.InitWithNewPipeAndPassReceiver()); pending_service_controller_remote.InitWithNewPipeAndPassReceiver());
service_controller_proxy_ = std::make_unique<ServiceControllerProxy>( service_controller_proxy_ = std::make_unique<ServiceControllerProxy>(
host, std::move(pending_service_controller_remote)); host, std::move(pending_url_loader_factory),
std::move(pending_service_controller_remote));
conversation_controller_proxy_ = conversation_controller_proxy_ =
std::make_unique<ConversationControllerProxy>( std::make_unique<ConversationControllerProxy>(
std::move(pending_conversation_controller_remote)); std::move(pending_conversation_controller_remote));
......
...@@ -18,6 +18,10 @@ class LibassistantService; ...@@ -18,6 +18,10 @@ class LibassistantService;
} // namespace libassistant } // namespace libassistant
} // namespace chromeos } // namespace chromeos
namespace network {
class PendingSharedURLLoaderFactory;
} // namespace network
namespace chromeos { namespace chromeos {
namespace assistant { namespace assistant {
...@@ -34,7 +38,9 @@ class AssistantProxy { ...@@ -34,7 +38,9 @@ class AssistantProxy {
AssistantProxy& operator=(AssistantProxy&) = delete; AssistantProxy& operator=(AssistantProxy&) = delete;
~AssistantProxy(); ~AssistantProxy();
void Initialize(LibassistantServiceHost* host); void Initialize(LibassistantServiceHost* host,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory);
// Returns the controller that manages starting and stopping of the Assistant // Returns the controller that manages starting and stopping of the Assistant
// service. // service.
...@@ -67,7 +73,9 @@ class AssistantProxy { ...@@ -67,7 +73,9 @@ class AssistantProxy {
void StopLibassistantService(); void StopLibassistantService();
void StopLibassistantServiceOnBackgroundThread(); void StopLibassistantServiceOnBackgroundThread();
void BindControllers(LibassistantServiceHost* host); void BindControllers(LibassistantServiceHost* host,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory);
// Owned by |AssistantManagerServiceImpl|. // Owned by |AssistantManagerServiceImpl|.
LibassistantServiceHost* libassistant_service_host_ = nullptr; LibassistantServiceHost* libassistant_service_host_ = nullptr;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "chromeos/services/libassistant/libassistant_service.h" #include "chromeos/services/libassistant/libassistant_service.h"
#include "chromeos/services/libassistant/public/mojom/service_controller.mojom-forward.h" #include "chromeos/services/libassistant/public/mojom/service_controller.mojom-forward.h"
#include "libassistant/shared/internal_api/assistant_manager_internal.h" #include "libassistant/shared/internal_api/assistant_manager_internal.h"
#include "libassistant/shared/internal_api/fuchsia_api_helper.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
namespace chromeos { namespace chromeos {
namespace assistant { namespace assistant {
...@@ -45,7 +45,6 @@ struct StartArguments { ...@@ -45,7 +45,6 @@ struct StartArguments {
~StartArguments() = default; ~StartArguments() = default;
assistant_client::ActionModule* action_module; assistant_client::ActionModule* action_module;
assistant_client::FuchsiaApiDelegate* fuchsia_api_delegate;
assistant_client::AssistantManagerDelegate* assistant_manager_delegate; assistant_client::AssistantManagerDelegate* assistant_manager_delegate;
assistant_client::ConversationStateListener* conversation_state_listener; assistant_client::ConversationStateListener* conversation_state_listener;
assistant_client::DeviceStateListener* device_state_listener; assistant_client::DeviceStateListener* device_state_listener;
...@@ -87,8 +86,6 @@ void InitializeAssistantManager( ...@@ -87,8 +86,6 @@ void InitializeAssistantManager(
assistant_manager_internal->RegisterActionModule(arguments.action_module); assistant_manager_internal->RegisterActionModule(arguments.action_module);
assistant_manager_internal->SetAssistantManagerDelegate( assistant_manager_internal->SetAssistantManagerDelegate(
arguments.assistant_manager_delegate); arguments.assistant_manager_delegate);
assistant_manager_internal->GetFuchsiaApiHelperOrDie()->SetFuchsiaApiDelegate(
arguments.fuchsia_api_delegate);
assistant_manager->AddConversationStateListener( assistant_manager->AddConversationStateListener(
arguments.conversation_state_listener); arguments.conversation_state_listener);
assistant_manager->AddDeviceStateListener(arguments.device_state_listener); assistant_manager->AddDeviceStateListener(arguments.device_state_listener);
...@@ -112,9 +109,13 @@ ToMojomAuthenticationTokens(const ServiceControllerProxy::AuthTokens& tokens) { ...@@ -112,9 +109,13 @@ ToMojomAuthenticationTokens(const ServiceControllerProxy::AuthTokens& tokens) {
ServiceControllerProxy::ServiceControllerProxy( ServiceControllerProxy::ServiceControllerProxy(
LibassistantServiceHost* host, LibassistantServiceHost* host,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory,
mojo::PendingRemote<chromeos::libassistant::mojom::ServiceController> mojo::PendingRemote<chromeos::libassistant::mojom::ServiceController>
client) client)
: host_(host), : host_(host),
url_loader_factory_(network::SharedURLLoaderFactory::Create(
std::move(pending_url_loader_factory))),
service_controller_remote_(std::move(client)), service_controller_remote_(std::move(client)),
state_observer_receiver_(this) { state_observer_receiver_(this) {
service_controller_remote_->AddAndFireStateObserver( service_controller_remote_->AddAndFireStateObserver(
...@@ -125,7 +126,6 @@ ServiceControllerProxy::~ServiceControllerProxy() = default; ...@@ -125,7 +126,6 @@ ServiceControllerProxy::~ServiceControllerProxy() = default;
void ServiceControllerProxy::Start( void ServiceControllerProxy::Start(
assistant_client::ActionModule* action_module, assistant_client::ActionModule* action_module,
assistant_client::FuchsiaApiDelegate* fuchsia_api_delegate,
assistant_client::AssistantManagerDelegate* assistant_manager_delegate, assistant_client::AssistantManagerDelegate* assistant_manager_delegate,
assistant_client::ConversationStateListener* conversation_state_listener, assistant_client::ConversationStateListener* conversation_state_listener,
assistant_client::DeviceStateListener* device_state_listener, assistant_client::DeviceStateListener* device_state_listener,
...@@ -145,7 +145,8 @@ void ServiceControllerProxy::Start( ...@@ -145,7 +145,8 @@ void ServiceControllerProxy::Start(
assistant::features::IsMediaSessionIntegrationEnabled()); assistant::features::IsMediaSessionIntegrationEnabled());
// The mojom service will create the |AssistantManager|. // The mojom service will create the |AssistantManager|.
service_controller_remote_->Initialize(std::move(bootup_config)); service_controller_remote_->Initialize(std::move(bootup_config),
BindURLLoaderFactory());
service_controller_remote_->SetLocaleOverride(locale_override); service_controller_remote_->SetLocaleOverride(locale_override);
UpdateInternalOptions(locale, spoken_feedback_enabled); UpdateInternalOptions(locale, spoken_feedback_enabled);
SetAuthTokens(auth_tokens); SetAuthTokens(auth_tokens);
...@@ -155,7 +156,6 @@ void ServiceControllerProxy::Start( ...@@ -155,7 +156,6 @@ void ServiceControllerProxy::Start(
// it's started, so we register a callback to do just that. // it's started, so we register a callback to do just that.
StartArguments arguments; StartArguments arguments;
arguments.action_module = action_module; arguments.action_module = action_module;
arguments.fuchsia_api_delegate = fuchsia_api_delegate;
arguments.assistant_manager_delegate = assistant_manager_delegate; arguments.assistant_manager_delegate = assistant_manager_delegate;
arguments.conversation_state_listener = conversation_state_listener; arguments.conversation_state_listener = conversation_state_listener;
arguments.device_state_listener = device_state_listener; arguments.device_state_listener = device_state_listener;
...@@ -241,5 +241,12 @@ void ServiceControllerProxy::FinishCreatingAssistant() { ...@@ -241,5 +241,12 @@ void ServiceControllerProxy::FinishCreatingAssistant() {
std::move(on_start_done_callback_.value()).Run(); std::move(on_start_done_callback_.value()).Run();
} }
mojo::PendingRemote<network::mojom::URLLoaderFactory>
ServiceControllerProxy::BindURLLoaderFactory() {
mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_remote;
url_loader_factory_->Clone(pending_remote.InitWithNewPipeAndPassReceiver());
return pending_remote;
}
} // namespace assistant } // namespace assistant
} // namespace chromeos } // namespace chromeos
...@@ -23,10 +23,14 @@ class AssistantManagerDelegate; ...@@ -23,10 +23,14 @@ class AssistantManagerDelegate;
class AssistantManagerInternal; class AssistantManagerInternal;
class ConversationStateListener; class ConversationStateListener;
class DeviceStateListener; class DeviceStateListener;
class FuchsiaApiDelegate;
} // namespace assistant_client } // namespace assistant_client
namespace network {
class PendingSharedURLLoaderFactory;
class SharedURLLoaderFactory;
} // namespace network
namespace chromeos { namespace chromeos {
namespace assistant { namespace assistant {
...@@ -45,6 +49,8 @@ class ServiceControllerProxy : private libassistant::mojom::StateObserver { ...@@ -45,6 +49,8 @@ class ServiceControllerProxy : private libassistant::mojom::StateObserver {
ServiceControllerProxy( ServiceControllerProxy(
LibassistantServiceHost* host, LibassistantServiceHost* host,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory,
mojo::PendingRemote<chromeos::libassistant::mojom::ServiceController> mojo::PendingRemote<chromeos::libassistant::mojom::ServiceController>
client); client);
...@@ -65,7 +71,6 @@ class ServiceControllerProxy : private libassistant::mojom::StateObserver { ...@@ -65,7 +71,6 @@ class ServiceControllerProxy : private libassistant::mojom::StateObserver {
// Start() can only be called when the service is stopped. // Start() can only be called when the service is stopped.
void Start( void Start(
assistant_client::ActionModule* action_module, assistant_client::ActionModule* action_module,
assistant_client::FuchsiaApiDelegate* fuchsia_api_delegate,
assistant_client::AssistantManagerDelegate* assistant_manager_delegate, assistant_client::AssistantManagerDelegate* assistant_manager_delegate,
assistant_client::ConversationStateListener* conversation_state_listener, assistant_client::ConversationStateListener* conversation_state_listener,
assistant_client::DeviceStateListener* device_state_listener, assistant_client::DeviceStateListener* device_state_listener,
...@@ -118,12 +123,16 @@ class ServiceControllerProxy : private libassistant::mojom::StateObserver { ...@@ -118,12 +123,16 @@ class ServiceControllerProxy : private libassistant::mojom::StateObserver {
void OnAssistantStarted(base::OnceClosure done_callback); void OnAssistantStarted(base::OnceClosure done_callback);
mojo::PendingRemote<network::mojom::URLLoaderFactory> BindURLLoaderFactory();
// Used internally for consistency checks. // Used internally for consistency checks.
State state_ = State::kStopped; State state_ = State::kStopped;
// Owned by |AssistantManagerServiceImpl| which (indirectly) also owns us. // Owned by |AssistantManagerServiceImpl| which (indirectly) also owns us.
LibassistantServiceHost* const host_; LibassistantServiceHost* const host_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
mojo::Remote<chromeos::libassistant::mojom::ServiceController> mojo::Remote<chromeos::libassistant::mojom::ServiceController>
service_controller_remote_; service_controller_remote_;
mojo::Receiver<chromeos::libassistant::mojom::StateObserver> mojo::Receiver<chromeos::libassistant::mojom::StateObserver>
......
...@@ -64,7 +64,8 @@ std::string FakeServiceController::gaia_id() { ...@@ -64,7 +64,8 @@ std::string FakeServiceController::gaia_id() {
} }
void FakeServiceController::Initialize( void FakeServiceController::Initialize(
libassistant::mojom::BootupConfigPtr config) { libassistant::mojom::BootupConfigPtr config,
mojo::PendingRemote<network::mojom::URLLoaderFactory> url_loader_factory) {
libassistant_config_ = std::move(*config); libassistant_config_ = std::move(*config);
} }
......
...@@ -75,7 +75,9 @@ class FakeServiceController : public libassistant::mojom::ServiceController { ...@@ -75,7 +75,9 @@ class FakeServiceController : public libassistant::mojom::ServiceController {
std::string gaia_id(); std::string gaia_id();
// mojom::ServiceController implementation: // mojom::ServiceController implementation:
void Initialize(libassistant::mojom::BootupConfigPtr config) override; void Initialize(libassistant::mojom::BootupConfigPtr config,
mojo::PendingRemote<network::mojom::URLLoaderFactory>
url_loader_factory) override;
void Start() override; void Start() override;
void Stop() override; void Stop() override;
void AddAndFireStateObserver( void AddAndFireStateObserver(
......
...@@ -41,6 +41,10 @@ source_set("internal") { ...@@ -41,6 +41,10 @@ source_set("internal") {
"audio/audio_input_stream.h", "audio/audio_input_stream.h",
"audio_input_controller.cc", "audio_input_controller.cc",
"audio_input_controller.h", "audio_input_controller.h",
"chromium_api_delegate.cc",
"chromium_api_delegate.h",
"chromium_http_connection.cc",
"chromium_http_connection.h",
"conversation_controller.cc", "conversation_controller.cc",
"conversation_controller.h", "conversation_controller.h",
"platform_api.cc", "platform_api.cc",
...@@ -66,6 +70,7 @@ source_set("internal") { ...@@ -66,6 +70,7 @@ source_set("internal") {
"//libassistant/shared/public:export", "//libassistant/shared/public:export",
"//media", "//media",
"//services/audio/public/cpp", "//services/audio/public/cpp",
"//services/network/public/cpp",
] ]
defines = [ "IS_LIBASSISTANT_SERVICE_IMPL" ] defines = [ "IS_LIBASSISTANT_SERVICE_IMPL" ]
...@@ -90,6 +95,8 @@ source_set("unit_tests") { ...@@ -90,6 +95,8 @@ source_set("unit_tests") {
"//chromeos/services/libassistant/public/mojom", "//chromeos/services/libassistant/public/mojom",
"//libassistant/shared/internal_api:assistant_manager_internal", "//libassistant/shared/internal_api:assistant_manager_internal",
"//services/audio/public/cpp:test_support", "//services/audio/public/cpp:test_support",
"//services/network:test_support",
"//services/network/public/cpp",
"//testing/gmock", "//testing/gmock",
"//testing/gtest", "//testing/gtest",
] ]
......
...@@ -3,4 +3,6 @@ include_rules = [ ...@@ -3,4 +3,6 @@ include_rules = [
"+media/audio", "+media/audio",
"+media/base", "+media/base",
"+services/audio/public", "+services/audio/public",
"+services/network/public",
"+services/network/test",
] ]
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chromeos/services/assistant/chromium_api_delegate.h" #include "chromeos/services/libassistant/chromium_api_delegate.h"
#include <utility> #include <utility>
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
namespace chromeos { namespace chromeos {
namespace assistant { namespace libassistant {
ChromiumApiDelegate::ChromiumApiDelegate( ChromiumApiDelegate::ChromiumApiDelegate(
std::unique_ptr<network::PendingSharedURLLoaderFactory> std::unique_ptr<network::PendingSharedURLLoaderFactory>
...@@ -24,5 +24,5 @@ ChromiumApiDelegate::GetHttpConnectionFactory() { ...@@ -24,5 +24,5 @@ ChromiumApiDelegate::GetHttpConnectionFactory() {
return &http_connection_factory_; return &http_connection_factory_;
} }
} // namespace assistant } // namespace libassistant
} // namespace chromeos } // namespace chromeos
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROMEOS_SERVICES_ASSISTANT_CHROMIUM_API_DELEGATE_H_ #ifndef CHROMEOS_SERVICES_LIBASSISTANT_CHROMIUM_API_DELEGATE_H_
#define CHROMEOS_SERVICES_ASSISTANT_CHROMIUM_API_DELEGATE_H_ #define CHROMEOS_SERVICES_LIBASSISTANT_CHROMIUM_API_DELEGATE_H_
#include "chromeos/services/assistant/chromium_http_connection.h" #include "chromeos/services/libassistant/chromium_http_connection.h"
#include <memory> #include <memory>
...@@ -17,7 +17,7 @@ class PendingSharedURLLoaderFactory; ...@@ -17,7 +17,7 @@ class PendingSharedURLLoaderFactory;
} // namespace network } // namespace network
namespace chromeos { namespace chromeos {
namespace assistant { namespace libassistant {
class ChromiumHttpConnectionFactory; class ChromiumHttpConnectionFactory;
...@@ -35,7 +35,7 @@ class ChromiumApiDelegate : public assistant_client::FuchsiaApiDelegate { ...@@ -35,7 +35,7 @@ class ChromiumApiDelegate : public assistant_client::FuchsiaApiDelegate {
DISALLOW_COPY_AND_ASSIGN(ChromiumApiDelegate); DISALLOW_COPY_AND_ASSIGN(ChromiumApiDelegate);
}; };
} // namespace assistant } // namespace libassistant
} // namespace chromeos } // namespace chromeos
#endif // CHROMEOS_SERVICES_ASSISTANT_CHROMIUM_API_DELEGATE_H_ #endif // CHROMEOS_SERVICES_LIBASSISTANT_CHROMIUM_API_DELEGATE_H_
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// The file comes from Google Home(cast) implementation. // The file comes from Google Home(cast) implementation.
#include "chromeos/services/assistant/chromium_http_connection.h" #include "chromeos/services/libassistant/chromium_http_connection.h"
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
...@@ -33,7 +33,7 @@ using network::SharedURLLoaderFactory; ...@@ -33,7 +33,7 @@ using network::SharedURLLoaderFactory;
} }
namespace chromeos { namespace chromeos {
namespace assistant { namespace libassistant {
namespace { namespace {
...@@ -176,6 +176,7 @@ void ChromiumHttpConnection::Start() { ...@@ -176,6 +176,7 @@ void ChromiumHttpConnection::Start() {
auto factory = auto factory =
SharedURLLoaderFactory::Create(std::move(pending_url_loader_factory_)); SharedURLLoaderFactory::Create(std::move(pending_url_loader_factory_));
if (handle_partial_response_) { if (handle_partial_response_) {
url_loader_->SetOnResponseStartedCallback( url_loader_->SetOnResponseStartedCallback(
base::BindOnce(&ChromiumHttpConnection::OnResponseStarted, this)); base::BindOnce(&ChromiumHttpConnection::OnResponseStarted, this));
...@@ -407,5 +408,5 @@ HttpConnection* ChromiumHttpConnectionFactory::Create( ...@@ -407,5 +408,5 @@ HttpConnection* ChromiumHttpConnectionFactory::Create(
return new ChromiumHttpConnection(url_loader_factory_->Clone(), delegate); return new ChromiumHttpConnection(url_loader_factory_->Clone(), delegate);
} }
} // namespace assistant } // namespace libassistant
} // namespace chromeos } // namespace chromeos
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROMEOS_SERVICES_ASSISTANT_CHROMIUM_HTTP_CONNECTION_H_ #ifndef CHROMEOS_SERVICES_LIBASSISTANT_CHROMIUM_HTTP_CONNECTION_H_
#define CHROMEOS_SERVICES_ASSISTANT_CHROMIUM_HTTP_CONNECTION_H_ #define CHROMEOS_SERVICES_LIBASSISTANT_CHROMIUM_HTTP_CONNECTION_H_
#include <stdint.h> #include <stdint.h>
...@@ -29,7 +29,7 @@ class PendingSharedURLLoaderFactory; ...@@ -29,7 +29,7 @@ class PendingSharedURLLoaderFactory;
} // namespace network } // namespace network
namespace chromeos { namespace chromeos {
namespace assistant { namespace libassistant {
// Implements libassistant's HttpConnection. // Implements libassistant's HttpConnection.
class ChromiumHttpConnection class ChromiumHttpConnection
...@@ -148,7 +148,7 @@ class ChromiumHttpConnectionFactory ...@@ -148,7 +148,7 @@ class ChromiumHttpConnectionFactory
DISALLOW_COPY_AND_ASSIGN(ChromiumHttpConnectionFactory); DISALLOW_COPY_AND_ASSIGN(ChromiumHttpConnectionFactory);
}; };
} // namespace assistant } // namespace libassistant
} // namespace chromeos } // namespace chromeos
#endif // CHROMEOS_SERVICES_ASSISTANT_CHROMIUM_HTTP_CONNECTION_H_ #endif // CHROMEOS_SERVICES_LIBASSISTANT_CHROMIUM_HTTP_CONNECTION_H_
...@@ -6,11 +6,14 @@ import("//mojo/public/tools/bindings/mojom.gni") ...@@ -6,11 +6,14 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojom") { mojom("mojom") {
sources = [ sources = [
"conversation_controller.mojom",
"audio_input_controller.mojom", "audio_input_controller.mojom",
"conversation_controller.mojom",
"service.mojom", "service.mojom",
"service_controller.mojom", "service_controller.mojom",
] ]
deps = [ "//services/audio/public/mojom" ] deps = [
"//services/audio/public/mojom",
"//services/network/public/mojom",
]
} }
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
module chromeos.libassistant.mojom; module chromeos.libassistant.mojom;
import "services/network/public/mojom/url_loader_factory.mojom";
enum ServiceState { enum ServiceState {
// The service has been started but is not ready yet to handle queries. // The service has been started but is not ready yet to handle queries.
kStarted, kStarted,
...@@ -22,7 +24,8 @@ interface ServiceController { ...@@ -22,7 +24,8 @@ interface ServiceController {
// Note that calling Initialize() will not cause any change in the service // Note that calling Initialize() will not cause any change in the service
// state, as the service will remain in state |kStopped| until Start() is // state, as the service will remain in state |kStopped| until Start() is
// called. // called.
Initialize(BootupConfig bootup_config); Initialize(BootupConfig bootup_config,
pending_remote<network.mojom.URLLoaderFactory> url_loading_factory);
// Start the service. Can be called multiple times, and will be a noop if // Start the service. Can be called multiple times, and will be a noop if
// the service is already started or running. // the service is already started or running.
......
...@@ -11,8 +11,11 @@ ...@@ -11,8 +11,11 @@
#include "chromeos/services/assistant/public/cpp/features.h" #include "chromeos/services/assistant/public/cpp/features.h"
#include "chromeos/services/assistant/public/cpp/migration/assistant_manager_service_delegate.h" #include "chromeos/services/assistant/public/cpp/migration/assistant_manager_service_delegate.h"
#include "chromeos/services/assistant/public/cpp/migration/libassistant_v1_api.h" #include "chromeos/services/assistant/public/cpp/migration/libassistant_v1_api.h"
#include "chromeos/services/libassistant/chromium_api_delegate.h"
#include "chromeos/services/libassistant/util.h" #include "chromeos/services/libassistant/util.h"
#include "libassistant/shared/internal_api/assistant_manager_internal.h" #include "libassistant/shared/internal_api/assistant_manager_internal.h"
#include "services/network/public/cpp/cross_thread_pending_shared_url_loader_factory.h"
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
namespace chromeos { namespace chromeos {
namespace libassistant { namespace libassistant {
...@@ -37,6 +40,23 @@ std::string ToLibassistantConfig(const mojom::BootupConfig& bootup_config) { ...@@ -37,6 +40,23 @@ std::string ToLibassistantConfig(const mojom::BootupConfig& bootup_config) {
bootup_config.log_in_home_dir); bootup_config.log_in_home_dir);
} }
std::unique_ptr<network::PendingSharedURLLoaderFactory>
CreatePendingURLLoaderFactory(
mojo::PendingRemote<network::mojom::URLLoaderFactory>
url_loader_factory_remote) {
// First create a wrapped factory that can accept the pending remote.
auto pending_url_loader_factory =
std::make_unique<network::WrapperPendingSharedURLLoaderFactory>(
std::move(url_loader_factory_remote));
auto wrapped_factory = network::SharedURLLoaderFactory::Create(
std::move(pending_url_loader_factory));
// Then move it into a cross thread factory, as the url loader factory will be
// used from internal Libassistant threads.
return std::make_unique<network::CrossThreadPendingSharedURLLoaderFactory>(
std::move(wrapped_factory));
}
} // namespace } // namespace
ServiceController::ServiceController( ServiceController::ServiceController(
...@@ -60,7 +80,9 @@ void ServiceController::SetInitializeCallback(InitializeCallback callback) { ...@@ -60,7 +80,9 @@ void ServiceController::SetInitializeCallback(InitializeCallback callback) {
initialize_callback_ = std::move(callback); initialize_callback_ = std::move(callback);
} }
void ServiceController::Initialize(mojom::BootupConfigPtr config) { void ServiceController::Initialize(
mojom::BootupConfigPtr config,
mojo::PendingRemote<network::mojom::URLLoaderFactory> url_loader_factory) {
if (assistant_manager_ != nullptr) { if (assistant_manager_ != nullptr) {
LOG(ERROR) << "Initialize() should only be called once."; LOG(ERROR) << "Initialize() should only be called once.";
return; return;
...@@ -71,6 +93,8 @@ void ServiceController::Initialize(mojom::BootupConfigPtr config) { ...@@ -71,6 +93,8 @@ void ServiceController::Initialize(mojom::BootupConfigPtr config) {
assistant_manager_internal_ = assistant_manager_internal_ =
delegate_->UnwrapAssistantManagerInternal(assistant_manager_.get()); delegate_->UnwrapAssistantManagerInternal(assistant_manager_.get());
CreateAndRegisterChromiumApiDelegate(std::move(url_loader_factory));
for (auto& observer : assistant_manager_observers_) { for (auto& observer : assistant_manager_observers_) {
observer.OnAssistantManagerCreated(assistant_manager(), observer.OnAssistantManagerCreated(assistant_manager(),
assistant_manager_internal()); assistant_manager_internal());
...@@ -115,6 +139,7 @@ void ServiceController::Stop() { ...@@ -115,6 +139,7 @@ void ServiceController::Stop() {
libassistant_v1_api_ = nullptr; libassistant_v1_api_ = nullptr;
assistant_manager_ = nullptr; assistant_manager_ = nullptr;
assistant_manager_internal_ = nullptr; assistant_manager_internal_ = nullptr;
chromium_api_delegate_ = nullptr;
} }
void ServiceController::AddAndFireStateObserver( void ServiceController::AddAndFireStateObserver(
...@@ -207,5 +232,24 @@ void ServiceController::SetStateAndInformObservers( ...@@ -207,5 +232,24 @@ void ServiceController::SetStateAndInformObservers(
observer->OnStateChanged(state_); observer->OnStateChanged(state_);
} }
void ServiceController::CreateAndRegisterChromiumApiDelegate(
mojo::PendingRemote<network::mojom::URLLoaderFactory>
url_loader_factory_remote) {
CreateChromiumApiDelegate(std::move(url_loader_factory_remote));
assistant_manager_internal()
->GetFuchsiaApiHelperOrDie()
->SetFuchsiaApiDelegate(chromium_api_delegate_.get());
}
void ServiceController::CreateChromiumApiDelegate(
mojo::PendingRemote<network::mojom::URLLoaderFactory>
url_loader_factory_remote) {
DCHECK(!chromium_api_delegate_);
chromium_api_delegate_ = std::make_unique<ChromiumApiDelegate>(
CreatePendingURLLoaderFactory(std::move(url_loader_factory_remote)));
}
} // namespace libassistant } // namespace libassistant
} // namespace chromeos } // namespace chromeos
...@@ -37,6 +37,8 @@ class AssistantManagerServiceDelegate; ...@@ -37,6 +37,8 @@ class AssistantManagerServiceDelegate;
namespace chromeos { namespace chromeos {
namespace libassistant { namespace libassistant {
class ChromiumApiDelegate;
// Component managing the lifecycle of Libassistant, // Component managing the lifecycle of Libassistant,
// exposing methods to start/stop and configure Libassistant. // exposing methods to start/stop and configure Libassistant.
// Note: to access the Libassistant objects from //chromeos/services/assistant, // Note: to access the Libassistant objects from //chromeos/services/assistant,
...@@ -63,7 +65,9 @@ class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) ServiceController ...@@ -63,7 +65,9 @@ class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) ServiceController
void SetInitializeCallback(InitializeCallback callback); void SetInitializeCallback(InitializeCallback callback);
// mojom::ServiceController implementation: // mojom::ServiceController implementation:
void Initialize(mojom::BootupConfigPtr libassistant_config) override; void Initialize(mojom::BootupConfigPtr libassistant_config,
mojo::PendingRemote<network::mojom::URLLoaderFactory>
url_loader_factory) override;
void Start() override; void Start() override;
void Stop() override; void Stop() override;
void AddAndFireStateObserver( void AddAndFireStateObserver(
...@@ -88,6 +92,11 @@ class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) ServiceController ...@@ -88,6 +92,11 @@ class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) ServiceController
private: private:
void SetStateAndInformObservers(mojom::ServiceState new_state); void SetStateAndInformObservers(mojom::ServiceState new_state);
void CreateAndRegisterChromiumApiDelegate(
mojo::PendingRemote<network::mojom::URLLoaderFactory> url_loader_factory);
void CreateChromiumApiDelegate(
mojo::PendingRemote<network::mojom::URLLoaderFactory> url_loader_factory);
mojom::ServiceState state_ = mojom::ServiceState::kStopped; mojom::ServiceState state_ = mojom::ServiceState::kStopped;
// Owned by |AssistantManagerServiceImpl| which indirectly owns us. // Owned by |AssistantManagerServiceImpl| which indirectly owns us.
...@@ -101,6 +110,7 @@ class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) ServiceController ...@@ -101,6 +110,7 @@ class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) ServiceController
std::unique_ptr<assistant_client::AssistantManager> assistant_manager_; std::unique_ptr<assistant_client::AssistantManager> assistant_manager_;
assistant_client::AssistantManagerInternal* assistant_manager_internal_ = assistant_client::AssistantManagerInternal* assistant_manager_internal_ =
nullptr; nullptr;
std::unique_ptr<ChromiumApiDelegate> chromium_api_delegate_;
std::unique_ptr<assistant::LibassistantV1Api> libassistant_v1_api_; std::unique_ptr<assistant::LibassistantV1Api> libassistant_v1_api_;
mojo::Receiver<mojom::ServiceController> receiver_; mojo::Receiver<mojom::ServiceController> receiver_;
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "chromeos/services/libassistant/public/mojom/service_controller.mojom.h" #include "chromeos/services/libassistant/public/mojom/service_controller.mojom.h"
#include "libassistant/shared/internal_api/assistant_manager_internal.h" #include "libassistant/shared/internal_api/assistant_manager_internal.h"
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -87,10 +89,9 @@ class AssistantManagerObserverMock : public AssistantManagerObserver { ...@@ -87,10 +89,9 @@ class AssistantManagerObserverMock : public AssistantManagerObserver {
class AssistantServiceControllerTest : public testing::Test { class AssistantServiceControllerTest : public testing::Test {
public: public:
AssistantServiceControllerTest() AssistantServiceControllerTest()
: service_controller_(std::make_unique<ServiceController>( : service_controller_(
std::make_unique<ServiceController>(&delegate_,
&delegate_, /*platform_api=*/nullptr)) {
/*platform_api=*/nullptr)) {
service_controller_->Bind(client_.BindNewPipeAndPassReceiver()); service_controller_->Bind(client_.BindNewPipeAndPassReceiver());
} }
...@@ -126,7 +127,7 @@ class AssistantServiceControllerTest : public testing::Test { ...@@ -126,7 +127,7 @@ class AssistantServiceControllerTest : public testing::Test {
} }
void Initialize(mojom::BootupConfigPtr config = mojom::BootupConfig::New()) { void Initialize(mojom::BootupConfigPtr config = mojom::BootupConfig::New()) {
service_controller().Initialize(std::move(config)); service_controller().Initialize(std::move(config), BindURLLoaderFactory());
} }
void Start() { void Start() {
...@@ -150,7 +151,16 @@ class AssistantServiceControllerTest : public testing::Test { ...@@ -150,7 +151,16 @@ class AssistantServiceControllerTest : public testing::Test {
} }
private: private:
mojo::PendingRemote<network::mojom::URLLoaderFactory> BindURLLoaderFactory() {
mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_remote;
url_loader_factory_.Clone(pending_remote.InitWithNewPipeAndPassReceiver());
return pending_remote;
}
base::test::SingleThreadTaskEnvironment environment_; base::test::SingleThreadTaskEnvironment environment_;
network::TestURLLoaderFactory url_loader_factory_;
assistant::FakeAssistantManagerServiceDelegate delegate_; assistant::FakeAssistantManagerServiceDelegate delegate_;
mojo::Remote<mojom::ServiceController> client_; mojo::Remote<mojom::ServiceController> client_;
std::unique_ptr<ServiceController> service_controller_; std::unique_ptr<ServiceController> service_controller_;
......
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