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

Side by Side Diff: net/disk_cache/blockfile/backend_impl.cc

Issue 1304363013: Add a size estimation mechanism to StoragePartitionHttpCacheDataRemover. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months 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
OLDNEW
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 #include "net/disk_cache/blockfile/backend_impl.h" 5 #include "net/disk_cache/blockfile/backend_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 SyncEndEnumeration(iterator.Pass()); 429 SyncEndEnumeration(iterator.Pass());
430 return net::OK; 430 return net::OK;
431 } 431 }
432 432
433 entry->DoomImpl(); 433 entry->DoomImpl();
434 entry->Release(); 434 entry->Release();
435 SyncEndEnumeration(iterator.Pass()); // The doom invalidated the iterator. 435 SyncEndEnumeration(iterator.Pass()); // The doom invalidated the iterator.
436 } 436 }
437 } 437 }
438 438
439 int BackendImpl::SyncCalculateSizeOfEntriesBetween(
440 const base::Time initial_time, const base::Time end_time) {
441 DCHECK_NE(net::APP_CACHE, cache_type_);
442 if (disabled_)
443 return net::ERR_FAILED;
444
445 EntryImpl* node;
446 scoped_ptr<Rankings::Iterator> iterator(new Rankings::Iterator());
447 EntryImpl* next = OpenNextEntryImpl(iterator.get());
448 if (!next)
449 return net::OK;
450
451 int size = 0;
452 while (next) {
453 node = next;
454 next = OpenNextEntryImpl(iterator.get());
455
456 if (node->GetLastUsed() >= initial_time &&
457 node->GetLastUsed() < end_time) {
458 node->DoomImpl();
msramek 2015/09/02 19:22:25 ...and since this method imitates SyncDoomEntriesB
459 } else if (node->GetLastUsed() < initial_time) {
460 if (next)
461 next->Release();
462 next = NULL;
463 SyncEndEnumeration(iterator.Pass());
464 }
465
466 size += node->GetEntrySize();
467 }
468
469 return size;
470 }
471
439 int BackendImpl::SyncOpenNextEntry(Rankings::Iterator* iterator, 472 int BackendImpl::SyncOpenNextEntry(Rankings::Iterator* iterator,
440 Entry** next_entry) { 473 Entry** next_entry) {
441 *next_entry = OpenNextEntryImpl(iterator); 474 *next_entry = OpenNextEntryImpl(iterator);
442 return (*next_entry) ? net::OK : net::ERR_FAILED; 475 return (*next_entry) ? net::OK : net::ERR_FAILED;
443 } 476 }
444 477
445 void BackendImpl::SyncEndEnumeration(scoped_ptr<Rankings::Iterator> iterator) { 478 void BackendImpl::SyncEndEnumeration(scoped_ptr<Rankings::Iterator> iterator) {
446 iterator->Reset(); 479 iterator->Reset();
447 } 480 }
448 481
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 return net::ERR_IO_PENDING; 1280 return net::ERR_IO_PENDING;
1248 } 1281 }
1249 1282
1250 int BackendImpl::DoomEntriesSince(const base::Time initial_time, 1283 int BackendImpl::DoomEntriesSince(const base::Time initial_time,
1251 const CompletionCallback& callback) { 1284 const CompletionCallback& callback) {
1252 DCHECK(!callback.is_null()); 1285 DCHECK(!callback.is_null());
1253 background_queue_.DoomEntriesSince(initial_time, callback); 1286 background_queue_.DoomEntriesSince(initial_time, callback);
1254 return net::ERR_IO_PENDING; 1287 return net::ERR_IO_PENDING;
1255 } 1288 }
1256 1289
1290 int BackendImpl::CalculateSizeOfEntriesBetween(
1291 base::Time initial_time,
1292 base::Time end_time,
1293 const CompletionCallback& callback) {
1294 DCHECK(!callback.is_null());
1295 background_queue_.CalculateSizeOfEntriesBetween(
1296 initial_time, end_time, callback);
1297 return net::ERR_IO_PENDING;
1298 }
1299
1257 class BackendImpl::IteratorImpl : public Backend::Iterator { 1300 class BackendImpl::IteratorImpl : public Backend::Iterator {
1258 public: 1301 public:
1259 explicit IteratorImpl(base::WeakPtr<InFlightBackendIO> background_queue) 1302 explicit IteratorImpl(base::WeakPtr<InFlightBackendIO> background_queue)
1260 : background_queue_(background_queue), 1303 : background_queue_(background_queue),
1261 iterator_(new Rankings::Iterator()) { 1304 iterator_(new Rankings::Iterator()) {
1262 } 1305 }
1263 1306
1264 ~IteratorImpl() override { 1307 ~IteratorImpl() override {
1265 if (background_queue_) 1308 if (background_queue_)
1266 background_queue_->EndEnumeration(iterator_.Pass()); 1309 background_queue_->EndEnumeration(iterator_.Pass());
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 if (total_memory > kMaxBuffersSize || total_memory <= 0) 2134 if (total_memory > kMaxBuffersSize || total_memory <= 0)
2092 total_memory = kMaxBuffersSize; 2135 total_memory = kMaxBuffersSize;
2093 2136
2094 done = true; 2137 done = true;
2095 } 2138 }
2096 2139
2097 return static_cast<int>(total_memory); 2140 return static_cast<int>(total_memory);
2098 } 2141 }
2099 2142
2100 } // namespace disk_cache 2143 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698