Skip to content

Commit

Permalink
Provide explicit template arguments to mojo::BinderMap{,WithContext}:…
Browse files Browse the repository at this point in the history
…:Add

In a follow-up CL, automatic type deduction will be prohibited.

Bug: 1278574
Change-Id: I89dd88cc8290bc88d4a6ce5ac3ddaf120818137d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3770660
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Sean Topping <seantopping@chromium.org>
Reviewed-by: Bo Liu <boliu@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1025586}
  • Loading branch information
rsesek authored and Chromium LUCI CQ committed Jul 19, 2022
1 parent 55a2e24 commit 80eba56
Show file tree
Hide file tree
Showing 17 changed files with 122 additions and 93 deletions.
2 changes: 1 addition & 1 deletion android_webview/common/aw_content_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void AwContentClient::ExposeInterfacesToBrowser(
// This creates a process-wide heap_profiling::ProfilingClient that listens
// for requests from the HeapProfilingService to start profiling the current
// process.
binders->Add(
binders->Add<heap_profiling::mojom::ProfilingClient>(
base::BindRepeating(
[](mojo::PendingReceiver<heap_profiling::mojom::ProfilingClient>
receiver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ namespace android_webview {

void ExposeRendererInterfacesToBrowser(AwContentRendererClient* client,
mojo::BinderMap* binders) {
binders->Add(client->visited_link_reader()->GetBindCallback(),
base::ThreadTaskRunnerHandle::Get());
binders->Add<visitedlink::mojom::VisitedLinkNotificationSink>(
client->visited_link_reader()->GetBindCallback(),
base::ThreadTaskRunnerHandle::Get());
}

} // namespace android_webview
2 changes: 1 addition & 1 deletion chrome/common/chrome_content_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ media::MediaDrmBridgeClient* ChromeContentClient::GetMediaDrmBridgeClient() {
void ChromeContentClient::ExposeInterfacesToBrowser(
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
mojo::BinderMap* binders) {
binders->Add(
binders->Add<heap_profiling::mojom::ProfilingClient>(
base::BindRepeating(
[](mojo::PendingReceiver<heap_profiling::mojom::ProfilingClient>
receiver) {
Expand Down
26 changes: 15 additions & 11 deletions chrome/gpu/browser_exposed_gpu_interfaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,23 @@ void ExposeChromeGpuInterfacesToBrowser(
const gpu::GpuDriverBugWorkarounds& gpu_workarounds,
mojo::BinderMap* binders) {
#if BUILDFLAG(IS_CHROMEOS_ASH) && BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
binders->Add(base::BindRepeating(&CreateArcVideoDecodeAccelerator, client,
gpu_preferences, gpu_workarounds),
base::ThreadTaskRunnerHandle::Get());
binders->Add(base::BindRepeating(&CreateArcVideoDecoder, client),
base::ThreadTaskRunnerHandle::Get());
binders->Add(base::BindRepeating(&CreateArcVideoEncodeAccelerator,
gpu_preferences, gpu_workarounds),
base::ThreadTaskRunnerHandle::Get());
binders->Add(
binders->Add<::arc::mojom::VideoDecodeAccelerator>(
base::BindRepeating(&CreateArcVideoDecodeAccelerator, client,
gpu_preferences, gpu_workarounds),
base::ThreadTaskRunnerHandle::Get());
binders->Add<::arc::mojom::VideoDecoder>(
base::BindRepeating(&CreateArcVideoDecoder, client),
base::ThreadTaskRunnerHandle::Get());
binders->Add<::arc::mojom::VideoEncodeAccelerator>(
base::BindRepeating(&CreateArcVideoEncodeAccelerator, gpu_preferences,
gpu_workarounds),
base::ThreadTaskRunnerHandle::Get());
binders->Add<::arc::mojom::VideoProtectedBufferAllocator>(
base::BindRepeating(&CreateArcVideoProtectedBufferAllocator, client),
base::ThreadTaskRunnerHandle::Get());
binders->Add(base::BindRepeating(&CreateProtectedBufferManager, client),
base::ThreadTaskRunnerHandle::Get());
binders->Add<::arc::mojom::ProtectedBufferManager>(
base::BindRepeating(&CreateProtectedBufferManager, client),
base::ThreadTaskRunnerHandle::Get());
#endif // BUILDFLAG(IS_CHROMEOS_ASH) &&
// BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
}
26 changes: 15 additions & 11 deletions chrome/renderer/browser_exposed_renderer_interfaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,24 @@ void BindSpellChecker(
void ExposeChromeRendererInterfacesToBrowser(
ChromeContentRendererClient* client,
mojo::BinderMap* binders) {
binders->Add(
binders->Add<visitedlink::mojom::VisitedLinkNotificationSink>(
client->GetChromeObserver()->visited_link_reader()->GetBindCallback(),
base::SequencedTaskRunnerHandle::Get());

binders->Add(base::BindRepeating(&web_cache::WebCacheImpl::BindReceiver,
base::Unretained(client->GetWebCache())),
base::SequencedTaskRunnerHandle::Get());
binders->Add<web_cache::mojom::WebCache>(
base::BindRepeating(&web_cache::WebCacheImpl::BindReceiver,
base::Unretained(client->GetWebCache())),
base::SequencedTaskRunnerHandle::Get());

binders->Add(base::BindRepeating(&BindWebRTCLoggingAgent, client),
base::SequencedTaskRunnerHandle::Get());
binders->Add<chrome::mojom::WebRtcLoggingAgent>(
base::BindRepeating(&BindWebRTCLoggingAgent, client),
base::SequencedTaskRunnerHandle::Get());

#if BUILDFLAG(IS_CHROMEOS_ASH)
#if defined(ARCH_CPU_X86_64)
if (performance_manager::mechanism::UserspaceSwapImpl::
PlatformSupportsUserspaceSwap()) {
binders->Add(
binders->Add<userspace_swap::mojom::UserspaceSwap>(
base::BindRepeating(
&performance_manager::mechanism::UserspaceSwapImpl::Create),
base::SequencedTaskRunnerHandle::Get());
Expand All @@ -80,12 +82,14 @@ void ExposeChromeRendererInterfacesToBrowser(
#endif // BUILDFLAG(IS_CHROMEOS_ASH)

#if BUILDFLAG(ENABLE_SPELLCHECK)
binders->Add(base::BindRepeating(&BindSpellChecker, client),
base::SequencedTaskRunnerHandle::Get());
binders->Add<spellcheck::mojom::SpellChecker>(
base::BindRepeating(&BindSpellChecker, client),
base::SequencedTaskRunnerHandle::Get());
#endif

#if BUILDFLAG(IS_WIN)
binders->Add(base::BindRepeating(&FontPrewarmer::Bind),
base::SequencedTaskRunnerHandle::Get());
binders->Add<chrome::mojom::FontPrewarmer>(
base::BindRepeating(&FontPrewarmer::Bind),
base::SequencedTaskRunnerHandle::Get());
#endif
}
5 changes: 3 additions & 2 deletions chrome/utility/browser_exposed_utility_interfaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

void ExposeElevatedChromeUtilityInterfacesToBrowser(mojo::BinderMap* binders) {
#if BUILDFLAG(ENABLE_PRINTING) && BUILDFLAG(IS_WIN)
binders->Add(base::BindRepeating(printing::PdfToEmfConverterFactory::Create),
base::ThreadTaskRunnerHandle::Get());
binders->Add<printing::mojom::PdfToEmfConverterFactory>(
base::BindRepeating(printing::PdfToEmfConverterFactory::Create),
base::ThreadTaskRunnerHandle::Get());
#endif
}
17 changes: 9 additions & 8 deletions chromecast/browser/cast_browser_interface_binders.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,22 @@ void PopulateCastFrameBinders(
binder_map->Add<::chromecast::mojom::AudioSocketBroker>(
base::BindRepeating(&BindAudioSocketBroker));

binder_map->Add(base::BindRepeating(
binder_map->Add<mojom::ApplicationMediaCapabilities>(base::BindRepeating(
&BindFromCastWebContents<mojom::ApplicationMediaCapabilities>));
binder_map->Add(
binder_map->Add<::media::mojom::Remotee>(
base::BindRepeating(&BindFromCastWebContents<::media::mojom::Remotee>));
binder_map->Add(base::BindRepeating(
binder_map->Add<::chromecast::mojom::ActivityWindow>(base::BindRepeating(
&BindFromCastWebContents<::chromecast::mojom::ActivityWindow>));
binder_map->Add(base::BindRepeating(
binder_map->Add<
::chromecast::mojom::AssistantMessageService>(base::BindRepeating(
&BindFromCastWebContents<::chromecast::mojom::AssistantMessageService>));
binder_map->Add(base::BindRepeating(
binder_map->Add<::chromecast::mojom::GestureSource>(base::BindRepeating(
&BindFromCastWebContents<::chromecast::mojom::GestureSource>));
binder_map->Add(base::BindRepeating(
binder_map->Add<::chromecast::mojom::SettingsPlatform>(base::BindRepeating(
&BindFromCastWebContents<::chromecast::mojom::SettingsPlatform>));
binder_map->Add(base::BindRepeating(
binder_map->Add<mojom::CastAccessibilityService>(base::BindRepeating(
&BindFromCastWebContents<mojom::CastAccessibilityService>));
binder_map->Add(
binder_map->Add<mojom::CastDemo>(
base::BindRepeating(&BindFromCastWebContents<mojom::CastDemo>));

binder_map->SetDefaultBinderDeprecated(
Expand Down
2 changes: 1 addition & 1 deletion chromecast/common/cast_content_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void CastContentClient::ExposeInterfacesToBrowser(
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
mojo::BinderMap* binders) {
#if !BUILDFLAG(IS_FUCHSIA)
binders->Add(
binders->Add<heap_profiling::mojom::ProfilingClient>(
base::BindRepeating(
[](mojo::PendingReceiver<heap_profiling::mojom::ProfilingClient>
receiver) {
Expand Down
7 changes: 4 additions & 3 deletions content/child/browser_exposed_child_interfaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ namespace content {
void ExposeChildInterfacesToBrowser(
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
mojo::BinderMap* binders) {
binders->Add(base::BindRepeating(&ChildHistogramFetcherFactoryImpl::Create),
io_task_runner);
binders->Add(
binders->Add<mojom::ChildHistogramFetcherFactory>(
base::BindRepeating(&ChildHistogramFetcherFactoryImpl::Create),
io_task_runner);
binders->Add<tracing::mojom::TracedProcess>(
base::BindRepeating(&tracing::TracedProcess::OnTracedProcessRequest),
base::SequencedTaskRunnerHandle::Get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InterfaceRegistrationHelper {
// binder_map.
binder_initializers_->push_back(
base::BindRepeating([](WebUIBinderMap* binder_map) {
binder_map->Add(base::BindRepeating(
binder_map->Add<Interface>(base::BindRepeating(
[](WebUIController* controller,
mojo::PendingReceiver<Interface> receiver) {
auto* concrete_controller = controller->GetAs<ControllerType>();
Expand Down Expand Up @@ -113,4 +113,4 @@ class CONTENT_EXPORT WebUIBrowserInterfaceBrokerRegistry {

} // namespace content

#endif // CONTENT_PUBLIC_BROWSER_WEB_UI_BROWSER_INTERFACE_BROKER_REGISTRY_H_
#endif // CONTENT_PUBLIC_BROWSER_WEB_UI_BROWSER_INTERFACE_BROKER_REGISTRY_H_
21 changes: 12 additions & 9 deletions content/renderer/browser_exposed_renderer_interfaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ void ExposeRendererInterfacesToBrowser(
mojo::BinderMap* binders) {
DCHECK(render_thread);

binders->Add(base::BindRepeating(&SharedWorkerFactoryImpl::Create),
base::ThreadTaskRunnerHandle::Get());
binders->Add(base::BindRepeating(&CreateResourceUsageReporter, render_thread),
base::ThreadTaskRunnerHandle::Get());
binders->Add<blink::mojom::SharedWorkerFactory>(
base::BindRepeating(&SharedWorkerFactoryImpl::Create),
base::ThreadTaskRunnerHandle::Get());
binders->Add<mojom::ResourceUsageReporter>(
base::BindRepeating(&CreateResourceUsageReporter, render_thread),
base::ThreadTaskRunnerHandle::Get());
#if BUILDFLAG(IS_ANDROID)
binders->Add(
binders->Add<auction_worklet::mojom::AuctionWorkletService>(
base::BindRepeating(
&auction_worklet::AuctionWorkletServiceImpl::CreateForRenderer),
base::ThreadTaskRunnerHandle::Get());
Expand All @@ -182,10 +184,11 @@ void ExposeRendererInterfacesToBrowser(
// instead of the main thread, so startup isn't blocked on the main thread.
// Currently it's on the main thread as CreateEmbeddedWorker accesses
// `cors_exempt_header_list` from `render_thread`.
binders->Add(base::BindRepeating(&CreateEmbeddedWorker,
task_runner_for_service_worker_startup,
render_thread),
base::ThreadTaskRunnerHandle::Get());
binders->Add<blink::mojom::EmbeddedWorkerInstanceClient>(
base::BindRepeating(&CreateEmbeddedWorker,
task_runner_for_service_worker_startup,
render_thread),
base::ThreadTaskRunnerHandle::Get());

GetContentClient()->renderer()->ExposeInterfacesToBrowser(binders);
}
Expand Down
14 changes: 8 additions & 6 deletions content/shell/renderer/shell_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,16 @@ void ShellContentRendererClient::RenderThreadStarted() {

void ShellContentRendererClient::ExposeInterfacesToBrowser(
mojo::BinderMap* binders) {
binders->Add(base::BindRepeating(&CreateRendererTestService),
base::ThreadTaskRunnerHandle::Get());
binders->Add(
binders->Add<mojom::TestService>(
base::BindRepeating(&CreateRendererTestService),
base::ThreadTaskRunnerHandle::Get());
binders->Add<mojom::PowerMonitorTest>(
base::BindRepeating(&PowerMonitorTestImpl::MakeSelfOwnedReceiver),
base::ThreadTaskRunnerHandle::Get());
binders->Add(base::BindRepeating(&web_cache::WebCacheImpl::BindReceiver,
base::Unretained(web_cache_impl_.get())),
base::ThreadTaskRunnerHandle::Get());
binders->Add<web_cache::mojom::WebCache>(
base::BindRepeating(&web_cache::WebCacheImpl::BindReceiver,
base::Unretained(web_cache_impl_.get())),
base::ThreadTaskRunnerHandle::Get());
}

void ShellContentRendererClient::RenderFrameCreated(RenderFrame* render_frame) {
Expand Down
5 changes: 3 additions & 2 deletions content/shell/utility/shell_content_utility_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ ShellContentUtilityClient::~ShellContentUtilityClient() = default;

void ShellContentUtilityClient::ExposeInterfacesToBrowser(
mojo::BinderMap* binders) {
binders->Add(base::BindRepeating(&TestUtilityServiceImpl::Create),
base::ThreadTaskRunnerHandle::Get());
binders->Add<mojom::TestService>(
base::BindRepeating(&TestUtilityServiceImpl::Create),
base::ThreadTaskRunnerHandle::Get());
binders->Add<mojom::PowerMonitorTest>(
base::BindRepeating(&PowerMonitorTestImpl::MakeSelfOwnedReceiver),
base::ThreadTaskRunnerHandle::Get());
Expand Down
5 changes: 3 additions & 2 deletions content/utility/browser_exposed_utility_interfaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ void ExposeUtilityInterfacesToBrowser(mojo::BinderMap* binders) {
}
#endif // BUILDFLAG(IS_WIN)
if (bind_usage_reporter) {
binders->Add(base::BindRepeating(&CreateResourceUsageReporter),
base::ThreadTaskRunnerHandle::Get());
binders->Add<mojom::ResourceUsageReporter>(
base::BindRepeating(&CreateResourceUsageReporter),
base::ThreadTaskRunnerHandle::Get());
}
#endif // !BUILDFLAG(IS_ANDROID)

Expand Down
23 changes: 13 additions & 10 deletions mojo/public/cpp/bindings/tests/binder_map_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ TEST_F(BinderMapTest, BasicMatch) {

TestInterface1Impl impl;
BinderMap map;
map.Add(base::BindRepeating(&TestInterface1Impl::Bind,
base::Unretained(&impl), nullptr),
base::SequencedTaskRunnerHandle::Get());
map.Add<mojom::TestInterface1>(
base::BindRepeating(&TestInterface1Impl::Bind, base::Unretained(&impl),
nullptr),
base::SequencedTaskRunnerHandle::Get());
EXPECT_TRUE(map.TryBind(&receiver));
remote.FlushForTesting();
EXPECT_TRUE(remote.is_connected());
Expand All @@ -92,7 +93,7 @@ TEST_F(BinderMapTest, WithContext) {
int context = 42;
TestInterface1Impl impl;
BinderMapWithContext<int*> map;
map.Add(base::BindRepeating(
map.Add<mojom::TestInterface1>(base::BindRepeating(
[](TestInterface1Impl* impl, int* expected_context, int* context,
mojo::PendingReceiver<mojom::TestInterface1> receiver) {
EXPECT_EQ(context, expected_context);
Expand Down Expand Up @@ -126,12 +127,14 @@ TEST_F(BinderMapTest, CorrectSequence) {
create_impl2_loop.Run();

BinderMap map;
map.Add(base::BindRepeating(&TestInterface1Impl::Bind,
base::Unretained(&impl1), task_runner1),
task_runner1);
map.Add(base::BindRepeating(&TestInterface2Impl::Bind,
base::Unretained(impl2.get()), task_runner2),
task_runner2);
map.Add<mojom::TestInterface1>(
base::BindRepeating(&TestInterface1Impl::Bind, base::Unretained(&impl1),
task_runner1),
task_runner1);
map.Add<mojom::TestInterface2>(
base::BindRepeating(&TestInterface2Impl::Bind,
base::Unretained(impl2.get()), task_runner2),
task_runner2);
EXPECT_TRUE(map.TryBind(&receiver1));
EXPECT_TRUE(map.TryBind(&receiver2));
remote1.FlushForTesting();
Expand Down
44 changes: 25 additions & 19 deletions third_party/blink/renderer/controller/blink_initializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,32 +240,38 @@ void BlinkInitializer::RegisterInterfaces(mojo::BinderMap& binders) {
return;

#if BUILDFLAG(IS_ANDROID)
binders.Add(ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&OomInterventionImpl::BindReceiver)),
main_thread->GetTaskRunner());

binders.Add(ConvertToBaseRepeatingCallback(CrossThreadBindRepeating(
&CrashMemoryMetricsReporterImpl::Bind)),
main_thread->GetTaskRunner());
binders.Add<mojom::blink::OomIntervention>(
ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&OomInterventionImpl::BindReceiver)),
main_thread->GetTaskRunner());

binders.Add<mojom::blink::CrashMemoryMetricsReporter>(
ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&CrashMemoryMetricsReporterImpl::Bind)),
main_thread->GetTaskRunner());
#endif

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
binders.Add(ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&MemoryUsageMonitorPosix::Bind)),
main_thread->GetTaskRunner());
binders.Add<mojom::blink::MemoryUsageMonitorLinux>(
ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&MemoryUsageMonitorPosix::Bind)),
main_thread->GetTaskRunner());
#endif

binders.Add(ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&BlinkLeakDetector::Bind)),
main_thread->GetTaskRunner());
binders.Add<mojom::blink::LeakDetector>(
ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&BlinkLeakDetector::Bind)),
main_thread->GetTaskRunner());

binders.Add(ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&DiskDataAllocator::Bind)),
main_thread->GetTaskRunner());
binders.Add<mojom::blink::DiskAllocator>(
ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&DiskDataAllocator::Bind)),
main_thread->GetTaskRunner());

binders.Add(ConvertToBaseRepeatingCallback(CrossThreadBindRepeating(
&V8DetailedMemoryReporterImpl::Bind)),
main_thread->GetTaskRunner());
binders.Add<mojom::blink::V8DetailedMemoryReporter>(
ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&V8DetailedMemoryReporterImpl::Bind)),
main_thread->GetTaskRunner());
}

void BlinkInitializer::InitLocalFrame(LocalFrame& frame) const {
Expand Down
7 changes: 4 additions & 3 deletions third_party/blink/renderer/modules/modules_initializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,10 @@ mojom::blink::FileSystemManager& ModulesInitializer::GetFileSystemManager(

void ModulesInitializer::RegisterInterfaces(mojo::BinderMap& binders) {
DCHECK(Platform::Current());
binders.Add(ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&WebDatabaseImpl::Bind)),
Platform::Current()->GetIOTaskRunner());
binders.Add<mojom::blink::WebDatabase>(
ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&WebDatabaseImpl::Bind)),
Platform::Current()->GetIOTaskRunner());
}

} // namespace blink

0 comments on commit 80eba56

Please sign in to comment.