| 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" |
| 11 #include "net/base/cache_type.h" | 11 #include "net/base/cache_type.h" |
| 12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 static const base::FilePath::CharType kGpuCachePath[] = | 19 static const base::FilePath::CharType kGpuCachePath[] = |
| 20 FILE_PATH_LITERAL("GPUCache"); | 20 FILE_PATH_LITERAL("GPUCache"); |
| 21 | 21 |
| 22 void EntryCloser(disk_cache::Entry* entry) { | 22 void EntryCloser(disk_cache::Entry* entry) { |
| 23 entry->Close(); | 23 entry->Close(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void FreeDiskCacheIterator(scoped_ptr<disk_cache::Backend::Iterator> iterator) { |
| 27 } |
| 28 |
| 26 } // namespace | 29 } // namespace |
| 27 | 30 |
| 28 // ShaderDiskCacheEntry handles the work of caching/updating the cached | 31 // ShaderDiskCacheEntry handles the work of caching/updating the cached |
| 29 // shaders. | 32 // shaders. |
| 30 class ShaderDiskCacheEntry | 33 class ShaderDiskCacheEntry |
| 31 : public base::ThreadChecker, | 34 : public base::ThreadChecker, |
| 32 public base::RefCounted<ShaderDiskCacheEntry> { | 35 public base::RefCounted<ShaderDiskCacheEntry> { |
| 33 public: | 36 public: |
| 34 ShaderDiskCacheEntry(base::WeakPtr<ShaderDiskCache> cache, | 37 ShaderDiskCacheEntry(base::WeakPtr<ShaderDiskCache> cache, |
| 35 const std::string& key, | 38 const std::string& key, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 91 |
| 89 void OnOpComplete(int rv); | 92 void OnOpComplete(int rv); |
| 90 | 93 |
| 91 int OpenNextEntry(); | 94 int OpenNextEntry(); |
| 92 int OpenNextEntryComplete(int rv); | 95 int OpenNextEntryComplete(int rv); |
| 93 int ReadComplete(int rv); | 96 int ReadComplete(int rv); |
| 94 int IterationComplete(int rv); | 97 int IterationComplete(int rv); |
| 95 | 98 |
| 96 base::WeakPtr<ShaderDiskCache> cache_; | 99 base::WeakPtr<ShaderDiskCache> cache_; |
| 97 OpType op_type_; | 100 OpType op_type_; |
| 98 void* iter_; | 101 scoped_ptr<disk_cache::Backend::Iterator> iter_; |
| 99 scoped_refptr<net::IOBufferWithSize> buf_; | 102 scoped_refptr<net::IOBufferWithSize> buf_; |
| 100 int host_id_; | 103 int host_id_; |
| 101 disk_cache::Entry* entry_; | 104 disk_cache::Entry* entry_; |
| 102 | 105 |
| 103 DISALLOW_COPY_AND_ASSIGN(ShaderDiskReadHelper); | 106 DISALLOW_COPY_AND_ASSIGN(ShaderDiskReadHelper); |
| 104 }; | 107 }; |
| 105 | 108 |
| 106 class ShaderClearHelper | 109 class ShaderClearHelper |
| 107 : public base::RefCounted<ShaderClearHelper>, | 110 : public base::RefCounted<ShaderClearHelper>, |
| 108 public base::SupportsWeakPtr<ShaderClearHelper> { | 111 public base::SupportsWeakPtr<ShaderClearHelper> { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 cache_->EntryComplete(this); | 239 cache_->EntryComplete(this); |
| 237 op_type_ = TERMINATE; | 240 op_type_ = TERMINATE; |
| 238 return rv; | 241 return rv; |
| 239 } | 242 } |
| 240 | 243 |
| 241 ShaderDiskReadHelper::ShaderDiskReadHelper( | 244 ShaderDiskReadHelper::ShaderDiskReadHelper( |
| 242 base::WeakPtr<ShaderDiskCache> cache, | 245 base::WeakPtr<ShaderDiskCache> cache, |
| 243 int host_id) | 246 int host_id) |
| 244 : cache_(cache), | 247 : cache_(cache), |
| 245 op_type_(OPEN_NEXT), | 248 op_type_(OPEN_NEXT), |
| 246 iter_(NULL), | |
| 247 buf_(NULL), | 249 buf_(NULL), |
| 248 host_id_(host_id), | 250 host_id_(host_id), |
| 249 entry_(NULL) { | 251 entry_(NULL) { |
| 250 } | 252 } |
| 251 | 253 |
| 252 void ShaderDiskReadHelper::LoadCache() { | 254 void ShaderDiskReadHelper::LoadCache() { |
| 253 DCHECK(CalledOnValidThread()); | 255 DCHECK(CalledOnValidThread()); |
| 254 if (!cache_.get()) | 256 if (!cache_.get()) |
| 255 return; | 257 return; |
| 256 OnOpComplete(net::OK); | 258 OnOpComplete(net::OK); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 284 rv = net::ERR_FAILED; | 286 rv = net::ERR_FAILED; |
| 285 break; | 287 break; |
| 286 } | 288 } |
| 287 } while (rv != net::ERR_IO_PENDING); | 289 } while (rv != net::ERR_IO_PENDING); |
| 288 } | 290 } |
| 289 | 291 |
| 290 int ShaderDiskReadHelper::OpenNextEntry() { | 292 int ShaderDiskReadHelper::OpenNextEntry() { |
| 291 DCHECK(CalledOnValidThread()); | 293 DCHECK(CalledOnValidThread()); |
| 292 // Called through OnOpComplete, so we know |cache_| is valid. | 294 // Called through OnOpComplete, so we know |cache_| is valid. |
| 293 op_type_ = OPEN_NEXT_COMPLETE; | 295 op_type_ = OPEN_NEXT_COMPLETE; |
| 294 return cache_->backend()->OpenNextEntry( | 296 if (!iter_) |
| 295 &iter_, | 297 iter_ = cache_->backend()->CreateIterator(); |
| 296 &entry_, | 298 return iter_->OpenNextEntry( |
| 297 base::Bind(&ShaderDiskReadHelper::OnOpComplete, this)); | 299 &entry_, base::Bind(&ShaderDiskReadHelper::OnOpComplete, this)); |
| 298 } | 300 } |
| 299 | 301 |
| 300 int ShaderDiskReadHelper::OpenNextEntryComplete(int rv) { | 302 int ShaderDiskReadHelper::OpenNextEntryComplete(int rv) { |
| 301 DCHECK(CalledOnValidThread()); | 303 DCHECK(CalledOnValidThread()); |
| 302 // Called through OnOpComplete, so we know |cache_| is valid. | 304 // Called through OnOpComplete, so we know |cache_| is valid. |
| 303 if (rv == net::ERR_FAILED) { | 305 if (rv == net::ERR_FAILED) { |
| 306 iter_.reset(); |
| 304 op_type_ = ITERATION_FINISHED; | 307 op_type_ = ITERATION_FINISHED; |
| 305 return net::OK; | 308 return net::OK; |
| 306 } | 309 } |
| 307 | 310 |
| 308 if (rv < 0) | 311 if (rv < 0) |
| 309 return rv; | 312 return rv; |
| 310 | 313 |
| 311 op_type_ = READ_COMPLETE; | 314 op_type_ = READ_COMPLETE; |
| 312 buf_ = new net::IOBufferWithSize(entry_->GetDataSize(1)); | 315 buf_ = new net::IOBufferWithSize(entry_->GetDataSize(1)); |
| 313 return entry_->ReadData( | 316 return entry_->ReadData( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 332 entry_->Close(); | 335 entry_->Close(); |
| 333 entry_ = NULL; | 336 entry_ = NULL; |
| 334 | 337 |
| 335 op_type_ = OPEN_NEXT; | 338 op_type_ = OPEN_NEXT; |
| 336 return net::OK; | 339 return net::OK; |
| 337 } | 340 } |
| 338 | 341 |
| 339 int ShaderDiskReadHelper::IterationComplete(int rv) { | 342 int ShaderDiskReadHelper::IterationComplete(int rv) { |
| 340 DCHECK(CalledOnValidThread()); | 343 DCHECK(CalledOnValidThread()); |
| 341 // Called through OnOpComplete, so we know |cache_| is valid. | 344 // Called through OnOpComplete, so we know |cache_| is valid. |
| 342 cache_->backend()->EndEnumeration(&iter_); | 345 iter_.reset(); |
| 343 iter_ = NULL; | |
| 344 op_type_ = TERMINATE; | 346 op_type_ = TERMINATE; |
| 345 return net::OK; | 347 return net::OK; |
| 346 } | 348 } |
| 347 | 349 |
| 348 ShaderDiskReadHelper::~ShaderDiskReadHelper() { | 350 ShaderDiskReadHelper::~ShaderDiskReadHelper() { |
| 349 if (entry_) | 351 if (entry_) { |
| 350 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 352 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 351 base::Bind(&EntryCloser, entry_)); | 353 base::Bind(&EntryCloser, entry_)); |
| 354 } |
| 355 if (iter_) { |
| 356 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 357 base::Bind(&FreeDiskCacheIterator, |
| 358 base::Passed(&iter_))); |
| 359 } |
| 352 } | 360 } |
| 353 | 361 |
| 354 ShaderClearHelper::ShaderClearHelper(scoped_refptr<ShaderDiskCache> cache, | 362 ShaderClearHelper::ShaderClearHelper(scoped_refptr<ShaderDiskCache> cache, |
| 355 const base::FilePath& path, | 363 const base::FilePath& path, |
| 356 const base::Time& delete_begin, | 364 const base::Time& delete_begin, |
| 357 const base::Time& delete_end, | 365 const base::Time& delete_end, |
| 358 const base::Closure& callback) | 366 const base::Closure& callback) |
| 359 : cache_(cache), | 367 : cache_(cache), |
| 360 op_type_(VERIFY_CACHE_SETUP), | 368 op_type_(VERIFY_CACHE_SETUP), |
| 361 path_(path), | 369 path_(path), |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 const net::CompletionCallback& callback) { | 616 const net::CompletionCallback& callback) { |
| 609 if (entry_map_.empty()) { | 617 if (entry_map_.empty()) { |
| 610 return net::OK; | 618 return net::OK; |
| 611 } | 619 } |
| 612 cache_complete_callback_ = callback; | 620 cache_complete_callback_ = callback; |
| 613 return net::ERR_IO_PENDING; | 621 return net::ERR_IO_PENDING; |
| 614 } | 622 } |
| 615 | 623 |
| 616 } // namespace content | 624 } // namespace content |
| 617 | 625 |
| OLD | NEW |