Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2009 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 class SparseControl; |
| 17 | 17 |
| 18 // This class implements the Entry interface. An object of this | 18 // This class implements the Entry interface. An object of this |
| 19 // class represents a single entry on the cache. | 19 // class represents a single entry on the cache. |
| 20 class EntryImpl : public Entry, public base::RefCounted<EntryImpl> { | 20 class EntryImpl : public Entry, public base::RefCounted<EntryImpl> { |
| 21 friend class base::RefCounted<EntryImpl>; | 21 friend class base::RefCounted<EntryImpl>; |
| 22 friend class SparseControl; | 22 friend class SparseControl; |
| 23 public: | 23 public: |
| 24 enum Operation { | |
|
darin (slow to review)
2009/08/28 23:14:37
nit: though kFoo is encouraged by the style guide,
| |
| 25 kRead, | |
| 26 kWrite, | |
| 27 kSparseRead, | |
| 28 kSparseWrite, | |
| 29 kAsyncIO | |
| 30 }; | |
| 31 | |
| 24 EntryImpl(BackendImpl* backend, Addr address); | 32 EntryImpl(BackendImpl* backend, Addr address); |
| 25 | 33 |
| 26 // Entry interface. | 34 // Entry interface. |
| 27 virtual void Doom(); | 35 virtual void Doom(); |
| 28 virtual void Close(); | 36 virtual void Close(); |
| 29 virtual std::string GetKey() const; | 37 virtual std::string GetKey() const; |
| 30 virtual base::Time GetLastUsed() const; | 38 virtual base::Time GetLastUsed() const; |
| 31 virtual base::Time GetLastModified() const; | 39 virtual base::Time GetLastModified() const; |
| 32 virtual int32 GetDataSize(int index) const; | 40 virtual int32 GetDataSize(int index) const; |
| 33 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, | 41 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 bool SanityCheck(); | 100 bool SanityCheck(); |
| 93 | 101 |
| 94 // Handle the pending asynchronous IO count. | 102 // Handle the pending asynchronous IO count. |
| 95 void IncrementIoCount(); | 103 void IncrementIoCount(); |
| 96 void DecrementIoCount(); | 104 void DecrementIoCount(); |
| 97 | 105 |
| 98 // Set the access times for this entry. This method provides support for | 106 // Set the access times for this entry. This method provides support for |
| 99 // the upgrade tool. | 107 // the upgrade tool. |
| 100 void SetTimes(base::Time last_used, base::Time last_modified); | 108 void SetTimes(base::Time last_used, base::Time last_modified); |
| 101 | 109 |
| 110 // Generates a histogram for the time spent working on this operation. | |
| 111 void ReportIOTime(Operation op, const base::Time& start); | |
| 112 | |
| 102 private: | 113 private: |
| 103 enum { | 114 enum { |
| 104 kNumStreams = 3 | 115 kNumStreams = 3 |
| 105 }; | 116 }; |
| 106 | 117 |
| 107 enum Operation { | |
| 108 kRead, | |
| 109 kWrite, | |
| 110 kSparseRead, | |
| 111 kSparseWrite | |
| 112 }; | |
| 113 | |
| 114 ~EntryImpl(); | 118 ~EntryImpl(); |
| 115 | 119 |
| 116 // Initializes the storage for an internal or external data block. | 120 // Initializes the storage for an internal or external data block. |
| 117 bool CreateDataBlock(int index, int size); | 121 bool CreateDataBlock(int index, int size); |
| 118 | 122 |
| 119 // Initializes the storage for an internal or external generic block. | 123 // Initializes the storage for an internal or external generic block. |
| 120 bool CreateBlock(int size, Addr* address); | 124 bool CreateBlock(int size, Addr* address); |
| 121 | 125 |
| 122 // Deletes the data pointed by address, maybe backed by files_[index]. | 126 // Deletes the data pointed by address, maybe backed by files_[index]. |
| 123 void DeleteData(Addr address, int index); | 127 void DeleteData(Addr address, int index); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 // Gets the data stored at the given index. If the information is in memory, | 163 // Gets the data stored at the given index. If the information is in memory, |
| 160 // a buffer will be allocated and the data will be copied to it (the caller | 164 // a buffer will be allocated and the data will be copied to it (the caller |
| 161 // can find out the size of the buffer before making this call). Otherwise, | 165 // can find out the size of the buffer before making this call). Otherwise, |
| 162 // the cache address of the data will be returned, and that address will be | 166 // the cache address of the data will be returned, and that address will be |
| 163 // removed from the regular book keeping of this entry so the caller is | 167 // removed from the regular book keeping of this entry so the caller is |
| 164 // responsible for deleting the block (or file) from the backing store at some | 168 // responsible for deleting the block (or file) from the backing store at some |
| 165 // point; there is no need to report any storage-size change, only to do the | 169 // point; there is no need to report any storage-size change, only to do the |
| 166 // actual cleanup. | 170 // actual cleanup. |
| 167 void GetData(int index, char** buffer, Addr* address); | 171 void GetData(int index, char** buffer, Addr* address); |
| 168 | 172 |
| 169 // Generates a histogram for the time spent working on this operation. | |
| 170 void ReportIOTime(Operation op, const base::Time& start); | |
| 171 | |
| 172 // Logs this entry to the internal trace buffer. | 173 // Logs this entry to the internal trace buffer. |
| 173 void Log(const char* msg); | 174 void Log(const char* msg); |
| 174 | 175 |
| 175 CacheEntryBlock entry_; // Key related information for this entry. | 176 CacheEntryBlock entry_; // Key related information for this entry. |
| 176 CacheRankingsBlock node_; // Rankings related information for this entry. | 177 CacheRankingsBlock node_; // Rankings related information for this entry. |
| 177 BackendImpl* backend_; // Back pointer to the cache. | 178 BackendImpl* backend_; // Back pointer to the cache. |
| 178 scoped_array<char> user_buffers_[kNumStreams]; // Store user data. | 179 scoped_array<char> user_buffers_[kNumStreams]; // Store user data. |
| 179 // Files to store external user data and key. | 180 // Files to store external user data and key. |
| 180 scoped_refptr<File> files_[kNumStreams + 1]; | 181 scoped_refptr<File> files_[kNumStreams + 1]; |
| 181 // Copy of the file used to store the key. We don't own this object. | 182 // Copy of the file used to store the key. We don't own this object. |
| 182 mutable File* key_file_; | 183 mutable File* key_file_; |
| 183 int unreported_size_[kNumStreams]; // Bytes not reported yet to the backend. | 184 int unreported_size_[kNumStreams]; // Bytes not reported yet to the backend. |
| 184 bool doomed_; // True if this entry was removed from the cache. | 185 bool doomed_; // True if this entry was removed from the cache. |
| 185 scoped_ptr<SparseControl> sparse_; // Support for sparse entries. | 186 scoped_ptr<SparseControl> sparse_; // Support for sparse entries. |
| 186 | 187 |
| 187 DISALLOW_EVIL_CONSTRUCTORS(EntryImpl); | 188 DISALLOW_EVIL_CONSTRUCTORS(EntryImpl); |
| 188 }; | 189 }; |
| 189 | 190 |
| 190 } // namespace disk_cache | 191 } // namespace disk_cache |
| 191 | 192 |
| 192 #endif // NET_DISK_CACHE_ENTRY_IMPL_H_ | 193 #endif // NET_DISK_CACHE_ENTRY_IMPL_H_ |
| OLD | NEW |