Chromium Code Reviews| Index: net/disk_cache/simple/simple_backend_impl.h |
| diff --git a/net/disk_cache/simple/simple_backend_impl.h b/net/disk_cache/simple/simple_backend_impl.h |
| index ebb96c7caca6a14d750108aed74eea9164ad109b..658df5ff79b1f87e294699b8759fc1d4dbde44f7 100644 |
| --- a/net/disk_cache/simple/simple_backend_impl.h |
| +++ b/net/disk_cache/simple/simple_backend_impl.h |
| @@ -16,11 +16,13 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/task_runner.h" |
| +#include "base/threading/sequenced_worker_pool.h" |
| #include "net/base/cache_type.h" |
| #include "net/disk_cache/disk_cache.h" |
| namespace base { |
| class SingleThreadTaskRunner; |
| +class TaskRunner; |
| } |
| namespace disk_cache { |
| @@ -57,9 +59,8 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, |
| // Returns the maximum file size permitted in this backend. |
| int GetMaxFileSize() const; |
| - // Removes |entry| from the |active_entries_| set, forcing future Open/Create |
| - // operations to construct a new object. |
| - void OnDeactivated(const SimpleEntryImpl* entry); |
| + void DeactivateEntry(uint64 entry_hash); |
| + void ClosedEntry(uint64 entry_hash); |
| // From Backend: |
| virtual net::CacheType GetCacheType() const OVERRIDE; |
| @@ -84,7 +85,24 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, |
| virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; |
| private: |
| - typedef std::map<uint64, base::WeakPtr<SimpleEntryImpl> > EntryMap; |
| + struct ActiveEntry; |
| + class ProxyTaskRunner; |
| + |
| + friend struct ActiveEntry; |
| + |
| + struct ActiveEntry : base::SupportsWeakPtr<ActiveEntry> { |
| + ActiveEntry(); |
| + ActiveEntry(const ActiveEntry& other); |
| + |
| + ~ActiveEntry(); |
| + |
| + ActiveEntry& operator=(const ActiveEntry& other); |
| + |
| + scoped_refptr<ProxyTaskRunner> task_runner; |
| + SimpleEntryImpl* entry; |
| + }; |
| + |
| + typedef std::map<uint64, ActiveEntry> EntryMap; |
|
Randy Smith (Not in Mondays)
2013/05/21 21:15:30
My understanding of how stl containers work is tha
|
| typedef base::Callback<void(uint64 max_size, int result)> |
| InitializeIndexCallback; |
| @@ -111,6 +129,8 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, |
| // Searches |active_entries_| for the entry corresponding to |key|. If found, |
| // returns the found entry. Otherwise, creates a new entry and returns that. |
| + // Returns a scoped_refptr<> as it may be returning a newly created entry and |
| + // this guards against leaking. |
| scoped_refptr<SimpleEntryImpl> CreateOrFindActiveEntry( |
| const std::string& key); |
| @@ -120,9 +140,17 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, |
| int orig_max_size_; |
| - // TODO(gavinp): Store the entry_hash in SimpleEntryImpl, and index this map |
| - // by hash. This will save memory, and make IndexReadyForDoom easier. |
| + // All currently open entries, indexed by their entry_hash. This stores a raw |
| + // pointer to a ref counted object, so it is important to remove entries as |
| + // they are destroyed. |
| EntryMap active_entries_; |
| + |
| + // A worker pool on which to perform IO operations. |
| + scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
| + |
| + // A sequenced task runner which serializes operations for which there is no |
| + // active entry. |
| + scoped_refptr<base::SequencedTaskRunner> inactive_entry_task_runner_; |
| }; |
| } // namespace disk_cache |