Chromium Code Reviews| Index: ui/ozone/public/ui_thread_gpu.cc |
| diff --git a/ui/ozone/public/ui_thread_gpu.cc b/ui/ozone/public/ui_thread_gpu.cc |
| index b788bd5c1c5e78018d6feb31243cd8800ef8ba5b..101a51d5764b7c0a78dde0ffdcc25adf37aa8888 100644 |
| --- a/ui/ozone/public/ui_thread_gpu.cc |
| +++ b/ui/ozone/public/ui_thread_gpu.cc |
| @@ -4,6 +4,7 @@ |
| #include "ui/ozone/public/ui_thread_gpu.h" |
| +#include "base/thread_task_runner_handle.h" |
| #include "ipc/ipc_listener.h" |
| #include "ipc/ipc_message.h" |
| #include "ipc/ipc_sender.h" |
| @@ -13,21 +14,73 @@ |
| namespace ui { |
| -class UiThreadGpuForwardingSender : public IPC::Sender { |
| +namespace { |
| + |
| +const int kGpuProcessHostId = 1; |
| + |
| +} // namespace |
| + |
| +class FakeGpuProcess : public IPC::Sender { |
| public: |
| - explicit UiThreadGpuForwardingSender(IPC::Listener* listener) |
| - : listener_(listener) {} |
| - ~UiThreadGpuForwardingSender() override {} |
| + FakeGpuProcess() : weak_factory_(this) {} |
| + ~FakeGpuProcess() {} |
| + |
| + void Init() { |
| + task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| + ui::OzonePlatform::GetInstance() |
| + ->GetGpuPlatformSupport() |
| + ->OnChannelEstablished(this); |
| + } |
| - // IPC::Sender: |
| bool Send(IPC::Message* msg) override { |
| - listener_->OnMessageReceived(*msg); |
| - delete msg; |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| + base::MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&FakeGpuProcess::DispatchToGpuPlatformSupportHostTask, |
| + weak_factory_.GetWeakPtr(), msg)); |
| return true; |
| } |
| private: |
| - IPC::Listener* listener_; |
| + void DispatchToGpuPlatformSupportHostTask(IPC::Message* msg) { |
| + ui::OzonePlatform::GetInstance() |
| + ->GetGpuPlatformSupportHost() |
| + ->OnMessageReceived(*msg); |
| + delete msg; |
| + } |
| + |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| + base::WeakPtrFactory<FakeGpuProcess> weak_factory_; |
| +}; |
| + |
| +class FakeGpuProcessHost { |
| + public: |
| + FakeGpuProcessHost() : weak_factory_(this) {} |
| + ~FakeGpuProcessHost() {} |
| + |
| + void Init() { |
| + task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| + |
| + base::Callback<void(IPC::Message*)> sender = |
| + base::Bind(&FakeGpuProcessHost::DispatchToGpuPlatformSupportTask, |
| + weak_factory_.GetWeakPtr()); |
| + |
| + ui::OzonePlatform::GetInstance() |
| + ->GetGpuPlatformSupportHost() |
| + ->OnChannelEstablished(kGpuProcessHostId, task_runner_, sender); |
|
alexst (slow to review)
2015/01/09 21:53:08
You call them send_runner and send_callback in oth
|
| + } |
| + |
| + private: |
| + void DispatchToGpuPlatformSupportTask(IPC::Message* msg) { |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| + ui::OzonePlatform::GetInstance() |
| + ->GetGpuPlatformSupport() |
| + ->OnMessageReceived(*msg); |
| + delete msg; |
| + } |
| + |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| + base::WeakPtrFactory<FakeGpuProcessHost> weak_factory_; |
| }; |
| UiThreadGpu::UiThreadGpu() { |
| @@ -37,17 +90,11 @@ UiThreadGpu::~UiThreadGpu() { |
| } |
| bool UiThreadGpu::Initialize() { |
| - OzonePlatform* platform = ui::OzonePlatform::GetInstance(); |
| - |
| - ui_sender_.reset( |
| - new UiThreadGpuForwardingSender(platform->GetGpuPlatformSupportHost())); |
| - gpu_sender_.reset( |
| - new UiThreadGpuForwardingSender(platform->GetGpuPlatformSupport())); |
| + fake_gpu_process_.reset(new FakeGpuProcess); |
| + fake_gpu_process_->Init(); |
| - const int kHostId = 1; |
| - platform->GetGpuPlatformSupportHost()->OnChannelEstablished( |
| - kHostId, gpu_sender_.get()); |
| - platform->GetGpuPlatformSupport()->OnChannelEstablished(ui_sender_.get()); |
| + fake_gpu_process_host_.reset(new FakeGpuProcessHost); |
| + fake_gpu_process_host_->Init(); |
| return true; |
| } |