Chromium Code Reviews| Index: content/browser/gpu/gpu_process_host.cc |
| diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc |
| index 813a54336e2542ceb2e0d92e1edf499b0c1c3677..ce1ca2f808bba4952dc30146e266d2f01ddb4c4b 100644 |
| --- a/content/browser/gpu/gpu_process_host.cc |
| +++ b/content/browser/gpu/gpu_process_host.cc |
| @@ -425,14 +425,6 @@ void GpuProcessHost::SendOnIO(GpuProcessKind kind, |
| } |
| } |
| -GpuProcessHost::EstablishChannelRequest::EstablishChannelRequest() |
| - : client_id(0) {} |
| - |
| -GpuProcessHost::EstablishChannelRequest::EstablishChannelRequest( |
| - const EstablishChannelRequest& other) = default; |
| - |
| -GpuProcessHost::EstablishChannelRequest::~EstablishChannelRequest() {} |
| - |
| service_manager::InterfaceProvider* GpuProcessHost::GetRemoteInterfaces() { |
| return process_->child_connection()->GetRemoteInterfaces(); |
| } |
| @@ -458,7 +450,8 @@ GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) |
| kind_(kind), |
| process_launched_(false), |
| initialized_(false), |
| - gpu_host_binding_(this) { |
| + gpu_host_binding_(this), |
| + weak_ptr_factory_(this) { |
| if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| switches::kSingleProcess) || |
| base::CommandLine::ForCurrentProcess()->HasSwitch( |
| @@ -667,7 +660,6 @@ bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { |
| DCHECK(CalledOnValidThread()); |
| IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) |
| IPC_MESSAGE_HANDLER(GpuHostMsg_Initialized, OnInitialized) |
| - IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) |
| IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryBufferCreated, |
| OnGpuMemoryBufferCreated) |
| #if defined(OS_ANDROID) |
| @@ -707,21 +699,15 @@ void GpuProcessHost::EstablishGpuChannel( |
| return; |
| } |
| - EstablishChannelParams params; |
| - params.client_id = client_id; |
| - params.client_tracing_id = client_tracing_id; |
| - params.preempts = preempts; |
| - params.allow_view_command_buffers = allow_view_command_buffers; |
| - params.allow_real_time_streams = allow_real_time_streams; |
| - if (Send(new GpuMsg_EstablishChannel(params))) { |
| - EstablishChannelRequest request; |
| - request.client_id = client_id; |
| - request.callback = callback; |
| - channel_requests_.push(request); |
| - } else { |
| - DVLOG(1) << "Failed to send GpuMsg_EstablishChannel."; |
|
Fady Samuel
2017/02/13 15:52:27
What happens if the MessagePipe has a connection e
sadrul
2017/02/13 15:57:23
That would be when the gpu process has crashed or
|
| - callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| - } |
| + DCHECK_EQ(preempts, allow_view_command_buffers); |
| + DCHECK_EQ(preempts, allow_real_time_streams); |
| + bool is_gpu_host = preempts; |
| + |
| + channel_requests_.push(callback); |
| + gpu_service_ptr_->EstablishGpuChannel( |
| + client_id, client_tracing_id, is_gpu_host, |
| + base::Bind(&GpuProcessHost::OnChannelEstablished, |
| + weak_ptr_factory_.GetWeakPtr(), client_id, callback)); |
| if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| switches::kDisableGpuShaderDiskCache)) { |
| @@ -796,32 +782,27 @@ void GpuProcessHost::OnInitialized( |
| } |
| void GpuProcessHost::OnChannelEstablished( |
| - const IPC::ChannelHandle& channel_handle) { |
| + int client_id, |
| + const EstablishChannelCallback& callback, |
| + mojo::ScopedMessagePipeHandle channel_handle) { |
| TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelEstablished"); |
| - |
| - if (channel_requests_.empty()) { |
| - // This happens when GPU process is compromised. |
| - RouteOnUIThread(GpuHostMsg_OnLogMessage( |
| - logging::LOG_WARNING, "WARNING", |
| - "Received a ChannelEstablished message but no requests in queue.")); |
| - return; |
| - } |
| - EstablishChannelRequest request = channel_requests_.front(); |
| + DCHECK(!channel_requests_.empty()); |
| + DCHECK(channel_requests_.front().Equals(callback)); |
| channel_requests_.pop(); |
| // Currently if any of the GPU features are blacklisted, we don't establish a |
| // GPU channel. |
| - if (channel_handle.mojo_handle.is_valid() && |
| - !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL)) { |
| - Send(new GpuMsg_CloseChannel(request.client_id)); |
| - request.callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| + if (channel_handle.is_valid() && |
| + !GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(nullptr)) { |
| + Send(new GpuMsg_CloseChannel(client_id)); |
| + callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| RouteOnUIThread( |
| GpuHostMsg_OnLogMessage(logging::LOG_WARNING, "WARNING", |
| "Hardware acceleration is unavailable.")); |
| return; |
| } |
| - request.callback.Run(channel_handle, gpu_info_); |
| + callback.Run(IPC::ChannelHandle(channel_handle.release()), gpu_info_); |
| } |
| void GpuProcessHost::OnGpuMemoryBufferCreated( |
| @@ -1076,11 +1057,12 @@ bool GpuProcessHost::LaunchGpuProcess(gpu::GpuPreferences* gpu_preferences) { |
| void GpuProcessHost::SendOutstandingReplies() { |
| valid_ = false; |
| + |
| // First send empty channel handles for all EstablishChannel requests. |
| while (!channel_requests_.empty()) { |
| - EstablishChannelRequest request = channel_requests_.front(); |
| + auto callback = channel_requests_.front(); |
| channel_requests_.pop(); |
| - request.callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| + callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| } |
| while (!create_gpu_memory_buffer_requests_.empty()) { |