Chromium Code Reviews| 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 "ipc/ipc_message_macros.h" | |
| 13 #include "ipc/ipc_message_utils.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 namespace { | |
| 18 void CreateChannelOnIOThread( | |
| 19 const GpuProcessHost::CreateArcVideoAcceleratorChannelCallback& callback) { | |
| 20 GpuProcessHost* gpu_process_host = | |
| 21 GpuProcessHost::Get(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | |
| 22 CAUSE_FOR_GPU_LAUNCH_ARCVIDEOACCELERATOR); | |
| 23 gpu_process_host->CreateArcVideoAcceleratorChannel(callback); | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 GpuArcVideoServiceHost::GpuArcVideoServiceHost( | |
| 28 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | |
| 29 : io_task_runner_(io_task_runner), | |
| 30 num_pending_request_(0), | |
| 31 weak_factory_(this) {} | |
| 32 | |
| 33 GpuArcVideoServiceHost::~GpuArcVideoServiceHost() { | |
| 34 DCHECK(CalledOnValidThread()); | |
| 35 | |
| 36 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | |
| 37 if (bridge_service) { | |
| 38 while (num_pending_request_ > 0) | |
| 39 NotifyArcAcceleratorChannelCreated(IPC::ChannelHandle()); | |
| 40 bridge_service->RemoveObserver(this); | |
| 41 bridge_service->RemoveVideoServiceObserver(this); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 void GpuArcVideoServiceHost::Initialize() { | |
| 46 DCHECK(CalledOnValidThread()); | |
| 47 | |
| 48 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | |
| 49 DCHECK(bridge_service); | |
|
Pawel Osciak
2015/12/16 10:17:58
Should we actually if(bridge_service) here (and in
kcwu
2015/12/16 14:05:33
Basically it is bug if bridge_service is null, hen
| |
| 50 bridge_service->AddObserver(this); | |
| 51 bridge_service->AddVideoServiceObserver(this); | |
| 52 } | |
| 53 | |
| 54 void GpuArcVideoServiceHost::OnStateChanged( | |
| 55 arc::ArcBridgeService::State state) { | |
| 56 DCHECK(CalledOnValidThread()); | |
| 57 switch (state) { | |
| 58 case arc::ArcBridgeService::State::STOPPING: | |
| 59 Shutdown(); | |
| 60 break; | |
| 61 default: | |
| 62 break; | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 void GpuArcVideoServiceHost::OnRequestArcVideoAcceleratorChannel() { | |
| 67 DCHECK(CalledOnValidThread()); | |
| 68 num_pending_request_++; | |
| 69 io_task_runner_->PostTask( | |
| 70 FROM_HERE, | |
| 71 base::Bind( | |
| 72 &CreateChannelOnIOThread, | |
| 73 base::Bind( | |
| 74 &GpuArcVideoServiceHost::NotifyArcAcceleratorChannelCreated, | |
| 75 weak_factory_.GetWeakPtr()))); | |
| 76 } | |
| 77 | |
| 78 void GpuArcVideoServiceHost::Shutdown() { | |
| 79 GpuProcessHost::SendOnIO(GpuProcessHost::GPU_PROCESS_KIND_SANDBOXED, | |
| 80 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, | |
| 81 new GpuMsg_ShutdownArcVideoService()); | |
| 82 } | |
| 83 | |
| 84 void GpuArcVideoServiceHost::NotifyArcAcceleratorChannelCreated( | |
| 85 const IPC::ChannelHandle& handle) { | |
| 86 DCHECK(CalledOnValidThread()); | |
| 87 | |
| 88 DCHECK_GT(num_pending_request_, 0); | |
| 89 | |
| 90 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get(); | |
| 91 DCHECK(bridge_service); | |
| 92 num_pending_request_--; | |
| 93 ignore_result(bridge_service->NotifyVideoAcceleratorChannelCreated(handle)); | |
|
Pawel Osciak
2015/12/16 10:17:58
Is there any other caller that doesn't ignore_resu
kcwu
2015/12/16 14:05:33
Done.
| |
| 94 } | |
| 95 | |
| 96 } // namespace content | |
| OLD | NEW |