Chromium Code Reviews| Index: content/browser/gpu/shader_disk_cache_impl.cc |
| diff --git a/content/browser/gpu/shader_disk_cache.cc b/content/browser/gpu/shader_disk_cache_impl.cc |
| similarity index 68% |
| rename from content/browser/gpu/shader_disk_cache.cc |
| rename to content/browser/gpu/shader_disk_cache_impl.cc |
| index ca309370e259798aa72dcbda0b89baf470e0037a..516733c2d24b1d024720190300d98326721f3a87 100644 |
| --- a/content/browser/gpu/shader_disk_cache.cc |
| +++ b/content/browser/gpu/shader_disk_cache_impl.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "content/browser/gpu/shader_disk_cache.h" |
| +#include "content/browser/gpu/shader_disk_cache_impl.h" |
| #include "base/threading/thread_checker.h" |
| #include "content/browser/gpu/gpu_process_host.h" |
| @@ -101,9 +101,10 @@ class ShaderDiskReadHelper |
| DISALLOW_COPY_AND_ASSIGN(ShaderDiskReadHelper); |
| }; |
| -ShaderDiskCacheEntry::ShaderDiskCacheEntry(base::WeakPtr<ShaderDiskCache> cache, |
| - const std::string& key, |
| - const std::string& shader) |
| +ShaderDiskCacheEntry::ShaderDiskCacheEntry( |
| + base::WeakPtr<ShaderDiskCache> cache, |
| + const std::string& key, |
| + const std::string& shader) |
|
jonathan.backer
2013/03/20 18:39:05
Why reformat?
dsinclair
2013/03/21 17:46:59
Done. For a change which has since been reverted.
|
| : cache_(cache), |
| op_type_(OPEN_ENTRY), |
| key_(key), |
| @@ -177,7 +178,6 @@ int ShaderDiskCacheEntry::WriteCallback(int rv) { |
| DCHECK(CalledOnValidThread()); |
| // Called through OnOpComplete, so we know |cache_| is valid. |
| if (rv != net::OK) { |
| - LOG(ERROR) << "Failed to create shader cache entry: " << rv; |
|
jonathan.backer
2013/03/20 18:39:05
Still an error, no?
dsinclair
2013/03/21 17:46:59
Done.
|
| cache_->EntryComplete(this); |
| op_type_ = TERMINATE; |
| return rv; |
| @@ -309,51 +309,105 @@ ShaderDiskReadHelper::~ShaderDiskReadHelper() { |
| base::Bind(&EntryCloser, entry_)); |
| } |
| -ShaderCacheFactory* ShaderCacheFactory::GetInstance() { |
| - return Singleton<ShaderCacheFactory, |
| - LeakySingletonTraits<ShaderCacheFactory> >::get(); |
| +// static |
| +ShaderCacheFactoryImpl* ShaderCacheFactoryImpl::GetInstance() { |
| + return Singleton<ShaderCacheFactoryImpl, |
| + LeakySingletonTraits<ShaderCacheFactoryImpl> >::get(); |
| } |
| -ShaderCacheFactory::ShaderCacheFactory() { |
| +ShaderCacheFactoryImpl::ShaderCacheFactoryImpl() |
| + : op_type_(CREATE_CACHE) { |
|
jonathan.backer
2013/03/20 18:39:05
Why CREATE_CACHE? There hasn't been a clear reques
dsinclair
2013/03/21 17:46:59
Good point. Made it TERMINATE so nothing will happ
|
| } |
| -ShaderCacheFactory::~ShaderCacheFactory() { |
| +ShaderCacheFactoryImpl::~ShaderCacheFactoryImpl() { |
| } |
| -void ShaderCacheFactory::SetCacheInfo(int32 client_id, |
| - const base::FilePath& path) { |
| - client_id_to_path_map_[client_id] = path.Append(kGpuCachePath); |
| +void ShaderCacheFactoryImpl::SetCacheInfo(int32 client_id, |
| + const base::FilePath& path) { |
| + client_id_to_path_map_[client_id] = path; |
| } |
| -void ShaderCacheFactory::RemoveCacheInfo(int32 client_id) { |
| +void ShaderCacheFactoryImpl::RemoveCacheInfo(int32 client_id) { |
| client_id_to_path_map_.erase(client_id); |
| } |
| -scoped_refptr<ShaderDiskCache> ShaderCacheFactory::Get(int32 client_id) { |
| - ClientIdToPathMap::iterator client_iter = |
| +scoped_refptr<ShaderDiskCache> ShaderCacheFactoryImpl::Get( |
| + int32 client_id) { |
| + ClientIdToPathMap::iterator iter = |
| client_id_to_path_map_.find(client_id); |
| - if (client_iter == client_id_to_path_map_.end()) |
| + if (iter == client_id_to_path_map_.end()) |
| return NULL; |
| + return ShaderCacheFactoryImpl::GetByPath(iter->second); |
| +} |
| - ShaderCacheMap::iterator iter = shader_cache_map_.find(client_iter->second); |
| +scoped_refptr<ShaderDiskCache> ShaderCacheFactoryImpl::GetByPath( |
| + const base::FilePath& path) { |
| + ShaderCacheMap::iterator iter = shader_cache_map_.find(path); |
| if (iter != shader_cache_map_.end()) |
| return iter->second; |
| - ShaderDiskCache* cache = new ShaderDiskCache(client_iter->second); |
| + ShaderDiskCache* cache = new ShaderDiskCache(path); |
| cache->Init(); |
| - |
| return cache; |
| } |
| -void ShaderCacheFactory::AddToCache(const base::FilePath& key, |
| - ShaderDiskCache* cache) { |
| +void ShaderCacheFactoryImpl::AddToCache(const base::FilePath& key, |
| + ShaderDiskCache* cache) { |
| shader_cache_map_[key] = cache; |
| } |
| -void ShaderCacheFactory::RemoveFromCache(const base::FilePath& key) { |
| +void ShaderCacheFactoryImpl::RemoveFromCache(const base::FilePath& key) { |
| shader_cache_map_.erase(key); |
| } |
| +void ShaderCacheFactoryImpl::ClearByPath(const base::FilePath& path, |
| + const base::Time& delete_begin, |
| + const base::Time& delete_end, |
| + const base::Closure& callback) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + DCHECK(!callback.is_null()); |
| + |
| + clear_path_ = path; |
| + delete_begin_ = delete_begin; |
| + delete_end_ = delete_end; |
| + clear_callback_ = callback; |
| + |
| + op_type_ = CREATE_CACHE; |
| + DoClearShaderCache(net::OK); |
| +} |
| + |
| +void ShaderCacheFactoryImpl::DoClearShaderCache(int rv) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + |
| + while (rv != net::ERR_IO_PENDING) { |
| + switch (op_type_) { |
| + case CREATE_CACHE: |
| + clear_shader_cache_ = GetByPath(clear_path_); |
| + rv = clear_shader_cache_->SetAvailableCallback( |
| + base::Bind(&ShaderCacheFactoryImpl::DoClearShaderCache, |
| + base::Unretained(this))); // We're a singleton. |
| + op_type_ = DELETE_CACHE; |
| + break; |
| + case DELETE_CACHE: |
| + rv = clear_shader_cache_->Clear( |
| + delete_begin_, delete_end_, |
| + base::Bind(&ShaderCacheFactoryImpl::DoClearShaderCache, |
| + base::Unretained(this))); // We're a singleton. |
| + op_type_ = TERMINATE; |
| + break; |
| + case TERMINATE: |
| + clear_shader_cache_ = NULL; |
| + clear_callback_.Run(); |
| + rv = net::ERR_IO_PENDING; // Break the loop. |
| + break; |
| + default: |
| + NOTREACHED(); // Invalid state provided. |
| + op_type_ = TERMINATE; |
| + break; |
| + } |
| + } |
| +} |
| + |
| ShaderDiskCache::ShaderDiskCache(const base::FilePath& cache_path) |
| : cache_available_(false), |
| max_cache_size_(0), |
| @@ -361,11 +415,13 @@ ShaderDiskCache::ShaderDiskCache(const base::FilePath& cache_path) |
| cache_path_(cache_path), |
| is_initialized_(false), |
| backend_(NULL) { |
| - ShaderCacheFactory::GetInstance()->AddToCache(cache_path_, this); |
| + static_cast<ShaderCacheFactoryImpl*>(ShaderCacheFactory::GetInstance())-> |
|
jonathan.backer
2013/03/20 18:39:05
Call the Impl getter and skip the cast?
dsinclair
2013/03/21 17:46:59
Done.
|
| + AddToCache(cache_path_, this); |
| } |
| ShaderDiskCache::~ShaderDiskCache() { |
| - ShaderCacheFactory::GetInstance()->RemoveFromCache(cache_path_); |
| + static_cast<ShaderCacheFactoryImpl*>(ShaderCacheFactory::GetInstance())-> |
|
jonathan.backer
2013/03/20 18:39:05
Ditto.
dsinclair
2013/03/21 17:46:59
Done.
|
| + RemoveFromCache(cache_path_); |
| } |
| void ShaderDiskCache::Init() { |
| @@ -377,7 +433,7 @@ void ShaderDiskCache::Init() { |
| int rv = disk_cache::CreateCacheBackend( |
| net::SHADER_CACHE, |
| - cache_path_, |
| + cache_path_.Append(kGpuCachePath), |
| max_cache_size_, |
| true, |
| BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE), |
| @@ -389,7 +445,16 @@ void ShaderDiskCache::Init() { |
| cache_available_ = true; |
| } |
| -void ShaderDiskCache::Cache(const std::string& key, const std::string& shader) { |
| +void ShaderDiskCache::set_host_id(int host_id) { |
| + host_id_ = host_id; |
| +} |
| + |
| +void ShaderDiskCache::set_max_cache_size(size_t max_cache_size) { |
| + max_cache_size_ = max_cache_size; |
| +} |
| + |
| +void ShaderDiskCache::Cache(const std::string& key, |
| + const std::string& shader) { |
|
jonathan.backer
2013/03/20 18:39:05
Why reformat?
dsinclair
2013/03/21 17:46:59
Reverted change. Fixed.
|
| if (!cache_available_) |
| return; |
| @@ -400,16 +465,41 @@ void ShaderDiskCache::Cache(const std::string& key, const std::string& shader) { |
| entry_map_[shim] = shim; |
| } |
| +int ShaderDiskCache::Clear( |
| + const base::Time begin_time, const base::Time end_time, |
| + const net::CompletionCallback& completion_callback) { |
| + int rv; |
| + if (begin_time.is_null()) { |
| + rv = backend_->DoomAllEntries(completion_callback); |
| + } else { |
| + rv = backend_->DoomEntriesBetween(begin_time, end_time, |
| + completion_callback); |
| + } |
| + return rv; |
| +} |
| + |
| +int ShaderDiskCache::SetAvailableCallback( |
| + const net::CompletionCallback& callback) { |
| + if (cache_available_) |
| + return net::OK; |
| + available_callback_ = callback; |
| + return net::ERR_IO_PENDING; |
| +} |
| + |
| void ShaderDiskCache::CacheCreatedCallback(int rv) { |
| if (rv != net::OK) { |
| LOG(ERROR) << "Shader Cache Creation failed: " << rv; |
| return; |
| } |
| - |
| cache_available_ = true; |
| helper_ = new ShaderDiskReadHelper(AsWeakPtr(), host_id_); |
| helper_->LoadCache(); |
| + |
| + if (!available_callback_.is_null()) { |
| + available_callback_.Run(net::OK); |
| + available_callback_.Reset(); |
| + } |
| } |
| void ShaderDiskCache::EntryComplete(void* entry) { |