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

Side by Side Diff: content/browser/gpu/browser_gpu_channel_host_factory.cc

Issue 1170623003: Revert "content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/gpu/browser_gpu_channel_host_factory.h" 5 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h"
11 #include "base/profiler/scoped_tracker.h" 10 #include "base/profiler/scoped_tracker.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
14 #include "base/thread_task_runner_handle.h"
15 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
16 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
17 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" 14 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
18 #include "content/browser/gpu/gpu_data_manager_impl.h" 15 #include "content/browser/gpu/gpu_data_manager_impl.h"
19 #include "content/browser/gpu/gpu_process_host.h" 16 #include "content/browser/gpu/gpu_process_host.h"
20 #include "content/browser/gpu/gpu_surface_tracker.h" 17 #include "content/browser/gpu/gpu_surface_tracker.h"
21 #include "content/common/child_process_host_impl.h" 18 #include "content/common/child_process_host_impl.h"
22 #include "content/common/gpu/gpu_memory_buffer_factory.h" 19 #include "content/common/gpu/gpu_memory_buffer_factory.h"
23 #include "content/common/gpu/gpu_messages.h" 20 #include "content/common/gpu/gpu_messages.h"
24 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void FinishOnMain(); 116 void FinishOnMain();
120 117
121 base::WaitableEvent event_; 118 base::WaitableEvent event_;
122 CauseForGpuLaunch cause_for_gpu_launch_; 119 CauseForGpuLaunch cause_for_gpu_launch_;
123 const int gpu_client_id_; 120 const int gpu_client_id_;
124 int gpu_host_id_; 121 int gpu_host_id_;
125 bool reused_gpu_process_; 122 bool reused_gpu_process_;
126 IPC::ChannelHandle channel_handle_; 123 IPC::ChannelHandle channel_handle_;
127 gpu::GPUInfo gpu_info_; 124 gpu::GPUInfo gpu_info_;
128 bool finished_; 125 bool finished_;
129 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 126 scoped_refptr<base::MessageLoopProxy> main_loop_;
130 }; 127 };
131 128
132 scoped_refptr<BrowserGpuChannelHostFactory::EstablishRequest> 129 scoped_refptr<BrowserGpuChannelHostFactory::EstablishRequest>
133 BrowserGpuChannelHostFactory::EstablishRequest::Create(CauseForGpuLaunch cause, 130 BrowserGpuChannelHostFactory::EstablishRequest::Create(CauseForGpuLaunch cause,
134 int gpu_client_id, 131 int gpu_client_id,
135 int gpu_host_id) { 132 int gpu_host_id) {
136 scoped_refptr<EstablishRequest> establish_request = 133 scoped_refptr<EstablishRequest> establish_request =
137 new EstablishRequest(cause, gpu_client_id, gpu_host_id); 134 new EstablishRequest(cause, gpu_client_id, gpu_host_id);
138 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 135 scoped_refptr<base::MessageLoopProxy> loop =
139 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 136 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
140 // PostTask outside the constructor to ensure at least one reference exists. 137 // PostTask outside the constructor to ensure at least one reference exists.
141 task_runner->PostTask( 138 loop->PostTask(
142 FROM_HERE, 139 FROM_HERE,
143 base::Bind(&BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO, 140 base::Bind(&BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO,
144 establish_request)); 141 establish_request));
145 return establish_request; 142 return establish_request;
146 } 143 }
147 144
148 BrowserGpuChannelHostFactory::EstablishRequest::EstablishRequest( 145 BrowserGpuChannelHostFactory::EstablishRequest::EstablishRequest(
149 CauseForGpuLaunch cause, 146 CauseForGpuLaunch cause,
150 int gpu_client_id, 147 int gpu_client_id,
151 int gpu_host_id) 148 int gpu_host_id)
152 : event_(false, false), 149 : event_(false, false),
153 cause_for_gpu_launch_(cause), 150 cause_for_gpu_launch_(cause),
154 gpu_client_id_(gpu_client_id), 151 gpu_client_id_(gpu_client_id),
155 gpu_host_id_(gpu_host_id), 152 gpu_host_id_(gpu_host_id),
156 reused_gpu_process_(false), 153 reused_gpu_process_(false),
157 finished_(false), 154 finished_(false),
158 main_task_runner_(base::ThreadTaskRunnerHandle::Get()) { 155 main_loop_(base::MessageLoopProxy::current()) {
159 } 156 }
160 157
161 void BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO() { 158 void BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO() {
162 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 159 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
163 tracked_objects::ScopedTracker tracking_profile( 160 tracked_objects::ScopedTracker tracking_profile(
164 FROM_HERE_WITH_EXPLICIT_FUNCTION( 161 FROM_HERE_WITH_EXPLICIT_FUNCTION(
165 "477117 " 162 "477117 "
166 "BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO")); 163 "BrowserGpuChannelHostFactory::EstablishRequest::EstablishOnIO"));
167 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_); 164 GpuProcessHost* host = GpuProcessHost::FromID(gpu_host_id_);
168 if (!host) { 165 if (!host) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 EstablishOnIO(); 205 EstablishOnIO();
209 } else { 206 } else {
210 channel_handle_ = channel_handle; 207 channel_handle_ = channel_handle;
211 gpu_info_ = gpu_info; 208 gpu_info_ = gpu_info;
212 FinishOnIO(); 209 FinishOnIO();
213 } 210 }
214 } 211 }
215 212
216 void BrowserGpuChannelHostFactory::EstablishRequest::FinishOnIO() { 213 void BrowserGpuChannelHostFactory::EstablishRequest::FinishOnIO() {
217 event_.Signal(); 214 event_.Signal();
218 main_task_runner_->PostTask( 215 main_loop_->PostTask(
219 FROM_HERE, 216 FROM_HERE,
220 base::Bind(&BrowserGpuChannelHostFactory::EstablishRequest::FinishOnMain, 217 base::Bind(&BrowserGpuChannelHostFactory::EstablishRequest::FinishOnMain,
221 this)); 218 this));
222 } 219 }
223 220
224 void BrowserGpuChannelHostFactory::EstablishRequest::FinishOnMain() { 221 void BrowserGpuChannelHostFactory::EstablishRequest::FinishOnMain() {
225 if (!finished_) { 222 if (!finished_) {
226 BrowserGpuChannelHostFactory* factory = 223 BrowserGpuChannelHostFactory* factory =
227 BrowserGpuChannelHostFactory::instance(); 224 BrowserGpuChannelHostFactory::instance();
228 factory->GpuChannelEstablished(); 225 factory->GpuChannelEstablished();
229 finished_ = true; 226 finished_ = true;
230 } 227 }
231 } 228 }
232 229
233 void BrowserGpuChannelHostFactory::EstablishRequest::Wait() { 230 void BrowserGpuChannelHostFactory::EstablishRequest::Wait() {
234 DCHECK(main_task_runner_->BelongsToCurrentThread()); 231 DCHECK(main_loop_->BelongsToCurrentThread());
235 { 232 {
236 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed. 233 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is fixed.
237 tracked_objects::ScopedTracker tracking_profile( 234 tracked_objects::ScopedTracker tracking_profile(
238 FROM_HERE_WITH_EXPLICIT_FUNCTION( 235 FROM_HERE_WITH_EXPLICIT_FUNCTION(
239 "125248 BrowserGpuChannelHostFactory::EstablishRequest::Wait")); 236 "125248 BrowserGpuChannelHostFactory::EstablishRequest::Wait"));
240 237
241 // We're blocking the UI thread, which is generally undesirable. 238 // We're blocking the UI thread, which is generally undesirable.
242 // In this case we need to wait for this before we can show any UI 239 // In this case we need to wait for this before we can show any UI
243 // /anyway/, so it won't cause additional jank. 240 // /anyway/, so it won't cause additional jank.
244 // TODO(piman): Make this asynchronous (http://crbug.com/125248). 241 // TODO(piman): Make this asynchronous (http://crbug.com/125248).
245 TRACE_EVENT0("browser", 242 TRACE_EVENT0("browser",
246 "BrowserGpuChannelHostFactory::EstablishGpuChannelSync"); 243 "BrowserGpuChannelHostFactory::EstablishGpuChannelSync");
247 base::ThreadRestrictions::ScopedAllowWait allow_wait; 244 base::ThreadRestrictions::ScopedAllowWait allow_wait;
248 event_.Wait(); 245 event_.Wait();
249 } 246 }
250 FinishOnMain(); 247 FinishOnMain();
251 } 248 }
252 249
253 void BrowserGpuChannelHostFactory::EstablishRequest::Cancel() { 250 void BrowserGpuChannelHostFactory::EstablishRequest::Cancel() {
254 DCHECK(main_task_runner_->BelongsToCurrentThread()); 251 DCHECK(main_loop_->BelongsToCurrentThread());
255 finished_ = true; 252 finished_ = true;
256 } 253 }
257 254
258 bool BrowserGpuChannelHostFactory::CanUseForTesting() { 255 bool BrowserGpuChannelHostFactory::CanUseForTesting() {
259 return GpuDataManager::GetInstance()->GpuAccessAllowed(NULL); 256 return GpuDataManager::GetInstance()->GpuAccessAllowed(NULL);
260 } 257 }
261 258
262 void BrowserGpuChannelHostFactory::Initialize(bool establish_gpu_channel) { 259 void BrowserGpuChannelHostFactory::Initialize(bool establish_gpu_channel) {
263 DCHECK(!instance_); 260 DCHECK(!instance_);
264 instance_ = new BrowserGpuChannelHostFactory(); 261 instance_ = new BrowserGpuChannelHostFactory();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 DCHECK_CURRENTLY_ON(BrowserThread::IO); 576 DCHECK_CURRENTLY_ON(BrowserThread::IO);
580 577
581 CreateGpuMemoryBufferCallbackMap::iterator iter = 578 CreateGpuMemoryBufferCallbackMap::iterator iter =
582 create_gpu_memory_buffer_requests_.find(request_id); 579 create_gpu_memory_buffer_requests_.find(request_id);
583 DCHECK(iter != create_gpu_memory_buffer_requests_.end()); 580 DCHECK(iter != create_gpu_memory_buffer_requests_.end());
584 iter->second.Run(handle); 581 iter->second.Run(handle);
585 create_gpu_memory_buffer_requests_.erase(iter); 582 create_gpu_memory_buffer_requests_.erase(iter);
586 } 583 }
587 584
588 } // namespace content 585 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/geolocation/wifi_data_provider_common.cc ('k') | content/browser/histogram_synchronizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698