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 "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // Performs the initialization of a EntryImpl that will be added to the | 55 // Performs the initialization of a EntryImpl that will be added to the |
56 // cache. | 56 // cache. |
57 bool CreateEntry(const std::string& key, net::NetLog* net_log); | 57 bool CreateEntry(const std::string& key, net::NetLog* net_log); |
58 | 58 |
59 // Permanently destroys this entry. | 59 // Permanently destroys this entry. |
60 void InternalDoom(); | 60 void InternalDoom(); |
61 | 61 |
62 void Open(); | 62 void Open(); |
63 bool InUse(); | 63 bool InUse(); |
64 | 64 |
65 MemEntryImpl* next() const { | 65 MemEntryImpl* next() const { return next_; } |
66 return next_; | |
67 } | |
68 | 66 |
69 MemEntryImpl* prev() const { | 67 MemEntryImpl* prev() const { return prev_; } |
70 return prev_; | |
71 } | |
72 | 68 |
73 void set_next(MemEntryImpl* next) { | 69 void set_next(MemEntryImpl* next) { next_ = next; } |
74 next_ = next; | |
75 } | |
76 | 70 |
77 void set_prev(MemEntryImpl* prev) { | 71 void set_prev(MemEntryImpl* prev) { prev_ = prev; } |
78 prev_ = prev; | |
79 } | |
80 | 72 |
81 EntryType type() const { | 73 EntryType type() const { return parent_ ? kChildEntry : kParentEntry; } |
82 return parent_ ? kChildEntry : kParentEntry; | |
83 } | |
84 | 74 |
85 const net::BoundNetLog& net_log() { | 75 const net::BoundNetLog& net_log() { return net_log_; } |
86 return net_log_; | |
87 } | |
88 | 76 |
89 // Entry interface. | 77 // Entry interface. |
90 virtual void Doom() OVERRIDE; | 78 virtual void Doom() OVERRIDE; |
91 virtual void Close() OVERRIDE; | 79 virtual void Close() OVERRIDE; |
92 virtual std::string GetKey() const OVERRIDE; | 80 virtual std::string GetKey() const OVERRIDE; |
93 virtual base::Time GetLastUsed() const OVERRIDE; | 81 virtual base::Time GetLastUsed() const OVERRIDE; |
94 virtual base::Time GetLastModified() const OVERRIDE; | 82 virtual base::Time GetLastModified() const OVERRIDE; |
95 virtual int32 GetDataSize(int index) const OVERRIDE; | 83 virtual int32 GetDataSize(int index) const OVERRIDE; |
96 virtual int ReadData(int index, int offset, IOBuffer* buf, int buf_len, | 84 virtual int ReadData(int index, |
| 85 int offset, |
| 86 IOBuffer* buf, |
| 87 int buf_len, |
97 const CompletionCallback& callback) OVERRIDE; | 88 const CompletionCallback& callback) OVERRIDE; |
98 virtual int WriteData(int index, int offset, IOBuffer* buf, int buf_len, | 89 virtual int WriteData(int index, |
| 90 int offset, |
| 91 IOBuffer* buf, |
| 92 int buf_len, |
99 const CompletionCallback& callback, | 93 const CompletionCallback& callback, |
100 bool truncate) OVERRIDE; | 94 bool truncate) OVERRIDE; |
101 virtual int ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, | 95 virtual int ReadSparseData(int64 offset, |
| 96 IOBuffer* buf, |
| 97 int buf_len, |
102 const CompletionCallback& callback) OVERRIDE; | 98 const CompletionCallback& callback) OVERRIDE; |
103 virtual int WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, | 99 virtual int WriteSparseData(int64 offset, |
| 100 IOBuffer* buf, |
| 101 int buf_len, |
104 const CompletionCallback& callback) OVERRIDE; | 102 const CompletionCallback& callback) OVERRIDE; |
105 virtual int GetAvailableRange(int64 offset, int len, int64* start, | 103 virtual int GetAvailableRange(int64 offset, |
| 104 int len, |
| 105 int64* start, |
106 const CompletionCallback& callback) OVERRIDE; | 106 const CompletionCallback& callback) OVERRIDE; |
107 virtual bool CouldBeSparse() const OVERRIDE; | 107 virtual bool CouldBeSparse() const OVERRIDE; |
108 virtual void CancelSparseIO() OVERRIDE {} | 108 virtual void CancelSparseIO() OVERRIDE {} |
109 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE; | 109 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE; |
110 | 110 |
111 private: | 111 private: |
112 typedef base::hash_map<int, MemEntryImpl*> EntryMap; | 112 typedef base::hash_map<int, MemEntryImpl*> EntryMap; |
113 | 113 |
114 enum { | 114 enum { NUM_STREAMS = 3 }; |
115 NUM_STREAMS = 3 | |
116 }; | |
117 | 115 |
118 virtual ~MemEntryImpl(); | 116 virtual ~MemEntryImpl(); |
119 | 117 |
120 // Do all the work for corresponding public functions. Implemented as | 118 // Do all the work for corresponding public functions. Implemented as |
121 // separate functions to make logging of results simpler. | 119 // separate functions to make logging of results simpler. |
122 int InternalReadData(int index, int offset, IOBuffer* buf, int buf_len); | 120 int InternalReadData(int index, int offset, IOBuffer* buf, int buf_len); |
123 int InternalWriteData(int index, int offset, IOBuffer* buf, int buf_len, | 121 int InternalWriteData(int index, |
| 122 int offset, |
| 123 IOBuffer* buf, |
| 124 int buf_len, |
124 bool truncate); | 125 bool truncate); |
125 int InternalReadSparseData(int64 offset, IOBuffer* buf, int buf_len); | 126 int InternalReadSparseData(int64 offset, IOBuffer* buf, int buf_len); |
126 int InternalWriteSparseData(int64 offset, IOBuffer* buf, int buf_len); | 127 int InternalWriteSparseData(int64 offset, IOBuffer* buf, int buf_len); |
127 | 128 |
128 // Old Entry interface. | 129 // Old Entry interface. |
129 int GetAvailableRange(int64 offset, int len, int64* start); | 130 int GetAvailableRange(int64 offset, int len, int64* start); |
130 | 131 |
131 // Grows and cleans up the data buffer. | 132 // Grows and cleans up the data buffer. |
132 void PrepareTarget(int index, int offset, int buf_len); | 133 void PrepareTarget(int index, int offset, int buf_len); |
133 | 134 |
(...skipping 21 matching lines...) Expand all Loading... |
155 int FindNextChild(int64 offset, int len, MemEntryImpl** child); | 156 int FindNextChild(int64 offset, int len, MemEntryImpl** child); |
156 | 157 |
157 // Removes child indexed by |child_id| from the children map. | 158 // Removes child indexed by |child_id| from the children map. |
158 void DetachChild(int child_id); | 159 void DetachChild(int child_id); |
159 | 160 |
160 std::string key_; | 161 std::string key_; |
161 std::vector<char> data_[NUM_STREAMS]; // User data. | 162 std::vector<char> data_[NUM_STREAMS]; // User data. |
162 int32 data_size_[NUM_STREAMS]; | 163 int32 data_size_[NUM_STREAMS]; |
163 int ref_count_; | 164 int ref_count_; |
164 | 165 |
165 int child_id_; // The ID of a child entry. | 166 int child_id_; // The ID of a child entry. |
166 int child_first_pos_; // The position of the first byte in a child | 167 int child_first_pos_; // The position of the first byte in a child |
167 // entry. | 168 // entry. |
168 MemEntryImpl* next_; // Pointers for the LRU list. | 169 MemEntryImpl* next_; // Pointers for the LRU list. |
169 MemEntryImpl* prev_; | 170 MemEntryImpl* prev_; |
170 MemEntryImpl* parent_; // Pointer to the parent entry. | 171 MemEntryImpl* parent_; // Pointer to the parent entry. |
171 scoped_ptr<EntryMap> children_; | 172 scoped_ptr<EntryMap> children_; |
172 | 173 |
173 base::Time last_modified_; // LRU information. | 174 base::Time last_modified_; // LRU information. |
174 base::Time last_used_; | 175 base::Time last_used_; |
175 MemBackendImpl* backend_; // Back pointer to the cache. | 176 MemBackendImpl* backend_; // Back pointer to the cache. |
176 bool doomed_; // True if this entry was removed from the cache. | 177 bool doomed_; // True if this entry was removed from the cache. |
177 | 178 |
178 net::BoundNetLog net_log_; | 179 net::BoundNetLog net_log_; |
179 | 180 |
180 DISALLOW_COPY_AND_ASSIGN(MemEntryImpl); | 181 DISALLOW_COPY_AND_ASSIGN(MemEntryImpl); |
181 }; | 182 }; |
182 | 183 |
183 } // namespace disk_cache | 184 } // namespace disk_cache |
184 | 185 |
185 #endif // NET_DISK_CACHE_MEMORY_MEM_ENTRY_IMPL_H_ | 186 #endif // NET_DISK_CACHE_MEMORY_MEM_ENTRY_IMPL_H_ |
OLD | NEW |