| 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> |
| 11 | 11 |
| 12 #include "base/callback_forward.h" |
| 12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 13 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
| 14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 18 #include "base/task_runner.h" | 19 #include "base/task_runner.h" |
| 19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 20 #include "net/base/cache_type.h" | 21 #include "net/base/cache_type.h" |
| 21 #include "net/disk_cache/disk_cache.h" | 22 #include "net/disk_cache/disk_cache.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // Returns the maximum file size permitted in this backend. | 61 // Returns the maximum file size permitted in this backend. |
| 61 int GetMaxFileSize() const; | 62 int GetMaxFileSize() const; |
| 62 | 63 |
| 63 // Removes |entry| from the |active_entries_| set, forcing future Open/Create | 64 // Removes |entry| from the |active_entries_| set, forcing future Open/Create |
| 64 // operations to construct a new object. | 65 // operations to construct a new object. |
| 65 void OnDeactivated(const SimpleEntryImpl* entry); | 66 void OnDeactivated(const SimpleEntryImpl* entry); |
| 66 | 67 |
| 67 // Flush our SequencedWorkerPool. | 68 // Flush our SequencedWorkerPool. |
| 68 static void FlushWorkerPoolForTesting(); | 69 static void FlushWorkerPoolForTesting(); |
| 69 | 70 |
| 71 // The entry for |entry_hash| is being doomed; the backend will not attempt |
| 72 // run new operations for this |entry_hash| until the Doom is completed. |
| 73 void OnDoomStart(uint64 entry_hash); |
| 74 |
| 75 // The entry for |entry_hash| has been successfully doomed, we can now allow |
| 76 // operations on this entry, and we can run any operations enqueued while the |
| 77 // doom completed. |
| 78 void OnDoomComplete(uint64 entry_hash); |
| 79 |
| 70 // Backend: | 80 // Backend: |
| 71 virtual net::CacheType GetCacheType() const OVERRIDE; | 81 virtual net::CacheType GetCacheType() const OVERRIDE; |
| 72 virtual int32 GetEntryCount() const OVERRIDE; | 82 virtual int32 GetEntryCount() const OVERRIDE; |
| 73 virtual int OpenEntry(const std::string& key, Entry** entry, | 83 virtual int OpenEntry(const std::string& key, Entry** entry, |
| 74 const CompletionCallback& callback) OVERRIDE; | 84 const CompletionCallback& callback) OVERRIDE; |
| 75 virtual int CreateEntry(const std::string& key, Entry** entry, | 85 virtual int CreateEntry(const std::string& key, Entry** entry, |
| 76 const CompletionCallback& callback) OVERRIDE; | 86 const CompletionCallback& callback) OVERRIDE; |
| 77 virtual int DoomEntry(const std::string& key, | 87 virtual int DoomEntry(const std::string& key, |
| 78 const CompletionCallback& callback) OVERRIDE; | 88 const CompletionCallback& callback) OVERRIDE; |
| 79 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; | 89 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 int result); | 124 int result); |
| 115 | 125 |
| 116 // Try to create the directory if it doesn't exist. This must run on the IO | 126 // Try to create the directory if it doesn't exist. This must run on the IO |
| 117 // thread. | 127 // thread. |
| 118 static DiskStatResult InitCacheStructureOnDisk(const base::FilePath& path, | 128 static DiskStatResult InitCacheStructureOnDisk(const base::FilePath& path, |
| 119 uint64 suggested_max_size); | 129 uint64 suggested_max_size); |
| 120 | 130 |
| 121 // Searches |active_entries_| for the entry corresponding to |key|. If found, | 131 // Searches |active_entries_| for the entry corresponding to |key|. If found, |
| 122 // returns the found entry. Otherwise, creates a new entry and returns that. | 132 // returns the found entry. Otherwise, creates a new entry and returns that. |
| 123 scoped_refptr<SimpleEntryImpl> CreateOrFindActiveEntry( | 133 scoped_refptr<SimpleEntryImpl> CreateOrFindActiveEntry( |
| 134 uint64 entry_hash, |
| 124 const std::string& key); | 135 const std::string& key); |
| 125 | 136 |
| 126 // Given a hash, will try to open the corresponding Entry. If we have an Entry | 137 // Given a hash, will try to open the corresponding Entry. If we have an Entry |
| 127 // corresponding to |hash| in the map of active entries, opens it. Otherwise, | 138 // corresponding to |hash| in the map of active entries, opens it. Otherwise, |
| 128 // a new empty Entry will be created, opened and filled with information from | 139 // a new empty Entry will be created, opened and filled with information from |
| 129 // the disk. | 140 // the disk. |
| 130 int OpenEntryFromHash(uint64 hash, | 141 int OpenEntryFromHash(uint64 hash, |
| 131 Entry** entry, | 142 Entry** entry, |
| 132 const CompletionCallback& callback); | 143 const CompletionCallback& callback); |
| 133 | 144 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 178 |
| 168 const base::FilePath path_; | 179 const base::FilePath path_; |
| 169 const net::CacheType cache_type_; | 180 const net::CacheType cache_type_; |
| 170 scoped_ptr<SimpleIndex> index_; | 181 scoped_ptr<SimpleIndex> index_; |
| 171 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; | 182 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; |
| 172 scoped_refptr<base::TaskRunner> worker_pool_; | 183 scoped_refptr<base::TaskRunner> worker_pool_; |
| 173 | 184 |
| 174 int orig_max_size_; | 185 int orig_max_size_; |
| 175 const SimpleEntryImpl::OperationsMode entry_operations_mode_; | 186 const SimpleEntryImpl::OperationsMode entry_operations_mode_; |
| 176 | 187 |
| 177 // TODO(gavinp): Store the entry_hash in SimpleEntryImpl, and index this map | |
| 178 // by hash. This will save memory, and make IndexReadyForDoom easier. | |
| 179 EntryMap active_entries_; | 188 EntryMap active_entries_; |
| 180 | 189 |
| 190 // The set of all entries which are currently being doomed. To avoid races, |
| 191 // these entries cannot have Doom/Create/Open operations run until the doom |
| 192 // is complete. The base::Closure map target is used to store deferred |
| 193 // operations to be run at the completion of the Doom. |
| 194 base::hash_map<uint64, std::vector<base::Closure> > entries_pending_doom_; |
| 195 |
| 181 net::NetLog* const net_log_; | 196 net::NetLog* const net_log_; |
| 182 }; | 197 }; |
| 183 | 198 |
| 184 } // namespace disk_cache | 199 } // namespace disk_cache |
| 185 | 200 |
| 186 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ | 201 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ |
| OLD | NEW |