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

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 <string> 9 #include <string>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "content/public/browser/shader_disk_cache.h"
14 #include "net/disk_cache/disk_cache.h" 15 #include "net/disk_cache/disk_cache.h"
15 16
16 namespace content { 17 namespace content {
17 18
18 class ShaderDiskCacheEntry; 19 class ShaderDiskCacheEntry;
19 class ShaderDiskReadHelper; 20 class ShaderDiskReadHelper;
20 21
21 // ShaderDiskCache is the interface to the on disk cache for 22 // ShaderDiskCache is the interface to the on disk cache for
22 // GL shaders. 23 // GL shaders.
23 // 24 //
24 // While this class is both RefCounted and SupportsWeakPtr 25 // While this class is both RefCounted and SupportsWeakPtr
25 // when using this class you should work with the RefCounting. 26 // when using this class you should work with the RefCounting.
26 // The WeakPtr is needed interally. 27 // The WeakPtr is needed interally.
27 class ShaderDiskCache 28 class ShaderDiskCache
28 : public base::RefCounted<ShaderDiskCache>, 29 : public base::RefCounted<ShaderDiskCache>,
29 public base::SupportsWeakPtr<ShaderDiskCache> { 30 public base::SupportsWeakPtr<ShaderDiskCache> {
30 public: 31 public:
31 void Init(); 32 void Init();
32 33
33 void set_host_id(int host_id) { host_id_ = host_id; } 34 void set_host_id(int host_id);
jonathan.backer 2013/03/20 18:39:05 Why not inline?
dsinclair 2013/03/21 17:46:59 Will put back. Was removed because the compiler di
34 void set_max_cache_size(size_t max_cache_size) { 35 void set_max_cache_size(size_t max_cache_size);
35 max_cache_size_ = max_cache_size;
36 }
37 36
38 void Cache(const std::string& key, const std::string& shader); 37 void Cache(const std::string& key, const std::string& shader);
39 38
39 int Clear(
40 const base::Time begin_time,
41 const base::Time end_time,
42 const net::CompletionCallback& completion_callback);
43
44 // Sets a callback for when the cache is available. If the cache is
45 // already availble the callback will not be called and net::OK is returned.
46 // If the callback is set net::ERR_IO_PENDING is returned and the callback
47 // will be executed when the cache is available.
48 int SetAvailableCallback(const net::CompletionCallback& callback);
jonathan.backer 2013/03/20 18:39:05 s/availble/available
dsinclair 2013/03/21 17:46:59 Done.
49
40 private: 50 private:
41 friend class base::RefCounted<ShaderDiskCache>; 51 friend class base::RefCounted<ShaderDiskCache>;
42 friend class ShaderDiskCacheEntry; 52 friend class ShaderDiskCacheEntry;
43 friend class ShaderDiskReadHelper; 53 friend class ShaderDiskReadHelper;
44 friend class ShaderCacheFactory; 54 friend class ShaderCacheFactoryImpl;
45 55
46 explicit ShaderDiskCache(const base::FilePath& cache_path); 56 explicit ShaderDiskCache(const base::FilePath& cache_path);
47 ~ShaderDiskCache(); 57 virtual ~ShaderDiskCache();
jonathan.backer 2013/03/20 18:39:05 Why is this now virtual?
dsinclair 2013/03/21 17:46:59 Done. Did have an interface which is now removed.
48 58
49 void CacheCreatedCallback(int rv); 59 void CacheCreatedCallback(int rv);
50 60
51 disk_cache::Backend* backend() { return backend_; } 61 disk_cache::Backend* backend() { return backend_; }
52 62
53 void EntryComplete(void* entry); 63 void EntryComplete(void* entry);
54 void ReadComplete(); 64 void ReadComplete();
55 65
56 bool cache_available_; 66 bool cache_available_;
57 size_t max_cache_size_; 67 size_t max_cache_size_;
58 int host_id_; 68 int host_id_;
59 base::FilePath cache_path_; 69 base::FilePath cache_path_;
60 bool is_initialized_; 70 bool is_initialized_;
71 net::CompletionCallback available_callback_;
61 72
62 disk_cache::Backend* backend_; 73 disk_cache::Backend* backend_;
63 74
64 scoped_refptr<ShaderDiskReadHelper> helper_; 75 scoped_refptr<ShaderDiskReadHelper> helper_;
65 std::map<void*, scoped_refptr<ShaderDiskCacheEntry> > entry_map_; 76 std::map<void*, scoped_refptr<ShaderDiskCacheEntry> > entry_map_;
66 77
67 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCache); 78 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCache);
68 }; 79 };
69 80
70 // ShaderCacheFactory maintains a cache of ShaderDiskCache objects 81 // ShaderCacheFactory maintains a cache of ShaderDiskCacheImpl objects
71 // so we only create one per profile directory. 82 // so we only create one per profile directory.
72 class ShaderCacheFactory { 83 class ShaderCacheFactoryImpl : public content::ShaderCacheFactory {
73 public: 84 public:
74 static ShaderCacheFactory* GetInstance(); 85 static ShaderCacheFactoryImpl* GetInstance();
75 86
87 virtual void ClearByPath(const base::FilePath& path,
88 const base::Time& begin_time,
89 const base::Time& end_time,
90 const base::Closure& callback) OVERRIDE;
91
92 scoped_refptr<ShaderDiskCache> GetByPath(const base::FilePath& path);
jonathan.backer 2013/03/20 18:39:05 private?
dsinclair 2013/03/21 17:46:59 Done.
76 scoped_refptr<ShaderDiskCache> Get(int32 client_id); 93 scoped_refptr<ShaderDiskCache> Get(int32 client_id);
77 94
78 void SetCacheInfo(int32 client_id, const base::FilePath& path); 95 void SetCacheInfo(int32 client_id, const base::FilePath& path);
79 void RemoveCacheInfo(int32 client_id); 96 void RemoveCacheInfo(int32 client_id);
80 97
81 void AddToCache(const base::FilePath& path, ShaderDiskCache* cache); 98 void AddToCache(const base::FilePath& path, ShaderDiskCache* cache);
82 void RemoveFromCache(const base::FilePath& path); 99 void RemoveFromCache(const base::FilePath& path);
83 100
84 private: 101 private:
85 friend struct DefaultSingletonTraits<ShaderCacheFactory>; 102 friend struct DefaultSingletonTraits<ShaderCacheFactoryImpl>;
103 friend content::ShaderCacheFactory;
86 104
87 ShaderCacheFactory(); 105 enum OpType {
88 ~ShaderCacheFactory(); 106 TERMINATE,
107 CREATE_CACHE,
108 DELETE_CACHE
109 };
110
111 ShaderCacheFactoryImpl();
112 virtual ~ShaderCacheFactoryImpl();
113
114 void DoClearShaderCache(int rv);
89 115
90 typedef std::map<base::FilePath, ShaderDiskCache*> ShaderCacheMap; 116 typedef std::map<base::FilePath, ShaderDiskCache*> ShaderCacheMap;
91 ShaderCacheMap shader_cache_map_; 117 ShaderCacheMap shader_cache_map_;
92 118
93 typedef std::map<int32, base::FilePath> ClientIdToPathMap; 119 typedef std::map<int32, base::FilePath> ClientIdToPathMap;
94 ClientIdToPathMap client_id_to_path_map_; 120 ClientIdToPathMap client_id_to_path_map_;
95 121
96 DISALLOW_COPY_AND_ASSIGN(ShaderCacheFactory); 122 // Used fo the cache Clear call.
jonathan.backer 2013/03/20 18:39:05 s/fo/for
dsinclair 2013/03/21 17:46:59 Done.
123 OpType op_type_;
124 base::FilePath clear_path_;
125 base::Time delete_begin_;
126 base::Time delete_end_;
127 base::Closure clear_callback_;
128 scoped_refptr<ShaderDiskCache> clear_shader_cache_;
jonathan.backer 2013/03/20 18:39:05 What happens if you clear multiple times in rapid
dsinclair 2013/03/21 17:46:59 Done.
129
130 DISALLOW_COPY_AND_ASSIGN(ShaderCacheFactoryImpl);
97 }; 131 };
98 132
99 } // namespace content 133 } // namespace content
100 134
101 #endif // CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_H_ 135 #endif // CONTENT_BROWSER_GPU_SHADER_DISK_CACHE_IMPL_H_
102 136
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698