OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/shader_disk_cache.h" | 5 #include "content/browser/gpu/shader_disk_cache.h" |
6 | 6 |
7 #include "base/threading/thread_checker.h" | 7 #include "base/threading/thread_checker.h" |
8 #include "content/browser/gpu/gpu_process_host.h" | 8 #include "content/browser/gpu/gpu_process_host.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "gpu/command_buffer/common/constants.h" | 10 #include "gpu/command_buffer/common/constants.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 void OnOpComplete(int rv); | 89 void OnOpComplete(int rv); |
90 | 90 |
91 int OpenNextEntry(); | 91 int OpenNextEntry(); |
92 int OpenNextEntryComplete(int rv); | 92 int OpenNextEntryComplete(int rv); |
93 int ReadComplete(int rv); | 93 int ReadComplete(int rv); |
94 int IterationComplete(int rv); | 94 int IterationComplete(int rv); |
95 | 95 |
96 base::WeakPtr<ShaderDiskCache> cache_; | 96 base::WeakPtr<ShaderDiskCache> cache_; |
97 OpType op_type_; | 97 OpType op_type_; |
98 void* iter_; | 98 scoped_ptr<disk_cache::Backend::Iterator> iter_; |
99 scoped_refptr<net::IOBufferWithSize> buf_; | 99 scoped_refptr<net::IOBufferWithSize> buf_; |
100 int host_id_; | 100 int host_id_; |
101 disk_cache::Entry* entry_; | 101 disk_cache::Entry* entry_; |
102 | 102 |
103 DISALLOW_COPY_AND_ASSIGN(ShaderDiskReadHelper); | 103 DISALLOW_COPY_AND_ASSIGN(ShaderDiskReadHelper); |
104 }; | 104 }; |
105 | 105 |
106 class ShaderClearHelper | 106 class ShaderClearHelper |
107 : public base::RefCounted<ShaderClearHelper>, | 107 : public base::RefCounted<ShaderClearHelper>, |
108 public base::SupportsWeakPtr<ShaderClearHelper> { | 108 public base::SupportsWeakPtr<ShaderClearHelper> { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 cache_->EntryComplete(this); | 236 cache_->EntryComplete(this); |
237 op_type_ = TERMINATE; | 237 op_type_ = TERMINATE; |
238 return rv; | 238 return rv; |
239 } | 239 } |
240 | 240 |
241 ShaderDiskReadHelper::ShaderDiskReadHelper( | 241 ShaderDiskReadHelper::ShaderDiskReadHelper( |
242 base::WeakPtr<ShaderDiskCache> cache, | 242 base::WeakPtr<ShaderDiskCache> cache, |
243 int host_id) | 243 int host_id) |
244 : cache_(cache), | 244 : cache_(cache), |
245 op_type_(OPEN_NEXT), | 245 op_type_(OPEN_NEXT), |
246 iter_(NULL), | |
247 buf_(NULL), | 246 buf_(NULL), |
248 host_id_(host_id), | 247 host_id_(host_id), |
249 entry_(NULL) { | 248 entry_(NULL) { |
250 } | 249 } |
251 | 250 |
252 void ShaderDiskReadHelper::LoadCache() { | 251 void ShaderDiskReadHelper::LoadCache() { |
253 DCHECK(CalledOnValidThread()); | 252 DCHECK(CalledOnValidThread()); |
254 if (!cache_.get()) | 253 if (!cache_.get()) |
255 return; | 254 return; |
256 OnOpComplete(net::OK); | 255 OnOpComplete(net::OK); |
(...skipping 27 matching lines...) Expand all Loading... |
284 rv = net::ERR_FAILED; | 283 rv = net::ERR_FAILED; |
285 break; | 284 break; |
286 } | 285 } |
287 } while (rv != net::ERR_IO_PENDING); | 286 } while (rv != net::ERR_IO_PENDING); |
288 } | 287 } |
289 | 288 |
290 int ShaderDiskReadHelper::OpenNextEntry() { | 289 int ShaderDiskReadHelper::OpenNextEntry() { |
291 DCHECK(CalledOnValidThread()); | 290 DCHECK(CalledOnValidThread()); |
292 // Called through OnOpComplete, so we know |cache_| is valid. | 291 // Called through OnOpComplete, so we know |cache_| is valid. |
293 op_type_ = OPEN_NEXT_COMPLETE; | 292 op_type_ = OPEN_NEXT_COMPLETE; |
294 return cache_->backend()->OpenNextEntry( | 293 if (!iter_) |
295 &iter_, | 294 iter_ = cache_->backend()->CreateIterator(); |
296 &entry_, | 295 return iter_->OpenNextEntry( |
297 base::Bind(&ShaderDiskReadHelper::OnOpComplete, this)); | 296 &entry_, base::Bind(&ShaderDiskReadHelper::OnOpComplete, this)); |
298 } | 297 } |
299 | 298 |
300 int ShaderDiskReadHelper::OpenNextEntryComplete(int rv) { | 299 int ShaderDiskReadHelper::OpenNextEntryComplete(int rv) { |
301 DCHECK(CalledOnValidThread()); | 300 DCHECK(CalledOnValidThread()); |
302 // Called through OnOpComplete, so we know |cache_| is valid. | 301 // Called through OnOpComplete, so we know |cache_| is valid. |
303 if (rv == net::ERR_FAILED) { | 302 if (rv == net::ERR_FAILED) { |
304 op_type_ = ITERATION_FINISHED; | 303 op_type_ = ITERATION_FINISHED; |
305 return net::OK; | 304 return net::OK; |
306 } | 305 } |
307 | 306 |
(...skipping 24 matching lines...) Expand all Loading... |
332 entry_->Close(); | 331 entry_->Close(); |
333 entry_ = NULL; | 332 entry_ = NULL; |
334 | 333 |
335 op_type_ = OPEN_NEXT; | 334 op_type_ = OPEN_NEXT; |
336 return net::OK; | 335 return net::OK; |
337 } | 336 } |
338 | 337 |
339 int ShaderDiskReadHelper::IterationComplete(int rv) { | 338 int ShaderDiskReadHelper::IterationComplete(int rv) { |
340 DCHECK(CalledOnValidThread()); | 339 DCHECK(CalledOnValidThread()); |
341 // Called through OnOpComplete, so we know |cache_| is valid. | 340 // Called through OnOpComplete, so we know |cache_| is valid. |
342 cache_->backend()->EndEnumeration(&iter_); | 341 iter_.reset(); |
343 iter_ = NULL; | |
344 op_type_ = TERMINATE; | 342 op_type_ = TERMINATE; |
345 return net::OK; | 343 return net::OK; |
346 } | 344 } |
347 | 345 |
348 ShaderDiskReadHelper::~ShaderDiskReadHelper() { | 346 ShaderDiskReadHelper::~ShaderDiskReadHelper() { |
349 if (entry_) | 347 if (entry_) |
350 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 348 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
351 base::Bind(&EntryCloser, entry_)); | 349 base::Bind(&EntryCloser, entry_)); |
352 } | 350 } |
353 | 351 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 const net::CompletionCallback& callback) { | 606 const net::CompletionCallback& callback) { |
609 if (entry_map_.empty()) { | 607 if (entry_map_.empty()) { |
610 return net::OK; | 608 return net::OK; |
611 } | 609 } |
612 cache_complete_callback_ = callback; | 610 cache_complete_callback_ = callback; |
613 return net::ERR_IO_PENDING; | 611 return net::ERR_IO_PENDING; |
614 } | 612 } |
615 | 613 |
616 } // namespace content | 614 } // namespace content |
617 | 615 |
OLD | NEW |