Commit 6179fa8c authored by Xu Xing's avatar Xu Xing Committed by Commit Bot

viz: Remove GpuClient dependency on BrowserThread

BUG=857217

Change-Id: I328529cc444ddcadad83eeb4b9aa5ff445844912
Reviewed-on: https://chromium-review.googlesource.com/1125518Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Xing Xu <xing.xu@intel.com>
Cr-Commit-Position: refs/heads/master@{#574789}
parent 0e162ebc
......@@ -14,19 +14,21 @@
namespace ash {
// InterfaceBinderImpl handles the actual binding. The binding (and destruction
// of this object) has to happen on the io-thread.
// InterfaceBinderImpl handles the actual binding. The binding has to happen on
// the IO thread.
class ContentGpuInterfaceProvider::InterfaceBinderImpl
: public base::RefCountedThreadSafe<
InterfaceBinderImpl,
content::BrowserThread::DeleteOnIOThread> {
: public base::RefCountedThreadSafe<InterfaceBinderImpl> {
public:
InterfaceBinderImpl() = default;
void BindGpuRequestOnGpuTaskRunner(ui::mojom::GpuRequest request) {
// The GPU task runner is bound to the IO thread.
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
auto gpu_client = content::GpuClient::Create(
std::move(request),
base::BindOnce(&InterfaceBinderImpl::OnGpuClientConnectionError, this));
base::BindOnce(&InterfaceBinderImpl::OnGpuClientConnectionError, this),
content::BrowserThread::GetTaskRunnerForThread(
content::BrowserThread::IO));
gpu_clients_.push_back(std::move(gpu_client));
}
......@@ -37,22 +39,17 @@ class ContentGpuInterfaceProvider::InterfaceBinderImpl
}
private:
friend struct content::BrowserThread::DeleteOnThread<
content::BrowserThread::IO>;
friend class base::DeleteHelper<InterfaceBinderImpl>;
friend class base::RefCountedThreadSafe<InterfaceBinderImpl>;
~InterfaceBinderImpl() = default;
void OnGpuClientConnectionError(content::GpuClient* client) {
base::EraseIf(
gpu_clients_,
base::UniquePtrMatcher<content::GpuClient,
content::BrowserThread::DeleteOnIOThread>(
base::UniquePtrMatcher<content::GpuClient, base::OnTaskRunnerDeleter>(
client));
}
std::vector<std::unique_ptr<content::GpuClient,
content::BrowserThread::DeleteOnIOThread>>
std::vector<std::unique_ptr<content::GpuClient, base::OnTaskRunnerDeleter>>
gpu_clients_;
DISALLOW_COPY_AND_ASSIGN(InterfaceBinderImpl);
......
......@@ -7,7 +7,6 @@
#include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/common/child_process_host_impl.h"
#include "content/public/browser/browser_thread.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "gpu/ipc/common/gpu_memory_buffer_impl.h"
#include "gpu/ipc/common/gpu_memory_buffer_impl_shared_memory.h"
......@@ -15,22 +14,28 @@
namespace content {
// static
std::unique_ptr<GpuClient, BrowserThread::DeleteOnIOThread> GpuClient::Create(
std::unique_ptr<GpuClient, base::OnTaskRunnerDeleter> GpuClient::Create(
ui::mojom::GpuRequest request,
ConnectionErrorHandlerClosure connection_error_handler) {
ConnectionErrorHandlerClosure connection_error_handler,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
const int client_id = ChildProcessHostImpl::GenerateChildProcessUniqueId();
const uint64_t client_tracing_id =
ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId(client_id);
std::unique_ptr<GpuClientImpl, BrowserThread::DeleteOnIOThread> gpu_client(
new GpuClientImpl(client_id, client_tracing_id));
std::unique_ptr<GpuClientImpl, base::OnTaskRunnerDeleter> gpu_client(
new GpuClientImpl(client_id, client_tracing_id, task_runner),
base::OnTaskRunnerDeleter(task_runner));
gpu_client->SetConnectionErrorHandler(std::move(connection_error_handler));
gpu_client->Add(std::move(request));
return gpu_client;
}
GpuClientImpl::GpuClientImpl(int client_id, uint64_t client_tracing_id)
GpuClientImpl::GpuClientImpl(
int client_id,
uint64_t client_tracing_id,
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: client_id_(client_id),
client_tracing_id_(client_tracing_id),
task_runner_(std::move(task_runner)),
weak_factory_(this) {
gpu_bindings_.set_connection_error_handler(
base::BindRepeating(&GpuClientImpl::OnError, base::Unretained(this),
......@@ -38,16 +43,18 @@ GpuClientImpl::GpuClientImpl(int client_id, uint64_t client_tracing_id)
}
GpuClientImpl::~GpuClientImpl() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(task_runner_->RunsTasksInCurrentSequence());
gpu_bindings_.CloseAllBindings();
OnError(ErrorReason::kInDestructor);
}
void GpuClientImpl::Add(ui::mojom::GpuRequest request) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
gpu_bindings_.AddBinding(this, std::move(request));
}
void GpuClientImpl::OnError(ErrorReason reason) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
ClearCallback();
if (gpu_bindings_.empty()) {
BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager =
......@@ -60,9 +67,9 @@ void GpuClientImpl::OnError(ErrorReason reason) {
}
void GpuClientImpl::PreEstablishGpuChannel() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
DCHECK(!task_runner_->RunsTasksInCurrentSequence());
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&GpuClientImpl::EstablishGpuChannel,
base::Unretained(this), EstablishGpuChannelCallback()));
}
......@@ -119,7 +126,7 @@ void GpuClientImpl::ClearCallback() {
}
void GpuClientImpl::EstablishGpuChannel(EstablishGpuChannelCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(task_runner_->RunsTasksInCurrentSequence());
// At most one channel should be requested. So clear previous request first.
ClearCallback();
if (channel_handle_.is_valid()) {
......
......@@ -17,9 +17,15 @@ class GpuClientImpl : public ui::mojom::GpuMemoryBufferFactory,
public ui::mojom::Gpu,
public GpuClient {
public:
GpuClientImpl(int client_id, uint64_t client_tracing_id);
// GpuClientImpl must be destroyed on the thread associated with
// |task_runner|.
GpuClientImpl(int client_id,
uint64_t client_tracing_id,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
~GpuClientImpl() override;
// This needs to be run on the thread associated with |task_runner_|.
void Add(ui::mojom::GpuRequest request);
void PreEstablishGpuChannel();
......@@ -75,6 +81,10 @@ class GpuClientImpl : public ui::mojom::GpuMemoryBufferFactory,
gpu::GPUInfo gpu_info_;
gpu::GpuFeatureInfo gpu_feature_info_;
ConnectionErrorHandlerClosure connection_error_handler_;
// |task_runner_| is associated with the thread |gpu_bindings_| is bound on.
// GpuClientImpl instance is bound to this thread, and must be destroyed on
// this thread.
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
base::WeakPtrFactory<GpuClientImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(GpuClientImpl);
......
......@@ -1462,7 +1462,9 @@ RenderProcessHostImpl::RenderProcessHostImpl(
const int id = GetID();
const uint64_t tracing_id =
ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId(id);
gpu_client_.reset(new GpuClientImpl(id, tracing_id));
gpu_client_.reset(new GpuClientImpl(
id, tracing_id,
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)));
}
GetMemoryDumpProvider().AddHost(this);
......
......@@ -104,8 +104,9 @@ class ConnectionFilterImpl : public ConnectionFilter {
const uint64_t gpu_client_tracing_id =
ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId(
gpu_client_id);
auto gpu_client =
std::make_unique<GpuClientImpl>(gpu_client_id, gpu_client_tracing_id);
auto gpu_client = std::make_unique<GpuClientImpl>(
gpu_client_id, gpu_client_tracing_id,
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO));
gpu_client->SetConnectionErrorHandler(
base::BindOnce(&ConnectionFilterImpl::OnGpuConnectionClosed,
base::Unretained(this), source_info.identity));
......
......@@ -9,7 +9,6 @@
#include "base/callback_forward.h"
#include "content/common/content_export.h"
#include "content/public/browser/browser_thread.h"
#include "services/ui/public/interfaces/gpu.mojom.h"
namespace content {
......@@ -21,9 +20,10 @@ class CONTENT_EXPORT GpuClient {
using ConnectionErrorHandlerClosure =
base::OnceCallback<void(GpuClient* client)>;
static std::unique_ptr<GpuClient, BrowserThread::DeleteOnIOThread> Create(
static std::unique_ptr<GpuClient, base::OnTaskRunnerDeleter> Create(
ui::mojom::GpuRequest request,
ConnectionErrorHandlerClosure connection_error_handler);
ConnectionErrorHandlerClosure connection_error_handler,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
};
} // namespace content
......
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