| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // Sets the maximum size for the total amount of data stored by this instance. | 58 // Sets the maximum size for the total amount of data stored by this instance. |
| 58 bool SetMaxSize(int max_bytes); | 59 bool SetMaxSize(int max_bytes); |
| 59 | 60 |
| 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 |
| 68 void OnDoomStart(uint64 entry_hash); |
| 69 void OnDoomComplete(uint64 entry_hash); |
| 70 |
| 67 // Backend: | 71 // Backend: |
| 68 virtual net::CacheType GetCacheType() const OVERRIDE; | 72 virtual net::CacheType GetCacheType() const OVERRIDE; |
| 69 virtual int32 GetEntryCount() const OVERRIDE; | 73 virtual int32 GetEntryCount() const OVERRIDE; |
| 70 virtual int OpenEntry(const std::string& key, Entry** entry, | 74 virtual int OpenEntry(const std::string& key, Entry** entry, |
| 71 const CompletionCallback& callback) OVERRIDE; | 75 const CompletionCallback& callback) OVERRIDE; |
| 72 virtual int CreateEntry(const std::string& key, Entry** entry, | 76 virtual int CreateEntry(const std::string& key, Entry** entry, |
| 73 const CompletionCallback& callback) OVERRIDE; | 77 const CompletionCallback& callback) OVERRIDE; |
| 74 virtual int DoomEntry(const std::string& key, | 78 virtual int DoomEntry(const std::string& key, |
| 75 const CompletionCallback& callback) OVERRIDE; | 79 const CompletionCallback& callback) OVERRIDE; |
| 76 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; | 80 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 int result); | 115 int result); |
| 112 | 116 |
| 113 // Try to create the directory if it doesn't exist. This must run on the IO | 117 // Try to create the directory if it doesn't exist. This must run on the IO |
| 114 // thread. | 118 // thread. |
| 115 static DiskStatResult InitCacheStructureOnDisk(const base::FilePath& path, | 119 static DiskStatResult InitCacheStructureOnDisk(const base::FilePath& path, |
| 116 uint64 suggested_max_size); | 120 uint64 suggested_max_size); |
| 117 | 121 |
| 118 // Searches |active_entries_| for the entry corresponding to |key|. If found, | 122 // Searches |active_entries_| for the entry corresponding to |key|. If found, |
| 119 // returns the found entry. Otherwise, creates a new entry and returns that. | 123 // returns the found entry. Otherwise, creates a new entry and returns that. |
| 120 scoped_refptr<SimpleEntryImpl> CreateOrFindActiveEntry( | 124 scoped_refptr<SimpleEntryImpl> CreateOrFindActiveEntry( |
| 125 uint64 entry_hash, |
| 121 const std::string& key); | 126 const std::string& key); |
| 122 | 127 |
| 123 // Given a hash, will try to open the corresponding Entry. If we have an Entry | 128 // Given a hash, will try to open the corresponding Entry. If we have an Entry |
| 124 // corresponding to |hash| in the map of active entries, opens it. Otherwise, | 129 // corresponding to |hash| in the map of active entries, opens it. Otherwise, |
| 125 // a new empty Entry will be created, opened and filled with information from | 130 // a new empty Entry will be created, opened and filled with information from |
| 126 // the disk. | 131 // the disk. |
| 127 int OpenEntryFromHash(uint64 hash, | 132 int OpenEntryFromHash(uint64 hash, |
| 128 Entry** entry, | 133 Entry** entry, |
| 129 const CompletionCallback& callback); | 134 const CompletionCallback& callback); |
| 130 | 135 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 int error_code); | 168 int error_code); |
| 164 | 169 |
| 165 const base::FilePath path_; | 170 const base::FilePath path_; |
| 166 scoped_ptr<SimpleIndex> index_; | 171 scoped_ptr<SimpleIndex> index_; |
| 167 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; | 172 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; |
| 168 scoped_refptr<base::TaskRunner> worker_pool_; | 173 scoped_refptr<base::TaskRunner> worker_pool_; |
| 169 | 174 |
| 170 int orig_max_size_; | 175 int orig_max_size_; |
| 171 const SimpleEntryImpl::OperationsMode entry_operations_mode_; | 176 const SimpleEntryImpl::OperationsMode entry_operations_mode_; |
| 172 | 177 |
| 173 // TODO(gavinp): Store the entry_hash in SimpleEntryImpl, and index this map | |
| 174 // by hash. This will save memory, and make IndexReadyForDoom easier. | |
| 175 EntryMap active_entries_; | 178 EntryMap active_entries_; |
| 176 | 179 |
| 180 // For each entry pending doom, stores an optional base::Closure which |
| 181 // contains operations delayed until the doom completes. |
| 182 base::hash_map<uint64, base::Closure> entries_pending_doom_; |
| 183 |
| 177 net::NetLog* const net_log_; | 184 net::NetLog* const net_log_; |
| 178 }; | 185 }; |
| 179 | 186 |
| 180 } // namespace disk_cache | 187 } // namespace disk_cache |
| 181 | 188 |
| 182 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ | 189 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ |
| OLD | NEW |