| 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 "net/base/cache_type.h" | 11 #include "net/base/cache_type.h" |
| 11 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 12 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 static const base::FilePath::CharType kGpuCachePath[] = | 19 static const base::FilePath::CharType kGpuCachePath[] = |
| 19 FILE_PATH_LITERAL("GPUCache"); | 20 FILE_PATH_LITERAL("GPUCache"); |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 if (!iter->second.empty()) { | 496 if (!iter->second.empty()) { |
| 496 iter->second.front()->Clear(); | 497 iter->second.front()->Clear(); |
| 497 return; | 498 return; |
| 498 } | 499 } |
| 499 | 500 |
| 500 shader_clear_map_.erase(path); | 501 shader_clear_map_.erase(path); |
| 501 } | 502 } |
| 502 | 503 |
| 503 ShaderDiskCache::ShaderDiskCache(const base::FilePath& cache_path) | 504 ShaderDiskCache::ShaderDiskCache(const base::FilePath& cache_path) |
| 504 : cache_available_(false), | 505 : cache_available_(false), |
| 505 max_cache_size_(0), | |
| 506 host_id_(0), | 506 host_id_(0), |
| 507 cache_path_(cache_path), | 507 cache_path_(cache_path), |
| 508 is_initialized_(false), | 508 is_initialized_(false), |
| 509 backend_(NULL) { | 509 backend_(NULL) { |
| 510 ShaderCacheFactory::GetInstance()->AddToCache(cache_path_, this); | 510 ShaderCacheFactory::GetInstance()->AddToCache(cache_path_, this); |
| 511 } | 511 } |
| 512 | 512 |
| 513 ShaderDiskCache::~ShaderDiskCache() { | 513 ShaderDiskCache::~ShaderDiskCache() { |
| 514 ShaderCacheFactory::GetInstance()->RemoveFromCache(cache_path_); | 514 ShaderCacheFactory::GetInstance()->RemoveFromCache(cache_path_); |
| 515 if (backend_) | 515 if (backend_) |
| 516 delete backend_; | 516 delete backend_; |
| 517 } | 517 } |
| 518 | 518 |
| 519 void ShaderDiskCache::Init() { | 519 void ShaderDiskCache::Init() { |
| 520 if (is_initialized_) { | 520 if (is_initialized_) { |
| 521 NOTREACHED(); // can't initialize disk cache twice. | 521 NOTREACHED(); // can't initialize disk cache twice. |
| 522 return; | 522 return; |
| 523 } | 523 } |
| 524 is_initialized_ = true; | 524 is_initialized_ = true; |
| 525 | 525 |
| 526 int rv = disk_cache::CreateCacheBackend( | 526 int rv = disk_cache::CreateCacheBackend( |
| 527 net::SHADER_CACHE, | 527 net::SHADER_CACHE, |
| 528 net::CACHE_BACKEND_BLOCKFILE, | 528 net::CACHE_BACKEND_BLOCKFILE, |
| 529 cache_path_.Append(kGpuCachePath), | 529 cache_path_.Append(kGpuCachePath), |
| 530 max_cache_size_, | 530 gpu::kDefaultMaxProgramCacheMemoryBytes, |
| 531 true, | 531 true, |
| 532 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE).get(), | 532 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE).get(), |
| 533 NULL, | 533 NULL, |
| 534 &backend_, | 534 &backend_, |
| 535 base::Bind(&ShaderDiskCache::CacheCreatedCallback, this)); | 535 base::Bind(&ShaderDiskCache::CacheCreatedCallback, this)); |
| 536 | 536 |
| 537 if (rv == net::OK) | 537 if (rv == net::OK) |
| 538 cache_available_ = true; | 538 cache_available_ = true; |
| 539 } | 539 } |
| 540 | 540 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 const net::CompletionCallback& callback) { | 609 const net::CompletionCallback& callback) { |
| 610 if (entry_map_.empty()) { | 610 if (entry_map_.empty()) { |
| 611 return net::OK; | 611 return net::OK; |
| 612 } | 612 } |
| 613 cache_complete_callback_ = callback; | 613 cache_complete_callback_ = callback; |
| 614 return net::ERR_IO_PENDING; | 614 return net::ERR_IO_PENDING; |
| 615 } | 615 } |
| 616 | 616 |
| 617 } // namespace content | 617 } // namespace content |
| 618 | 618 |
| OLD | NEW |