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

Unified Diff: content/browser/gpu/shader_disk_cache.h

Issue 2472473002: gpu shader cache: Clarify lifetime/ownership/threadiness of objects. (Closed)
Patch Set: iwyu Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/browser_main_loop.cc ('k') | content/browser/gpu/shader_disk_cache.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/gpu/shader_disk_cache.h
diff --git a/content/browser/gpu/shader_disk_cache.h b/content/browser/gpu/shader_disk_cache.h
index 740a14124b81b011bb0b58b5fb8dd8dbcb7e14bb..975bc080351ac26ef808d40a3eb7a04999f997b5 100644
--- a/content/browser/gpu/shader_disk_cache.h
+++ b/content/browser/gpu/shader_disk_cache.h
@@ -14,7 +14,7 @@
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/memory/singleton.h"
+#include "base/threading/thread_checker.h"
#include "content/common/content_export.h"
#include "net/disk_cache/disk_cache.h"
@@ -26,17 +26,11 @@ class ShaderClearHelper;
// ShaderDiskCache is the interface to the on disk cache for
// GL shaders.
-//
-// While this class is both RefCounted and SupportsWeakPtr
-// when using this class you should work with the RefCounting.
-// The WeakPtr is needed interally.
class CONTENT_EXPORT ShaderDiskCache
- : public base::RefCounted<ShaderDiskCache>,
- public base::SupportsWeakPtr<ShaderDiskCache> {
+ : public base::RefCounted<ShaderDiskCache> {
public:
using ShaderLoadedCallback =
base::Callback<void(const std::string&, const std::string&)>;
- void Init();
void set_shader_loaded_callback(const ShaderLoadedCallback& callback) {
shader_loaded_callback_ = callback;
@@ -80,11 +74,12 @@ class CONTENT_EXPORT ShaderDiskCache
explicit ShaderDiskCache(const base::FilePath& cache_path);
~ShaderDiskCache();
+ void Init(scoped_refptr<base::SingleThreadTaskRunner> cache_task_runner);
void CacheCreatedCallback(int rv);
disk_cache::Backend* backend() { return backend_.get(); }
- void EntryComplete(void* entry);
+ void EntryComplete(ShaderDiskCacheEntry* entry);
void ReadComplete();
bool cache_available_;
@@ -96,16 +91,29 @@ class CONTENT_EXPORT ShaderDiskCache
std::unique_ptr<disk_cache::Backend> backend_;
- scoped_refptr<ShaderDiskReadHelper> helper_;
- std::map<void*, scoped_refptr<ShaderDiskCacheEntry> > entry_map_;
+ std::unique_ptr<ShaderDiskReadHelper> helper_;
+ std::unordered_map<ShaderDiskCacheEntry*,
+ std::unique_ptr<ShaderDiskCacheEntry>>
+ entries_;
DISALLOW_COPY_AND_ASSIGN(ShaderDiskCache);
};
// ShaderCacheFactory maintains a cache of ShaderDiskCache objects
// so we only create one per profile directory.
-class CONTENT_EXPORT ShaderCacheFactory {
+class CONTENT_EXPORT ShaderCacheFactory
+ : NON_EXPORTED_BASE(public base::ThreadChecker) {
public:
+ // Initializes the ShaderCacheFactory singleton instance. The singleton
+ // instance is created and used in the thread associated with |task_runner|.
+ // |cache_task_runner| is associated with the thread responsible for managing
+ // the disk cache.
+ static void InitInstance(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> cache_task_runner);
+
+ // Returns an instance previously created by InitInstance(). This can return
+ // nullptr if an instance has not yet been created.
static ShaderCacheFactory* GetInstance();
// Clear the shader disk cache for the given |path|. This supports unbounded
@@ -133,12 +141,17 @@ class CONTENT_EXPORT ShaderCacheFactory {
void RemoveFromCache(const base::FilePath& path);
private:
- friend struct base::DefaultSingletonTraits<ShaderCacheFactory>;
friend class ShaderClearHelper;
- ShaderCacheFactory();
+ explicit ShaderCacheFactory(
+ scoped_refptr<base::SingleThreadTaskRunner> cache_task_runner);
~ShaderCacheFactory();
+ static void CreateFactoryInstance(
+ scoped_refptr<base::SingleThreadTaskRunner> cache_task_runner);
+
+ scoped_refptr<base::SingleThreadTaskRunner> cache_task_runner_;
+
scoped_refptr<ShaderDiskCache> GetByPath(const base::FilePath& path);
void CacheCleared(const base::FilePath& path);
« no previous file with comments | « content/browser/browser_main_loop.cc ('k') | content/browser/gpu/shader_disk_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698