Chromium Code Reviews| Index: content/browser/gpu/gpu_arc_video_service_host.cc |
| diff --git a/content/browser/gpu/gpu_arc_video_service_host.cc b/content/browser/gpu/gpu_arc_video_service_host.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2d540c47a73cfb7f54046a24a4302aadce1d0907 |
| --- /dev/null |
| +++ b/content/browser/gpu/gpu_arc_video_service_host.cc |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/gpu/gpu_arc_video_service_host.h" |
| + |
| +#include "base/location.h" |
| +#include "base/logging.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "content/browser/gpu/gpu_process_host.h" |
| +#include "content/common/gpu/gpu_messages.h" |
| +#include "content/public/browser/arc_video_host_delegate.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "ipc/ipc_channel_handle.h" |
| +#include "ipc/ipc_message_macros.h" |
| +#include "ipc/ipc_message_utils.h" |
| +#include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| +void CreateChannelOnIOThread( |
| + const GpuProcessHost::CreateArcVideoAcceleratorChannelCallback& callback) { |
| + GpuProcessHost* gpu_process_host = |
| + GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| + CAUSE_FOR_GPU_LAUNCH_ARCVIDEOACCELERATOR); |
| + gpu_process_host->CreateArcVideoAcceleratorChannel(callback); |
| +} |
| +} |
| + |
| +scoped_ptr<arc::VideoHostDelegate> CreateArcVideoHostDelegate() { |
| + return make_scoped_ptr(new GpuArcVideoServiceHost()); |
| +} |
| + |
| +GpuArcVideoServiceHost::GpuArcVideoServiceHost() |
| + : io_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( |
| + content::BrowserThread::IO)), |
| + weak_factory_(this) {} |
| + |
| +GpuArcVideoServiceHost::~GpuArcVideoServiceHost() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| +} |
| + |
| +void GpuArcVideoServiceHost::OnRequestArcVideoAcceleratorChannel( |
| + const OnRequestArcVideoAcceleratorChannelCallback& callback) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + |
| + io_task_runner_->PostTask( |
|
jbauman
2015/12/30 01:29:29
What threads can this be called on? HandleChannelC
kcwu
2015/12/30 09:40:33
Ah, HandleChannelCreatedReply is called on the IO
|
| + FROM_HERE, |
| + base::Bind(&CreateChannelOnIOThread, |
| + base::Bind(&GpuArcVideoServiceHost::HandleChannelCreatedReply, |
| + weak_factory_.GetWeakPtr(), callback))); |
| +} |
| + |
| +void GpuArcVideoServiceHost::Shutdown() { |
| + GpuProcessHost::SendOnIO(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, |
| + CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, |
| + new GpuMsg_ShutdownArcVideoService()); |
| +} |
| + |
| +void GpuArcVideoServiceHost::HandleChannelCreatedReply( |
| + const OnRequestArcVideoAcceleratorChannelCallback& callback, |
| + const IPC::ChannelHandle& handle) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + |
| + MojoHandle wrapped_handle; |
| + MojoResult wrap_result = mojo::embedder::CreatePlatformHandleWrapper( |
| + mojo::embedder::ScopedPlatformHandle( |
| + mojo::embedder::PlatformHandle(handle.socket.fd)), |
| + &wrapped_handle); |
| + if (wrap_result != MOJO_RESULT_OK) { |
| + LOG(WARNING) << "Pipe failed to wrap handles. Closing: " << wrap_result; |
| + callback.Run(mojo::ScopedHandle()); |
| + return; |
| + } |
| + callback.Run(mojo::ScopedHandle(mojo::Handle(wrapped_handle))); |
| +} |
| + |
| +} // namespace content |