| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/gpu/gpu_arc_video_service_host.h" | |
| 6 | |
| 7 #include "base/location.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/message_loop/message_loop.h" | |
| 10 #include "content/browser/gpu/gpu_process_host.h" | |
| 11 #include "content/common/gpu/gpu_messages.h" | |
| 12 #include "content/public/browser/arc_video_host_delegate.h" | |
| 13 #include "content/public/browser/browser_thread.h" | |
| 14 #include "ipc/ipc_channel_handle.h" | |
| 15 #include "ipc/ipc_message_macros.h" | |
| 16 #include "ipc/ipc_message_utils.h" | |
| 17 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | |
| 18 | |
| 19 namespace content { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 void CreateChannelOnIOThread( | |
| 24 const GpuProcessHost::CreateArcVideoAcceleratorChannelCallback& callback) { | |
| 25 GpuProcessHost* gpu_process_host = | |
| 26 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | |
| 27 CAUSE_FOR_GPU_LAUNCH_ARCVIDEOACCELERATOR); | |
| 28 gpu_process_host->CreateArcVideoAcceleratorChannel(callback); | |
| 29 } | |
| 30 | |
| 31 void HandleChannelCreatedReply( | |
| 32 const arc::VideoHost::OnRequestArcVideoAcceleratorChannelCallback& callback, | |
| 33 const IPC::ChannelHandle& handle) { | |
| 34 MojoHandle wrapped_handle; | |
| 35 MojoResult wrap_result = mojo::embedder::CreatePlatformHandleWrapper( | |
| 36 mojo::embedder::ScopedPlatformHandle( | |
| 37 mojo::embedder::PlatformHandle(handle.socket.fd)), | |
| 38 &wrapped_handle); | |
| 39 if (wrap_result != MOJO_RESULT_OK) { | |
| 40 LOG(WARNING) << "Pipe failed to wrap handles. Closing: " << wrap_result; | |
| 41 callback.Run(mojo::ScopedHandle()); | |
| 42 return; | |
| 43 } | |
| 44 callback.Run(mojo::ScopedHandle(mojo::Handle(wrapped_handle))); | |
| 45 } | |
| 46 | |
| 47 } // namespace | |
| 48 | |
| 49 scoped_ptr<arc::VideoHostDelegate> CreateArcVideoHostDelegate() { | |
| 50 return make_scoped_ptr(new GpuArcVideoServiceHost()); | |
| 51 } | |
| 52 | |
| 53 GpuArcVideoServiceHost::GpuArcVideoServiceHost() | |
| 54 : io_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( | |
| 55 content::BrowserThread::IO)) {} | |
| 56 | |
| 57 GpuArcVideoServiceHost::~GpuArcVideoServiceHost() { | |
| 58 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 59 } | |
| 60 | |
| 61 void GpuArcVideoServiceHost::OnRequestArcVideoAcceleratorChannel( | |
| 62 const OnRequestArcVideoAcceleratorChannelCallback& callback) { | |
| 63 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 64 | |
| 65 io_task_runner_->PostTask( | |
| 66 FROM_HERE, base::Bind(&CreateChannelOnIOThread, | |
| 67 base::Bind(&HandleChannelCreatedReply, callback))); | |
| 68 } | |
| 69 | |
| 70 void GpuArcVideoServiceHost::OnStopping() { | |
| 71 GpuProcessHost::SendOnIO(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | |
| 72 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, | |
| 73 new GpuMsg_ShutdownArcVideoService()); | |
| 74 } | |
| 75 | |
| 76 } // namespace content | |
| OLD | NEW |