| 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..e2180c17274f7d6e6bd39f9286ff505e681d4656
 | 
| --- /dev/null
 | 
| +++ b/content/browser/gpu/gpu_arc_video_service_host.cc
 | 
| @@ -0,0 +1,111 @@
 | 
| +// 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/browser_thread.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);
 | 
| +}
 | 
| +}
 | 
| +
 | 
| +GpuArcVideoServiceHost::GpuArcVideoServiceHost()
 | 
| +    : io_task_runner_(content::BrowserThread::GetMessageLoopProxyForThread(
 | 
| +          content::BrowserThread::IO)),
 | 
| +      binding_(this),
 | 
| +      weak_factory_(this) {}
 | 
| +
 | 
| +GpuArcVideoServiceHost::~GpuArcVideoServiceHost() {
 | 
| +  DCHECK(CalledOnValidThread());
 | 
| +
 | 
| +  arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
 | 
| +  if (bridge_service) {
 | 
| +    bridge_service->RemoveObserver(this);
 | 
| +  }
 | 
| +}
 | 
| +
 | 
| +void GpuArcVideoServiceHost::Initialize() {
 | 
| +  DCHECK(CalledOnValidThread());
 | 
| +
 | 
| +  arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
 | 
| +  DCHECK(bridge_service);
 | 
| +  bridge_service->AddObserver(this);
 | 
| +  if (bridge_service->video_instance())
 | 
| +    OnVideoInstanceReady();
 | 
| +}
 | 
| +
 | 
| +void GpuArcVideoServiceHost::OnStateChanged(
 | 
| +    arc::ArcBridgeService::State state) {
 | 
| +  DCHECK(CalledOnValidThread());
 | 
| +  switch (state) {
 | 
| +    case arc::ArcBridgeService::State::STOPPING:
 | 
| +      Shutdown();
 | 
| +      break;
 | 
| +    default:
 | 
| +      break;
 | 
| +  }
 | 
| +}
 | 
| +
 | 
| +void GpuArcVideoServiceHost::OnVideoInstanceReady() {
 | 
| +  DCHECK(CalledOnValidThread());
 | 
| +  arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
 | 
| +  DCHECK(bridge_service);
 | 
| +
 | 
| +  arc::VideoHostPtr host;
 | 
| +  binding_.Bind(mojo::GetProxy(&host));
 | 
| +  bridge_service->video_instance()->Init(std::move(host));
 | 
| +}
 | 
| +
 | 
| +void GpuArcVideoServiceHost::OnRequestArcVideoAcceleratorChannel(
 | 
| +    const OnRequestArcVideoAcceleratorChannelCallback& callback) {
 | 
| +  DCHECK(CalledOnValidThread());
 | 
| +
 | 
| +  io_task_runner_->PostTask(
 | 
| +      FROM_HERE,
 | 
| +      base::Bind(&CreateChannelOnIOThread,
 | 
| +                 base::Bind(&GpuArcVideoServiceHost::ReplyChannelCreated,
 | 
| +                            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::ReplyChannelCreated(
 | 
| +    const OnRequestArcVideoAcceleratorChannelCallback& callback,
 | 
| +    const IPC::ChannelHandle& handle) {
 | 
| +  DCHECK(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
 | 
| 
 |