ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / ui / ozone / public / ozone_gpu_test_helper.cc
blob1fa265c6b35fd822c457ad43a5ee9dc4687b25f9
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 class FakeGpuProcess : public IPC::Sender {
25 public:
26 FakeGpuProcess(
27 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
28 : ui_task_runner_(ui_task_runner), weak_factory_(this) {}
29 ~FakeGpuProcess() override {}
31 void Init() {
32 ui::OzonePlatform::GetInstance()
33 ->GetGpuPlatformSupport()
34 ->OnChannelEstablished(this);
37 void InitOnIO() {
38 ui::OzonePlatform::GetInstance()
39 ->GetGpuPlatformSupport()
40 ->GetMessageFilter()
41 ->OnFilterAdded(this);
44 bool Send(IPC::Message* msg) override {
45 ui_task_runner_->PostTask(
46 FROM_HERE,
47 base::Bind(&FakeGpuProcess::DispatchToGpuPlatformSupportHostTask,
48 weak_factory_.GetWeakPtr(), msg));
49 return true;
52 private:
53 void DispatchToGpuPlatformSupportHostTask(IPC::Message* msg) {
54 ui::OzonePlatform::GetInstance()
55 ->GetGpuPlatformSupportHost()
56 ->OnMessageReceived(*msg);
57 delete msg;
60 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
61 base::WeakPtrFactory<FakeGpuProcess> weak_factory_;
64 class FakeGpuProcessHost {
65 public:
66 FakeGpuProcessHost(
67 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner)
68 : gpu_task_runner_(gpu_task_runner), weak_factory_(this) {}
69 ~FakeGpuProcessHost() {}
71 void Init() {
72 base::Callback<void(IPC::Message*)> sender =
73 base::Bind(&FakeGpuProcessHost::DispatchToGpuPlatformSupportTask,
74 weak_factory_.GetWeakPtr());
76 ui::OzonePlatform::GetInstance()
77 ->GetGpuPlatformSupportHost()
78 ->OnChannelEstablished(kGpuProcessHostId, gpu_task_runner_, sender);
81 private:
82 void DispatchToGpuPlatformSupportTask(IPC::Message* msg) {
83 ui::OzonePlatform::GetInstance()
84 ->GetGpuPlatformSupport()
85 ->OnMessageReceived(*msg);
86 delete msg;
89 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_;
90 base::WeakPtrFactory<FakeGpuProcessHost> weak_factory_;
93 OzoneGpuTestHelper::OzoneGpuTestHelper() {
96 OzoneGpuTestHelper::~OzoneGpuTestHelper() {
99 bool OzoneGpuTestHelper::Initialize(
100 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
101 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner) {
102 io_helper_thread_.reset(new base::Thread("IOHelperThread"));
103 if (!io_helper_thread_->StartWithOptions(
104 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)))
105 return false;
107 fake_gpu_process_.reset(new FakeGpuProcess(ui_task_runner));
108 io_helper_thread_->task_runner()->PostTask(
109 FROM_HERE, base::Bind(&FakeGpuProcess::InitOnIO,
110 base::Unretained(fake_gpu_process_.get())));
111 fake_gpu_process_->Init();
113 fake_gpu_process_host_.reset(new FakeGpuProcessHost(gpu_task_runner));
114 fake_gpu_process_host_->Init();
116 return true;
119 } // namespace ui