OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 void CreateChannelOnIOThread( | |
23 const GpuProcessHost::CreateArcVideoAcceleratorChannelCallback& callback) { | |
24 GpuProcessHost* gpu_process_host = | |
25 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | |
26 CAUSE_FOR_GPU_LAUNCH_ARCVIDEOACCELERATOR); | |
27 gpu_process_host->CreateArcVideoAcceleratorChannel(callback); | |
28 } | |
29 } | |
30 | |
31 scoped_ptr<arc::VideoHostDelegate> CreateArcVideoHostDelegate() { | |
32 return make_scoped_ptr(new GpuArcVideoServiceHost()); | |
33 } | |
34 | |
35 GpuArcVideoServiceHost::GpuArcVideoServiceHost() | |
36 : io_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread( | |
37 content::BrowserThread::IO)), | |
38 weak_factory_(this) {} | |
39 | |
40 GpuArcVideoServiceHost::~GpuArcVideoServiceHost() { | |
41 DCHECK(thread_checker_.CalledOnValidThread()); | |
42 } | |
43 | |
44 void GpuArcVideoServiceHost::OnRequestArcVideoAcceleratorChannel( | |
45 const OnRequestArcVideoAcceleratorChannelCallback& callback) { | |
46 DCHECK(thread_checker_.CalledOnValidThread()); | |
47 | |
48 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
| |
49 FROM_HERE, | |
50 base::Bind(&CreateChannelOnIOThread, | |
51 base::Bind(&GpuArcVideoServiceHost::HandleChannelCreatedReply, | |
52 weak_factory_.GetWeakPtr(), callback))); | |
53 } | |
54 | |
55 void GpuArcVideoServiceHost::Shutdown() { | |
56 GpuProcessHost::SendOnIO(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | |
57 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, | |
58 new GpuMsg_ShutdownArcVideoService()); | |
59 } | |
60 | |
61 void GpuArcVideoServiceHost::HandleChannelCreatedReply( | |
62 const OnRequestArcVideoAcceleratorChannelCallback& callback, | |
63 const IPC::ChannelHandle& handle) { | |
64 DCHECK(thread_checker_.CalledOnValidThread()); | |
65 | |
66 MojoHandle wrapped_handle; | |
67 MojoResult wrap_result = mojo::embedder::CreatePlatformHandleWrapper( | |
68 mojo::embedder::ScopedPlatformHandle( | |
69 mojo::embedder::PlatformHandle(handle.socket.fd)), | |
70 &wrapped_handle); | |
71 if (wrap_result != MOJO_RESULT_OK) { | |
72 LOG(WARNING) << "Pipe failed to wrap handles. Closing: " << wrap_result; | |
73 callback.Run(mojo::ScopedHandle()); | |
74 return; | |
75 } | |
76 callback.Run(mojo::ScopedHandle(mojo::Handle(wrapped_handle))); | |
77 } | |
78 | |
79 } // namespace content | |
OLD | NEW |