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

Always create the |ServiceController|

Previously it was only created when it was bound to a receiver,
which caused complications if other controllers are created first,
because those controllers need access to the Libassistant objects
created by the |ServiceController|.

This CL also removes unused accessor methods.

Bug: b/171748795
Test: chromeos_unittests --gtest_filter="ServiceController*"
Change-Id: I1eed788e51a108b6f2b70929f059daabe7b70d65
Cq-Include-Trybots: luci.chrome.try:linux-chromeos-chrome
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2569847
Commit-Queue: Jeroen Dhollander <jeroendh@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Reviewed-by: default avatarMeilin Wang <meilinw@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835916}
parent 9d210153
...@@ -18,29 +18,15 @@ LibassistantService::LibassistantService( ...@@ -18,29 +18,15 @@ LibassistantService::LibassistantService(
mojo::PendingReceiver<mojom::LibassistantService> receiver, mojo::PendingReceiver<mojom::LibassistantService> receiver,
assistant_client::PlatformApi* platform_api, assistant_client::PlatformApi* platform_api,
assistant::AssistantManagerServiceDelegate* delegate) assistant::AssistantManagerServiceDelegate* delegate)
: platform_api_(platform_api), : receiver_(this, std::move(receiver)),
delegate_(delegate), service_controller_(
receiver_(this, std::move(receiver)) {} std::make_unique<ServiceController>(delegate, platform_api)) {}
LibassistantService::~LibassistantService() = default; LibassistantService::~LibassistantService() = default;
assistant_client::AssistantManager* LibassistantService::assistant_manager() {
DCHECK(service_controller_);
return service_controller_->assistant_manager();
}
assistant_client::AssistantManagerInternal*
LibassistantService::assistant_manager_internal() {
DCHECK(service_controller_);
return service_controller_->assistant_manager_internal();
}
void LibassistantService::BindServiceController( void LibassistantService::BindServiceController(
mojo::PendingReceiver<mojom::ServiceController> receiver) { mojo::PendingReceiver<mojom::ServiceController> receiver) {
// Cannot bind the service controller twice. service_controller_->Bind(std::move(receiver));
DCHECK(!service_controller_);
service_controller_ = std::make_unique<ServiceController>(
std::move(receiver), delegate_, platform_api_);
} }
} // namespace libassistant } // namespace libassistant
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
namespace assistant_client { namespace assistant_client {
class AssistantManager;
class AssistantManagerInternal;
class PlatformApi; class PlatformApi;
} // namespace assistant_client } // namespace assistant_client
...@@ -39,12 +37,6 @@ class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) LibassistantService ...@@ -39,12 +37,6 @@ class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) LibassistantService
LibassistantService& operator=(LibassistantService&) = delete; LibassistantService& operator=(LibassistantService&) = delete;
~LibassistantService() override; ~LibassistantService() override;
// Retrieve the |AssistantManager|. The pointer is valid as long as the
// |ServiceController| is in state |kStarted| (and this class is not
// destroyed).
assistant_client::AssistantManager* assistant_manager();
assistant_client::AssistantManagerInternal* assistant_manager_internal();
private: private:
// mojom::LibassistantService implementation: // mojom::LibassistantService implementation:
void BindServiceController( void BindServiceController(
...@@ -53,11 +45,6 @@ class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) LibassistantService ...@@ -53,11 +45,6 @@ class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) LibassistantService
void BindAudioOutputController() override {} void BindAudioOutputController() override {}
void BindInteractionController() override {} void BindInteractionController() override {}
// Owned by |AssistantManagerServiceImpl| which indirectly owns us.
assistant_client::PlatformApi* const platform_api_;
// Owned by |AssistantManagerServiceImpl| which indirectly owns us.
assistant::AssistantManagerServiceDelegate* const delegate_;
mojo::Receiver<mojom::LibassistantService> receiver_; mojo::Receiver<mojom::LibassistantService> receiver_;
std::unique_ptr<ServiceController> service_controller_; std::unique_ptr<ServiceController> service_controller_;
}; };
......
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
// 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 <memory>
#include "chromeos/services/libassistant/service_controller.h" #include "chromeos/services/libassistant/service_controller.h"
#include <memory>
#include "base/check.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"
...@@ -15,15 +16,18 @@ namespace libassistant { ...@@ -15,15 +16,18 @@ namespace libassistant {
using mojom::ServiceState; using mojom::ServiceState;
ServiceController::ServiceController( ServiceController::ServiceController(
mojo::PendingReceiver<mojom::ServiceController> receiver,
assistant::AssistantManagerServiceDelegate* delegate, assistant::AssistantManagerServiceDelegate* delegate,
assistant_client::PlatformApi* platform_api) assistant_client::PlatformApi* platform_api)
: delegate_(delegate), : delegate_(delegate), platform_api_(platform_api), receiver_(this) {}
platform_api_(platform_api),
receiver_(this, std::move(receiver)) {}
ServiceController::~ServiceController() = default; ServiceController::~ServiceController() = default;
void ServiceController::Bind(
mojo::PendingReceiver<mojom::ServiceController> receiver) {
DCHECK(!receiver_.is_bound());
receiver_.Bind(std::move(receiver));
}
void ServiceController::Start(const std::string& libassistant_config) { void ServiceController::Start(const std::string& libassistant_config) {
if (state_ != ServiceState::kStopped) if (state_ != ServiceState::kStopped)
return; return;
......
...@@ -35,16 +35,19 @@ namespace libassistant { ...@@ -35,16 +35,19 @@ namespace libassistant {
// 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,
// use the |LibassistantV1Api| singleton, which will be populated by this class.
class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) ServiceController class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) ServiceController
: public mojom::ServiceController { : public mojom::ServiceController {
public: public:
ServiceController(mojo::PendingReceiver<mojom::ServiceController> receiver, ServiceController(assistant::AssistantManagerServiceDelegate* delegate,
assistant::AssistantManagerServiceDelegate* delegate,
assistant_client::PlatformApi* platform_api); assistant_client::PlatformApi* platform_api);
ServiceController(ServiceController&) = delete; ServiceController(ServiceController&) = delete;
ServiceController& operator=(ServiceController&) = delete; ServiceController& operator=(ServiceController&) = delete;
~ServiceController() override; ~ServiceController() override;
void Bind(mojo::PendingReceiver<mojom::ServiceController> receiver);
// mojom::ServiceController implementation: // mojom::ServiceController implementation:
void Start(const std::string& libassistant_config) override; void Start(const std::string& libassistant_config) override;
void Stop() override; void Stop() override;
...@@ -61,7 +64,7 @@ class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) ServiceController ...@@ -61,7 +64,7 @@ class COMPONENT_EXPORT(LIBASSISTANT_SERVICE) ServiceController
mojom::ServiceState state_ = mojom::ServiceState::kStopped; mojom::ServiceState state_ = mojom::ServiceState::kStopped;
// Owned by |AssistantProxy| which owns us. // Owned by |AssistantManagerServiceImpl| which indirectly owns us.
assistant::AssistantManagerServiceDelegate* const delegate_; assistant::AssistantManagerServiceDelegate* const delegate_;
// Owned by |AssistantManagerServiceImpl| which indirectly owns us. // Owned by |AssistantManagerServiceImpl| which indirectly owns us.
assistant_client::PlatformApi* const platform_api_; assistant_client::PlatformApi* const platform_api_;
......
...@@ -45,9 +45,10 @@ class StateObserverMock : public mojom::StateObserver { ...@@ -45,9 +45,10 @@ class StateObserverMock : public mojom::StateObserver {
class ServiceControllerTest : public testing::Test { class ServiceControllerTest : public testing::Test {
public: public:
ServiceControllerTest() ServiceControllerTest()
: service_controller_(client_.BindNewPipeAndPassReceiver(), : service_controller_(&delegate_,
&delegate_, /*platform_api=*/nullptr) {
/*platform_api=*/nullptr) {} service_controller_.Bind(client_.BindNewPipeAndPassReceiver());
}
mojo::Remote<mojom::ServiceController>& client() { return client_; } mojo::Remote<mojom::ServiceController>& client() { return client_; }
ServiceController& service_controller() { return service_controller_; } ServiceController& service_controller() { return 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