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 CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ |
6 #define CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ | 6 #define CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <queue> | |
9 #include <string> | 10 #include <string> |
10 | 11 |
11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
15 #include "content/common/content_export.h" | |
14 #include "net/disk_cache/disk_cache.h" | 16 #include "net/disk_cache/disk_cache.h" |
15 | 17 |
16 namespace content { | 18 namespace content { |
17 | 19 |
18 class ShaderDiskCacheEntry; | 20 class ShaderDiskCacheEntry; |
19 class ShaderDiskReadHelper; | 21 class ShaderDiskReadHelper; |
22 class ShaderClearHelper; | |
20 | 23 |
21 // ShaderDiskCache is the interface to the on disk cache for | 24 // ShaderDiskCache is the interface to the on disk cache for |
22 // GL shaders. | 25 // GL shaders. |
23 // | 26 // |
24 // While this class is both RefCounted and SupportsWeakPtr | 27 // While this class is both RefCounted and SupportsWeakPtr |
25 // when using this class you should work with the RefCounting. | 28 // when using this class you should work with the RefCounting. |
26 // The WeakPtr is needed interally. | 29 // The WeakPtr is needed interally. |
27 class ShaderDiskCache | 30 class CONTENT_EXPORT ShaderDiskCache |
28 : public base::RefCounted<ShaderDiskCache>, | 31 : public base::RefCounted<ShaderDiskCache>, |
29 public base::SupportsWeakPtr<ShaderDiskCache> { | 32 public base::SupportsWeakPtr<ShaderDiskCache> { |
30 public: | 33 public: |
31 void Init(); | 34 void Init(); |
32 | 35 |
33 void set_host_id(int host_id) { host_id_ = host_id; } | 36 void set_host_id(int host_id) { host_id_ = host_id; } |
34 void set_max_cache_size(size_t max_cache_size) { | 37 void set_max_cache_size(size_t max_cache_size) { |
35 max_cache_size_ = max_cache_size; | 38 max_cache_size_ = max_cache_size; |
36 } | 39 } |
37 | 40 |
38 void Cache(const std::string& key, const std::string& shader); | 41 void Cache(const std::string& key, const std::string& shader); |
39 | 42 |
43 int Clear( | |
jam
2013/04/02 17:34:50
nit: here and below, add comments for (at least) p
dsinclair
2013/04/03 18:59:23
Done.
| |
44 const base::Time begin_time, | |
45 const base::Time end_time, | |
46 const net::CompletionCallback& completion_callback); | |
47 | |
48 // Sets a callback for when the cache is available. If the cache is | |
49 // already available the callback will not be called and net::OK is returned. | |
50 // If the callback is set net::ERR_IO_PENDING is returned and the callback | |
51 // will be executed when the cache is available. | |
52 int SetAvailableCallback(const net::CompletionCallback& callback); | |
53 | |
54 int32 Size(); | |
55 | |
56 int SetCacheCompleteCallback(const net::CompletionCallback& callback); | |
57 | |
40 private: | 58 private: |
41 friend class base::RefCounted<ShaderDiskCache>; | 59 friend class base::RefCounted<ShaderDiskCache>; |
42 friend class ShaderDiskCacheEntry; | 60 friend class ShaderDiskCacheEntry; |
43 friend class ShaderDiskReadHelper; | 61 friend class ShaderDiskReadHelper; |
44 friend class ShaderCacheFactory; | 62 friend class ShaderCacheFactory; |
45 | 63 |
46 explicit ShaderDiskCache(const base::FilePath& cache_path); | 64 explicit ShaderDiskCache(const base::FilePath& cache_path); |
47 ~ShaderDiskCache(); | 65 ~ShaderDiskCache(); |
48 | 66 |
49 void CacheCreatedCallback(int rv); | 67 void CacheCreatedCallback(int rv); |
50 | 68 |
51 disk_cache::Backend* backend() { return backend_; } | 69 disk_cache::Backend* backend() { return backend_; } |
52 | 70 |
53 void EntryComplete(void* entry); | 71 void EntryComplete(void* entry); |
54 void ReadComplete(); | 72 void ReadComplete(); |
55 | 73 |
56 bool cache_available_; | 74 bool cache_available_; |
57 size_t max_cache_size_; | 75 size_t max_cache_size_; |
58 int host_id_; | 76 int host_id_; |
59 base::FilePath cache_path_; | 77 base::FilePath cache_path_; |
60 bool is_initialized_; | 78 bool is_initialized_; |
79 net::CompletionCallback available_callback_; | |
80 net::CompletionCallback cache_complete_callback_; | |
61 | 81 |
62 disk_cache::Backend* backend_; | 82 disk_cache::Backend* backend_; |
63 | 83 |
64 scoped_refptr<ShaderDiskReadHelper> helper_; | 84 scoped_refptr<ShaderDiskReadHelper> helper_; |
65 std::map<void*, scoped_refptr<ShaderDiskCacheEntry> > entry_map_; | 85 std::map<void*, scoped_refptr<ShaderDiskCacheEntry> > entry_map_; |
66 | 86 |
67 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCache); | 87 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCache); |
68 }; | 88 }; |
69 | 89 |
70 // ShaderCacheFactory maintains a cache of ShaderDiskCache objects | 90 // ShaderCacheFactory maintains a cache of ShaderDiskCache objects |
71 // so we only create one per profile directory. | 91 // so we only create one per profile directory. |
72 class ShaderCacheFactory { | 92 class CONTENT_EXPORT ShaderCacheFactory { |
73 public: | 93 public: |
74 static ShaderCacheFactory* GetInstance(); | 94 static ShaderCacheFactory* GetInstance(); |
75 | 95 |
96 void ClearByPath(const base::FilePath& path, | |
97 const base::Time& begin_time, | |
98 const base::Time& end_time, | |
99 const base::Closure& callback); | |
100 | |
76 scoped_refptr<ShaderDiskCache> Get(int32 client_id); | 101 scoped_refptr<ShaderDiskCache> Get(int32 client_id); |
77 | 102 |
78 void SetCacheInfo(int32 client_id, const base::FilePath& path); | 103 void SetCacheInfo(int32 client_id, const base::FilePath& path); |
79 void RemoveCacheInfo(int32 client_id); | 104 void RemoveCacheInfo(int32 client_id); |
80 | 105 |
81 void AddToCache(const base::FilePath& path, ShaderDiskCache* cache); | 106 void AddToCache(const base::FilePath& path, ShaderDiskCache* cache); |
82 void RemoveFromCache(const base::FilePath& path); | 107 void RemoveFromCache(const base::FilePath& path); |
83 | 108 |
84 private: | 109 private: |
85 friend struct DefaultSingletonTraits<ShaderCacheFactory>; | 110 friend struct DefaultSingletonTraits<ShaderCacheFactory>; |
111 friend class ShaderClearHelper; | |
86 | 112 |
87 ShaderCacheFactory(); | 113 ShaderCacheFactory(); |
88 ~ShaderCacheFactory(); | 114 virtual ~ShaderCacheFactory(); |
jam
2013/04/02 17:34:50
nit: not needed anymore?
dsinclair
2013/04/03 18:59:23
error: [chromium-style] Complex class/struct needs
jam
2013/04/04 14:53:31
I meant the virtual
dsinclair
2013/04/04 16:04:00
Oh, sorry. Done.
| |
115 | |
116 scoped_refptr<ShaderDiskCache> GetByPath(const base::FilePath& path); | |
117 void CacheCleared(const base::FilePath& path); | |
89 | 118 |
90 typedef std::map<base::FilePath, ShaderDiskCache*> ShaderCacheMap; | 119 typedef std::map<base::FilePath, ShaderDiskCache*> ShaderCacheMap; |
91 ShaderCacheMap shader_cache_map_; | 120 ShaderCacheMap shader_cache_map_; |
92 | 121 |
93 typedef std::map<int32, base::FilePath> ClientIdToPathMap; | 122 typedef std::map<int32, base::FilePath> ClientIdToPathMap; |
94 ClientIdToPathMap client_id_to_path_map_; | 123 ClientIdToPathMap client_id_to_path_map_; |
95 | 124 |
125 typedef std::queue<scoped_refptr<ShaderClearHelper> > ShaderClearQueue; | |
126 typedef std::map<base::FilePath, ShaderClearQueue> ShaderClearMap; | |
127 ShaderClearMap shader_clear_map_; | |
128 | |
96 DISALLOW_COPY_AND_ASSIGN(ShaderCacheFactory); | 129 DISALLOW_COPY_AND_ASSIGN(ShaderCacheFactory); |
97 }; | 130 }; |
98 | 131 |
99 } // namespace content | 132 } // namespace content |
100 | 133 |
101 #endif // CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ | 134 #endif // CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ |
102 | 135 |
OLD | NEW |