1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chromeos/services/assistant/assistant_manager_service_delegate_impl.h"
6 
7 #include <memory>
8 #include <string>
9 #include <utility>
10 
11 #include "ash/public/cpp/assistant/assistant_state_base.h"
12 #include "chromeos/services/assistant/platform_api_impl.h"
13 #include "chromeos/services/assistant/service_context.h"
14 #include "libassistant/shared/internal_api/assistant_manager_internal.h"
15 #include "libassistant/shared/public/assistant_manager.h"
16 
17 namespace chromeos {
18 namespace assistant {
19 
AssistantManagerServiceDelegateImpl(mojo::PendingRemote<device::mojom::BatteryMonitor> battery_monitor,ServiceContext * context)20 AssistantManagerServiceDelegateImpl::AssistantManagerServiceDelegateImpl(
21     mojo::PendingRemote<device::mojom::BatteryMonitor> battery_monitor,
22     ServiceContext* context)
23     : battery_monitor_(std::move(battery_monitor)),
24       context_(context) {}
25 
26 AssistantManagerServiceDelegateImpl::~AssistantManagerServiceDelegateImpl() =
27     default;
28 
29 std::unique_ptr<CrosPlatformApi>
CreatePlatformApi(AssistantMediaSession * media_session,scoped_refptr<base::SingleThreadTaskRunner> background_thread_task_runner)30 AssistantManagerServiceDelegateImpl::CreatePlatformApi(
31     AssistantMediaSession* media_session,
32     scoped_refptr<base::SingleThreadTaskRunner> background_thread_task_runner) {
33   return std::make_unique<PlatformApiImpl>(
34       media_session, context_->power_manager_client(),
35       context_->cras_audio_handler(), std::move(battery_monitor_),
36       context_->main_task_runner(), background_thread_task_runner,
37       context_->assistant_state()->locale().value());
38 }
39 
40 std::unique_ptr<assistant_client::AssistantManager>
CreateAssistantManager(assistant_client::PlatformApi * platform_api,const std::string & lib_assistant_config)41 AssistantManagerServiceDelegateImpl::CreateAssistantManager(
42     assistant_client::PlatformApi* platform_api,
43     const std::string& lib_assistant_config) {
44   // This circumnvent way of creating the unique_ptr is required because
45   // |AssistantManager::Create| returns a raw pointer, and passing that in the
46   // constructor of unique_ptr is blocked by our presubmit checks that try to
47   // force us to use make_unique, which we can't use here.
48   std::unique_ptr<assistant_client::AssistantManager> result;
49   result.reset(assistant_client::AssistantManager::Create(
50       platform_api, lib_assistant_config));
51   return result;
52 }
53 
54 assistant_client::AssistantManagerInternal*
UnwrapAssistantManagerInternal(assistant_client::AssistantManager * assistant_manager)55 AssistantManagerServiceDelegateImpl::UnwrapAssistantManagerInternal(
56     assistant_client::AssistantManager* assistant_manager) {
57   return assistant_client::UnwrapAssistantManagerInternal(assistant_manager);
58 }
59 
60 }  // namespace assistant
61 }  // namespace chromeos
62