blob: a10a83f0e862f2a21dc1ff98f6a12b78a403882c (
plain)
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
|
// Copyright 2019 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.
// This file exposes services in the browser to child processes.
#include "content/browser/browser_child_process_host_impl.h"
#include "base/bind.h"
#include "base/no_destructor.h"
#include "base/task/thread_pool.h"
#include "build/build_config.h"
#include "components/discardable_memory/public/mojom/discardable_shared_memory_manager.mojom.h"
#include "components/discardable_memory/service/discardable_shared_memory_manager.h"
#include "content/browser/field_trial_recorder.h"
#include "content/common/field_trial_recorder.mojom.h"
#include "content/public/browser/browser_child_process_host_delegate.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/device_service.h"
#include "services/device/public/mojom/power_monitor.mojom.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/mojom/ukm_interface.mojom.h"
#include "services/metrics/ukm_recorder_interface.h"
#if defined(OS_MAC)
#include "content/browser/sandbox_support_mac_impl.h"
#include "content/common/sandbox_support_mac.mojom.h"
#endif
#if defined(OS_WIN)
#include "content/browser/renderer_host/dwrite_font_proxy_impl_win.h"
#include "content/public/common/font_cache_dispatcher_win.h"
#include "content/public/common/font_cache_win.mojom.h"
#endif
namespace content {
namespace {
BrowserChildProcessHost::BindHostReceiverInterceptor&
GetBindHostReceiverInterceptor() {
static base::NoDestructor<
BrowserChildProcessHost::BindHostReceiverInterceptor>
interceptor;
return *interceptor;
}
} // namespace
void BrowserChildProcessHostImpl::BindHostReceiver(
mojo::GenericPendingReceiver receiver) {
const auto& interceptor = GetBindHostReceiverInterceptor();
if (interceptor) {
interceptor.Run(this, &receiver);
if (!receiver)
return;
}
if (auto r =
receiver.As<memory_instrumentation::mojom::CoordinatorConnector>()) {
// Well-behaved child processes do not bind this interface more than once.
if (!coordinator_connector_receiver_.is_bound())
coordinator_connector_receiver_.Bind(std::move(r));
return;
}
#if defined(OS_MAC)
if (auto r = receiver.As<mojom::SandboxSupportMac>()) {
static base::NoDestructor<SandboxSupportMacImpl> sandbox_support;
sandbox_support->BindReceiver(std::move(r));
return;
}
#endif
#if defined(OS_WIN)
if (auto r = receiver.As<mojom::FontCacheWin>()) {
FontCacheDispatcher::Create(std::move(r));
return;
}
if (auto r = receiver.As<blink::mojom::DWriteFontProxy>()) {
base::ThreadPool::CreateSequencedTaskRunner(
{base::TaskPriority::USER_BLOCKING, base::MayBlock()})
->PostTask(FROM_HERE,
base::BindOnce(&DWriteFontProxyImpl::Create, std::move(r)));
return;
}
#endif
if (auto r = receiver.As<mojom::FieldTrialRecorder>()) {
GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(&FieldTrialRecorder::Create, std::move(r)));
return;
}
if (auto r = receiver.As<
discardable_memory::mojom::DiscardableSharedMemoryManager>()) {
discardable_memory::DiscardableSharedMemoryManager::Get()->Bind(
std::move(r));
return;
}
if (auto r = receiver.As<device::mojom::PowerMonitor>()) {
GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(
[](mojo::PendingReceiver<device::mojom::PowerMonitor> r) {
GetDeviceService().BindPowerMonitor(std::move(r));
},
std::move(r)));
return;
}
if (auto r = receiver.As<ukm::mojom::UkmRecorderInterface>()) {
metrics::UkmRecorderInterface::Create(ukm::UkmRecorder::Get(),
std::move(r));
return;
}
delegate_->BindHostReceiver(std::move(receiver));
}
// static
void BrowserChildProcessHost::InterceptBindHostReceiverForTesting(
BindHostReceiverInterceptor callback) {
GetBindHostReceiverInterceptor() = std::move(callback);
}
} // namespace content
|