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/common/gpu/media/gpu_arc_video_service.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "content/common/gpu/gpu_messages.h" | |
9 #include "ipc/ipc_listener.h" | |
10 #include "ipc/ipc_message_macros.h" | |
11 #include "ipc/ipc_sync_channel.h" | |
12 | |
13 namespace content { | |
14 | |
15 // TODO(kcwu) implement ArcVideoAccelerator::Client. | |
16 class GpuArcVideoService::AcceleratorStub : public IPC::Listener, | |
17 public IPC::Sender { | |
18 public: | |
19 // |owner| outlives AcceleratorStub. | |
20 explicit AcceleratorStub(GpuArcVideoService* owner) : owner_(owner) {} | |
21 | |
22 ~AcceleratorStub() override { | |
23 DCHECK(thread_checker_.CalledOnValidThread()); | |
24 channel_->Close(); | |
25 } | |
26 | |
27 IPC::ChannelHandle CreateChannel( | |
28 base::WaitableEvent* shutdown_event, | |
29 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) { | |
30 IPC::ChannelHandle handle = | |
31 IPC::Channel::GenerateVerifiedChannelID("arc-video"); | |
32 channel_ = IPC::SyncChannel::Create(handle, IPC::Channel::MODE_SERVER, this, | |
33 io_task_runner, false, shutdown_event); | |
34 base::ScopedFD client_fd = channel_->TakeClientFileDescriptor(); | |
35 DCHECK(client_fd.is_valid()); | |
36 handle.socket = base::FileDescriptor(std::move(client_fd)); | |
37 return handle; | |
38 } | |
39 | |
40 // IPC::Sender implementation: | |
41 bool Send(IPC::Message* msg) override { | |
42 DCHECK(msg); | |
43 return channel_->Send(msg); | |
44 } | |
45 | |
46 // IPC::Listener implementation: | |
47 void OnChannelError() override { | |
48 DCHECK(thread_checker_.CalledOnValidThread()); | |
49 // RemoveClient will delete |this|. | |
mdempsky
2016/01/09 01:07:05
Why not just do "delete this;"? RemoveClient does
kcwu
2016/01/09 03:22:04
We have to keep accelerator_stubs_ because GpuChan
| |
50 owner_->RemoveClient(this); | |
51 } | |
52 | |
53 // IPC::Listener implementation: | |
54 bool OnMessageReceived(const IPC::Message& msg) override { | |
55 DCHECK(thread_checker_.CalledOnValidThread()); | |
56 | |
57 // TODO(kcwu) Add handlers here. | |
58 return false; | |
59 } | |
60 | |
61 private: | |
62 base::ThreadChecker thread_checker_; | |
63 GpuArcVideoService* const owner_; | |
64 scoped_ptr<IPC::SyncChannel> channel_; | |
65 }; | |
66 | |
67 GpuArcVideoService::GpuArcVideoService( | |
68 base::WaitableEvent* shutdown_event, | |
69 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | |
70 : shutdown_event_(shutdown_event), io_task_runner_(io_task_runner) {} | |
71 | |
72 GpuArcVideoService::~GpuArcVideoService() {} | |
73 | |
74 void GpuArcVideoService::CreateChannel(const CreateChannelCallback& callback) { | |
75 DCHECK(thread_checker_.CalledOnValidThread()); | |
76 | |
77 scoped_ptr<AcceleratorStub> stub(new AcceleratorStub(this)); | |
78 | |
79 IPC::ChannelHandle handle = | |
80 stub->CreateChannel(shutdown_event_, io_task_runner_); | |
81 accelerator_stubs_[stub.get()] = std::move(stub); | |
82 | |
83 callback.Run(handle); | |
84 } | |
85 | |
86 void GpuArcVideoService::RemoveClient(AcceleratorStub* stub) { | |
87 DCHECK(thread_checker_.CalledOnValidThread()); | |
88 | |
89 accelerator_stubs_.erase(stub); | |
90 } | |
91 | |
92 } // namespace content | |
OLD | NEW |