Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: content/browser/gpu/shader_disk_cache_impl.h

Issue 12500009: Add the ability to clear the shader disk cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_IMPL_H_
6 #define CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ 6 #define CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_IMPL_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/public/browser/shader_disk_cache.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 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(
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
40 private: 54 private:
41 friend class base::RefCounted<ShaderDiskCache>; 55 friend class base::RefCounted<ShaderDiskCache>;
42 friend class ShaderDiskCacheEntry; 56 friend class ShaderDiskCacheEntry;
43 friend class ShaderDiskReadHelper; 57 friend class ShaderDiskReadHelper;
44 friend class ShaderCacheFactory; 58 friend class ShaderCacheFactoryImpl;
45 59
46 explicit ShaderDiskCache(const base::FilePath& cache_path); 60 explicit ShaderDiskCache(const base::FilePath& cache_path);
47 ~ShaderDiskCache(); 61 ~ShaderDiskCache();
48 62
49 void CacheCreatedCallback(int rv); 63 void CacheCreatedCallback(int rv);
50 64
51 disk_cache::Backend* backend() { return backend_; } 65 disk_cache::Backend* backend() { return backend_; }
52 66
53 void EntryComplete(void* entry); 67 void EntryComplete(void* entry);
54 void ReadComplete(); 68 void ReadComplete();
55 69
56 bool cache_available_; 70 bool cache_available_;
57 size_t max_cache_size_; 71 size_t max_cache_size_;
58 int host_id_; 72 int host_id_;
59 base::FilePath cache_path_; 73 base::FilePath cache_path_;
60 bool is_initialized_; 74 bool is_initialized_;
75 net::CompletionCallback available_callback_;
61 76
62 disk_cache::Backend* backend_; 77 disk_cache::Backend* backend_;
63 78
64 scoped_refptr<ShaderDiskReadHelper> helper_; 79 scoped_refptr<ShaderDiskReadHelper> helper_;
65 std::map<void*, scoped_refptr<ShaderDiskCacheEntry> > entry_map_; 80 std::map<void*, scoped_refptr<ShaderDiskCacheEntry> > entry_map_;
66 81
67 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCache); 82 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCache);
68 }; 83 };
69 84
70 // ShaderCacheFactory maintains a cache of ShaderDiskCache objects 85 // ShaderCacheFactory maintains a cache of ShaderDiskCacheImpl objects
71 // so we only create one per profile directory. 86 // so we only create one per profile directory.
72 class ShaderCacheFactory { 87 class ShaderCacheFactoryImpl : public content::ShaderCacheFactory {
73 public: 88 public:
74 static ShaderCacheFactory* GetInstance(); 89 static ShaderCacheFactoryImpl* GetInstance();
90
91 virtual void ClearByPath(const base::FilePath& path,
92 const base::Time& begin_time,
93 const base::Time& end_time,
94 const base::Closure& callback) OVERRIDE;
75 95
76 scoped_refptr<ShaderDiskCache> Get(int32 client_id); 96 scoped_refptr<ShaderDiskCache> Get(int32 client_id);
77 97
78 void SetCacheInfo(int32 client_id, const base::FilePath& path); 98 void SetCacheInfo(int32 client_id, const base::FilePath& path);
79 void RemoveCacheInfo(int32 client_id); 99 void RemoveCacheInfo(int32 client_id);
80 100
81 void AddToCache(const base::FilePath& path, ShaderDiskCache* cache); 101 void AddToCache(const base::FilePath& path, ShaderDiskCache* cache);
82 void RemoveFromCache(const base::FilePath& path); 102 void RemoveFromCache(const base::FilePath& path);
83 103
84 private: 104 private:
85 friend struct DefaultSingletonTraits<ShaderCacheFactory>; 105 friend struct DefaultSingletonTraits<ShaderCacheFactoryImpl>;
106 friend class ShaderCacheFactory;
107 friend class ShaderClearHelper;
86 108
87 ShaderCacheFactory(); 109 ShaderCacheFactoryImpl();
88 ~ShaderCacheFactory(); 110 virtual ~ShaderCacheFactoryImpl();
111
112 scoped_refptr<ShaderDiskCache> GetByPath(const base::FilePath& path);
113 void CacheCleared(const base::FilePath& path);
89 114
90 typedef std::map<base::FilePath, ShaderDiskCache*> ShaderCacheMap; 115 typedef std::map<base::FilePath, ShaderDiskCache*> ShaderCacheMap;
91 ShaderCacheMap shader_cache_map_; 116 ShaderCacheMap shader_cache_map_;
92 117
93 typedef std::map<int32, base::FilePath> ClientIdToPathMap; 118 typedef std::map<int32, base::FilePath> ClientIdToPathMap;
94 ClientIdToPathMap client_id_to_path_map_; 119 ClientIdToPathMap client_id_to_path_map_;
95 120
96 DISALLOW_COPY_AND_ASSIGN(ShaderCacheFactory); 121 typedef std::queue<scoped_refptr<ShaderClearHelper> > ShaderClearQueue;
122 typedef std::map<base::FilePath, ShaderClearQueue> ShaderClearMap;
123 ShaderClearMap shader_clear_map_;
124
125 DISALLOW_COPY_AND_ASSIGN(ShaderCacheFactoryImpl);
97 }; 126 };
98 127
99 } // namespace content 128 } // namespace content
100 129
101 #endif // CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ 130 #endif // CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_IMPL_H_
102 131
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698