forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathash_service.cc
242 lines (198 loc) · 9.12 KB
/
ash_service.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/ash_service.h"
#include "ash/mojo_interface_factory.h"
#include "ash/network_connect_delegate_mus.h"
#include "ash/shell.h"
#include "ash/shell_delegate_mash.h"
#include "ash/shell_init_params.h"
#include "ash/ws/ash_gpu_interface_provider.h"
#include "ash/ws/window_service_owner.h"
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/hammerd/hammerd_client.h"
#include "chromeos/dbus/power/power_policy_controller.h"
#include "chromeos/dbus/system_clock/system_clock_client.h"
#include "chromeos/network/network_connect.h"
#include "chromeos/network/network_handler.h"
#include "chromeos/system/fake_statistics_provider.h"
#include "components/discardable_memory/service/discardable_shared_memory_manager.h"
#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include "components/viz/common/switches.h"
#include "components/viz/host/host_frame_sink_manager.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/ws/gpu_host/gpu_host.h"
#include "services/ws/host_context_factory.h"
#include "services/ws/public/cpp/gpu/gpu.h"
#include "services/ws/public/cpp/input_devices/input_device_controller.h"
#include "services/ws/public/mojom/constants.mojom.h"
#include "services/ws/window_service.h"
#include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ui_base_features.h"
#include "ui/views/layout/layout_provider.h"
#include "ui/views/views_delegate.h"
#include "ui/wm/core/wm_state.h"
namespace ash {
namespace {
class AshViewsDelegate : public views::ViewsDelegate {
public:
AshViewsDelegate() = default;
~AshViewsDelegate() override = default;
private:
// views::ViewsDelegate:
void OnBeforeWidgetInit(
views::Widget::InitParams* params,
views::internal::NativeWidgetDelegate* delegate) override {}
// TODO: this may need to create ChromeLayoutProvider.
// https://crbug.com/853989 .
views::LayoutProvider layout_provider_;
DISALLOW_COPY_AND_ASSIGN(AshViewsDelegate);
};
} // namespace
AshService::AshService(service_manager::mojom::ServiceRequest request)
: service_binding_(this, std::move(request)) {}
AshService::~AshService() {
if (!::features::IsMultiProcessMash())
return;
// Shutdown part of GpuHost before deleting Shell. This is necessary to
// avoid a deadlock between the raster thread and main thread. GpuHost can't
// be deleted here as that causes other DCHECKs.
gpu_host_->Shutdown();
Shell::DeleteInstance();
statistics_provider_.reset();
chromeos::NetworkConnect::Shutdown();
network_connect_delegate_.reset();
chromeos::NetworkHandler::Shutdown();
device::BluetoothAdapterFactory::Shutdown();
bluez::BluezDBusManager::Shutdown();
chromeos::PowerPolicyController::Shutdown();
chromeos::SystemClockClient::Shutdown();
chromeos::PowerManagerClient::Shutdown();
chromeos::HammerdClient::Shutdown();
chromeos::CrasAudioHandler::Shutdown();
chromeos::DBusThreadManager::Shutdown();
// |gpu_host_| must be completely destroyed before Env as GpuHost depends on
// Ozone, which Env owns.
gpu_host_.reset();
}
void AshService::InitForMash() {
wm_state_ = std::make_unique<::wm::WMState>();
discardable_shared_memory_manager_ =
std::make_unique<discardable_memory::DiscardableSharedMemoryManager>();
gpu_host_ = std::make_unique<ws::gpu_host::GpuHost>(
this, service_binding_.GetConnector(),
discardable_shared_memory_manager_.get());
host_frame_sink_manager_ = std::make_unique<viz::HostFrameSinkManager>();
CreateFrameSinkManager();
io_thread_ = std::make_unique<base::Thread>("IOThread");
base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
thread_options.priority = base::ThreadPriority::NORMAL;
CHECK(io_thread_->StartWithOptions(thread_options));
gpu_ = ws::Gpu::Create(service_binding_.GetConnector(),
ws::mojom::kServiceName, io_thread_->task_runner());
context_factory_ = std::make_unique<ws::HostContextFactory>(
gpu_.get(), host_frame_sink_manager_.get());
env_ = aura::Env::CreateInstanceToHostViz(service_binding_.GetConnector());
views_delegate_ = std::make_unique<AshViewsDelegate>();
// Must occur after mojo::ApplicationRunner has initialized AtExitManager, but
// before WindowManager::Init(). Tests might initialize their own instance.
InitializeDBusClients();
// TODO(jamescook): Refactor StatisticsProvider so we can get just the data
// we need in ash. Right now StatisticsProviderImpl launches the crossystem
// binary to get system data, which we don't want to do twice on startup.
statistics_provider_.reset(
new chromeos::system::ScopedFakeStatisticsProvider());
statistics_provider_->SetMachineStatistic("initial_locale", "en-US");
statistics_provider_->SetMachineStatistic("keyboard_layout", "");
ShellInitParams shell_init_params;
shell_init_params.delegate = std::make_unique<ShellDelegateMash>();
shell_init_params.context_factory = context_factory_.get();
shell_init_params.context_factory_private =
context_factory_->GetContextFactoryPrivate();
shell_init_params.connector = service_binding_.GetConnector();
shell_init_params.gpu_interface_provider =
std::make_unique<AshGpuInterfaceProvider>(
gpu_host_.get(), discardable_shared_memory_manager_.get());
Shell::CreateInstance(std::move(shell_init_params));
Shell::GetPrimaryRootWindow()->GetHost()->Show();
}
void AshService::InitializeDBusClients() {
CHECK(!chromeos::DBusThreadManager::IsInitialized());
// TODO(stevenjb): Eliminate use of DBusThreadManager and initialize
// dbus::Thread, dbus::Bus and required clients directly.
chromeos::DBusThreadManager::Initialize(chromeos::DBusThreadManager::kShared);
dbus::Bus* bus = chromeos::DBusThreadManager::Get()->GetSystemBus();
if (bus)
chromeos::CrasAudioClient::Initialize(bus);
else
chromeos::CrasAudioClient::InitializeFake();
// TODO(jamescook): Initialize real audio handler.
chromeos::CrasAudioHandler::InitializeForTesting();
if (bus) {
chromeos::HammerdClient::Initialize(bus);
chromeos::PowerManagerClient::Initialize(bus);
chromeos::SystemClockClient::Initialize(bus);
} else {
chromeos::HammerdClient::InitializeFake();
chromeos::PowerManagerClient::InitializeFake();
chromeos::SystemClockClient::InitializeFake();
}
chromeos::PowerPolicyController::Initialize(
chromeos::PowerManagerClient::Get());
// TODO(ortuno): Eliminate BluezDBusManager code from Ash, crbug.com/830893.
bluez::BluezDBusManager::Initialize();
// TODO(stevenjb): Eliminate NetworkHandler code from Ash, crbug.com/644355.
CHECK(!chromeos::NetworkHandler::IsInitialized());
chromeos::NetworkHandler::Initialize();
network_connect_delegate_ = std::make_unique<NetworkConnectDelegateMus>();
chromeos::NetworkConnect::Initialize(network_connect_delegate_.get());
}
void AshService::OnStart() {
mojo_interface_factory::RegisterInterfaces(
®istry_, base::ThreadTaskRunnerHandle::Get());
if (::features::IsMultiProcessMash())
InitForMash();
}
void AshService::OnBindInterface(
const service_manager::BindSourceInfo& remote_info,
const std::string& interface_name,
mojo::ScopedMessagePipeHandle handle) {
registry_.BindInterface(interface_name, std::move(handle));
}
void AshService::CreatePackagedServiceInstance(
const std::string& service_name,
mojo::PendingReceiver<service_manager::mojom::Service> receiver,
CreatePackagedServiceInstanceCallback callback) {
DCHECK_EQ(service_name, ws::mojom::kServiceName);
Shell::Get()->window_service_owner()->BindWindowService(std::move(receiver));
if (::features::IsMultiProcessMash()) {
ws::WindowService* window_service =
Shell::Get()->window_service_owner()->window_service();
input_device_controller_ = std::make_unique<ws::InputDeviceController>();
input_device_controller_->AddInterface(window_service->registry());
}
std::move(callback).Run(base::GetCurrentProcId());
}
void AshService::CreateFrameSinkManager() {
viz::mojom::FrameSinkManagerPtr frame_sink_manager;
viz::mojom::FrameSinkManagerRequest frame_sink_manager_request =
mojo::MakeRequest(&frame_sink_manager);
viz::mojom::FrameSinkManagerClientPtr frame_sink_manager_client;
viz::mojom::FrameSinkManagerClientRequest frame_sink_manager_client_request =
mojo::MakeRequest(&frame_sink_manager_client);
gpu_host_->CreateFrameSinkManager(std::move(frame_sink_manager_request),
frame_sink_manager_client.PassInterface());
host_frame_sink_manager_->BindAndSetManager(
std::move(frame_sink_manager_client_request), nullptr /* task_runner */,
std::move(frame_sink_manager));
}
void AshService::OnGpuServiceInitialized() {}
} // namespace ash