| OLD | NEW |
| 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_MEMORY_MEM_ENTRY_IMPL_H_ | 5 #ifndef NET_DISK_CACHE_MEMORY_MEM_ENTRY_IMPL_H_ |
| 6 #define NET_DISK_CACHE_MEMORY_MEM_ENTRY_IMPL_H_ | 6 #define NET_DISK_CACHE_MEMORY_MEM_ENTRY_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 11 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 10 #include "net/disk_cache/disk_cache.h" | 13 #include "net/disk_cache/disk_cache.h" |
| 11 #include "net/log/net_log.h" | 14 #include "net/log/net_log.h" |
| 12 | 15 |
| 13 namespace disk_cache { | 16 namespace disk_cache { |
| 14 | 17 |
| 15 class MemBackendImpl; | 18 class MemBackendImpl; |
| 16 | 19 |
| 17 // This class implements the Entry interface for the memory-only cache. An | 20 // This class implements the Entry interface for the memory-only cache. An |
| 18 // object of this class represents a single entry on the cache. We use two | 21 // object of this class represents a single entry on the cache. We use two |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 const net::BoundNetLog& net_log() { | 87 const net::BoundNetLog& net_log() { |
| 85 return net_log_; | 88 return net_log_; |
| 86 } | 89 } |
| 87 | 90 |
| 88 // Entry interface. | 91 // Entry interface. |
| 89 void Doom() override; | 92 void Doom() override; |
| 90 void Close() override; | 93 void Close() override; |
| 91 std::string GetKey() const override; | 94 std::string GetKey() const override; |
| 92 base::Time GetLastUsed() const override; | 95 base::Time GetLastUsed() const override; |
| 93 base::Time GetLastModified() const override; | 96 base::Time GetLastModified() const override; |
| 94 int32 GetDataSize(int index) const override; | 97 int32_t GetDataSize(int index) const override; |
| 95 int ReadData(int index, | 98 int ReadData(int index, |
| 96 int offset, | 99 int offset, |
| 97 IOBuffer* buf, | 100 IOBuffer* buf, |
| 98 int buf_len, | 101 int buf_len, |
| 99 const CompletionCallback& callback) override; | 102 const CompletionCallback& callback) override; |
| 100 int WriteData(int index, | 103 int WriteData(int index, |
| 101 int offset, | 104 int offset, |
| 102 IOBuffer* buf, | 105 IOBuffer* buf, |
| 103 int buf_len, | 106 int buf_len, |
| 104 const CompletionCallback& callback, | 107 const CompletionCallback& callback, |
| 105 bool truncate) override; | 108 bool truncate) override; |
| 106 int ReadSparseData(int64 offset, | 109 int ReadSparseData(int64_t offset, |
| 107 IOBuffer* buf, | 110 IOBuffer* buf, |
| 108 int buf_len, | 111 int buf_len, |
| 109 const CompletionCallback& callback) override; | 112 const CompletionCallback& callback) override; |
| 110 int WriteSparseData(int64 offset, | 113 int WriteSparseData(int64_t offset, |
| 111 IOBuffer* buf, | 114 IOBuffer* buf, |
| 112 int buf_len, | 115 int buf_len, |
| 113 const CompletionCallback& callback) override; | 116 const CompletionCallback& callback) override; |
| 114 int GetAvailableRange(int64 offset, | 117 int GetAvailableRange(int64_t offset, |
| 115 int len, | 118 int len, |
| 116 int64* start, | 119 int64_t* start, |
| 117 const CompletionCallback& callback) override; | 120 const CompletionCallback& callback) override; |
| 118 bool CouldBeSparse() const override; | 121 bool CouldBeSparse() const override; |
| 119 void CancelSparseIO() override {} | 122 void CancelSparseIO() override {} |
| 120 int ReadyForSparseIO(const CompletionCallback& callback) override; | 123 int ReadyForSparseIO(const CompletionCallback& callback) override; |
| 121 | 124 |
| 122 private: | 125 private: |
| 123 typedef base::hash_map<int, MemEntryImpl*> EntryMap; | 126 typedef base::hash_map<int, MemEntryImpl*> EntryMap; |
| 124 | 127 |
| 125 enum { | 128 enum { |
| 126 NUM_STREAMS = 3 | 129 NUM_STREAMS = 3 |
| 127 }; | 130 }; |
| 128 | 131 |
| 129 ~MemEntryImpl() override; | 132 ~MemEntryImpl() override; |
| 130 | 133 |
| 131 // Do all the work for corresponding public functions. Implemented as | 134 // Do all the work for corresponding public functions. Implemented as |
| 132 // separate functions to make logging of results simpler. | 135 // separate functions to make logging of results simpler. |
| 133 int InternalReadData(int index, int offset, IOBuffer* buf, int buf_len); | 136 int InternalReadData(int index, int offset, IOBuffer* buf, int buf_len); |
| 134 int InternalWriteData(int index, int offset, IOBuffer* buf, int buf_len, | 137 int InternalWriteData(int index, int offset, IOBuffer* buf, int buf_len, |
| 135 bool truncate); | 138 bool truncate); |
| 136 int InternalReadSparseData(int64 offset, IOBuffer* buf, int buf_len); | 139 int InternalReadSparseData(int64_t offset, IOBuffer* buf, int buf_len); |
| 137 int InternalWriteSparseData(int64 offset, IOBuffer* buf, int buf_len); | 140 int InternalWriteSparseData(int64_t offset, IOBuffer* buf, int buf_len); |
| 138 | 141 |
| 139 // Old Entry interface. | 142 // Old Entry interface. |
| 140 int GetAvailableRange(int64 offset, int len, int64* start); | 143 int GetAvailableRange(int64_t offset, int len, int64_t* start); |
| 141 | 144 |
| 142 // Grows and cleans up the data buffer. | 145 // Grows and cleans up the data buffer. |
| 143 void PrepareTarget(int index, int offset, int buf_len); | 146 void PrepareTarget(int index, int offset, int buf_len); |
| 144 | 147 |
| 145 // Updates ranking information. | 148 // Updates ranking information. |
| 146 void UpdateRank(bool modified); | 149 void UpdateRank(bool modified); |
| 147 | 150 |
| 148 // Initializes the children map and sparse info. This method is only called | 151 // Initializes the children map and sparse info. This method is only called |
| 149 // on a parent entry. | 152 // on a parent entry. |
| 150 bool InitSparseInfo(); | 153 bool InitSparseInfo(); |
| 151 | 154 |
| 152 // Performs the initialization of a MemEntryImpl as a child entry. | 155 // Performs the initialization of a MemEntryImpl as a child entry. |
| 153 // |parent| is the pointer to the parent entry. |child_id| is the ID of | 156 // |parent| is the pointer to the parent entry. |child_id| is the ID of |
| 154 // the new child. | 157 // the new child. |
| 155 bool InitChildEntry(MemEntryImpl* parent, int child_id, net::NetLog* net_log); | 158 bool InitChildEntry(MemEntryImpl* parent, int child_id, net::NetLog* net_log); |
| 156 | 159 |
| 157 // Returns an entry responsible for |offset|. The returned entry can be a | 160 // Returns an entry responsible for |offset|. The returned entry can be a |
| 158 // child entry or this entry itself if |offset| points to the first range. | 161 // child entry or this entry itself if |offset| points to the first range. |
| 159 // If such entry does not exist and |create| is true, a new child entry is | 162 // If such entry does not exist and |create| is true, a new child entry is |
| 160 // created. | 163 // created. |
| 161 MemEntryImpl* OpenChild(int64 offset, bool create); | 164 MemEntryImpl* OpenChild(int64_t offset, bool create); |
| 162 | 165 |
| 163 // Finds the first child located within the range [|offset|, |offset + len|). | 166 // Finds the first child located within the range [|offset|, |offset + len|). |
| 164 // Returns the number of bytes ahead of |offset| to reach the first available | 167 // Returns the number of bytes ahead of |offset| to reach the first available |
| 165 // bytes in the entry. The first child found is output to |child|. | 168 // bytes in the entry. The first child found is output to |child|. |
| 166 int FindNextChild(int64 offset, int len, MemEntryImpl** child); | 169 int FindNextChild(int64_t offset, int len, MemEntryImpl** child); |
| 167 | 170 |
| 168 // Removes child indexed by |child_id| from the children map. | 171 // Removes child indexed by |child_id| from the children map. |
| 169 void DetachChild(int child_id); | 172 void DetachChild(int child_id); |
| 170 | 173 |
| 171 std::string key_; | 174 std::string key_; |
| 172 std::vector<char> data_[NUM_STREAMS]; // User data. | 175 std::vector<char> data_[NUM_STREAMS]; // User data. |
| 173 int32 data_size_[NUM_STREAMS]; | 176 int32_t data_size_[NUM_STREAMS]; |
| 174 int ref_count_; | 177 int ref_count_; |
| 175 | 178 |
| 176 int child_id_; // The ID of a child entry. | 179 int child_id_; // The ID of a child entry. |
| 177 int child_first_pos_; // The position of the first byte in a child | 180 int child_first_pos_; // The position of the first byte in a child |
| 178 // entry. | 181 // entry. |
| 179 MemEntryImpl* next_; // Pointers for the LRU list. | 182 MemEntryImpl* next_; // Pointers for the LRU list. |
| 180 MemEntryImpl* prev_; | 183 MemEntryImpl* prev_; |
| 181 MemEntryImpl* parent_; // Pointer to the parent entry. | 184 MemEntryImpl* parent_; // Pointer to the parent entry. |
| 182 scoped_ptr<EntryMap> children_; | 185 scoped_ptr<EntryMap> children_; |
| 183 | 186 |
| 184 base::Time last_modified_; // LRU information. | 187 base::Time last_modified_; // LRU information. |
| 185 base::Time last_used_; | 188 base::Time last_used_; |
| 186 MemBackendImpl* backend_; // Back pointer to the cache. | 189 MemBackendImpl* backend_; // Back pointer to the cache. |
| 187 bool doomed_; // True if this entry was removed from the cache. | 190 bool doomed_; // True if this entry was removed from the cache. |
| 188 | 191 |
| 189 net::BoundNetLog net_log_; | 192 net::BoundNetLog net_log_; |
| 190 | 193 |
| 191 DISALLOW_COPY_AND_ASSIGN(MemEntryImpl); | 194 DISALLOW_COPY_AND_ASSIGN(MemEntryImpl); |
| 192 }; | 195 }; |
| 193 | 196 |
| 194 } // namespace disk_cache | 197 } // namespace disk_cache |
| 195 | 198 |
| 196 #endif // NET_DISK_CACHE_MEMORY_MEM_ENTRY_IMPL_H_ | 199 #endif // NET_DISK_CACHE_MEMORY_MEM_ENTRY_IMPL_H_ |
| OLD | NEW |