Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: ui/ozone/public/ozone_gpu_test_helper.cc

Issue 1017673003: Simplify FakeGpuProcess* video accelerator tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/ozone/public/ozone_gpu_test_helper.h" 5 #include "ui/ozone/public/ozone_gpu_test_helper.h"
6 6
7 #include "base/synchronization/waitable_event.h"
7 #include "base/thread_task_runner_handle.h" 8 #include "base/thread_task_runner_handle.h"
8 #include "ipc/ipc_listener.h" 9 #include "ipc/ipc_listener.h"
9 #include "ipc/ipc_message.h" 10 #include "ipc/ipc_message.h"
10 #include "ipc/ipc_sender.h" 11 #include "ipc/ipc_sender.h"
11 #include "ipc/message_filter.h" 12 #include "ipc/message_filter.h"
12 #include "ui/ozone/public/gpu_platform_support.h" 13 #include "ui/ozone/public/gpu_platform_support.h"
13 #include "ui/ozone/public/gpu_platform_support_host.h" 14 #include "ui/ozone/public/gpu_platform_support_host.h"
14 #include "ui/ozone/public/ozone_platform.h" 15 #include "ui/ozone/public/ozone_platform.h"
15 16
16 namespace ui { 17 namespace ui {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 60
60 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 61 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
61 base::WeakPtrFactory<FakeGpuProcess> weak_factory_; 62 base::WeakPtrFactory<FakeGpuProcess> weak_factory_;
62 }; 63 };
63 64
64 class FakeGpuProcessHost { 65 class FakeGpuProcessHost {
65 public: 66 public:
66 FakeGpuProcessHost( 67 FakeGpuProcessHost(
67 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner) 68 const scoped_refptr<base::SingleThreadTaskRunner>& gpu_task_runner)
68 : gpu_task_runner_(gpu_task_runner), weak_factory_(this) {} 69 : gpu_task_runner_(gpu_task_runner), weak_factory_(this) {}
69 ~FakeGpuProcessHost() {} 70 ~FakeGpuProcessHost() {
71 base::WaitableEvent done(false, false);
72 gpu_task_runner_->PostTask(FROM_HERE,
73 base::Bind(&FakeGpuProcessHost::Destroy,
74 weak_factory_.GetWeakPtr(), &done));
75 done.Wait();
76 }
70 77
71 void Init() { 78 void Init() {
72 base::Callback<void(IPC::Message*)> sender = 79 base::Callback<void(IPC::Message*)> sender =
73 base::Bind(&FakeGpuProcessHost::DispatchToGpuPlatformSupportTask, 80 base::Bind(&FakeGpuProcessHost::DispatchToGpuPlatformSupportTask,
74 weak_factory_.GetWeakPtr()); 81 weak_factory_.GetWeakPtr());
75 82
76 ui::OzonePlatform::GetInstance() 83 ui::OzonePlatform::GetInstance()
77 ->GetGpuPlatformSupportHost() 84 ->GetGpuPlatformSupportHost()
78 ->OnChannelEstablished(kGpuProcessHostId, gpu_task_runner_, sender); 85 ->OnChannelEstablished(kGpuProcessHostId, gpu_task_runner_, sender);
dnicoara 2015/03/17 18:15:16 Grr, this is where the actual issue is. Can't use
vignatti (out of this project) 2015/03/17 18:59:05 oh, I thought this snip was correct?
dnicoara 2015/03/17 21:28:56 No, this is actually where this is very very wrong
vignatti (out of this project) 2015/03/18 15:38:29 I actually think that the way you used weak_ptr he
dnicoara 2015/03/18 17:19:28 You're right, I'm getting confused by the code :(
79 } 86 }
80 87
81 private: 88 private:
89 void Destroy(base::WaitableEvent* done) {
90 DCHECK(gpu_task_runner_->BelongsToCurrentThread());
91 this->weak_factory_.InvalidateWeakPtrs();
92 done->Signal();
93 }
94
82 void DispatchToGpuPlatformSupportTask(IPC::Message* msg) { 95 void DispatchToGpuPlatformSupportTask(IPC::Message* msg) {
83 ui::OzonePlatform::GetInstance() 96 ui::OzonePlatform::GetInstance()
84 ->GetGpuPlatformSupport() 97 ->GetGpuPlatformSupport()
85 ->OnMessageReceived(*msg); 98 ->OnMessageReceived(*msg);
86 delete msg; 99 delete msg;
87 } 100 }
88 101
89 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_; 102 scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_;
90 base::WeakPtrFactory<FakeGpuProcessHost> weak_factory_; 103 base::WeakPtrFactory<FakeGpuProcessHost> weak_factory_;
91 }; 104 };
(...skipping 18 matching lines...) Expand all
110 base::Unretained(fake_gpu_process_.get()))); 123 base::Unretained(fake_gpu_process_.get())));
111 fake_gpu_process_->Init(); 124 fake_gpu_process_->Init();
112 125
113 fake_gpu_process_host_.reset(new FakeGpuProcessHost(gpu_task_runner)); 126 fake_gpu_process_host_.reset(new FakeGpuProcessHost(gpu_task_runner));
114 fake_gpu_process_host_->Init(); 127 fake_gpu_process_host_->Init();
115 128
116 return true; 129 return true;
117 } 130 }
118 131
119 } // namespace ui 132 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698