| OLD | NEW |
| 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 NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ | 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ |
| 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ | 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 class SingleThreadTaskRunner; | 27 class SingleThreadTaskRunner; |
| 28 class TaskRunner; | 28 class TaskRunner; |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace disk_cache { | 31 namespace disk_cache { |
| 32 | 32 |
| 33 // SimpleBackendImpl is a new cache backend that stores entries in individual | 33 // SimpleBackendImpl is a new cache backend that stores entries in individual |
| 34 // files. | 34 // files. |
| 35 // See http://www.chromium.org/developers/design-documents/network-stack/disk-ca
che/very-simple-backend | 35 // See http://www.chromium.org/developers/design-documents/network-stack/disk-ca
che/very-simple-backend |
| 36 // | 36 // |
| 37 // The SimpleBackendImpl provides safe iteration; mutating entries during |
| 38 // iteration cannot cause a crash. It is undefined whether entries created or |
| 39 // destroyed during the iteration will be included in the iteration. |
| 40 // |
| 37 // The non-static functions below must be called on the IO thread unless | 41 // The non-static functions below must be called on the IO thread unless |
| 38 // otherwise stated. | 42 // otherwise stated. |
| 39 | 43 |
| 40 class SimpleEntryImpl; | 44 class SimpleEntryImpl; |
| 41 class SimpleIndex; | 45 class SimpleIndex; |
| 42 | 46 |
| 43 class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, | 47 class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend, |
| 44 public SimpleIndexDelegate, | 48 public SimpleIndexDelegate, |
| 45 public base::SupportsWeakPtr<SimpleBackendImpl> { | 49 public base::SupportsWeakPtr<SimpleBackendImpl> { |
| 46 public: | 50 public: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 virtual int CreateEntry(const std::string& key, Entry** entry, | 94 virtual int CreateEntry(const std::string& key, Entry** entry, |
| 91 const CompletionCallback& callback) OVERRIDE; | 95 const CompletionCallback& callback) OVERRIDE; |
| 92 virtual int DoomEntry(const std::string& key, | 96 virtual int DoomEntry(const std::string& key, |
| 93 const CompletionCallback& callback) OVERRIDE; | 97 const CompletionCallback& callback) OVERRIDE; |
| 94 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; | 98 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; |
| 95 virtual int DoomEntriesBetween(base::Time initial_time, | 99 virtual int DoomEntriesBetween(base::Time initial_time, |
| 96 base::Time end_time, | 100 base::Time end_time, |
| 97 const CompletionCallback& callback) OVERRIDE; | 101 const CompletionCallback& callback) OVERRIDE; |
| 98 virtual int DoomEntriesSince(base::Time initial_time, | 102 virtual int DoomEntriesSince(base::Time initial_time, |
| 99 const CompletionCallback& callback) OVERRIDE; | 103 const CompletionCallback& callback) OVERRIDE; |
| 100 virtual int OpenNextEntry(void** iter, Entry** next_entry, | 104 virtual scoped_ptr<Iterator> CreateIterator() OVERRIDE; |
| 101 const CompletionCallback& callback) OVERRIDE; | |
| 102 virtual void EndEnumeration(void** iter) OVERRIDE; | |
| 103 virtual void GetStats( | 105 virtual void GetStats( |
| 104 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE; | 106 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE; |
| 105 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; | 107 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; |
| 106 | 108 |
| 107 private: | 109 private: |
| 110 class SimpleIterator; |
| 111 friend class SimpleIterator; |
| 112 |
| 108 typedef base::hash_map<uint64, SimpleEntryImpl*> EntryMap; | 113 typedef base::hash_map<uint64, SimpleEntryImpl*> EntryMap; |
| 109 | 114 |
| 110 typedef base::Callback<void(base::Time mtime, uint64 max_size, int result)> | 115 typedef base::Callback<void(base::Time mtime, uint64 max_size, int result)> |
| 111 InitializeIndexCallback; | 116 InitializeIndexCallback; |
| 112 | 117 |
| 113 class ActiveEntryProxy; | 118 class ActiveEntryProxy; |
| 114 friend class ActiveEntryProxy; | 119 friend class ActiveEntryProxy; |
| 115 | 120 |
| 116 // Return value of InitCacheStructureOnDisk(). | 121 // Return value of InitCacheStructureOnDisk(). |
| 117 struct DiskStatResult { | 122 struct DiskStatResult { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 148 // the disk. | 153 // the disk. |
| 149 int OpenEntryFromHash(uint64 entry_hash, | 154 int OpenEntryFromHash(uint64 entry_hash, |
| 150 Entry** entry, | 155 Entry** entry, |
| 151 const CompletionCallback& callback); | 156 const CompletionCallback& callback); |
| 152 | 157 |
| 153 // Doom the entry corresponding to |entry_hash|, if it's active or currently | 158 // Doom the entry corresponding to |entry_hash|, if it's active or currently |
| 154 // pending doom. This function does not block if there is an active entry, | 159 // pending doom. This function does not block if there is an active entry, |
| 155 // which is very important to prevent races in DoomEntries() above. | 160 // which is very important to prevent races in DoomEntries() above. |
| 156 int DoomEntryFromHash(uint64 entry_hash, const CompletionCallback & callback); | 161 int DoomEntryFromHash(uint64 entry_hash, const CompletionCallback & callback); |
| 157 | 162 |
| 158 // Called when the index is initilized to find the next entry in the iterator | |
| 159 // |iter|. If there are no more hashes in the iterator list, net::ERR_FAILED | |
| 160 // is returned. Otherwise, calls OpenEntryFromHash. | |
| 161 void GetNextEntryInIterator(void** iter, | |
| 162 Entry** next_entry, | |
| 163 const CompletionCallback& callback, | |
| 164 int error_code); | |
| 165 | |
| 166 // Called when we tried to open an entry with hash alone. When a blank entry | 163 // Called when we tried to open an entry with hash alone. When a blank entry |
| 167 // has been created and filled in with information from the disk - based on a | 164 // has been created and filled in with information from the disk - based on a |
| 168 // hash alone - this checks that a duplicate active entry was not created | 165 // hash alone - this checks that a duplicate active entry was not created |
| 169 // using a key in the meantime. | 166 // using a key in the meantime. |
| 170 void OnEntryOpenedFromHash(uint64 hash, | 167 void OnEntryOpenedFromHash(uint64 hash, |
| 171 Entry** entry, | 168 Entry** entry, |
| 172 const scoped_refptr<SimpleEntryImpl>& simple_entry, | 169 const scoped_refptr<SimpleEntryImpl>& simple_entry, |
| 173 const CompletionCallback& callback, | 170 const CompletionCallback& callback, |
| 174 int error_code); | 171 int error_code); |
| 175 | 172 |
| 176 // Called when we tried to open an entry from key. When the entry has been | 173 // Called when we tried to open an entry from key. When the entry has been |
| 177 // opened, a check for key mismatch is performed. | 174 // opened, a check for key mismatch is performed. |
| 178 void OnEntryOpenedFromKey(const std::string key, | 175 void OnEntryOpenedFromKey(const std::string key, |
| 179 Entry** entry, | 176 Entry** entry, |
| 180 const scoped_refptr<SimpleEntryImpl>& simple_entry, | 177 const scoped_refptr<SimpleEntryImpl>& simple_entry, |
| 181 const CompletionCallback& callback, | 178 const CompletionCallback& callback, |
| 182 int error_code); | 179 int error_code); |
| 183 | 180 |
| 184 // Called at the end of the asynchronous operation triggered by | |
| 185 // OpenEntryFromHash. Makes sure to continue iterating if the open entry was | |
| 186 // not a success. | |
| 187 void CheckIterationReturnValue(void** iter, | |
| 188 Entry** entry, | |
| 189 const CompletionCallback& callback, | |
| 190 int error_code); | |
| 191 | |
| 192 // A callback thunk used by DoomEntries to clear the |entries_pending_doom_| | 181 // A callback thunk used by DoomEntries to clear the |entries_pending_doom_| |
| 193 // after a mass doom. | 182 // after a mass doom. |
| 194 void DoomEntriesComplete(scoped_ptr<std::vector<uint64> > entry_hashes, | 183 void DoomEntriesComplete(scoped_ptr<std::vector<uint64> > entry_hashes, |
| 195 const CompletionCallback& callback, | 184 const CompletionCallback& callback, |
| 196 int result); | 185 int result); |
| 197 | 186 |
| 198 const base::FilePath path_; | 187 const base::FilePath path_; |
| 199 const net::CacheType cache_type_; | 188 const net::CacheType cache_type_; |
| 200 scoped_ptr<SimpleIndex> index_; | 189 scoped_ptr<SimpleIndex> index_; |
| 201 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; | 190 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; |
| 202 scoped_refptr<base::TaskRunner> worker_pool_; | 191 scoped_refptr<base::TaskRunner> worker_pool_; |
| 203 | 192 |
| 204 int orig_max_size_; | 193 int orig_max_size_; |
| 205 const SimpleEntryImpl::OperationsMode entry_operations_mode_; | 194 const SimpleEntryImpl::OperationsMode entry_operations_mode_; |
| 206 | 195 |
| 207 EntryMap active_entries_; | 196 EntryMap active_entries_; |
| 208 | 197 |
| 209 // The set of all entries which are currently being doomed. To avoid races, | 198 // The set of all entries which are currently being doomed. To avoid races, |
| 210 // these entries cannot have Doom/Create/Open operations run until the doom | 199 // these entries cannot have Doom/Create/Open operations run until the doom |
| 211 // is complete. The base::Closure map target is used to store deferred | 200 // is complete. The base::Closure map target is used to store deferred |
| 212 // operations to be run at the completion of the Doom. | 201 // operations to be run at the completion of the Doom. |
| 213 base::hash_map<uint64, std::vector<base::Closure> > entries_pending_doom_; | 202 base::hash_map<uint64, std::vector<base::Closure> > entries_pending_doom_; |
| 214 | 203 |
| 215 net::NetLog* const net_log_; | 204 net::NetLog* const net_log_; |
| 216 }; | 205 }; |
| 217 | 206 |
| 218 } // namespace disk_cache | 207 } // namespace disk_cache |
| 219 | 208 |
| 220 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ | 209 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ |
| OLD | NEW |