Commit ad845bdc authored by Peter Qiu's avatar Peter Qiu Committed by Commit Bot

browser: allow non-Renderer processes to bind to ui::mojo::Gpu interface

Currently, when ui::mojo::Gpu interface is exposed by the Browser process
(kMash feature is not enabled), only the binding requests from the
Renderer processes are being handled.

For certain devices and applications, it is desirable to access the
ui::mojo::Gpu interface from a non-Renderer process, in order for that process
to access video encode/decode accelerators hosted in the GPU process.

This CL will allow other processes to bind to ui::mojom::Gpu interface
hosted by the Browser process (assuming allowed by the manifest), by
also handling ui::mojom::Gpu interface binding requests in
CommonBrowserInterface. The handling for ui::mojom::Gpu interface binding
requests from Renderer processes will stay the same.

Bug: 836874
Test: run content_browsertests
Change-Id: Ib1e3751d8c593a3c8d29096e7dc9cc609f6a1fa4
Reviewed-on: https://chromium-review.googlesource.com/1028556Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Peter Qiu <zqiu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564814}
parent 18da31da
......@@ -4,6 +4,7 @@
#include "content/browser/service_manager/common_browser_interfaces.h"
#include <map>
#include <memory>
#include <utility>
......@@ -15,10 +16,15 @@
#include "build/build_config.h"
#include "components/discardable_memory/service/discardable_shared_memory_manager.h"
#include "content/browser/browser_main_loop.h"
#include "content/browser/gpu/gpu_client_impl.h"
#include "content/common/child_process_host_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/connection_filter.h"
#include "content/public/common/service_manager_connection.h"
#include "content/public/common/service_names.mojom.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/ui/public/interfaces/gpu.mojom.h"
#include "ui/base/ui_base_features.h"
#if defined(OS_WIN)
......@@ -57,9 +63,13 @@ class ConnectionFilterImpl : public ConnectionFilter {
}
}
}
if (!base::FeatureList::IsEnabled(features::kMash)) {
registry_.AddInterface(base::BindRepeating(
&ConnectionFilterImpl::BindGpuRequest, base::Unretained(this)));
}
}
~ConnectionFilterImpl() override {}
~ConnectionFilterImpl() override { DCHECK_CURRENTLY_ON(BrowserThread::IO); }
private:
template <typename Interface>
......@@ -72,9 +82,38 @@ class ConnectionFilterImpl : public ConnectionFilter {
const std::string& interface_name,
mojo::ScopedMessagePipeHandle* interface_pipe,
service_manager::Connector* connector) override {
// Ignore ui::mojom::Gpu interface request from Renderer process.
// The request will be handled in RenderProcessHostImpl.
if (source_info.identity.name() == mojom::kRendererServiceName &&
interface_name == ui::mojom::Gpu::Name_)
return;
registry_.TryBindInterface(interface_name, interface_pipe, source_info);
}
void BindGpuRequest(ui::mojom::GpuRequest request,
const service_manager::BindSourceInfo& source_info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// Only allow one connection per service to avoid possible race condition.
// So Reset the current connection if there is one.
gpu_clients_.erase(source_info.identity);
std::unique_ptr<GpuClientImpl> gpu_client = std::make_unique<GpuClientImpl>(
ChildProcessHostImpl::GenerateChildProcessUniqueId());
gpu_client->SetConnectionErrorHandler(
base::BindOnce(&ConnectionFilterImpl::OnGpuConnectionClosed,
base::Unretained(this), source_info.identity));
gpu_client->Add(std::move(request));
gpu_clients_.emplace(source_info.identity, std::move(gpu_client));
}
void OnGpuConnectionClosed(const service_manager::Identity& service_identity,
GpuClient* client) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
gpu_clients_.erase(service_identity);
}
template <typename Interface>
static void BindOnTaskRunner(
const scoped_refptr<base::TaskRunner>& task_runner,
......@@ -88,6 +127,8 @@ class ConnectionFilterImpl : public ConnectionFilter {
service_manager::BinderRegistryWithArgs<
const service_manager::BindSourceInfo&>
registry_;
std::map<service_manager::Identity, std::unique_ptr<GpuClientImpl>>
gpu_clients_;
DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl);
};
......
......@@ -26,6 +26,9 @@
"discardable_memory.mojom.DiscardableSharedMemoryManager",
"media.mojom.AndroidOverlayProvider"
],
"gpu_client": [
"ui.mojom.Gpu"
],
"plugin": [
"discardable_memory.mojom.DiscardableSharedMemoryManager",
"ui.mojom.Gpu"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment