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