OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_ENTRY_IMPL_H_ | 5 #ifndef NET_DISK_CACHE_ENTRY_IMPL_H_ |
6 #define NET_DISK_CACHE_ENTRY_IMPL_H_ | 6 #define NET_DISK_CACHE_ENTRY_IMPL_H_ |
7 | 7 |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "net/disk_cache/disk_cache.h" | 9 #include "net/disk_cache/disk_cache.h" |
10 #include "net/disk_cache/storage_block.h" | 10 #include "net/disk_cache/storage_block.h" |
11 #include "net/disk_cache/storage_block-inl.h" | 11 #include "net/disk_cache/storage_block-inl.h" |
12 | 12 |
13 namespace disk_cache { | 13 namespace disk_cache { |
14 | 14 |
15 class BackendImpl; | 15 class BackendImpl; |
| 16 class SparseControl; |
16 | 17 |
17 // This class implements the Entry interface. An object of this | 18 // This class implements the Entry interface. An object of this |
18 // class represents a single entry on the cache. | 19 // class represents a single entry on the cache. |
19 class EntryImpl : public Entry, public base::RefCounted<EntryImpl> { | 20 class EntryImpl : public Entry, public base::RefCounted<EntryImpl> { |
20 friend class base::RefCounted<EntryImpl>; | 21 friend class base::RefCounted<EntryImpl>; |
| 22 friend class SparseControl; |
21 public: | 23 public: |
22 EntryImpl(BackendImpl* backend, Addr address); | 24 EntryImpl(BackendImpl* backend, Addr address); |
23 | 25 |
24 // Entry interface. | 26 // Entry interface. |
25 virtual void Doom(); | 27 virtual void Doom(); |
26 virtual void Close(); | 28 virtual void Close(); |
27 virtual std::string GetKey() const; | 29 virtual std::string GetKey() const; |
28 virtual base::Time GetLastUsed() const; | 30 virtual base::Time GetLastUsed() const; |
29 virtual base::Time GetLastModified() const; | 31 virtual base::Time GetLastModified() const; |
30 virtual int32 GetDataSize(int index) const; | 32 virtual int32 GetDataSize(int index) const; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 93 |
92 // Handle the pending asynchronous IO count. | 94 // Handle the pending asynchronous IO count. |
93 void IncrementIoCount(); | 95 void IncrementIoCount(); |
94 void DecrementIoCount(); | 96 void DecrementIoCount(); |
95 | 97 |
96 // Set the access times for this entry. This method provides support for | 98 // Set the access times for this entry. This method provides support for |
97 // the upgrade tool. | 99 // the upgrade tool. |
98 void SetTimes(base::Time last_used, base::Time last_modified); | 100 void SetTimes(base::Time last_used, base::Time last_modified); |
99 | 101 |
100 private: | 102 private: |
101 enum { | 103 enum { |
102 NUM_STREAMS = 3 | 104 NUM_STREAMS = 3 |
103 }; | 105 }; |
104 | 106 |
105 ~EntryImpl(); | 107 ~EntryImpl(); |
106 | 108 |
107 // Initializes the storage for an internal or external data block. | 109 // Initializes the storage for an internal or external data block. |
108 bool CreateDataBlock(int index, int size); | 110 bool CreateDataBlock(int index, int size); |
109 | 111 |
110 // Initializes the storage for an internal or external generic block. | 112 // Initializes the storage for an internal or external generic block. |
111 bool CreateBlock(int size, Addr* address); | 113 bool CreateBlock(int size, Addr* address); |
112 | 114 |
113 // Deletes the data pointed by address, maybe backed by files_[index]. | 115 // Deletes the data pointed by address, maybe backed by files_[index]. |
(...skipping 17 matching lines...) Expand all Loading... |
131 | 133 |
132 // Reads from a block data file to this object's memory buffer. | 134 // Reads from a block data file to this object's memory buffer. |
133 bool MoveToLocalBuffer(int index); | 135 bool MoveToLocalBuffer(int index); |
134 | 136 |
135 // Loads the external file to this object's memory buffer. | 137 // Loads the external file to this object's memory buffer. |
136 bool ImportSeparateFile(int index, int offset, int buf_len); | 138 bool ImportSeparateFile(int index, int offset, int buf_len); |
137 | 139 |
138 // Flush the in-memory data to the backing storage. | 140 // Flush the in-memory data to the backing storage. |
139 bool Flush(int index, int size, bool async); | 141 bool Flush(int index, int size, bool async); |
140 | 142 |
| 143 // Initializes the sparse control object. Returns a net error code. |
| 144 int InitSparseData(); |
| 145 |
141 // Logs this entry to the internal trace buffer. | 146 // Logs this entry to the internal trace buffer. |
142 void Log(const char* msg); | 147 void Log(const char* msg); |
143 | 148 |
144 CacheEntryBlock entry_; // Key related information for this entry. | 149 CacheEntryBlock entry_; // Key related information for this entry. |
145 CacheRankingsBlock node_; // Rankings related information for this entry. | 150 CacheRankingsBlock node_; // Rankings related information for this entry. |
146 BackendImpl* backend_; // Back pointer to the cache. | 151 BackendImpl* backend_; // Back pointer to the cache. |
147 scoped_array<char> user_buffers_[NUM_STREAMS]; // Store user data. | 152 scoped_array<char> user_buffers_[NUM_STREAMS]; // Store user data. |
148 scoped_refptr<File> files_[NUM_STREAMS + 1]; // Files to store external user | 153 scoped_refptr<File> files_[NUM_STREAMS + 1]; // Files to store external user |
149 // data and key. | 154 // data and key. |
150 int unreported_size_[NUM_STREAMS]; // Bytes not reported yet to the backend. | 155 int unreported_size_[NUM_STREAMS]; // Bytes not reported yet to the backend. |
151 bool doomed_; // True if this entry was removed from the cache. | 156 bool doomed_; // True if this entry was removed from the cache. |
| 157 scoped_ptr<SparseControl> sparse_; // Support for sparse entries. |
| 158 |
152 DISALLOW_EVIL_CONSTRUCTORS(EntryImpl); | 159 DISALLOW_EVIL_CONSTRUCTORS(EntryImpl); |
153 }; | 160 }; |
154 | 161 |
155 } // namespace disk_cache | 162 } // namespace disk_cache |
156 | 163 |
157 #endif // NET_DISK_CACHE_ENTRY_IMPL_H_ | 164 #endif // NET_DISK_CACHE_ENTRY_IMPL_H_ |
OLD | NEW |