| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // See net/disk_cache/disk_cache.h for the public interface of the cache. | 5 // See net/disk_cache/disk_cache.h for the public interface of the cache. |
| 6 | 6 |
| 7 #ifndef NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ | 7 #ifndef NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ |
| 8 #define NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ | 8 #define NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "net/disk_cache/disk_cache.h" | 13 #include "net/disk_cache/disk_cache.h" |
| 14 #include "net/disk_cache/memory/mem_rankings.h" | 14 #include "net/disk_cache/memory/mem_rankings.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 class NetLog; | 17 class NetLog; |
| 18 } // namespace net | 18 } // namespace net |
| 19 | 19 |
| 20 namespace disk_cache { | 20 namespace disk_cache { |
| 21 | 21 |
| 22 class MemEntryImpl; | 22 class MemEntryImpl; |
| 23 | 23 |
| 24 // This class implements the Backend interface. An object of this class handles | 24 // This class implements the Backend interface. An object of this class handles |
| 25 // the operations of the cache without writing to disk. | 25 // the operations of the cache without writing to disk. |
| 26 class NET_EXPORT_PRIVATE MemBackendImpl : public Backend { | 26 class NET_EXPORT_PRIVATE MemBackendImpl : public Backend { |
| 27 public: | 27 public: |
| 28 explicit MemBackendImpl(net::NetLog* net_log); | 28 explicit MemBackendImpl(net::NetLog* net_log); |
| 29 virtual ~MemBackendImpl(); | 29 ~MemBackendImpl() override; |
| 30 | 30 |
| 31 // Returns an instance of a Backend implemented only in memory. The returned | 31 // Returns an instance of a Backend implemented only in memory. The returned |
| 32 // object should be deleted when not needed anymore. max_bytes is the maximum | 32 // object should be deleted when not needed anymore. max_bytes is the maximum |
| 33 // size the cache can grow to. If zero is passed in as max_bytes, the cache | 33 // size the cache can grow to. If zero is passed in as max_bytes, the cache |
| 34 // will determine the value to use based on the available memory. The returned | 34 // will determine the value to use based on the available memory. The returned |
| 35 // pointer can be NULL if a fatal error is found. | 35 // pointer can be NULL if a fatal error is found. |
| 36 static scoped_ptr<Backend> CreateBackend(int max_bytes, net::NetLog* net_log); | 36 static scoped_ptr<Backend> CreateBackend(int max_bytes, net::NetLog* net_log); |
| 37 | 37 |
| 38 // Performs general initialization for this current instance of the cache. | 38 // Performs general initialization for this current instance of the cache. |
| 39 bool Init(); | 39 bool Init(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 56 // Insert an MemEntryImpl into the ranking list. This method is only called | 56 // Insert an MemEntryImpl into the ranking list. This method is only called |
| 57 // from MemEntryImpl to insert child entries. The reference can be removed | 57 // from MemEntryImpl to insert child entries. The reference can be removed |
| 58 // by calling RemoveFromRankingList(|entry|). | 58 // by calling RemoveFromRankingList(|entry|). |
| 59 void InsertIntoRankingList(MemEntryImpl* entry); | 59 void InsertIntoRankingList(MemEntryImpl* entry); |
| 60 | 60 |
| 61 // Remove |entry| from ranking list. This method is only called from | 61 // Remove |entry| from ranking list. This method is only called from |
| 62 // MemEntryImpl to remove a child entry from the ranking list. | 62 // MemEntryImpl to remove a child entry from the ranking list. |
| 63 void RemoveFromRankingList(MemEntryImpl* entry); | 63 void RemoveFromRankingList(MemEntryImpl* entry); |
| 64 | 64 |
| 65 // Backend interface. | 65 // Backend interface. |
| 66 virtual net::CacheType GetCacheType() const override; | 66 net::CacheType GetCacheType() const override; |
| 67 virtual int32 GetEntryCount() const override; | 67 int32 GetEntryCount() const override; |
| 68 virtual int OpenEntry(const std::string& key, Entry** entry, | 68 int OpenEntry(const std::string& key, |
| 69 const CompletionCallback& callback) override; | 69 Entry** entry, |
| 70 virtual int CreateEntry(const std::string& key, Entry** entry, | 70 const CompletionCallback& callback) override; |
| 71 const CompletionCallback& callback) override; | 71 int CreateEntry(const std::string& key, |
| 72 virtual int DoomEntry(const std::string& key, | 72 Entry** entry, |
| 73 const CompletionCallback& callback) override; | 73 const CompletionCallback& callback) override; |
| 74 virtual int DoomAllEntries(const CompletionCallback& callback) override; | 74 int DoomEntry(const std::string& key, |
| 75 virtual int DoomEntriesBetween(base::Time initial_time, | 75 const CompletionCallback& callback) override; |
| 76 base::Time end_time, | 76 int DoomAllEntries(const CompletionCallback& callback) override; |
| 77 const CompletionCallback& callback) override; | 77 int DoomEntriesBetween(base::Time initial_time, |
| 78 virtual int DoomEntriesSince(base::Time initial_time, | 78 base::Time end_time, |
| 79 const CompletionCallback& callback) override; | 79 const CompletionCallback& callback) override; |
| 80 virtual scoped_ptr<Iterator> CreateIterator() override; | 80 int DoomEntriesSince(base::Time initial_time, |
| 81 virtual void GetStats( | 81 const CompletionCallback& callback) override; |
| 82 std::vector<std::pair<std::string, std::string> >* stats) override {} | 82 scoped_ptr<Iterator> CreateIterator() override; |
| 83 virtual void OnExternalCacheHit(const std::string& key) override; | 83 void GetStats( |
| 84 std::vector<std::pair<std::string, std::string>>* stats) override {} |
| 85 void OnExternalCacheHit(const std::string& key) override; |
| 84 | 86 |
| 85 private: | 87 private: |
| 86 class MemIterator; | 88 class MemIterator; |
| 87 friend class MemIterator; | 89 friend class MemIterator; |
| 88 | 90 |
| 89 typedef base::hash_map<std::string, MemEntryImpl*> EntryMap; | 91 typedef base::hash_map<std::string, MemEntryImpl*> EntryMap; |
| 90 | 92 |
| 91 // Old Backend interface. | 93 // Old Backend interface. |
| 92 bool OpenEntry(const std::string& key, Entry** entry); | 94 bool OpenEntry(const std::string& key, Entry** entry); |
| 93 bool CreateEntry(const std::string& key, Entry** entry); | 95 bool CreateEntry(const std::string& key, Entry** entry); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 114 net::NetLog* net_log_; | 116 net::NetLog* net_log_; |
| 115 | 117 |
| 116 base::WeakPtrFactory<MemBackendImpl> weak_factory_; | 118 base::WeakPtrFactory<MemBackendImpl> weak_factory_; |
| 117 | 119 |
| 118 DISALLOW_COPY_AND_ASSIGN(MemBackendImpl); | 120 DISALLOW_COPY_AND_ASSIGN(MemBackendImpl); |
| 119 }; | 121 }; |
| 120 | 122 |
| 121 } // namespace disk_cache | 123 } // namespace disk_cache |
| 122 | 124 |
| 123 #endif // NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ | 125 #endif // NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ |
| OLD | NEW |