forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmash_service_factory.cc
106 lines (87 loc) · 3.82 KB
/
mash_service_factory.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
// Copyright 2017 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 "chrome/utility/mash_service_factory.h"
#include <memory>
#include "ash/ash_service.h"
#include "ash/components/quick_launch/public/mojom/constants.mojom.h"
#include "ash/components/quick_launch/quick_launch_application.h"
#include "ash/components/shortcut_viewer/public/mojom/shortcut_viewer.mojom.h"
#include "ash/components/shortcut_viewer/shortcut_viewer_application.h"
#include "ash/components/tap_visualizer/public/mojom/constants.mojom.h"
#include "ash/components/tap_visualizer/tap_visualizer_app.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
namespace {
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class MashService {
kAsh = 0,
kAutoclickDeprecated = 1, // Deleted Aug 2018, https://crbug.com/876115
kQuickLaunch = 2,
kShortcutViewer = 3,
kTapVisualizer = 4,
kFontDeprecated = 5, // Font Service is not in use for mash, but run
// in-process in the browser
// process. https://crbug.com/862553
kMaxValue = kFontDeprecated,
};
using ServiceFactoryFunction = std::unique_ptr<service_manager::Service>();
void RegisterMashService(
content::ContentUtilityClient::StaticServiceMap* services,
const std::string& name,
ServiceFactoryFunction factory_function) {
service_manager::EmbeddedServiceInfo service_info;
service_info.factory = base::BindRepeating(factory_function);
services->emplace(name, service_info);
}
// Wrapper function so we only have one copy of histogram macro generated code.
void RecordMashServiceLaunch(MashService service) {
UMA_HISTOGRAM_ENUMERATION("Launch.MashService", service);
}
std::unique_ptr<service_manager::Service> CreateAshService() {
RecordMashServiceLaunch(MashService::kAsh);
logging::SetLogPrefix("ash");
return std::make_unique<ash::AshService>();
}
std::unique_ptr<service_manager::Service> CreateQuickLaunchService(
service_manager::mojom::ServiceRequest request) {
RecordMashServiceLaunch(MashService::kQuickLaunch);
logging::SetLogPrefix("quick");
return std::make_unique<quick_launch::QuickLaunchApplication>(
std::move(request));
}
std::unique_ptr<service_manager::Service> CreateShortcutViewerApp() {
RecordMashServiceLaunch(MashService::kShortcutViewer);
logging::SetLogPrefix("shortcut");
return std::make_unique<
keyboard_shortcut_viewer::ShortcutViewerApplication>();
}
std::unique_ptr<service_manager::Service> CreateTapVisualizerApp() {
RecordMashServiceLaunch(MashService::kTapVisualizer);
logging::SetLogPrefix("tap");
return std::make_unique<tap_visualizer::TapVisualizerApp>();
}
} // namespace
MashServiceFactory::MashServiceFactory() = default;
MashServiceFactory::~MashServiceFactory() = default;
void MashServiceFactory::RegisterOutOfProcessServices(
content::ContentUtilityClient::StaticServiceMap* services) {
RegisterMashService(services, ash::mojom::kServiceName, &CreateAshService);
RegisterMashService(services, shortcut_viewer::mojom::kServiceName,
&CreateShortcutViewerApp);
RegisterMashService(services, tap_visualizer::mojom::kServiceName,
&CreateTapVisualizerApp);
keyboard_shortcut_viewer::ShortcutViewerApplication::RegisterForTraceEvents();
}
std::unique_ptr<service_manager::Service>
MashServiceFactory::HandleServiceRequest(
const std::string& service_name,
service_manager::mojom::ServiceRequest request) {
if (service_name == quick_launch::mojom::kServiceName)
return CreateQuickLaunchService(std::move(request));
return nullptr;
}