Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: net/disk_cache/simple/simple_backend_impl.h

Issue 23486006: Track entries pending Doom in SimpleCache backend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remediation and test update Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // The entry for |entry_hash| is being doomed; the backend will not attempt
69 // run new operations for this |entry_hash| until the Doom is completed.
70 void OnDoomStart(uint64 entry_hash);
71
72 // The entry for |entry_hash| has been successfully doomed, we can now allow
73 // operations on this entry, and we can run any operations enqueued while the
74 // doom completed.
75 void OnDoomComplete(uint64 entry_hash);
76
67 // Backend: 77 // Backend:
68 virtual net::CacheType GetCacheType() const OVERRIDE; 78 virtual net::CacheType GetCacheType() const OVERRIDE;
69 virtual int32 GetEntryCount() const OVERRIDE; 79 virtual int32 GetEntryCount() const OVERRIDE;
70 virtual int OpenEntry(const std::string& key, Entry** entry, 80 virtual int OpenEntry(const std::string& key, Entry** entry,
71 const CompletionCallback& callback) OVERRIDE; 81 const CompletionCallback& callback) OVERRIDE;
72 virtual int CreateEntry(const std::string& key, Entry** entry, 82 virtual int CreateEntry(const std::string& key, Entry** entry,
73 const CompletionCallback& callback) OVERRIDE; 83 const CompletionCallback& callback) OVERRIDE;
74 virtual int DoomEntry(const std::string& key, 84 virtual int DoomEntry(const std::string& key,
75 const CompletionCallback& callback) OVERRIDE; 85 const CompletionCallback& callback) OVERRIDE;
76 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; 86 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 int result); 121 int result);
112 122
113 // Try to create the directory if it doesn't exist. This must run on the IO 123 // Try to create the directory if it doesn't exist. This must run on the IO
114 // thread. 124 // thread.
115 static DiskStatResult InitCacheStructureOnDisk(const base::FilePath& path, 125 static DiskStatResult InitCacheStructureOnDisk(const base::FilePath& path,
116 uint64 suggested_max_size); 126 uint64 suggested_max_size);
117 127
118 // Searches |active_entries_| for the entry corresponding to |key|. If found, 128 // Searches |active_entries_| for the entry corresponding to |key|. If found,
119 // returns the found entry. Otherwise, creates a new entry and returns that. 129 // returns the found entry. Otherwise, creates a new entry and returns that.
120 scoped_refptr<SimpleEntryImpl> CreateOrFindActiveEntry( 130 scoped_refptr<SimpleEntryImpl> CreateOrFindActiveEntry(
131 uint64 entry_hash,
121 const std::string& key); 132 const std::string& key);
122 133
123 // Given a hash, will try to open the corresponding Entry. If we have an Entry 134 // 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, 135 // 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 136 // a new empty Entry will be created, opened and filled with information from
126 // the disk. 137 // the disk.
127 int OpenEntryFromHash(uint64 hash, 138 int OpenEntryFromHash(uint64 hash,
128 Entry** entry, 139 Entry** entry,
129 const CompletionCallback& callback); 140 const CompletionCallback& callback);
130 141
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 int error_code); 174 int error_code);
164 175
165 const base::FilePath path_; 176 const base::FilePath path_;
166 scoped_ptr<SimpleIndex> index_; 177 scoped_ptr<SimpleIndex> index_;
167 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; 178 const scoped_refptr<base::SingleThreadTaskRunner> cache_thread_;
168 scoped_refptr<base::TaskRunner> worker_pool_; 179 scoped_refptr<base::TaskRunner> worker_pool_;
169 180
170 int orig_max_size_; 181 int orig_max_size_;
171 const SimpleEntryImpl::OperationsMode entry_operations_mode_; 182 const SimpleEntryImpl::OperationsMode entry_operations_mode_;
172 183
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_; 184 EntryMap active_entries_;
176 185
186 // The set of all entries which are currently being doomed. To avoid races,
187 // these entries cannot have Doom/Create/Open operations run until the doom
188 // is complete. The base::Closure map target is used to store deferred
189 // operations to be run at the completion of the Doom.
190 base::hash_map<uint64, base::Closure> entries_pending_doom_;
191
177 net::NetLog* const net_log_; 192 net::NetLog* const net_log_;
178 }; 193 };
179 194
180 } // namespace disk_cache 195 } // namespace disk_cache
181 196
182 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_ 197 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698