| 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 #ifndef CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ | 5 #ifndef GPU_IPC_HOST_SHADER_DISK_CACHE_H_ |
| 6 #define CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ | 6 #define GPU_IPC_HOST_SHADER_DISK_CACHE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <queue> | 11 #include <queue> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 18 #include "content/common/content_export.h" | |
| 19 #include "net/disk_cache/disk_cache.h" | 18 #include "net/disk_cache/disk_cache.h" |
| 20 | 19 |
| 21 namespace content { | 20 namespace gpu { |
| 22 | 21 |
| 23 class ShaderCacheFactory; | 22 class ShaderCacheFactory; |
| 24 class ShaderDiskCacheEntry; | 23 class ShaderDiskCacheEntry; |
| 25 class ShaderDiskReadHelper; | 24 class ShaderDiskReadHelper; |
| 26 class ShaderClearHelper; | 25 class ShaderClearHelper; |
| 27 | 26 |
| 28 // ShaderDiskCache is the interface to the on disk cache for | 27 // ShaderDiskCache is the interface to the on disk cache for |
| 29 // GL shaders. | 28 // GL shaders. |
| 30 class CONTENT_EXPORT ShaderDiskCache | 29 class ShaderDiskCache : public base::RefCounted<ShaderDiskCache> { |
| 31 : public base::RefCounted<ShaderDiskCache> { | |
| 32 public: | 30 public: |
| 33 using ShaderLoadedCallback = | 31 using ShaderLoadedCallback = |
| 34 base::Callback<void(const std::string&, const std::string&)>; | 32 base::Callback<void(const std::string&, const std::string&)>; |
| 35 | 33 |
| 36 void set_shader_loaded_callback(const ShaderLoadedCallback& callback) { | 34 void set_shader_loaded_callback(const ShaderLoadedCallback& callback) { |
| 37 shader_loaded_callback_ = callback; | 35 shader_loaded_callback_ = callback; |
| 38 } | 36 } |
| 39 | 37 |
| 40 // Store the |shader| into the cache under |key|. | 38 // Store the |shader| into the cache under |key|. |
| 41 void Cache(const std::string& key, const std::string& shader); | 39 void Cache(const std::string& key, const std::string& shader); |
| 42 | 40 |
| 43 // Clear a range of entries. This supports unbounded deletes in either | 41 // Clear a range of entries. This supports unbounded deletes in either |
| 44 // direction by using null Time values for either |begin_time| or |end_time|. | 42 // direction by using null Time values for either |begin_time| or |end_time|. |
| 45 // The return value is a net error code. If this method returns | 43 // The return value is a net error code. If this method returns |
| 46 // ERR_IO_PENDING, the |completion_callback| will be invoked when the | 44 // ERR_IO_PENDING, the |completion_callback| will be invoked when the |
| 47 // operation completes. | 45 // operation completes. |
| 48 int Clear( | 46 int Clear(const base::Time begin_time, |
| 49 const base::Time begin_time, | 47 const base::Time end_time, |
| 50 const base::Time end_time, | 48 const net::CompletionCallback& completion_callback); |
| 51 const net::CompletionCallback& completion_callback); | |
| 52 | 49 |
| 53 // Sets a callback for when the cache is available. If the cache is | 50 // Sets a callback for when the cache is available. If the cache is |
| 54 // already available the callback will not be called and net::OK is returned. | 51 // already available the callback will not be called and net::OK is returned. |
| 55 // If the callback is set net::ERR_IO_PENDING is returned and the callback | 52 // If the callback is set net::ERR_IO_PENDING is returned and the callback |
| 56 // will be executed when the cache is available. | 53 // will be executed when the cache is available. |
| 57 int SetAvailableCallback(const net::CompletionCallback& callback); | 54 int SetAvailableCallback(const net::CompletionCallback& callback); |
| 58 | 55 |
| 59 // Returns the number of elements currently in the cache. | 56 // Returns the number of elements currently in the cache. |
| 60 int32_t Size(); | 57 int32_t Size(); |
| 61 | 58 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 std::unique_ptr<ShaderDiskReadHelper> helper_; | 94 std::unique_ptr<ShaderDiskReadHelper> helper_; |
| 98 std::unordered_map<ShaderDiskCacheEntry*, | 95 std::unordered_map<ShaderDiskCacheEntry*, |
| 99 std::unique_ptr<ShaderDiskCacheEntry>> | 96 std::unique_ptr<ShaderDiskCacheEntry>> |
| 100 entries_; | 97 entries_; |
| 101 | 98 |
| 102 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCache); | 99 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCache); |
| 103 }; | 100 }; |
| 104 | 101 |
| 105 // ShaderCacheFactory maintains a cache of ShaderDiskCache objects | 102 // ShaderCacheFactory maintains a cache of ShaderDiskCache objects |
| 106 // so we only create one per profile directory. | 103 // so we only create one per profile directory. |
| 107 class CONTENT_EXPORT ShaderCacheFactory | 104 class ShaderCacheFactory : NON_EXPORTED_BASE(public base::ThreadChecker) { |
| 108 : NON_EXPORTED_BASE(public base::ThreadChecker) { | |
| 109 public: | 105 public: |
| 110 explicit ShaderCacheFactory( | 106 explicit ShaderCacheFactory( |
| 111 scoped_refptr<base::SingleThreadTaskRunner> cache_task_runner); | 107 scoped_refptr<base::SingleThreadTaskRunner> cache_task_runner); |
| 112 ~ShaderCacheFactory(); | 108 ~ShaderCacheFactory(); |
| 113 | 109 |
| 114 // Clear the shader disk cache for the given |path|. This supports unbounded | 110 // Clear the shader disk cache for the given |path|. This supports unbounded |
| 115 // deletes in either direction by using null Time values for either | 111 // deletes in either direction by using null Time values for either |
| 116 // |begin_time| or |end_time|. The |callback| will be executed when the | 112 // |begin_time| or |end_time|. The |callback| will be executed when the |
| 117 // clear is complete. | 113 // clear is complete. |
| 118 void ClearByPath(const base::FilePath& path, | 114 void ClearByPath(const base::FilePath& path, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 149 using ClientIdToPathMap = std::map<int32_t, base::FilePath>; | 145 using ClientIdToPathMap = std::map<int32_t, base::FilePath>; |
| 150 ClientIdToPathMap client_id_to_path_map_; | 146 ClientIdToPathMap client_id_to_path_map_; |
| 151 | 147 |
| 152 using ShaderClearQueue = std::queue<std::unique_ptr<ShaderClearHelper>>; | 148 using ShaderClearQueue = std::queue<std::unique_ptr<ShaderClearHelper>>; |
| 153 using ShaderClearMap = std::map<base::FilePath, ShaderClearQueue>; | 149 using ShaderClearMap = std::map<base::FilePath, ShaderClearQueue>; |
| 154 ShaderClearMap shader_clear_map_; | 150 ShaderClearMap shader_clear_map_; |
| 155 | 151 |
| 156 DISALLOW_COPY_AND_ASSIGN(ShaderCacheFactory); | 152 DISALLOW_COPY_AND_ASSIGN(ShaderCacheFactory); |
| 157 }; | 153 }; |
| 158 | 154 |
| 159 } // namespace content | 155 } // namespace gpu |
| 160 | 156 |
| 161 #endif // CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ | 157 #endif // GPU_IPC_HOST_SHADER_DISK_CACHE_H_ |
| OLD | NEW |