| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ | |
| 6 #define CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/singleton.h" | |
| 14 #include "net/disk_cache/disk_cache.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 class ShaderDiskCacheEntry; | |
| 19 class ShaderDiskReadHelper; | |
| 20 | |
| 21 // ShaderDiskCache is the interface to the on disk cache for | |
| 22 // GL shaders. | |
| 23 // | |
| 24 // While this class is both RefCounted and SupportsWeakPtr | |
| 25 // when using this class you should work with the RefCounting. | |
| 26 // The WeakPtr is needed interally. | |
| 27 class ShaderDiskCache | |
| 28 : public base::RefCounted<ShaderDiskCache>, | |
| 29 public base::SupportsWeakPtr<ShaderDiskCache> { | |
| 30 public: | |
| 31 void Init(); | |
| 32 | |
| 33 void set_host_id(int host_id) { host_id_ = host_id; } | |
| 34 void set_max_cache_size(size_t max_cache_size) { | |
| 35 max_cache_size_ = max_cache_size; | |
| 36 } | |
| 37 | |
| 38 void Cache(const std::string& key, const std::string& shader); | |
| 39 | |
| 40 private: | |
| 41 friend class base::RefCounted<ShaderDiskCache>; | |
| 42 friend class ShaderDiskCacheEntry; | |
| 43 friend class ShaderDiskReadHelper; | |
| 44 friend class ShaderCacheFactory; | |
| 45 | |
| 46 explicit ShaderDiskCache(const base::FilePath& cache_path); | |
| 47 ~ShaderDiskCache(); | |
| 48 | |
| 49 void CacheCreatedCallback(int rv); | |
| 50 | |
| 51 disk_cache::Backend* backend() { return backend_; } | |
| 52 | |
| 53 void EntryComplete(void* entry); | |
| 54 void ReadComplete(); | |
| 55 | |
| 56 bool cache_available_; | |
| 57 size_t max_cache_size_; | |
| 58 int host_id_; | |
| 59 base::FilePath cache_path_; | |
| 60 bool is_initialized_; | |
| 61 | |
| 62 disk_cache::Backend* backend_; | |
| 63 | |
| 64 scoped_refptr<ShaderDiskReadHelper> helper_; | |
| 65 std::map<void*, scoped_refptr<ShaderDiskCacheEntry> > entry_map_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCache); | |
| 68 }; | |
| 69 | |
| 70 // ShaderCacheFactory maintains a cache of ShaderDiskCache objects | |
| 71 // so we only create one per profile directory. | |
| 72 class ShaderCacheFactory { | |
| 73 public: | |
| 74 static ShaderCacheFactory* GetInstance(); | |
| 75 | |
| 76 scoped_refptr<ShaderDiskCache> Get(int32 client_id); | |
| 77 | |
| 78 void SetCacheInfo(int32 client_id, const base::FilePath& path); | |
| 79 void RemoveCacheInfo(int32 client_id); | |
| 80 | |
| 81 void AddToCache(const base::FilePath& path, ShaderDiskCache* cache); | |
| 82 void RemoveFromCache(const base::FilePath& path); | |
| 83 | |
| 84 private: | |
| 85 friend struct DefaultSingletonTraits<ShaderCacheFactory>; | |
| 86 | |
| 87 ShaderCacheFactory(); | |
| 88 ~ShaderCacheFactory(); | |
| 89 | |
| 90 typedef std::map<base::FilePath, ShaderDiskCache*> ShaderCacheMap; | |
| 91 ShaderCacheMap shader_cache_map_; | |
| 92 | |
| 93 typedef std::map<int32, base::FilePath> ClientIdToPathMap; | |
| 94 ClientIdToPathMap client_id_to_path_map_; | |
| 95 | |
| 96 DISALLOW_COPY_AND_ASSIGN(ShaderCacheFactory); | |
| 97 }; | |
| 98 | |
| 99 } // namespace content | |
| 100 | |
| 101 #endif // CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ | |
| 102 | |
| OLD | NEW |