Remove unused parameter.
[chromium-blink-merge.git] / ui / ozone / public / ozone_gpu_test_helper.cc
blobfe88647a8a3d2086d4f7a0eef829e9bbd72a866f
1 // Copyright 2014 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.
5 #include "ui/ozone/public/ozone_gpu_test_helper.h"
7 #include "base/thread_task_runner_handle.h"
8 #include "ipc/ipc_listener.h"
9 #include "ipc/ipc_message.h"
10 #include "ipc/ipc_sender.h"
11 #include "ipc/message_filter.h"
12 #include "ui/ozone/public/gpu_platform_support.h"
13 #include "ui/ozone/public/gpu_platform_support_host.h"
14 #include "ui/ozone/public/ozone_platform.h"
16 namespace ui {
18 namespace {
20 const int kGpuProcessHostId = 1;
22 } // namespace
24 static void DispatchToGpuPlatformSupportHostTask(IPC::Message* msg) {
25 ui::OzonePlatform::GetInstance()
26 ->GetGpuPlatformSupportHost()
27 ->OnMessageReceived(*msg);
28 delete msg;
31 class FakeGpuProcess : public IPC::Sender {
32 public:
33 FakeGpuProcess(
34 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
35 : ui_task_runner_(ui_task_runner) {}
36 ~FakeGpuProcess() override {}
38 void Init() {
39 ui::OzonePlatform::GetInstance()
40 ->GetGpuPlatformSupport()
41 ->OnChannelEstablished(this);
44 void InitOnIO() {
45 ui::OzonePlatform::GetInstance()
46 ->GetGpuPlatformSupport()
47 ->GetMessageFilter()
48 ->OnFilterAdded(this);
51 bool Send(IPC::Message* msg) override {
52 ui_task_runner_->PostTask(
53 FROM_HERE, base::Bind(&DispatchToGpuPlatformSupportHostTask, msg));
54 return true;
57 private:
58 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
61 static void DispatchToGpuPlatformSupportTask(IPC::Message* msg) {
62 ui::OzonePlatform::GetInstance()->GetGpuPlatformSupport()->OnMessageReceived(
63 *msg);
64 delete msg;
67 class FakeGpuProcessHost {
68 public:
69 FakeGpuProcessHost(
70 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner)
71 : gpu_task_runner_(gpu_task_runner) {}
72 ~FakeGpuProcessHost() {}
74 void Init() {
75 base::Callback<void(IPC::Message*)> sender =
76 base::Bind(&DispatchToGpuPlatformSupportTask);
78 ui::OzonePlatform::GetInstance()
79 ->GetGpuPlatformSupportHost()
80 ->OnChannelEstablished(kGpuProcessHostId, gpu_task_runner_, sender);
83 private:
84 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_;
87 OzoneGpuTestHelper::OzoneGpuTestHelper() {
90 OzoneGpuTestHelper::~OzoneGpuTestHelper() {
93 bool OzoneGpuTestHelper::Initialize(
94 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
95 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner) {
96 io_helper_thread_.reset(new base::Thread("IOHelperThread"));
97 if (!io_helper_thread_->StartWithOptions(
98 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)))
99 return false;
101 fake_gpu_process_.reset(new FakeGpuProcess(ui_task_runner));
102 io_helper_thread_->task_runner()->PostTask(
103 FROM_HERE, base::Bind(&FakeGpuProcess::InitOnIO,
104 base::Unretained(fake_gpu_process_.get())));
105 fake_gpu_process_->Init();
107 fake_gpu_process_host_.reset(new FakeGpuProcessHost(gpu_task_runner));
108 fake_gpu_process_host_->Init();
110 return true;
113 } // namespace ui