James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 1 | // Copyright 2016 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 "ash/mojo_interface_factory.h" |
| 6 | |
| 7 | #include <utility> |
| 8 | |
Jiaquan He | 4b48f91 | 2018-03-01 03:59:39 | [diff] [blame] | 9 | #include "ash/app_list/app_list_controller_impl.h" |
David Black | 8c19e83e | 2018-12-10 23:35:10 | [diff] [blame] | 10 | #include "ash/assistant/assistant_alarm_timer_controller.h" |
David Black | 00fdce3 | 2018-05-10 20:59:14 | [diff] [blame] | 11 | #include "ash/assistant/assistant_controller.h" |
David Black | 3e154a72 | 2018-12-18 21:34:06 | [diff] [blame] | 12 | #include "ash/assistant/assistant_notification_controller.h" |
David Black | c5c3e34 | 2018-11-27 21:20:40 | [diff] [blame] | 13 | #include "ash/assistant/assistant_screen_context_controller.h" |
| 14 | #include "ash/assistant/assistant_setup_controller.h" |
Steven Bennetts | 2a9b438 | 2018-04-26 23:41:19 | [diff] [blame] | 15 | #include "ash/display/cros_display_config.h" |
James Cook | fdee024 | 2017-06-20 14:14:00 | [diff] [blame] | 16 | #include "ash/ime/ime_controller.h" |
Jacob Dufault | ffd9b0d | 2017-11-15 23:07:16 | [diff] [blame] | 17 | #include "ash/login/login_screen_controller.h" |
Xiyuan Xia | d03bd2f | 2019-06-05 22:00:49 | [diff] [blame] | 18 | #include "ash/media/media_controller_impl.h" |
Ahmed Fakhry | 4af48e4 | 2018-02-28 17:45:38 | [diff] [blame] | 19 | #include "ash/public/cpp/ash_features.h" |
Jun Mukai | 6ce2a060 | 2019-06-04 23:23:10 | [diff] [blame] | 20 | #include "ash/public/cpp/voice_interaction_controller.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 21 | #include "ash/shell.h" |
| 22 | #include "ash/shell_delegate.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 23 | #include "ash/system/network/vpn_list.h" |
tbarzic | c78da1ff9 | 2017-05-08 20:46:15 | [diff] [blame] | 24 | #include "ash/tray_action/tray_action.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 25 | #include "base/bind.h" |
James Cook | 625eff0 | 2017-10-11 20:44:31 | [diff] [blame] | 26 | #include "base/lazy_instance.h" |
Gabriel Charette | 5ff87ce | 2017-05-16 18:03:45 | [diff] [blame] | 27 | #include "base/single_thread_task_runner.h" |
James Cook | 8ab85f3 | 2019-08-05 18:30:11 | [diff] [blame] | 28 | #include "chromeos/constants/chromeos_features.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 29 | |
| 30 | namespace ash { |
James Cook | 625eff0 | 2017-10-11 20:44:31 | [diff] [blame] | 31 | namespace mojo_interface_factory { |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 32 | namespace { |
| 33 | |
James Cook | 625eff0 | 2017-10-11 20:44:31 | [diff] [blame] | 34 | base::LazyInstance<RegisterInterfacesCallback>::Leaky |
| 35 | g_register_interfaces_callback = LAZY_INSTANCE_INITIALIZER; |
| 36 | |
David Black | 8c19e83e | 2018-12-10 23:35:10 | [diff] [blame] | 37 | void BindAssistantAlarmTimerControllerRequestOnMainThread( |
| 38 | mojom::AssistantAlarmTimerControllerRequest request) { |
Ken Rockot | c20c6011 | 2019-06-20 22:54:16 | [diff] [blame] | 39 | if (Shell::HasInstance()) { |
| 40 | Shell::Get()->assistant_controller()->alarm_timer_controller()->BindRequest( |
| 41 | std::move(request)); |
| 42 | } |
David Black | 8c19e83e | 2018-12-10 23:35:10 | [diff] [blame] | 43 | } |
| 44 | |
David Black | 00fdce3 | 2018-05-10 20:59:14 | [diff] [blame] | 45 | void BindAssistantControllerRequestOnMainThread( |
| 46 | mojom::AssistantControllerRequest request) { |
Ken Rockot | c20c6011 | 2019-06-20 22:54:16 | [diff] [blame] | 47 | if (Shell::HasInstance()) |
| 48 | Shell::Get()->assistant_controller()->BindRequest(std::move(request)); |
David Black | 00fdce3 | 2018-05-10 20:59:14 | [diff] [blame] | 49 | } |
| 50 | |
David Black | 3e154a72 | 2018-12-18 21:34:06 | [diff] [blame] | 51 | void BindAssistantNotificationControllerRequestOnMainThread( |
| 52 | mojom::AssistantNotificationControllerRequest request) { |
Ken Rockot | c20c6011 | 2019-06-20 22:54:16 | [diff] [blame] | 53 | if (Shell::HasInstance()) { |
| 54 | Shell::Get() |
| 55 | ->assistant_controller() |
| 56 | ->notification_controller() |
| 57 | ->BindRequest(std::move(request)); |
| 58 | } |
David Black | 3e154a72 | 2018-12-18 21:34:06 | [diff] [blame] | 59 | } |
| 60 | |
David Black | c5c3e34 | 2018-11-27 21:20:40 | [diff] [blame] | 61 | void BindAssistantScreenContextControllerRequestOnMainThread( |
| 62 | mojom::AssistantScreenContextControllerRequest request) { |
Ken Rockot | c20c6011 | 2019-06-20 22:54:16 | [diff] [blame] | 63 | if (Shell::HasInstance()) { |
| 64 | Shell::Get() |
| 65 | ->assistant_controller() |
| 66 | ->screen_context_controller() |
| 67 | ->BindRequest(std::move(request)); |
| 68 | } |
David Black | c5c3e34 | 2018-11-27 21:20:40 | [diff] [blame] | 69 | } |
| 70 | |
Muyuan Li | ed7c7640 | 2018-08-07 23:59:00 | [diff] [blame] | 71 | void BindAssistantVolumeControlRequestOnMainThread( |
| 72 | mojom::AssistantVolumeControlRequest request) { |
Ken Rockot | c20c6011 | 2019-06-20 22:54:16 | [diff] [blame] | 73 | if (Shell::HasInstance()) |
| 74 | Shell::Get()->assistant_controller()->BindRequest(std::move(request)); |
Muyuan Li | ed7c7640 | 2018-08-07 23:59:00 | [diff] [blame] | 75 | } |
| 76 | |
Steven Bennetts | 2a9b438 | 2018-04-26 23:41:19 | [diff] [blame] | 77 | void BindCrosDisplayConfigControllerRequestOnMainThread( |
| 78 | mojom::CrosDisplayConfigControllerRequest request) { |
Ken Rockot | c20c6011 | 2019-06-20 22:54:16 | [diff] [blame] | 79 | if (Shell::HasInstance()) |
| 80 | Shell::Get()->cros_display_config()->BindRequest(std::move(request)); |
Steven Bennetts | 2a9b438 | 2018-04-26 23:41:19 | [diff] [blame] | 81 | } |
| 82 | |
Ben Goodger | 21ada1e | 2017-07-19 14:53:01 | [diff] [blame] | 83 | void BindImeControllerRequestOnMainThread(mojom::ImeControllerRequest request) { |
Ken Rockot | c20c6011 | 2019-06-20 22:54:16 | [diff] [blame] | 84 | if (Shell::HasInstance()) |
| 85 | Shell::Get()->ime_controller()->BindRequest(std::move(request)); |
James Cook | fdee024 | 2017-06-20 14:14:00 | [diff] [blame] | 86 | } |
| 87 | |
Ben Goodger | 21ada1e | 2017-07-19 14:53:01 | [diff] [blame] | 88 | void BindTrayActionRequestOnMainThread(mojom::TrayActionRequest request) { |
Ken Rockot | c20c6011 | 2019-06-20 22:54:16 | [diff] [blame] | 89 | if (Shell::HasInstance()) |
| 90 | Shell::Get()->tray_action()->BindRequest(std::move(request)); |
tbarzic | c78da1ff9 | 2017-05-08 20:46:15 | [diff] [blame] | 91 | } |
| 92 | |
Yue Li | a33960a | 2017-11-01 22:06:07 | [diff] [blame] | 93 | void BindVoiceInteractionControllerRequestOnMainThread( |
| 94 | mojom::VoiceInteractionControllerRequest request) { |
Ken Rockot | c20c6011 | 2019-06-20 22:54:16 | [diff] [blame] | 95 | if (Shell::HasInstance()) |
| 96 | VoiceInteractionController::Get()->BindRequest(std::move(request)); |
Yue Li | a33960a | 2017-11-01 22:06:07 | [diff] [blame] | 97 | } |
| 98 | |
Ben Goodger | 21ada1e | 2017-07-19 14:53:01 | [diff] [blame] | 99 | void BindVpnListRequestOnMainThread(mojom::VpnListRequest request) { |
Ken Rockot | c20c6011 | 2019-06-20 22:54:16 | [diff] [blame] | 100 | if (Shell::HasInstance()) |
| 101 | Shell::Get()->vpn_list()->BindRequest(std::move(request)); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 102 | } |
| 103 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 104 | } // namespace |
| 105 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 106 | void RegisterInterfaces( |
| 107 | service_manager::BinderRegistry* registry, |
| 108 | scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner) { |
James Cook | 8ab85f3 | 2019-08-05 18:30:11 | [diff] [blame] | 109 | if (chromeos::features::IsAssistantEnabled()) { |
David Black | e8f81504 | 2018-03-28 18:59:37 | [diff] [blame] | 110 | registry->AddInterface( |
David Black | 8c19e83e | 2018-12-10 23:35:10 | [diff] [blame] | 111 | base::BindRepeating( |
| 112 | &BindAssistantAlarmTimerControllerRequestOnMainThread), |
| 113 | main_thread_task_runner); |
| 114 | registry->AddInterface( |
Muyuan Li | d48e2e1 | 2018-07-17 21:45:54 | [diff] [blame] | 115 | base::BindRepeating(&BindAssistantControllerRequestOnMainThread), |
David Black | e8f81504 | 2018-03-28 18:59:37 | [diff] [blame] | 116 | main_thread_task_runner); |
Muyuan Li | ed7c7640 | 2018-08-07 23:59:00 | [diff] [blame] | 117 | registry->AddInterface( |
David Black | c5c3e34 | 2018-11-27 21:20:40 | [diff] [blame] | 118 | base::BindRepeating( |
David Black | 3e154a72 | 2018-12-18 21:34:06 | [diff] [blame] | 119 | &BindAssistantNotificationControllerRequestOnMainThread), |
| 120 | main_thread_task_runner); |
| 121 | registry->AddInterface( |
| 122 | base::BindRepeating( |
David Black | c5c3e34 | 2018-11-27 21:20:40 | [diff] [blame] | 123 | &BindAssistantScreenContextControllerRequestOnMainThread), |
| 124 | main_thread_task_runner); |
| 125 | registry->AddInterface( |
Muyuan Li | ed7c7640 | 2018-08-07 23:59:00 | [diff] [blame] | 126 | base::BindRepeating(&BindAssistantVolumeControlRequestOnMainThread), |
| 127 | main_thread_task_runner); |
David Black | e8f81504 | 2018-03-28 18:59:37 | [diff] [blame] | 128 | } |
Scott Violet | d64dac1 | 2017-06-02 21:50:08 | [diff] [blame] | 129 | registry->AddInterface( |
Steven Bennetts | 2a9b438 | 2018-04-26 23:41:19 | [diff] [blame] | 130 | base::BindRepeating(&BindCrosDisplayConfigControllerRequestOnMainThread), |
| 131 | main_thread_task_runner); |
| 132 | registry->AddInterface( |
Muyuan Li | d48e2e1 | 2018-07-17 21:45:54 | [diff] [blame] | 133 | base::BindRepeating(&BindImeControllerRequestOnMainThread), |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 134 | main_thread_task_runner); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 135 | registry->AddInterface( |
Muyuan Li | d48e2e1 | 2018-07-17 21:45:54 | [diff] [blame] | 136 | base::BindRepeating(&BindTrayActionRequestOnMainThread), |
| 137 | main_thread_task_runner); |
| 138 | registry->AddInterface( |
| 139 | base::BindRepeating(&BindVoiceInteractionControllerRequestOnMainThread), |
| 140 | main_thread_task_runner); |
| 141 | registry->AddInterface(base::BindRepeating(&BindVpnListRequestOnMainThread), |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 142 | main_thread_task_runner); |
James Cook | 625eff0 | 2017-10-11 20:44:31 | [diff] [blame] | 143 | |
| 144 | // Inject additional optional interfaces. |
| 145 | if (g_register_interfaces_callback.Get()) { |
| 146 | std::move(g_register_interfaces_callback.Get()) |
| 147 | .Run(registry, main_thread_task_runner); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | void SetRegisterInterfacesCallback(RegisterInterfacesCallback callback) { |
| 152 | g_register_interfaces_callback.Get() = std::move(callback); |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | } // namespace mojo_interface_factory |
| 156 | |
| 157 | } // namespace ash |