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

Side by Side Diff: net/disk_cache/blockfile/entry_impl.h

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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) 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 #ifndef NET_DISK_CACHE_BLOCKFILE_ENTRY_IMPL_H_ 5 #ifndef NET_DISK_CACHE_BLOCKFILE_ENTRY_IMPL_H_
6 #define NET_DISK_CACHE_BLOCKFILE_ENTRY_IMPL_H_ 6 #define NET_DISK_CACHE_BLOCKFILE_ENTRY_IMPL_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "net/base/net_log.h" 9 #include "net/base/net_log.h"
10 #include "net/disk_cache/blockfile/disk_format.h" 10 #include "net/disk_cache/blockfile/disk_format.h"
11 #include "net/disk_cache/blockfile/storage_block-inl.h" 11 #include "net/disk_cache/blockfile/storage_block-inl.h"
12 #include "net/disk_cache/blockfile/storage_block.h" 12 #include "net/disk_cache/blockfile/storage_block.h"
13 #include "net/disk_cache/disk_cache.h" 13 #include "net/disk_cache/disk_cache.h"
14 14
15 namespace disk_cache { 15 namespace disk_cache {
16 16
17 class BackendImpl; 17 class BackendImpl;
18 class InFlightBackendIO; 18 class InFlightBackendIO;
19 class SparseControl; 19 class SparseControl;
20 typedef StorageBlock<EntryStore> CacheEntryBlock; 20 typedef StorageBlock<EntryStore> CacheEntryBlock;
21 typedef StorageBlock<RankingsNode> CacheRankingsBlock; 21 typedef StorageBlock<RankingsNode> CacheRankingsBlock;
22 22
23 // This class implements the Entry interface. An object of this 23 // This class implements the Entry interface. An object of this
24 // class represents a single entry on the cache. 24 // class represents a single entry on the cache.
25 class NET_EXPORT_PRIVATE EntryImpl 25 class NET_EXPORT_PRIVATE EntryImpl : public Entry,
26 : public Entry, 26 public base::RefCounted<EntryImpl> {
27 public base::RefCounted<EntryImpl> {
28 friend class base::RefCounted<EntryImpl>; 27 friend class base::RefCounted<EntryImpl>;
29 friend class SparseControl; 28 friend class SparseControl;
29
30 public: 30 public:
31 enum Operation { 31 enum Operation {
32 kRead, 32 kRead,
33 kWrite, 33 kWrite,
34 kSparseRead, 34 kSparseRead,
35 kSparseWrite, 35 kSparseWrite,
36 kAsyncIO, 36 kAsyncIO,
37 kReadAsync1, 37 kReadAsync1,
38 kWriteAsync1 38 kWriteAsync1
39 }; 39 };
40 40
41 EntryImpl(BackendImpl* backend, Addr address, bool read_only); 41 EntryImpl(BackendImpl* backend, Addr address, bool read_only);
42 42
43 // Background implementation of the Entry interface. 43 // Background implementation of the Entry interface.
44 void DoomImpl(); 44 void DoomImpl();
45 int ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, 45 int ReadDataImpl(int index,
46 int offset,
47 IOBuffer* buf,
48 int buf_len,
46 const CompletionCallback& callback); 49 const CompletionCallback& callback);
47 int WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, 50 int WriteDataImpl(int index,
48 const CompletionCallback& callback, bool truncate); 51 int offset,
49 int ReadSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len, 52 IOBuffer* buf,
53 int buf_len,
54 const CompletionCallback& callback,
55 bool truncate);
56 int ReadSparseDataImpl(int64 offset,
57 IOBuffer* buf,
58 int buf_len,
50 const CompletionCallback& callback); 59 const CompletionCallback& callback);
51 int WriteSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len, 60 int WriteSparseDataImpl(int64 offset,
61 IOBuffer* buf,
62 int buf_len,
52 const CompletionCallback& callback); 63 const CompletionCallback& callback);
53 int GetAvailableRangeImpl(int64 offset, int len, int64* start); 64 int GetAvailableRangeImpl(int64 offset, int len, int64* start);
54 void CancelSparseIOImpl(); 65 void CancelSparseIOImpl();
55 int ReadyForSparseIOImpl(const CompletionCallback& callback); 66 int ReadyForSparseIOImpl(const CompletionCallback& callback);
56 67
57 inline CacheEntryBlock* entry() { 68 inline CacheEntryBlock* entry() { return &entry_; }
58 return &entry_;
59 }
60 69
61 inline CacheRankingsBlock* rankings() { 70 inline CacheRankingsBlock* rankings() { return &node_; }
62 return &node_;
63 }
64 71
65 uint32 GetHash(); 72 uint32 GetHash();
66 73
67 // Performs the initialization of a EntryImpl that will be added to the 74 // Performs the initialization of a EntryImpl that will be added to the
68 // cache. 75 // cache.
69 bool CreateEntry(Addr node_address, const std::string& key, uint32 hash); 76 bool CreateEntry(Addr node_address, const std::string& key, uint32 hash);
70 77
71 // Returns true if this entry matches the lookup arguments. 78 // Returns true if this entry matches the lookup arguments.
72 bool IsSameEntry(const std::string& key, uint32 hash); 79 bool IsSameEntry(const std::string& key, uint32 hash);
73 80
(...skipping 13 matching lines...) Expand all
87 void SetNextAddress(Addr address); 94 void SetNextAddress(Addr address);
88 95
89 // Reloads the rankings node information. 96 // Reloads the rankings node information.
90 bool LoadNodeAddress(); 97 bool LoadNodeAddress();
91 98
92 // Updates the stored data to reflect the run-time information for this entry. 99 // Updates the stored data to reflect the run-time information for this entry.
93 // Returns false if the data could not be updated. The purpose of this method 100 // Returns false if the data could not be updated. The purpose of this method
94 // is to be able to detect entries that are currently in use. 101 // is to be able to detect entries that are currently in use.
95 bool Update(); 102 bool Update();
96 103
97 bool dirty() { 104 bool dirty() { return dirty_; }
98 return dirty_;
99 }
100 105
101 bool doomed() { 106 bool doomed() { return doomed_; }
102 return doomed_;
103 }
104 107
105 // Marks this entry as dirty (in memory) if needed. This is intended only for 108 // Marks this entry as dirty (in memory) if needed. This is intended only for
106 // entries that are being read from disk, to be called during loading. 109 // entries that are being read from disk, to be called during loading.
107 void SetDirtyFlag(int32 current_id); 110 void SetDirtyFlag(int32 current_id);
108 111
109 // Fixes this entry so it can be treated as valid (to delete it). 112 // Fixes this entry so it can be treated as valid (to delete it).
110 void SetPointerForInvalidEntry(int32 new_id); 113 void SetPointerForInvalidEntry(int32 new_id);
111 114
112 // Returns true if this entry is so meesed up that not everything is going to 115 // Returns true if this entry is so meesed up that not everything is going to
113 // be removed. 116 // be removed.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // Returns the number of blocks needed to store an EntryStore. 149 // Returns the number of blocks needed to store an EntryStore.
147 static int NumBlocksForEntry(int key_size); 150 static int NumBlocksForEntry(int key_size);
148 151
149 // Entry interface. 152 // Entry interface.
150 virtual void Doom() OVERRIDE; 153 virtual void Doom() OVERRIDE;
151 virtual void Close() OVERRIDE; 154 virtual void Close() OVERRIDE;
152 virtual std::string GetKey() const OVERRIDE; 155 virtual std::string GetKey() const OVERRIDE;
153 virtual base::Time GetLastUsed() const OVERRIDE; 156 virtual base::Time GetLastUsed() const OVERRIDE;
154 virtual base::Time GetLastModified() const OVERRIDE; 157 virtual base::Time GetLastModified() const OVERRIDE;
155 virtual int32 GetDataSize(int index) const OVERRIDE; 158 virtual int32 GetDataSize(int index) const OVERRIDE;
156 virtual int ReadData(int index, int offset, IOBuffer* buf, int buf_len, 159 virtual int ReadData(int index,
160 int offset,
161 IOBuffer* buf,
162 int buf_len,
157 const CompletionCallback& callback) OVERRIDE; 163 const CompletionCallback& callback) OVERRIDE;
158 virtual int WriteData(int index, int offset, IOBuffer* buf, int buf_len, 164 virtual int WriteData(int index,
165 int offset,
166 IOBuffer* buf,
167 int buf_len,
159 const CompletionCallback& callback, 168 const CompletionCallback& callback,
160 bool truncate) OVERRIDE; 169 bool truncate) OVERRIDE;
161 virtual int ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, 170 virtual int ReadSparseData(int64 offset,
171 IOBuffer* buf,
172 int buf_len,
162 const CompletionCallback& callback) OVERRIDE; 173 const CompletionCallback& callback) OVERRIDE;
163 virtual int WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, 174 virtual int WriteSparseData(int64 offset,
175 IOBuffer* buf,
176 int buf_len,
164 const CompletionCallback& callback) OVERRIDE; 177 const CompletionCallback& callback) OVERRIDE;
165 virtual int GetAvailableRange(int64 offset, int len, int64* start, 178 virtual int GetAvailableRange(int64 offset,
179 int len,
180 int64* start,
166 const CompletionCallback& callback) OVERRIDE; 181 const CompletionCallback& callback) OVERRIDE;
167 virtual bool CouldBeSparse() const OVERRIDE; 182 virtual bool CouldBeSparse() const OVERRIDE;
168 virtual void CancelSparseIO() OVERRIDE; 183 virtual void CancelSparseIO() OVERRIDE;
169 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE; 184 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE;
170 185
171 private: 186 private:
172 enum { 187 enum { kNumStreams = 3 };
173 kNumStreams = 3
174 };
175 class UserBuffer; 188 class UserBuffer;
176 189
177 virtual ~EntryImpl(); 190 virtual ~EntryImpl();
178 191
179 // Do all the work for ReadDataImpl and WriteDataImpl. Implemented as 192 // Do all the work for ReadDataImpl and WriteDataImpl. Implemented as
180 // separate functions to make logging of results simpler. 193 // separate functions to make logging of results simpler.
181 int InternalReadData(int index, int offset, IOBuffer* buf, 194 int InternalReadData(int index,
182 int buf_len, const CompletionCallback& callback); 195 int offset,
183 int InternalWriteData(int index, int offset, IOBuffer* buf, int buf_len, 196 IOBuffer* buf,
184 const CompletionCallback& callback, bool truncate); 197 int buf_len,
198 const CompletionCallback& callback);
199 int InternalWriteData(int index,
200 int offset,
201 IOBuffer* buf,
202 int buf_len,
203 const CompletionCallback& callback,
204 bool truncate);
185 205
186 // Initializes the storage for an internal or external data block. 206 // Initializes the storage for an internal or external data block.
187 bool CreateDataBlock(int index, int size); 207 bool CreateDataBlock(int index, int size);
188 208
189 // Initializes the storage for an internal or external generic block. 209 // Initializes the storage for an internal or external generic block.
190 bool CreateBlock(int size, Addr* address); 210 bool CreateBlock(int size, Addr* address);
191 211
192 // Deletes the data pointed by address, maybe backed by files_[index]. 212 // Deletes the data pointed by address, maybe backed by files_[index].
193 // Note that most likely the caller should delete (and store) the reference to 213 // Note that most likely the caller should delete (and store) the reference to
194 // |address| *before* calling this method because we don't want to have an 214 // |address| *before* calling this method because we don't want to have an
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // the cache address of the data will be returned, and that address will be 267 // the cache address of the data will be returned, and that address will be
248 // removed from the regular book keeping of this entry so the caller is 268 // removed from the regular book keeping of this entry so the caller is
249 // responsible for deleting the block (or file) from the backing store at some 269 // responsible for deleting the block (or file) from the backing store at some
250 // point; there is no need to report any storage-size change, only to do the 270 // point; there is no need to report any storage-size change, only to do the
251 // actual cleanup. 271 // actual cleanup.
252 void GetData(int index, char** buffer, Addr* address); 272 void GetData(int index, char** buffer, Addr* address);
253 273
254 // Logs this entry to the internal trace buffer. 274 // Logs this entry to the internal trace buffer.
255 void Log(const char* msg); 275 void Log(const char* msg);
256 276
257 CacheEntryBlock entry_; // Key related information for this entry. 277 CacheEntryBlock entry_; // Key related information for this entry.
258 CacheRankingsBlock node_; // Rankings related information for this entry. 278 CacheRankingsBlock node_; // Rankings related information for this entry.
259 base::WeakPtr<BackendImpl> backend_; // Back pointer to the cache. 279 base::WeakPtr<BackendImpl> backend_; // Back pointer to the cache.
260 base::WeakPtr<InFlightBackendIO> background_queue_; // In-progress queue. 280 base::WeakPtr<InFlightBackendIO> background_queue_; // In-progress queue.
261 scoped_ptr<UserBuffer> user_buffers_[kNumStreams]; // Stores user data. 281 scoped_ptr<UserBuffer> user_buffers_[kNumStreams]; // Stores user data.
262 // Files to store external user data and key. 282 // Files to store external user data and key.
263 scoped_refptr<File> files_[kNumStreams + 1]; 283 scoped_refptr<File> files_[kNumStreams + 1];
264 mutable std::string key_; // Copy of the key. 284 mutable std::string key_; // Copy of the key.
265 int unreported_size_[kNumStreams]; // Bytes not reported yet to the backend. 285 int unreported_size_[kNumStreams]; // Bytes not reported yet to the backend.
266 bool doomed_; // True if this entry was removed from the cache. 286 bool doomed_; // True if this entry was removed from the cache.
267 bool read_only_; // True if not yet writing. 287 bool read_only_; // True if not yet writing.
268 bool dirty_; // True if we detected that this is a dirty entry. 288 bool dirty_; // True if we detected that this is a dirty entry.
269 scoped_ptr<SparseControl> sparse_; // Support for sparse entries. 289 scoped_ptr<SparseControl> sparse_; // Support for sparse entries.
270 290
271 net::BoundNetLog net_log_; 291 net::BoundNetLog net_log_;
272 292
273 DISALLOW_COPY_AND_ASSIGN(EntryImpl); 293 DISALLOW_COPY_AND_ASSIGN(EntryImpl);
274 }; 294 };
275 295
276 } // namespace disk_cache 296 } // namespace disk_cache
277 297
278 #endif // NET_DISK_CACHE_BLOCKFILE_ENTRY_IMPL_H_ 298 #endif // NET_DISK_CACHE_BLOCKFILE_ENTRY_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698