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

Side by Side Diff: net/disk_cache/mem_backend_impl.cc

Issue 355028: Disk Cache: New interface that enables asynchronous completion... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
« no previous file with comments | « net/disk_cache/mem_backend_impl.h ('k') | net/disk_cache/mem_entry_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "net/disk_cache/mem_backend_impl.h" 5 #include "net/disk_cache/mem_backend_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/sys_info.h" 8 #include "base/sys_info.h"
9 #include "net/base/net_errors.h"
9 #include "net/disk_cache/cache_util.h" 10 #include "net/disk_cache/cache_util.h"
10 #include "net/disk_cache/mem_entry_impl.h" 11 #include "net/disk_cache/mem_entry_impl.h"
11 12
12 using base::Time; 13 using base::Time;
13 14
14 namespace { 15 namespace {
15 16
16 const int kDefaultCacheSize = 10 * 1024 * 1024; 17 const int kDefaultCacheSize = 10 * 1024 * 1024;
17 const int kCleanUpMargin = 1024 * 1024; 18 const int kCleanUpMargin = 1024 * 1024;
18 19
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 EntryMap::iterator it = entries_.find(key); 93 EntryMap::iterator it = entries_.find(key);
93 if (it == entries_.end()) 94 if (it == entries_.end())
94 return false; 95 return false;
95 96
96 it->second->Open(); 97 it->second->Open();
97 98
98 *entry = it->second; 99 *entry = it->second;
99 return true; 100 return true;
100 } 101 }
101 102
103 int MemBackendImpl::OpenEntry(const std::string& key, Entry** entry,
104 CompletionCallback* callback) {
105 if (OpenEntry(key, entry))
106 return net::OK;
107
108 return net::ERR_FAILED;
109 }
110
102 bool MemBackendImpl::CreateEntry(const std::string& key, Entry** entry) { 111 bool MemBackendImpl::CreateEntry(const std::string& key, Entry** entry) {
103 EntryMap::iterator it = entries_.find(key); 112 EntryMap::iterator it = entries_.find(key);
104 if (it != entries_.end()) 113 if (it != entries_.end())
105 return false; 114 return false;
106 115
107 MemEntryImpl* cache_entry = new MemEntryImpl(this); 116 MemEntryImpl* cache_entry = new MemEntryImpl(this);
108 if (!cache_entry->CreateEntry(key)) { 117 if (!cache_entry->CreateEntry(key)) {
109 delete entry; 118 delete entry;
110 return false; 119 return false;
111 } 120 }
112 121
113 rankings_.Insert(cache_entry); 122 rankings_.Insert(cache_entry);
114 entries_[key] = cache_entry; 123 entries_[key] = cache_entry;
115 124
116 *entry = cache_entry; 125 *entry = cache_entry;
117 return true; 126 return true;
118 } 127 }
119 128
129 int MemBackendImpl::CreateEntry(const std::string& key, Entry** entry,
130 CompletionCallback* callback) {
131 if (CreateEntry(key, entry))
132 return net::OK;
133
134 return net::ERR_FAILED;
135 }
136
120 bool MemBackendImpl::DoomEntry(const std::string& key) { 137 bool MemBackendImpl::DoomEntry(const std::string& key) {
121 Entry* entry; 138 Entry* entry;
122 if (!OpenEntry(key, &entry)) 139 if (!OpenEntry(key, &entry))
123 return false; 140 return false;
124 141
125 entry->Doom(); 142 entry->Doom();
126 entry->Close(); 143 entry->Close();
127 return true; 144 return true;
128 } 145 }
129 146
130 void MemBackendImpl::InternalDoomEntry(MemEntryImpl* entry) { 147 void MemBackendImpl::InternalDoomEntry(MemEntryImpl* entry) {
131 // Only parent entries can be passed into this method. 148 // Only parent entries can be passed into this method.
132 DCHECK(entry->type() == MemEntryImpl::kParentEntry); 149 DCHECK(entry->type() == MemEntryImpl::kParentEntry);
133 150
134 rankings_.Remove(entry); 151 rankings_.Remove(entry);
135 EntryMap::iterator it = entries_.find(entry->GetKey()); 152 EntryMap::iterator it = entries_.find(entry->GetKey());
136 if (it != entries_.end()) 153 if (it != entries_.end())
137 entries_.erase(it); 154 entries_.erase(it);
138 else 155 else
139 NOTREACHED(); 156 NOTREACHED();
140 157
141 entry->InternalDoom(); 158 entry->InternalDoom();
142 } 159 }
143 160
144 bool MemBackendImpl::DoomAllEntries() { 161 bool MemBackendImpl::DoomAllEntries() {
145 TrimCache(true); 162 TrimCache(true);
146 return true; 163 return true;
147 } 164 }
148 165
166 int MemBackendImpl::DoomAllEntries(CompletionCallback* callback) {
167 if (DoomAllEntries())
168 return net::OK;
169
170 return net::ERR_FAILED;
171 }
172
149 bool MemBackendImpl::DoomEntriesBetween(const Time initial_time, 173 bool MemBackendImpl::DoomEntriesBetween(const Time initial_time,
150 const Time end_time) { 174 const Time end_time) {
151 if (end_time.is_null()) 175 if (end_time.is_null())
152 return DoomEntriesSince(initial_time); 176 return DoomEntriesSince(initial_time);
153 177
154 DCHECK(end_time >= initial_time); 178 DCHECK(end_time >= initial_time);
155 179
156 MemEntryImpl* next = rankings_.GetNext(NULL); 180 MemEntryImpl* next = rankings_.GetNext(NULL);
157 181
158 // rankings_ is ordered by last used, this will descend through the cache 182 // rankings_ is ordered by last used, this will descend through the cache
159 // and start dooming items before the end_time, and will stop once it reaches 183 // and start dooming items before the end_time, and will stop once it reaches
160 // an item used before the initial time. 184 // an item used before the initial time.
161 while (next) { 185 while (next) {
162 MemEntryImpl* node = next; 186 MemEntryImpl* node = next;
163 next = rankings_.GetNext(next); 187 next = rankings_.GetNext(next);
164 188
165 if (node->GetLastUsed() < initial_time) 189 if (node->GetLastUsed() < initial_time)
166 break; 190 break;
167 191
168 if (node->GetLastUsed() < end_time) 192 if (node->GetLastUsed() < end_time)
169 node->Doom(); 193 node->Doom();
170 } 194 }
171 195
172 return true; 196 return true;
173 } 197 }
174 198
199 int MemBackendImpl::DoomEntriesBetween(const base::Time initial_time,
200 const base::Time end_time,
201 CompletionCallback* callback) {
202 if (DoomEntriesBetween(initial_time, end_time))
203 return net::OK;
204
205 return net::ERR_FAILED;
206 }
207
175 bool MemBackendImpl::DoomEntriesSince(const Time initial_time) { 208 bool MemBackendImpl::DoomEntriesSince(const Time initial_time) {
176 for (;;) { 209 for (;;) {
177 // Get the entry in the front. 210 // Get the entry in the front.
178 Entry* entry = rankings_.GetNext(NULL); 211 Entry* entry = rankings_.GetNext(NULL);
179 212
180 // Break the loop when there are no more entries or the entry is too old. 213 // Break the loop when there are no more entries or the entry is too old.
181 if (!entry || entry->GetLastUsed() < initial_time) 214 if (!entry || entry->GetLastUsed() < initial_time)
182 return true; 215 return true;
183 entry->Doom(); 216 entry->Doom();
184 } 217 }
185 } 218 }
186 219
220 int MemBackendImpl::DoomEntriesSince(const base::Time initial_time,
221 CompletionCallback* callback) {
222 if (DoomEntriesSince(initial_time))
223 return net::OK;
224
225 return net::ERR_FAILED;
226 }
227
187 bool MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry) { 228 bool MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry) {
188 MemEntryImpl* current = reinterpret_cast<MemEntryImpl*>(*iter); 229 MemEntryImpl* current = reinterpret_cast<MemEntryImpl*>(*iter);
189 MemEntryImpl* node = rankings_.GetNext(current); 230 MemEntryImpl* node = rankings_.GetNext(current);
190 // We should never return a child entry so iterate until we hit a parent 231 // We should never return a child entry so iterate until we hit a parent
191 // entry. 232 // entry.
192 while (node && node->type() != MemEntryImpl::kParentEntry) { 233 while (node && node->type() != MemEntryImpl::kParentEntry) {
193 node = rankings_.GetNext(node); 234 node = rankings_.GetNext(node);
194 } 235 }
195 *next_entry = node; 236 *next_entry = node;
196 *iter = node; 237 *iter = node;
197 238
198 if (node) 239 if (node)
199 node->Open(); 240 node->Open();
200 241
201 return NULL != node; 242 return NULL != node;
202 } 243 }
203 244
245 int MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry,
246 CompletionCallback* callback) {
247 if (OpenNextEntry(iter, next_entry))
248 return net::OK;
249
250 return net::ERR_FAILED;
251 }
252
204 void MemBackendImpl::EndEnumeration(void** iter) { 253 void MemBackendImpl::EndEnumeration(void** iter) {
205 *iter = NULL; 254 *iter = NULL;
206 } 255 }
207 256
208 void MemBackendImpl::TrimCache(bool empty) { 257 void MemBackendImpl::TrimCache(bool empty) {
209 MemEntryImpl* next = rankings_.GetPrev(NULL); 258 MemEntryImpl* next = rankings_.GetPrev(NULL);
210 259
211 DCHECK(next); 260 DCHECK(next);
212 261
213 int target_size = empty ? 0 : LowWaterAdjust(max_size_); 262 int target_size = empty ? 0 : LowWaterAdjust(max_size_);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 301
253 void MemBackendImpl::InsertIntoRankingList(MemEntryImpl* entry) { 302 void MemBackendImpl::InsertIntoRankingList(MemEntryImpl* entry) {
254 rankings_.Insert(entry); 303 rankings_.Insert(entry);
255 } 304 }
256 305
257 void MemBackendImpl::RemoveFromRankingList(MemEntryImpl* entry) { 306 void MemBackendImpl::RemoveFromRankingList(MemEntryImpl* entry) {
258 rankings_.Remove(entry); 307 rankings_.Remove(entry);
259 } 308 }
260 309
261 } // namespace disk_cache 310 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/mem_backend_impl.h ('k') | net/disk_cache/mem_entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698